| 1 | // SchedulerView.cpp |
|---|
| 2 | // $Id$ |
|---|
| 3 | // |
|---|
| 4 | // Eraser. Secure data removal. For Windows. |
|---|
| 5 | // Copyright © 1997-2001 Sami Tolvanen (sami@tolvanen.com). |
|---|
| 6 | // Copyright © 2007 The Eraser Project |
|---|
| 7 | // |
|---|
| 8 | // This program is free software; you can redistribute it and/or |
|---|
| 9 | // modify it under the terms of the GNU General Public License |
|---|
| 10 | // as published by the Free Software Foundation; either version 2 |
|---|
| 11 | // of the License, or (at your option) any later version. |
|---|
| 12 | // |
|---|
| 13 | // This program is distributed in the hope that it will be useful, |
|---|
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | // GNU General Public License for more details. |
|---|
| 17 | // |
|---|
| 18 | // You should have received a copy of the GNU General Public License |
|---|
| 19 | // along with this program; if not, write to the Free Software |
|---|
| 20 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|---|
| 21 | // 02111-1307, USA. |
|---|
| 22 | |
|---|
| 23 | #include "stdafx.h" |
|---|
| 24 | #include "Eraser.h" |
|---|
| 25 | #include "EraserDoc.h" |
|---|
| 26 | #include "shared\key.h" |
|---|
| 27 | #include "SchedulerView.h" |
|---|
| 28 | |
|---|
| 29 | #include "TaskPropertySheet.h" |
|---|
| 30 | #include "shared\FileHelper.h" |
|---|
| 31 | #include "EraserUI\DriveCombo.h" |
|---|
| 32 | #include "EraserUI\GfxPopupMenu.h" |
|---|
| 33 | #include "EraserUI\TimeOutMessageBox.h" |
|---|
| 34 | |
|---|
| 35 | #include "EraserDll\OptionPages.h" |
|---|
| 36 | #include "EraserDll\options.h" |
|---|
| 37 | #include "EraserDll\EraserDllInternal.h" |
|---|
| 38 | |
|---|
| 39 | #ifdef _DEBUG |
|---|
| 40 | #define new DEBUG_NEW |
|---|
| 41 | #undef THIS_FILE |
|---|
| 42 | static char THIS_FILE[] = __FILE__; |
|---|
| 43 | #endif |
|---|
| 44 | |
|---|
| 45 | enum Columns |
|---|
| 46 | { |
|---|
| 47 | ColumnName, |
|---|
| 48 | ColumnType, |
|---|
| 49 | ColumnLast, |
|---|
| 50 | ColumnNext, |
|---|
| 51 | ColumnSchedule |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | static const int iColumnCount = 5; |
|---|
| 55 | |
|---|
| 56 | static const LPTSTR szColumnNames[iColumnCount] = |
|---|
| 57 | { |
|---|
| 58 | "Name", |
|---|
| 59 | "Type", |
|---|
| 60 | "Last Run", |
|---|
| 61 | "Next Run", |
|---|
| 62 | "Schedule" |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | static const int iMinFirstColumnWidth = 100; |
|---|
| 66 | static const int iOtherColumnWidth = 370; |
|---|
| 67 | |
|---|
| 68 | static const int iColumnWidths[] = |
|---|
| 69 | { |
|---|
| 70 | -1, |
|---|
| 71 | 100, |
|---|
| 72 | 90, |
|---|
| 73 | 90, |
|---|
| 74 | 90 |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | #define FIRST_TIMER (WM_USER + 42) // HHGTG |
|---|
| 78 | |
|---|
| 79 | // for accessing the process counter |
|---|
| 80 | static CEvent evWaitForCounterAccess(TRUE, TRUE); |
|---|
| 81 | |
|---|
| 82 | #define counterLock() \ |
|---|
| 83 | WaitForSingleObject(evWaitForCounterAccess, INFINITE); \ |
|---|
| 84 | evWaitForCounterAccess.ResetEvent() |
|---|
| 85 | #define counterUnlock() \ |
|---|
| 86 | evWaitForCounterAccess.SetEvent() |
|---|
| 87 | |
|---|
| 88 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 89 | // CSchedulerView |
|---|
| 90 | |
|---|
| 91 | IMPLEMENT_DYNCREATE(CSchedulerView, CFlatListView) |
|---|
| 92 | |
|---|
| 93 | CSchedulerView::CSchedulerView() : |
|---|
| 94 | m_uNextTimerID(FIRST_TIMER) |
|---|
| 95 | { |
|---|
| 96 | TRACE("CSchedulerView::CSchedulerView\n"); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | CSchedulerView::~CSchedulerView() |
|---|
| 100 | { |
|---|
| 101 | TRACE("CSchedulerView::~CSchedulerView\n"); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | BEGIN_MESSAGE_MAP(CSchedulerView, CFlatListView) |
|---|
| 106 | ON_WM_CONTEXTMENU() |
|---|
| 107 | //{{AFX_MSG_MAP(CSchedulerView) |
|---|
| 108 | ON_WM_SIZE() |
|---|
| 109 | ON_COMMAND(ID_FILE_NEW_TASK, OnFileNewTask) |
|---|
| 110 | ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE_TASK, OnUpdateEditDeleteTask) |
|---|
| 111 | ON_COMMAND(ID_EDIT_DELETE_TASK, OnEditDeleteTask) |
|---|
| 112 | ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditProperties) |
|---|
| 113 | ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties) |
|---|
| 114 | ON_WM_TIMER() |
|---|
| 115 | ON_WM_DESTROY() |
|---|
| 116 | ON_WM_LBUTTONDBLCLK() |
|---|
| 117 | ON_UPDATE_COMMAND_UI(ID_PROCESS_RUN, OnUpdateProcessRun) |
|---|
| 118 | ON_UPDATE_COMMAND_UI(ID_PROCESS_RUNALL, OnUpdateProcessRunAll) |
|---|
| 119 | ON_COMMAND(ID_PROCESS_RUN, OnProcessRun) |
|---|
| 120 | ON_COMMAND(ID_PROCESS_RUNALL, OnProcessRunAll) |
|---|
| 121 | ON_UPDATE_COMMAND_UI(ID_PROCESS_STOP, OnUpdateProcessStop) |
|---|
| 122 | ON_COMMAND(ID_PROCESS_STOP, OnProcessStop) |
|---|
| 123 | ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll) |
|---|
| 124 | ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll) |
|---|
| 125 | ON_COMMAND(ID_EDIT_REFRESH, OnEditRefresh) |
|---|
| 126 | //}}AFX_MSG_MAP |
|---|
| 127 | ON_MESSAGE(WM_ERASERNOTIFY, OnEraserNotify) |
|---|
| 128 | ON_UPDATE_COMMAND_UI(ID_INDICATOR_ITEMS, OnUpdateItems) |
|---|
| 129 | END_MESSAGE_MAP() |
|---|
| 130 | |
|---|
| 131 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 132 | // CSchedulerView drawing |
|---|
| 133 | |
|---|
| 134 | void CSchedulerView::OnDraw(CDC* /*pDC*/) |
|---|
| 135 | { |
|---|
| 136 | |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 140 | // CSchedulerView diagnostics |
|---|
| 141 | |
|---|
| 142 | #ifdef _DEBUG |
|---|
| 143 | void CSchedulerView::AssertValid() const |
|---|
| 144 | { |
|---|
| 145 | CFlatListView::AssertValid(); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void CSchedulerView::Dump(CDumpContext& dc) const |
|---|
| 149 | { |
|---|
| 150 | CFlatListView::Dump(dc); |
|---|
| 151 | } |
|---|
| 152 | #endif //_DEBUG |
|---|
| 153 | |
|---|
| 154 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 155 | // CSchedulerView message handlers |
|---|
| 156 | |
|---|
| 157 | BOOL CSchedulerView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) |
|---|
| 158 | { |
|---|
| 159 | TRACE("CSchedulerView::Create\n"); |
|---|
| 160 | |
|---|
| 161 | dwStyle |= LVS_REPORT | LVS_NOSORTHEADER | LVS_SORTASCENDING | LVS_SHOWSELALWAYS; |
|---|
| 162 | |
|---|
| 163 | if (CFlatListView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext)) |
|---|
| 164 | { |
|---|
| 165 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 166 | CListCtrl& lcList = GetListCtrl(); |
|---|
| 167 | |
|---|
| 168 | try |
|---|
| 169 | { |
|---|
| 170 | CRect rClient; |
|---|
| 171 | lcList.GetClientRect(&rClient); |
|---|
| 172 | |
|---|
| 173 | int iWidth = rClient.Width() - iOtherColumnWidth - GetSystemMetrics(SM_CXBORDER); |
|---|
| 174 | |
|---|
| 175 | if (iWidth < iMinFirstColumnWidth) iWidth = iMinFirstColumnWidth; |
|---|
| 176 | |
|---|
| 177 | LVCOLUMN lvc; |
|---|
| 178 | ZeroMemory(&lvc, sizeof(LVCOLUMN)); |
|---|
| 179 | |
|---|
| 180 | lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
|---|
| 181 | lvc.fmt = LVCFMT_LEFT; |
|---|
| 182 | lvc.pszText = szColumnNames[ColumnName]; |
|---|
| 183 | lvc.cx = iWidth; |
|---|
| 184 | lvc.iSubItem = ColumnName; |
|---|
| 185 | lcList.InsertColumn(ColumnName, &lvc); |
|---|
| 186 | |
|---|
| 187 | for (int i = 1; i <= (iColumnCount - 1); i++) |
|---|
| 188 | { |
|---|
| 189 | lvc.pszText = szColumnNames[i]; |
|---|
| 190 | lvc.cx = iColumnWidths[i]; |
|---|
| 191 | lvc.iSubItem = i; |
|---|
| 192 | lcList.InsertColumn(i, &lvc); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | lcList.SetExtendedStyle(LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); |
|---|
| 196 | // lcList.SetImageList(&pDoc->m_smallImageList, LVSIL_SMALL); |
|---|
| 197 | lcList.SetImageList(pDoc->m_smallImageList, LVSIL_SMALL); |
|---|
| 198 | |
|---|
| 199 | CFlatHeaderCtrl *pfhFlatHeader = (CFlatHeaderCtrl*)lcList.GetHeaderCtrl(); |
|---|
| 200 | |
|---|
| 201 | if (pfhFlatHeader != NULL) |
|---|
| 202 | { |
|---|
| 203 | pfhFlatHeader->SetImageList(&pDoc->m_ilHeader); |
|---|
| 204 | |
|---|
| 205 | HDITEMEX hie; |
|---|
| 206 | |
|---|
| 207 | hie.m_iMinWidth = iMinFirstColumnWidth; |
|---|
| 208 | hie.m_iMaxWidth = -1; |
|---|
| 209 | |
|---|
| 210 | pfhFlatHeader->SetItemEx(ColumnName, &hie); |
|---|
| 211 | |
|---|
| 212 | HDITEM hditem; |
|---|
| 213 | |
|---|
| 214 | hditem.mask = HDI_FORMAT | HDI_IMAGE; |
|---|
| 215 | pfhFlatHeader->GetItem(ColumnName, &hditem); |
|---|
| 216 | |
|---|
| 217 | hditem.fmt |= HDF_IMAGE; |
|---|
| 218 | hditem.iImage = IconEraser; |
|---|
| 219 | pfhFlatHeader->SetItem(ColumnName, &hditem); |
|---|
| 220 | |
|---|
| 221 | hditem.mask = HDI_FORMAT | HDI_IMAGE; |
|---|
| 222 | pfhFlatHeader->GetItem(ColumnSchedule, &hditem); |
|---|
| 223 | |
|---|
| 224 | hditem.fmt |= HDF_IMAGE; |
|---|
| 225 | hditem.iImage = IconClock; |
|---|
| 226 | pfhFlatHeader->SetItem(ColumnSchedule, &hditem); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | ModifyStyleEx(WS_EX_CLIENTEDGE, 0); |
|---|
| 230 | |
|---|
| 231 | return TRUE; |
|---|
| 232 | } |
|---|
| 233 | catch (CException *e) |
|---|
| 234 | { |
|---|
| 235 | ASSERT(FALSE); |
|---|
| 236 | REPORT_ERROR(e); |
|---|
| 237 | e->Delete(); |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | return FALSE; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | void CSchedulerView::OnSize(UINT nType, int cx, int cy) |
|---|
| 245 | { |
|---|
| 246 | TRACE("CSchedulerView::OnSize\n"); |
|---|
| 247 | |
|---|
| 248 | CFlatListView::OnSize(nType, cx, cy); |
|---|
| 249 | ResizeColumns(); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | void CSchedulerView::ResizeColumns() |
|---|
| 253 | { |
|---|
| 254 | TRACE("CSchedulerView::ResizeColumns\n"); |
|---|
| 255 | |
|---|
| 256 | CListCtrl& lc = GetListCtrl(); |
|---|
| 257 | |
|---|
| 258 | CRect rClient; |
|---|
| 259 | lc.GetClientRect(&rClient); |
|---|
| 260 | |
|---|
| 261 | int iWidth; |
|---|
| 262 | int iColumn; |
|---|
| 263 | int iRest = 0; |
|---|
| 264 | |
|---|
| 265 | for (iColumn = (iColumnCount - 1); iColumn >= 1; iColumn--) |
|---|
| 266 | iRest += lc.GetColumnWidth(iColumn); |
|---|
| 267 | |
|---|
| 268 | iWidth = rClient.Width() - iRest - GetSystemMetrics(SM_CXBORDER); |
|---|
| 269 | |
|---|
| 270 | if (iWidth < iMinFirstColumnWidth) |
|---|
| 271 | iWidth = iMinFirstColumnWidth; |
|---|
| 272 | |
|---|
| 273 | lc.SetColumnWidth(0, iWidth); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | void CSchedulerView::OnContextMenu(CWnd*, CPoint point) |
|---|
| 277 | { |
|---|
| 278 | TRACE("CSchedulerView::OnContextMenu\n"); |
|---|
| 279 | |
|---|
| 280 | try |
|---|
| 281 | { |
|---|
| 282 | if (point.x == -1 && point.y == -1) |
|---|
| 283 | { |
|---|
| 284 | CRect rect; |
|---|
| 285 | GetClientRect(rect); |
|---|
| 286 | ClientToScreen(rect); |
|---|
| 287 | |
|---|
| 288 | point = rect.TopLeft(); |
|---|
| 289 | point.Offset(5, 5); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | CGfxPopupMenu menu; |
|---|
| 293 | menu.LoadMenu(IDR_MENU_SCHEDULERVIEW, IDR_MAINFRAME, this); |
|---|
| 294 | |
|---|
| 295 | CWnd* pWndPopupOwner = this; |
|---|
| 296 | |
|---|
| 297 | while (pWndPopupOwner->GetStyle() & WS_CHILD) |
|---|
| 298 | pWndPopupOwner = pWndPopupOwner->GetParent(); |
|---|
| 299 | |
|---|
| 300 | menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, |
|---|
| 301 | pWndPopupOwner); |
|---|
| 302 | |
|---|
| 303 | menu.DestroyMenu(); |
|---|
| 304 | } |
|---|
| 305 | catch (CException *e) |
|---|
| 306 | { |
|---|
| 307 | ASSERT(FALSE); |
|---|
| 308 | REPORT_ERROR(e); |
|---|
| 309 | e->Delete(); |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | void CSchedulerView::OnInitialUpdate() |
|---|
| 315 | { |
|---|
| 316 | TRACE("CSchedulerView::OnInitialUpdate\n"); |
|---|
| 317 | |
|---|
| 318 | SetTimers(); |
|---|
| 319 | |
|---|
| 320 | if (!IsWindow(m_pbProgress.GetSafeHwnd())) |
|---|
| 321 | m_pbProgress.Create("", 30, 100, TRUE, 0); |
|---|
| 322 | |
|---|
| 323 | CFlatListView::OnInitialUpdate(); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | void CSchedulerView::OnFileNewTask() |
|---|
| 327 | { |
|---|
| 328 | TRACE("CSchedulerView::OnFileNewTask\n"); |
|---|
| 329 | |
|---|
| 330 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 331 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 332 | |
|---|
| 333 | try |
|---|
| 334 | { |
|---|
| 335 | CTaskPropertySheet tps(TRUE, TRUE); |
|---|
| 336 | LibrarySettings plsTmp; |
|---|
| 337 | loadLibrarySettings(&plsTmp); |
|---|
| 338 | if (tps.DoModal() == IDOK) |
|---|
| 339 | { |
|---|
| 340 | if (tps.m_pgData.m_strSelectedDrive.IsEmpty() && |
|---|
| 341 | tps.m_pgData.m_strFolder.IsEmpty() && |
|---|
| 342 | tps.m_pgData.m_strFile.IsEmpty()) |
|---|
| 343 | { |
|---|
| 344 | // no data |
|---|
| 345 | return; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | COleDateTime odtTime; |
|---|
| 349 | Schedule scWhen; |
|---|
| 350 | |
|---|
| 351 | odtTime = tps.m_pgSchedule.m_odtTime; |
|---|
| 352 | scWhen = static_cast<Schedule>(tps.m_pgSchedule.m_iWhen); |
|---|
| 353 | |
|---|
| 354 | // save the new scheduled task |
|---|
| 355 | |
|---|
| 356 | if (pDoc->m_bLog && !pDoc->m_bLogOnlyErrors) |
|---|
| 357 | { |
|---|
| 358 | CString strAction; |
|---|
| 359 | CString strData; |
|---|
| 360 | |
|---|
| 361 | switch (tps.m_pgData.m_tType) |
|---|
| 362 | { |
|---|
| 363 | case Drive: |
|---|
| 364 | strData = tps.m_pgData.m_strSelectedDrive; |
|---|
| 365 | break; |
|---|
| 366 | case Folder: |
|---|
| 367 | strData = tps.m_pgData.m_strFolder; |
|---|
| 368 | break; |
|---|
| 369 | case File: |
|---|
| 370 | strData = tps.m_pgData.m_strFile; |
|---|
| 371 | break; |
|---|
| 372 | default: |
|---|
| 373 | NODEFAULT; |
|---|
| 374 | }; |
|---|
| 375 | AfxFormatString1(strAction, IDS_ACTION_NEW, strData); |
|---|
| 376 | pDoc->LogAction(strAction); |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | CScheduleItem *psiItem = new CScheduleItem(); |
|---|
| 380 | psiItem->SetSchedule(scWhen); |
|---|
| 381 | psiItem->SetTime((WORD)odtTime.GetHour(), (WORD)odtTime.GetMinute()); |
|---|
| 382 | |
|---|
| 383 | switch (tps.m_pgData.m_tType) |
|---|
| 384 | { |
|---|
| 385 | case Drive: |
|---|
| 386 | psiItem->SetDrive(tps.m_pgData.m_strSelectedDrive); |
|---|
| 387 | break; |
|---|
| 388 | case Folder: |
|---|
| 389 | psiItem->SetFolder(tps.m_pgData.m_strFolder); |
|---|
| 390 | psiItem->RemoveFolder(tps.m_pgData.m_bRemoveFolder); |
|---|
| 391 | psiItem->Subfolders(tps.m_pgData.m_bSubfolders); |
|---|
| 392 | psiItem->OnlySubfolders(tps.m_pgData.m_bRemoveOnlySub); |
|---|
| 393 | break; |
|---|
| 394 | case File: |
|---|
| 395 | psiItem->SetFile(tps.m_pgData.m_strFile); |
|---|
| 396 | psiItem->UseWildcards(tps.m_pgData.m_bUseWildCards); |
|---|
| 397 | psiItem->WildcardsInSubfolders(tps.m_pgData.m_bWildCardsInSubfolders); |
|---|
| 398 | break; |
|---|
| 399 | default: |
|---|
| 400 | NODEFAULT; |
|---|
| 401 | }; |
|---|
| 402 | |
|---|
| 403 | psiItem->CalcNextTime(); |
|---|
| 404 | |
|---|
| 405 | if (!pDoc->AddScheduledTask(psiItem)) |
|---|
| 406 | { |
|---|
| 407 | delete psiItem; |
|---|
| 408 | psiItem = 0; |
|---|
| 409 | } |
|---|
| 410 | else |
|---|
| 411 | { |
|---|
| 412 | psiItem->m_uTimerID = GetNextTimerID(); |
|---|
| 413 | |
|---|
| 414 | if (!SetTimer(psiItem->m_uTimerID, psiItem->GetTimeSpan(), NULL)) |
|---|
| 415 | { |
|---|
| 416 | AfxTimeOutMessageBox(IDS_ERROR_TIMER, MB_ICONERROR); |
|---|
| 417 | |
|---|
| 418 | if (pDoc->m_bLog) |
|---|
| 419 | pDoc->LogAction(IDS_ERROR_TIMER); |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | // Here we just add it to the bootup sequence if it is on boot |
|---|
| 423 | if (scWhen == Reboot) |
|---|
| 424 | { |
|---|
| 425 | //Here we are setting the appropriate entry into the Registry Key : |
|---|
| 426 | //HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run |
|---|
| 427 | //The entry should be in Name - Data pair, where Name is the name of the application and Data is the path of the executable |
|---|
| 428 | CKey kReg; |
|---|
| 429 | CString m_strExePath; |
|---|
| 430 | CString m_strName; |
|---|
| 431 | char Fullname[260]; |
|---|
| 432 | char Filename[260]; |
|---|
| 433 | char Extension[5]; |
|---|
| 434 | char Pathname[260]; |
|---|
| 435 | char myDrive[10]; |
|---|
| 436 | char *buffer = new char[260]; |
|---|
| 437 | |
|---|
| 438 | if (kReg.Open(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")) |
|---|
| 439 | { |
|---|
| 440 | GetModuleFileName(AfxGetInstanceHandle(),Fullname,sizeof Fullname); |
|---|
| 441 | _splitpath(Fullname,myDrive,Pathname,Filename,Extension); |
|---|
| 442 | strcpy(buffer,myDrive); |
|---|
| 443 | strncat(buffer,Pathname,250); |
|---|
| 444 | strncpy(Pathname,buffer,260); |
|---|
| 445 | delete buffer; |
|---|
| 446 | m_strExePath = '"'; |
|---|
| 447 | m_strExePath+= CString(Pathname); |
|---|
| 448 | m_strExePath+= "Eraserl.exe"; |
|---|
| 449 | m_strExePath+= '"'; |
|---|
| 450 | switch (tps.m_pgData.m_tType) |
|---|
| 451 | { |
|---|
| 452 | case Drive: |
|---|
| 453 | m_strExePath+= " -disk " + tps.m_pgData.m_strSelectedDrive; |
|---|
| 454 | break; |
|---|
| 455 | case Folder: |
|---|
| 456 | m_strExePath+= " -folder "; |
|---|
| 457 | m_strExePath+= '"'; |
|---|
| 458 | m_strExePath+= tps.m_pgData.m_strFolder; |
|---|
| 459 | m_strExePath+= '"'; |
|---|
| 460 | if (tps.m_pgData.m_bRemoveFolder==FALSE) {m_strExePath+= " -keepfolder ";} |
|---|
| 461 | if (tps.m_pgData.m_bSubfolders) {m_strExePath+= " -subfolders ";} |
|---|
| 462 | break; |
|---|
| 463 | case File: |
|---|
| 464 | m_strExePath+= " -file "; |
|---|
| 465 | m_strExePath+= '"'; |
|---|
| 466 | m_strExePath+= tps.m_pgData.m_strFile; |
|---|
| 467 | m_strExePath+= '"'; |
|---|
| 468 | break; |
|---|
| 469 | |
|---|
| 470 | default: |
|---|
| 471 | NODEFAULT; |
|---|
| 472 | }; |
|---|
| 473 | kReg.SetValue(m_strExePath, psiItem->GetId()); |
|---|
| 474 | m_strExePath.ReleaseBuffer(); |
|---|
| 475 | kReg.Close(); |
|---|
| 476 | } |
|---|
| 477 | } |
|---|
| 478 | UpdateList(); |
|---|
| 479 | |
|---|
| 480 | LibrarySettings* plsTmp1 = tps.m_pPageFileMethodOptions->GetLibSettings(); |
|---|
| 481 | psiItem->m_bMethod = plsTmp1->m_nFileMethodID; |
|---|
| 482 | psiItem->m_uEraseItems = plsTmp1->m_uItems; |
|---|
| 483 | psiItem->m_nRndPass = plsTmp1->m_nFileRandom; |
|---|
| 484 | plsTmp1->m_nFileMethodID = plsTmp.m_nFileMethodID; |
|---|
| 485 | plsTmp1->m_nFileRandom = plsTmp.m_nFileRandom; |
|---|
| 486 | plsTmp1->m_uItems = plsTmp.m_uItems; |
|---|
| 487 | saveLibrarySettings(plsTmp1); |
|---|
| 488 | |
|---|
| 489 | pDoc->CalcNextAssignment(); |
|---|
| 490 | pDoc->UpdateToolTip(); |
|---|
| 491 | pDoc->SaveTasksToDefault(); |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | } |
|---|
| 496 | } |
|---|
| 497 | catch (CException *e) |
|---|
| 498 | { |
|---|
| 499 | ASSERT(FALSE); |
|---|
| 500 | REPORT_ERROR(e); |
|---|
| 501 | e->Delete(); |
|---|
| 502 | } |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | void CSchedulerView::OnUpdateEditDeleteTask(CCmdUI* pCmdUI) |
|---|
| 506 | { |
|---|
| 507 | CListCtrl& lc = GetListCtrl(); |
|---|
| 508 | pCmdUI->Enable(lc.GetSelectedCount() > 0); |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | void CSchedulerView::OnEditDeleteTask() |
|---|
| 512 | { |
|---|
| 513 | TRACE("CSchedulerView::OnEditDeleteTask\n"); |
|---|
| 514 | CString strData; |
|---|
| 515 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 516 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 517 | |
|---|
| 518 | try |
|---|
| 519 | { |
|---|
| 520 | CListCtrl& lc = GetListCtrl(); |
|---|
| 521 | |
|---|
| 522 | if (lc.GetSelectedCount() > 0) |
|---|
| 523 | { |
|---|
| 524 | int nItem, nIndex, iSize = pDoc->m_paScheduledTasks.GetSize(); |
|---|
| 525 | CScheduleItem *psiItem = 0; |
|---|
| 526 | |
|---|
| 527 | POSITION pos = lc.GetFirstSelectedItemPosition(); |
|---|
| 528 | |
|---|
| 529 | while (pos) |
|---|
| 530 | { |
|---|
| 531 | nItem = lc.GetNextSelectedItem(pos); |
|---|
| 532 | nIndex = lc.GetItemData(nItem); |
|---|
| 533 | |
|---|
| 534 | if (nIndex >= 0 && nIndex < iSize) |
|---|
| 535 | { |
|---|
| 536 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[nIndex]); |
|---|
| 537 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 538 | { |
|---|
| 539 | if (pDoc->m_bLog && !pDoc->m_bLogOnlyErrors) |
|---|
| 540 | { |
|---|
| 541 | CString strAction; |
|---|
| 542 | |
|---|
| 543 | psiItem->GetData(strData); |
|---|
| 544 | AfxFormatString1(strAction, IDS_ACTION_DELETE, strData); |
|---|
| 545 | pDoc->LogAction(strAction); |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | // kill the timer assigned to the task |
|---|
| 549 | KillTimer(psiItem->m_uTimerID); |
|---|
| 550 | |
|---|
| 551 | // turn off the thread just in case it is running |
|---|
| 552 | TerminateThread(psiItem); |
|---|
| 553 | if (psiItem->GetSchedule() == Reboot) |
|---|
| 554 | { |
|---|
| 555 | CKey kReg; |
|---|
| 556 | if (kReg.Open(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")) |
|---|
| 557 | { |
|---|
| 558 | kReg.DeleteValue(psiItem->GetId()); |
|---|
| 559 | kReg.Close(); |
|---|
| 560 | } |
|---|
| 561 | } |
|---|
| 562 | |
|---|
| 563 | // remove it from the queue just in case it happens to be there |
|---|
| 564 | RemoveTaskFromQueue(psiItem); |
|---|
| 565 | |
|---|
| 566 | delete psiItem; |
|---|
| 567 | psiItem = 0; |
|---|
| 568 | |
|---|
| 569 | pDoc->m_paScheduledTasks.SetAt(nIndex, 0); |
|---|
| 570 | } |
|---|
| 571 | } |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | UpdateList(); |
|---|
| 575 | pDoc->CalcNextAssignment(); |
|---|
| 576 | pDoc->UpdateToolTip(); |
|---|
| 577 | pDoc->SaveTasksToDefault(); |
|---|
| 578 | } |
|---|
| 579 | } |
|---|
| 580 | catch (CException *e) |
|---|
| 581 | { |
|---|
| 582 | ASSERT(FALSE); |
|---|
| 583 | REPORT_ERROR(e); |
|---|
| 584 | e->Delete(); |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | void CSchedulerView::OnUpdateEditProperties(CCmdUI* pCmdUI) |
|---|
| 589 | { |
|---|
| 590 | CListCtrl& lc = GetListCtrl(); |
|---|
| 591 | pCmdUI->Enable(lc.GetSelectedCount() == 1); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | void CSchedulerView::OnEditProperties() |
|---|
| 595 | { |
|---|
| 596 | TRACE("CSchedulerView::OnEditProperties\n"); |
|---|
| 597 | |
|---|
| 598 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 599 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 600 | |
|---|
| 601 | try |
|---|
| 602 | { |
|---|
| 603 | CListCtrl& lc = GetListCtrl(); |
|---|
| 604 | |
|---|
| 605 | if (lc.GetSelectedCount() == 1) |
|---|
| 606 | { |
|---|
| 607 | POSITION pos = lc.GetFirstSelectedItemPosition(); |
|---|
| 608 | |
|---|
| 609 | int nItem = lc.GetNextSelectedItem(pos); |
|---|
| 610 | int nIndex = lc.GetItemData(nItem); |
|---|
| 611 | |
|---|
| 612 | if (nIndex >= 0 && nIndex < pDoc->m_paScheduledTasks.GetSize()) |
|---|
| 613 | { |
|---|
| 614 | CScheduleItem *psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[nIndex]); |
|---|
| 615 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 616 | { |
|---|
| 617 | CString strData; |
|---|
| 618 | CTaskPropertySheet tps(TRUE, FALSE); |
|---|
| 619 | |
|---|
| 620 | LibrarySettings plsTmp; |
|---|
| 621 | loadLibrarySettings(&plsTmp); |
|---|
| 622 | if (psiItem->m_bMethod) { |
|---|
| 623 | BOOL bExist = FALSE; |
|---|
| 624 | for (int i = 0; i < plsTmp.m_nCMethods; i++) |
|---|
| 625 | bExist = (plsTmp.m_lpCMethods->m_nMethodID == psiItem->m_bMethod); |
|---|
| 626 | if (bExist||(psiItem->m_bMethod == GUTMANN_METHOD_ID || psiItem->m_bMethod == DOD_METHOD_ID || |
|---|
| 627 | psiItem->m_bMethod == DOD_E_METHOD_ID || psiItem->m_bMethod == RANDOM_METHOD_ID || |
|---|
| 628 | psiItem->m_bMethod == FL2KB_METHOD_ID)){ |
|---|
| 629 | //tps.m_pPageFileMethodOptions->SetLibSettings(&plsTmp); |
|---|
| 630 | tps.m_pPageFileMethodOptions->GetLibSettings()->m_nFileMethodID=psiItem->m_bMethod; |
|---|
| 631 | tps.m_pPageFileMethodOptions->GetLibSettings()->m_uItems = psiItem->m_uEraseItems; |
|---|
| 632 | tps.m_pPageFileMethodOptions->GetLibSettings()->m_nFileRandom = psiItem->m_nRndPass; |
|---|
| 633 | } |
|---|
| 634 | else { |
|---|
| 635 | tps.m_pPageFileMethodOptions->GetLibSettings()->m_nFileMethodID=plsTmp.m_nFileMethodID; |
|---|
| 636 | psiItem->m_bMethod = plsTmp.m_nFileMethodID; |
|---|
| 637 | psiItem->m_nRndPass = plsTmp.m_nFileRandom; |
|---|
| 638 | psiItem->m_uEraseItems = plsTmp.m_uItems; |
|---|
| 639 | } |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | tps.m_pgData.m_tType = psiItem->GetType(); |
|---|
| 643 | tps.m_pgData.m_bRemoveFolder = psiItem->RemoveFolder(); |
|---|
| 644 | tps.m_pgData.m_bSubfolders = psiItem->Subfolders(); |
|---|
| 645 | tps.m_pgData.m_bRemoveOnlySub = psiItem->OnlySubfolders(); |
|---|
| 646 | tps.m_pgData.m_bUseWildCards = psiItem->UseWildcards(); |
|---|
| 647 | tps.m_pgData.m_bWildCardsInSubfolders = psiItem->WildcardsInSubfolders(); |
|---|
| 648 | |
|---|
| 649 | psiItem->GetData(strData); |
|---|
| 650 | |
|---|
| 651 | switch (tps.m_pgData.m_tType) |
|---|
| 652 | { |
|---|
| 653 | case Drive: |
|---|
| 654 | tps.m_pgData.m_strSelectedDrive = strData; |
|---|
| 655 | break; |
|---|
| 656 | case Folder: |
|---|
| 657 | tps.m_pgData.m_strFolder = strData; |
|---|
| 658 | break; |
|---|
| 659 | case File: |
|---|
| 660 | tps.m_pgData.m_strFile = strData; |
|---|
| 661 | break; |
|---|
| 662 | default: |
|---|
| 663 | NODEFAULT; |
|---|
| 664 | }; |
|---|
| 665 | |
|---|
| 666 | tps.m_pgSchedule.m_odtTime.SetTime(psiItem->GetHour(), psiItem->GetMinute(), 0); |
|---|
| 667 | tps.m_pgSchedule.m_iWhen = static_cast<int>(psiItem->GetSchedule()); |
|---|
| 668 | tps.m_pgStatistics.m_lpts = psiItem->GetStatistics(); |
|---|
| 669 | |
|---|
| 670 | if (tps.DoModal() == IDOK) |
|---|
| 671 | { |
|---|
| 672 | if (tps.m_pgData.m_strSelectedDrive.IsEmpty() && |
|---|
| 673 | tps.m_pgData.m_strFolder.IsEmpty() && |
|---|
| 674 | tps.m_pgData.m_strFile.IsEmpty()) |
|---|
| 675 | { |
|---|
| 676 | // no data |
|---|
| 677 | return; |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | if (psiItem->IsRunning()) |
|---|
| 681 | { |
|---|
| 682 | if (AfxTimeOutMessageBox(IDS_QUESTION_INTERRUPT, MB_ICONWARNING | MB_YESNO) != IDYES) |
|---|
| 683 | return; |
|---|
| 684 | |
|---|
| 685 | TerminateThread(psiItem); |
|---|
| 686 | } |
|---|
| 687 | |
|---|
| 688 | KillTimer(psiItem->m_uTimerID); |
|---|
| 689 | |
|---|
| 690 | psiItem->SetSchedule(static_cast<Schedule>(tps.m_pgSchedule.m_iWhen)); |
|---|
| 691 | psiItem->SetTime((WORD)tps.m_pgSchedule.m_odtTime.GetHour(), |
|---|
| 692 | (WORD)tps.m_pgSchedule.m_odtTime.GetMinute()); |
|---|
| 693 | |
|---|
| 694 | switch (tps.m_pgData.m_tType) |
|---|
| 695 | { |
|---|
| 696 | case Drive: |
|---|
| 697 | psiItem->SetDrive(tps.m_pgData.m_strSelectedDrive); |
|---|
| 698 | break; |
|---|
| 699 | case Folder: |
|---|
| 700 | psiItem->SetFolder(tps.m_pgData.m_strFolder); |
|---|
| 701 | psiItem->RemoveFolder(tps.m_pgData.m_bRemoveFolder); |
|---|
| 702 | psiItem->Subfolders(tps.m_pgData.m_bSubfolders); |
|---|
| 703 | psiItem->OnlySubfolders(tps.m_pgData.m_bRemoveOnlySub); |
|---|
| 704 | break; |
|---|
| 705 | case File: |
|---|
| 706 | psiItem->SetFile(tps.m_pgData.m_strFile); |
|---|
| 707 | psiItem->UseWildcards(tps.m_pgData.m_bUseWildCards); |
|---|
| 708 | psiItem->WildcardsInSubfolders(tps.m_pgData.m_bWildCardsInSubfolders); |
|---|
| 709 | break; |
|---|
| 710 | default: |
|---|
| 711 | NODEFAULT; |
|---|
| 712 | }; |
|---|
| 713 | |
|---|
| 714 | CString strTmp; |
|---|
| 715 | psiItem->GetData(strTmp); |
|---|
| 716 | |
|---|
| 717 | if (strTmp != strData) |
|---|
| 718 | { |
|---|
| 719 | // data has changed -> reset statistics |
|---|
| 720 | |
|---|
| 721 | psiItem->GetStatistics()->Reset(); |
|---|
| 722 | |
|---|
| 723 | COleDateTime odt; |
|---|
| 724 | odt.SetStatus(COleDateTime::null); |
|---|
| 725 | |
|---|
| 726 | psiItem->SetLastTime(odt); |
|---|
| 727 | } |
|---|
| 728 | |
|---|
| 729 | psiItem->CalcNextTime(); |
|---|
| 730 | |
|---|
| 731 | if (!SetTimer(psiItem->m_uTimerID, psiItem->GetTimeSpan(), NULL)) |
|---|
| 732 | { |
|---|
| 733 | AfxTimeOutMessageBox(IDS_ERROR_TIMER, MB_ICONERROR); |
|---|
| 734 | |
|---|
| 735 | if (pDoc->m_bLog) |
|---|
| 736 | pDoc->LogAction(IDS_ERROR_TIMER); |
|---|
| 737 | } |
|---|
| 738 | //Update Reboot Part |
|---|
| 739 | if (tps.m_pgSchedule.m_iWhen == Reboot) |
|---|
| 740 | { |
|---|
| 741 | //Here we are setting the appropriate entry into the Registry Key : |
|---|
| 742 | //HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run |
|---|
| 743 | //The entry should be in Name - Data pair, where Name is the name of the application and Data is the path of the executable |
|---|
| 744 | CKey kReg; |
|---|
| 745 | CString m_strExePath; |
|---|
| 746 | CString m_strName; |
|---|
| 747 | char Fullname[260]; |
|---|
| 748 | char Filename[260]; |
|---|
| 749 | char Extension[5]; |
|---|
| 750 | char Pathname[260]; |
|---|
| 751 | char myDrive[10]; |
|---|
| 752 | char *buffer = new char[260]; |
|---|
| 753 | |
|---|
| 754 | if (kReg.Open(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run")) |
|---|
| 755 | { |
|---|
| 756 | GetModuleFileName(AfxGetInstanceHandle(),Fullname,sizeof Fullname); |
|---|
| 757 | _splitpath(Fullname,myDrive,Pathname,Filename,Extension); |
|---|
| 758 | strcpy(buffer,myDrive); |
|---|
| 759 | strncat(buffer,Pathname,250); |
|---|
| 760 | strncpy(Pathname,buffer,260); |
|---|
| 761 | delete buffer; |
|---|
| 762 | m_strExePath = '"'; |
|---|
| 763 | m_strExePath+= CString(Pathname); |
|---|
| 764 | m_strExePath+= "Eraserl.exe"; |
|---|
| 765 | m_strExePath+= '"'; |
|---|
| 766 | |
|---|
| 767 | switch (tps.m_pgData.m_tType) |
|---|
| 768 | { |
|---|
| 769 | case Drive: |
|---|
| 770 | m_strExePath+= " -disk " + tps.m_pgData.m_strSelectedDrive; |
|---|
| 771 | break; |
|---|
| 772 | case Folder: |
|---|
| 773 | m_strExePath+= " -folder "; |
|---|
| 774 | m_strExePath+= '"'; |
|---|
| 775 | m_strExePath+= tps.m_pgData.m_strFolder; |
|---|
| 776 | m_strExePath+= '"'; |
|---|
| 777 | if (tps.m_pgData.m_bRemoveFolder==FALSE) {m_strExePath+= "-keepfolder ";} |
|---|
| 778 | if (tps.m_pgData.m_bSubfolders) {m_strExePath+= "-subfolders ";} |
|---|
| 779 | break; |
|---|
| 780 | case File: |
|---|
| 781 | m_strExePath+= " -file "; |
|---|
| 782 | m_strExePath+= '"'; |
|---|
| 783 | m_strExePath+= tps.m_pgData.m_strFile; |
|---|
| 784 | m_strExePath+= '"'; |
|---|
| 785 | break; |
|---|
| 786 | default: |
|---|
| 787 | NODEFAULT; |
|---|
| 788 | }; |
|---|
| 789 | kReg.SetValue(m_strExePath,psiItem->GetId()); |
|---|
| 790 | m_strExePath.ReleaseBuffer(); |
|---|
| 791 | kReg.Close(); |
|---|
| 792 | } |
|---|
| 793 | } |
|---|
| 794 | // |
|---|
| 795 | UpdateList(); |
|---|
| 796 | |
|---|
| 797 | LibrarySettings* plsTmp1 = tps.m_pPageFileMethodOptions->GetLibSettings(); |
|---|
| 798 | psiItem->m_bMethod = plsTmp1->m_nFileMethodID; |
|---|
| 799 | psiItem->m_uEraseItems = plsTmp1->m_uItems; |
|---|
| 800 | psiItem->m_nRndPass = plsTmp1->m_nFileRandom; |
|---|
| 801 | plsTmp1->m_nFileMethodID = plsTmp.m_nFileMethodID; |
|---|
| 802 | plsTmp1->m_nFileRandom = plsTmp.m_nFileRandom; |
|---|
| 803 | plsTmp1->m_uItems = plsTmp.m_uItems; |
|---|
| 804 | saveLibrarySettings(plsTmp1); |
|---|
| 805 | |
|---|
| 806 | pDoc->CalcNextAssignment(); |
|---|
| 807 | pDoc->UpdateToolTip(); |
|---|
| 808 | pDoc->SaveTasksToDefault(); |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | } |
|---|
| 813 | |
|---|
| 814 | } |
|---|
| 815 | } |
|---|
| 816 | } |
|---|
| 817 | } |
|---|
| 818 | catch (CException *e) |
|---|
| 819 | { |
|---|
| 820 | ASSERT(FALSE); |
|---|
| 821 | REPORT_ERROR(e); |
|---|
| 822 | e->Delete(); |
|---|
| 823 | } |
|---|
| 824 | } |
|---|
| 825 | |
|---|
| 826 | void CSchedulerView::OnTimer(UINT_PTR nIDEvent) |
|---|
| 827 | { |
|---|
| 828 | TRACE("CSchedulerView::OnTimer\n"); |
|---|
| 829 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 830 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 831 | |
|---|
| 832 | try |
|---|
| 833 | { |
|---|
| 834 | int iSize = pDoc->m_paScheduledTasks.GetSize(); |
|---|
| 835 | CScheduleItem *psiItem = 0; |
|---|
| 836 | |
|---|
| 837 | while (iSize--) |
|---|
| 838 | { |
|---|
| 839 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iSize]); |
|---|
| 840 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem)) & !(psiItem->GetSchedule() == Reboot)) |
|---|
| 841 | { |
|---|
| 842 | if (psiItem->m_uTimerID == nIDEvent) |
|---|
| 843 | { |
|---|
| 844 | KillTimer(psiItem->m_uTimerID); |
|---|
| 845 | |
|---|
| 846 | if (!pDoc->m_bSchedulerEnabled) |
|---|
| 847 | { |
|---|
| 848 | // Scheduler not active at the moment, just |
|---|
| 849 | // calculate the next time |
|---|
| 850 | |
|---|
| 851 | psiItem->CalcNextTime(); |
|---|
| 852 | |
|---|
| 853 | if (!SetTimer(psiItem->m_uTimerID, psiItem->GetTimeSpan(), NULL)) |
|---|
| 854 | { |
|---|
| 855 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 856 | AfxTimeOutMessageBox(IDS_ERROR_TIMER, MB_ICONERROR); |
|---|
| 857 | |
|---|
| 858 | if (pDoc->m_bLog) |
|---|
| 859 | pDoc->LogAction(IDS_ERROR_TIMER); |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | UpdateList(); |
|---|
| 863 | pDoc->CalcNextAssignment(); |
|---|
| 864 | } |
|---|
| 865 | else |
|---|
| 866 | { |
|---|
| 867 | if (psiItem->IsRunning() || psiItem->IsQueued() || !psiItem->ScheduledNow()) |
|---|
| 868 | { |
|---|
| 869 | // thread still running, queued or is not due anytime soon, |
|---|
| 870 | // skip procedure and calculate next time |
|---|
| 871 | |
|---|
| 872 | psiItem->CalcNextTime(); |
|---|
| 873 | |
|---|
| 874 | if (!SetTimer(psiItem->m_uTimerID, psiItem->GetTimeSpan(), NULL)) |
|---|
| 875 | { |
|---|
| 876 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 877 | AfxTimeOutMessageBox(IDS_ERROR_TIMER, MB_ICONERROR); |
|---|
| 878 | |
|---|
| 879 | if (pDoc->m_bLog) |
|---|
| 880 | pDoc->LogAction(IDS_ERROR_TIMER); |
|---|
| 881 | } |
|---|
| 882 | } |
|---|
| 883 | else if (pDoc->m_bQueueTasks) |
|---|
| 884 | { |
|---|
| 885 | counterLock(); |
|---|
| 886 | |
|---|
| 887 | if (pDoc->m_wProcessCount > 0) |
|---|
| 888 | { |
|---|
| 889 | QueueTask(psiItem); |
|---|
| 890 | UpdateList(); |
|---|
| 891 | counterUnlock(); |
|---|
| 892 | } |
|---|
| 893 | else |
|---|
| 894 | { |
|---|
| 895 | counterUnlock(); |
|---|
| 896 | RunScheduledTask(psiItem); |
|---|
| 897 | } |
|---|
| 898 | } |
|---|
| 899 | else |
|---|
| 900 | { |
|---|
| 901 | RunScheduledTask(psiItem); |
|---|
| 902 | } |
|---|
| 903 | } // m_bEnabled |
|---|
| 904 | |
|---|
| 905 | pDoc->UpdateToolTip(); |
|---|
| 906 | return; |
|---|
| 907 | } // == nIDEvent |
|---|
| 908 | } // valid |
|---|
| 909 | } |
|---|
| 910 | } |
|---|
| 911 | catch (CException *e) |
|---|
| 912 | { |
|---|
| 913 | ASSERT(FALSE); |
|---|
| 914 | counterUnlock(); |
|---|
| 915 | |
|---|
| 916 | try |
|---|
| 917 | { |
|---|
| 918 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 919 | { |
|---|
| 920 | TCHAR szError[255]; |
|---|
| 921 | e->GetErrorMessage(szError, 255); |
|---|
| 922 | AfxTimeOutMessageBox(szError, MB_ICONERROR); |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | if (pDoc->m_bLog) |
|---|
| 926 | pDoc->LogException(e); |
|---|
| 927 | } |
|---|
| 928 | catch (...) |
|---|
| 929 | { |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | e->Delete(); |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | // no such timer !? kill it anyway... |
|---|
| 936 | KillTimer(nIDEvent); |
|---|
| 937 | |
|---|
| 938 | CFlatListView::OnTimer(nIDEvent); |
|---|
| 939 | } |
|---|
| 940 | |
|---|
| 941 | LRESULT CSchedulerView::OnEraserNotify(WPARAM wParam, LPARAM) |
|---|
| 942 | { |
|---|
| 943 | TRACE("CSchedulerView::OnEraserNotify\n"); |
|---|
| 944 | |
|---|
| 945 | switch (wParam) |
|---|
| 946 | { |
|---|
| 947 | case ERASER_WIPE_BEGIN: |
|---|
| 948 | EraserWipeBegin(); |
|---|
| 949 | break; |
|---|
| 950 | case ERASER_WIPE_UPDATE: |
|---|
| 951 | EraserWipeUpdate(); |
|---|
| 952 | break; |
|---|
| 953 | case ERASER_WIPE_DONE: |
|---|
| 954 | EraserWipeDone(); |
|---|
| 955 | break; |
|---|
| 956 | } |
|---|
| 957 | |
|---|
| 958 | return TRUE; |
|---|
| 959 | } |
|---|
| 960 | |
|---|
| 961 | BOOL CSchedulerView::EraserWipeDone() |
|---|
| 962 | { |
|---|
| 963 | TRACE("CSchedulerView::EraserWipeDone\n"); |
|---|
| 964 | |
|---|
| 965 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 966 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 967 | |
|---|
| 968 | try |
|---|
| 969 | { |
|---|
| 970 | int iSize = pDoc->m_paScheduledTasks.GetSize(); |
|---|
| 971 | CScheduleItem *psiItem = 0; |
|---|
| 972 | |
|---|
| 973 | while (iSize--) |
|---|
| 974 | { |
|---|
| 975 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iSize]); |
|---|
| 976 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 977 | { |
|---|
| 978 | // if thread has been running lately but has stopped since. |
|---|
| 979 | // that is, we have not destroyed the context yet |
|---|
| 980 | |
|---|
| 981 | if (eraserOK(eraserIsValidContext(psiItem->m_ehContext)) && !psiItem->IsRunning()) |
|---|
| 982 | { |
|---|
| 983 | E_UINT8 uValue = 0; |
|---|
| 984 | COleDateTime odt = GetTimeTimeZoneBased(); |
|---|
| 985 | psiItem->SetLastTime(odt); |
|---|
| 986 | |
|---|
| 987 | // not completed |
|---|
| 988 | if (eraserOK(eraserCompleted(psiItem->m_ehContext, &uValue)) && !uValue) |
|---|
| 989 | { |
|---|
| 990 | // not terminated |
|---|
| 991 | if (eraserOK(eraserTerminated(psiItem->m_ehContext, &uValue)) && !uValue) |
|---|
| 992 | { |
|---|
| 993 | // --> failed |
|---|
| 994 | if (pDoc->m_bLog) |
|---|
| 995 | { |
|---|
| 996 | CString str, strData; |
|---|
| 997 | psiItem->GetData(strData); |
|---|
| 998 | |
|---|
| 999 | AfxFormatString1(str, IDS_ACTION_ERROR, strData); |
|---|
| 1000 | pDoc->LogAction(str); |
|---|
| 1001 | |
|---|
| 1002 | // log failed items |
|---|
| 1003 | E_UINT32 uFailed = 0; |
|---|
| 1004 | E_UINT16 uErrors = 0, uSize = 0; |
|---|
| 1005 | eraserFailedCount(psiItem->m_ehContext, &uFailed); |
|---|
| 1006 | eraserErrorStringCount(psiItem->m_ehContext, &uErrors); |
|---|
| 1007 | |
|---|
| 1008 | if (uErrors > 0) |
|---|
| 1009 | { |
|---|
| 1010 | for (E_UINT16 uIndex = 0; uIndex < uErrors; uIndex++) |
|---|
| 1011 | { |
|---|
| 1012 | if (eraserOK(eraserErrorString(psiItem->m_ehContext, uIndex, 0, &uSize))) |
|---|
| 1013 | { |
|---|
| 1014 | if (eraserOK(eraserErrorString(psiItem->m_ehContext, uIndex, |
|---|
| 1015 | (LPVOID)strData.GetBuffer((int)uSize), &uSize))) |
|---|
| 1016 | { |
|---|
| 1017 | strData.ReleaseBuffer(); |
|---|
| 1018 | pDoc->LogAction(strData); |
|---|
| 1019 | } |
|---|
| 1020 | else |
|---|
| 1021 | strData.ReleaseBuffer(); |
|---|
| 1022 | } |
|---|
| 1023 | } |
|---|
| 1024 | } |
|---|
| 1025 | |
|---|
| 1026 | if (uFailed > 0) |
|---|
| 1027 | { |
|---|
| 1028 | UINT nError; |
|---|
| 1029 | |
|---|
| 1030 | if (psiItem->GetType() == Drive) |
|---|
| 1031 | nError = IDS_ACTION_ERROR_UNUSED; |
|---|
| 1032 | else |
|---|
| 1033 | nError = IDS_ACTION_ERROR_FILE; |
|---|
| 1034 | |
|---|
| 1035 | for (E_UINT32 uIndex = 0; uIndex < uFailed; uIndex++) |
|---|
| 1036 | { |
|---|
| 1037 | if (eraserOK(eraserFailedString(psiItem->m_ehContext, uIndex, 0, &uSize))) |
|---|
| 1038 | { |
|---|
| 1039 | if (eraserOK(eraserFailedString(psiItem->m_ehContext, uIndex, |
|---|
| 1040 | (LPVOID)strData.GetBuffer((int)uSize), &uSize))) |
|---|
| 1041 | { |
|---|
| 1042 | strData.ReleaseBuffer(); |
|---|
| 1043 | AfxFormatString1(str, nError, strData); |
|---|
| 1044 | pDoc->LogAction(str); |
|---|
| 1045 | } |
|---|
| 1046 | else |
|---|
| 1047 | strData.ReleaseBuffer(); |
|---|
| 1048 | } |
|---|
| 1049 | } |
|---|
| 1050 | } |
|---|
| 1051 | } // m_bLog |
|---|
| 1052 | |
|---|
| 1053 | // update task statistics |
|---|
| 1054 | psiItem->UpdateStatistics(); |
|---|
| 1055 | } |
|---|
| 1056 | } // Done |
|---|
| 1057 | else |
|---|
| 1058 | { |
|---|
| 1059 | if (pDoc->m_bLog && !pDoc->m_bLogOnlyErrors) |
|---|
| 1060 | { |
|---|
| 1061 | CString str, strData; |
|---|
| 1062 | psiItem->GetData(strData); |
|---|
| 1063 | |
|---|
| 1064 | AfxFormatString1(str, IDS_ACTION_DONE, strData); |
|---|
| 1065 | pDoc->LogAction(str); |
|---|
| 1066 | } |
|---|
| 1067 | |
|---|
| 1068 | // update task statistics |
|---|
| 1069 | psiItem->UpdateStatistics(); |
|---|
| 1070 | psiItem->GetStatistics()->m_dwTimesSuccess++; |
|---|
| 1071 | } |
|---|
| 1072 | |
|---|
| 1073 | // remove folders |
|---|
| 1074 | |
|---|
| 1075 | if (psiItem->GetType() == Folder && psiItem->RemoveFolder()) |
|---|
| 1076 | { |
|---|
| 1077 | CString strFolder; |
|---|
| 1078 | CStringArray saFiles, saFolders; |
|---|
| 1079 | |
|---|
| 1080 | psiItem->GetData(strFolder); |
|---|
| 1081 | |
|---|
| 1082 | parseDirectory((LPCTSTR)strFolder, |
|---|
| 1083 | saFiles, |
|---|
| 1084 | saFolders, |
|---|
| 1085 | psiItem->Subfolders()); |
|---|
| 1086 | |
|---|
| 1087 | if (psiItem->OnlySubfolders()) |
|---|
| 1088 | { |
|---|
| 1089 | // remove the last folder from the list, |
|---|
| 1090 | // since the user wishes it would not be |
|---|
| 1091 | // removed |
|---|
| 1092 | |
|---|
| 1093 | if (saFolders.GetSize() > 0) |
|---|
| 1094 | saFolders.SetSize(saFolders.GetSize() - 1); |
|---|
| 1095 | } |
|---|
| 1096 | |
|---|
| 1097 | int iSize = saFolders.GetSize(); |
|---|
| 1098 | if (iSize > 0) |
|---|
| 1099 | { |
|---|
| 1100 | for (int i = 0; i < iSize; i++) |
|---|
| 1101 | { |
|---|
| 1102 | if (eraserOK(eraserRemoveFolder((LPVOID)(LPCTSTR)saFolders[i], |
|---|
| 1103 | (E_UINT16)saFolders[i].GetLength(), ERASER_REMOVE_FOLDERONLY))) |
|---|
| 1104 | { |
|---|
| 1105 | SHChangeNotify(SHCNE_RMDIR, SHCNF_PATH, (LPCTSTR)saFolders[i], NULL); |
|---|
| 1106 | } |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | saFolders.RemoveAll(); |
|---|
| 1110 | } |
|---|
| 1111 | } |
|---|
| 1112 | |
|---|
| 1113 | uValue = 0; |
|---|
| 1114 | eraserTerminated(psiItem->m_ehContext, &uValue); |
|---|
| 1115 | |
|---|
| 1116 | counterLock(); |
|---|
| 1117 | |
|---|
| 1118 | if (!uValue && pDoc->m_wProcessCount > 0) |
|---|
| 1119 | pDoc->m_wProcessCount--; |
|---|
| 1120 | |
|---|
| 1121 | counterUnlock(); |
|---|
| 1122 | |
|---|
| 1123 | // destroy context |
|---|
| 1124 | VERIFY(eraserOK(eraserDestroyContext(psiItem->m_ehContext))); |
|---|
| 1125 | psiItem->m_ehContext = ERASER_INVALID_CONTEXT; |
|---|
| 1126 | |
|---|
| 1127 | } // not running |
|---|
| 1128 | } // valid |
|---|
| 1129 | } |
|---|
| 1130 | |
|---|
| 1131 | // run possible queued tasks |
|---|
| 1132 | psiItem = GetNextQueuedTask(); |
|---|
| 1133 | |
|---|
| 1134 | if (psiItem) |
|---|
| 1135 | RunScheduledTask(psiItem); |
|---|
| 1136 | |
|---|
| 1137 | UpdateList(); |
|---|
| 1138 | pDoc->CalcNextAssignment(); |
|---|
| 1139 | pDoc->UpdateToolTip(); |
|---|
| 1140 | |
|---|
| 1141 | return TRUE; |
|---|
| 1142 | } |
|---|
| 1143 | catch (CException *e) |
|---|
| 1144 | { |
|---|
| 1145 | ASSERT(FALSE); |
|---|
| 1146 | counterUnlock(); |
|---|
| 1147 | |
|---|
| 1148 | try |
|---|
| 1149 | { |
|---|
| 1150 | if (pDoc->m_bLog) |
|---|
| 1151 | pDoc->LogException(e); |
|---|
| 1152 | } |
|---|
| 1153 | catch (...) |
|---|
| 1154 | { |
|---|
| 1155 | } |
|---|
| 1156 | |
|---|
| 1157 | e->Delete(); |
|---|
| 1158 | } |
|---|
| 1159 | |
|---|
| 1160 | return FALSE; |
|---|
| 1161 | } |
|---|
| 1162 | |
|---|
| 1163 | BOOL CSchedulerView::EraserWipeBegin() |
|---|
| 1164 | { |
|---|
| 1165 | TRACE("CSchedulerView::EraserWipeBegin\n"); |
|---|
| 1166 | |
|---|
| 1167 | if (IsWindowVisible()) |
|---|
| 1168 | { |
|---|
| 1169 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1170 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1171 | |
|---|
| 1172 | try |
|---|
| 1173 | { |
|---|
| 1174 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1175 | int iCount = lc.GetItemCount(); |
|---|
| 1176 | DWORD_PTR iIndex = 0; |
|---|
| 1177 | CScheduleItem *psiItem = 0; |
|---|
| 1178 | CString str; |
|---|
| 1179 | CString strOld; |
|---|
| 1180 | |
|---|
| 1181 | str.LoadString(IDS_INFO_RUNNING); |
|---|
| 1182 | |
|---|
| 1183 | // update information for all active threads |
|---|
| 1184 | for (int iItem = 0; iItem < iCount; iItem++) |
|---|
| 1185 | { |
|---|
| 1186 | iIndex = lc.GetItemData(iItem); |
|---|
| 1187 | |
|---|
| 1188 | if (iIndex >= 0 && iIndex < pDoc->m_paScheduledTasks.GetSize()) |
|---|
| 1189 | { |
|---|
| 1190 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iIndex]); |
|---|
| 1191 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1192 | { |
|---|
| 1193 | if (psiItem->IsRunning()) |
|---|
| 1194 | { |
|---|
| 1195 | strOld = lc.GetItemText(iItem, 3); |
|---|
| 1196 | |
|---|
| 1197 | if (str.CompareNoCase(strOld) != 0) |
|---|
| 1198 | { |
|---|
| 1199 | SetRedraw(FALSE); |
|---|
| 1200 | lc.SetItemText(iItem, 3, (LPCTSTR)str); |
|---|
| 1201 | SetRedraw(TRUE); |
|---|
| 1202 | } |
|---|
| 1203 | } |
|---|
| 1204 | } |
|---|
| 1205 | } |
|---|
| 1206 | } |
|---|
| 1207 | |
|---|
| 1208 | pDoc->UpdateToolTip(); |
|---|
| 1209 | |
|---|
| 1210 | return TRUE; |
|---|
| 1211 | } |
|---|
| 1212 | catch (CException *e) |
|---|
| 1213 | { |
|---|
| 1214 | ASSERT(FALSE); |
|---|
| 1215 | |
|---|
| 1216 | try |
|---|
| 1217 | { |
|---|
| 1218 | if (pDoc->m_bLog) |
|---|
| 1219 | pDoc->LogException(e); |
|---|
| 1220 | } |
|---|
| 1221 | catch (...) |
|---|
| 1222 | { |
|---|
| 1223 | } |
|---|
| 1224 | |
|---|
| 1225 | e->Delete(); |
|---|
| 1226 | } |
|---|
| 1227 | } |
|---|
| 1228 | |
|---|
| 1229 | return FALSE; |
|---|
| 1230 | } |
|---|
| 1231 | |
|---|
| 1232 | BOOL CSchedulerView::EraserWipeUpdate() |
|---|
| 1233 | { |
|---|
| 1234 | TRACE("CSchedulerView::EraserWipeUpdate\n"); |
|---|
| 1235 | |
|---|
| 1236 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1237 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1238 | |
|---|
| 1239 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1240 | BOOL bSetProgress = FALSE; |
|---|
| 1241 | |
|---|
| 1242 | if (IsWindowVisible()) |
|---|
| 1243 | { |
|---|
| 1244 | SetRedraw(FALSE); |
|---|
| 1245 | |
|---|
| 1246 | int iCount = lc.GetItemCount(); |
|---|
| 1247 | int iIndex = 0; |
|---|
| 1248 | CScheduleItem *psiItem = 0; |
|---|
| 1249 | CString str; |
|---|
| 1250 | CString strOld; |
|---|
| 1251 | CString strFormat; |
|---|
| 1252 | |
|---|
| 1253 | try |
|---|
| 1254 | { |
|---|
| 1255 | // update information for all active threads |
|---|
| 1256 | for (int iItem = 0; iItem < iCount; iItem++) |
|---|
| 1257 | { |
|---|
| 1258 | iIndex = lc.GetItemData(iItem); |
|---|
| 1259 | |
|---|
| 1260 | if (iIndex >= 0 && iIndex < pDoc->m_paScheduledTasks.GetSize()) |
|---|
| 1261 | { |
|---|
| 1262 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iIndex]); |
|---|
| 1263 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1264 | { |
|---|
| 1265 | if (psiItem->IsRunning()) |
|---|
| 1266 | { |
|---|
| 1267 | // if only one task (us) is selected, show the progress |
|---|
| 1268 | // bar on the status bar |
|---|
| 1269 | |
|---|
| 1270 | if (lc.GetSelectedCount() == 1 && |
|---|
| 1271 | lc.GetItemState(iItem, LVIS_SELECTED) == LVIS_SELECTED) |
|---|
| 1272 | { |
|---|
| 1273 | TCHAR szValue[255]; |
|---|
| 1274 | E_UINT16 uSize = 255; |
|---|
| 1275 | E_UINT8 uValue = 0; |
|---|
| 1276 | |
|---|
| 1277 | if (eraserOK(eraserProgGetTotalPercent(psiItem->m_ehContext, &uValue))) |
|---|
| 1278 | m_pbProgress.SetPos(uValue); |
|---|
| 1279 | |
|---|
| 1280 | if (eraserOK(eraserProgGetMessage(psiItem->m_ehContext, (LPVOID)szValue, &uSize))) |
|---|
| 1281 | m_pbProgress.SetText((LPCTSTR)szValue); |
|---|
| 1282 | |
|---|
| 1283 | bSetProgress = TRUE; |
|---|
| 1284 | } |
|---|
| 1285 | } // running |
|---|
| 1286 | } |
|---|
| 1287 | } |
|---|
| 1288 | } |
|---|
| 1289 | } |
|---|
| 1290 | catch (CException *e) |
|---|
| 1291 | { |
|---|
| 1292 | ASSERT(FALSE); |
|---|
| 1293 | |
|---|
| 1294 | try |
|---|
| 1295 | { |
|---|
| 1296 | if (pDoc->m_bLog) |
|---|
| 1297 | pDoc->LogException(e); |
|---|
| 1298 | } |
|---|
| 1299 | catch (...) |
|---|
| 1300 | { |
|---|
| 1301 | } |
|---|
| 1302 | |
|---|
| 1303 | e->Delete(); |
|---|
| 1304 | } |
|---|
| 1305 | |
|---|
| 1306 | SetRedraw(TRUE); |
|---|
| 1307 | } |
|---|
| 1308 | |
|---|
| 1309 | // if there were no tasks selected, or the selected task |
|---|
| 1310 | // was not running, or the Scheduler window is not visible, |
|---|
| 1311 | // remove the progress bar |
|---|
| 1312 | |
|---|
| 1313 | if (!bSetProgress && m_pbProgress.IsWindowVisible()) |
|---|
| 1314 | m_pbProgress.Clear(); |
|---|
| 1315 | |
|---|
| 1316 | pDoc->UpdateToolTip(); |
|---|
| 1317 | |
|---|
| 1318 | return TRUE; |
|---|
| 1319 | } |
|---|
| 1320 | |
|---|
| 1321 | |
|---|
| 1322 | void CSchedulerView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/) |
|---|
| 1323 | { |
|---|
| 1324 | TRACE("CSchedulerView::OnUpdate\n"); |
|---|
| 1325 | |
|---|
| 1326 | if (lHint == SCHEDULER_SET_TIMERS) |
|---|
| 1327 | { |
|---|
| 1328 | SetTimers(); |
|---|
| 1329 | lHint = 0L; |
|---|
| 1330 | } |
|---|
| 1331 | |
|---|
| 1332 | if (lHint == 0L) |
|---|
| 1333 | { |
|---|
| 1334 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1335 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1336 | |
|---|
| 1337 | try |
|---|
| 1338 | { |
|---|
| 1339 | UpdateList(); |
|---|
| 1340 | pDoc->CalcNextAssignment(); |
|---|
| 1341 | pDoc->UpdateToolTip(); |
|---|
| 1342 | } |
|---|
| 1343 | catch (...) |
|---|
| 1344 | { |
|---|
| 1345 | ASSERT(FALSE); |
|---|
| 1346 | } |
|---|
| 1347 | } |
|---|
| 1348 | } |
|---|
| 1349 | |
|---|
| 1350 | void CSchedulerView::OnDestroy() |
|---|
| 1351 | { |
|---|
| 1352 | TRACE("CSchedulerView::OnDestroy\n"); |
|---|
| 1353 | |
|---|
| 1354 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1355 | |
|---|
| 1356 | if (AfxIsValidAddress(pDoc, sizeof(CEraserDoc))) |
|---|
| 1357 | { |
|---|
| 1358 | try |
|---|
| 1359 | { |
|---|
| 1360 | CScheduleItem *psiItem = 0; |
|---|
| 1361 | int iSize = pDoc->m_paScheduledTasks.GetSize(); |
|---|
| 1362 | |
|---|
| 1363 | while (iSize--) |
|---|
| 1364 | { |
|---|
| 1365 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iSize]); |
|---|
| 1366 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1367 | KillTimer(psiItem->m_uTimerID); |
|---|
| 1368 | } |
|---|
| 1369 | } |
|---|
| 1370 | catch (CException *e) |
|---|
| 1371 | { |
|---|
| 1372 | ASSERT(FALSE); |
|---|
| 1373 | |
|---|
| 1374 | if (pDoc->m_bLog) |
|---|
| 1375 | pDoc->LogException(e); |
|---|
| 1376 | |
|---|
| 1377 | e->Delete(); |
|---|
| 1378 | } |
|---|
| 1379 | } |
|---|
| 1380 | |
|---|
| 1381 | CFlatListView::OnDestroy(); |
|---|
| 1382 | } |
|---|
| 1383 | |
|---|
| 1384 | BOOL CSchedulerView::SetTimers() |
|---|
| 1385 | { |
|---|
| 1386 | TRACE("CSchedulerView::SetTimers\n"); |
|---|
| 1387 | |
|---|
| 1388 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1389 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1390 | |
|---|
| 1391 | try |
|---|
| 1392 | { |
|---|
| 1393 | CScheduleItem *psiItem = 0; |
|---|
| 1394 | int iSize = pDoc->m_paScheduledTasks.GetSize(); |
|---|
| 1395 | |
|---|
| 1396 | while (iSize--) |
|---|
| 1397 | { |
|---|
| 1398 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iSize]); |
|---|
| 1399 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1400 | { |
|---|
| 1401 | if (psiItem->m_uTimerID > 0) |
|---|
| 1402 | KillTimer(psiItem->m_uTimerID); |
|---|
| 1403 | |
|---|
| 1404 | psiItem->m_uTimerID = GetNextTimerID(); |
|---|
| 1405 | |
|---|
| 1406 | if (!psiItem->StillValid()) |
|---|
| 1407 | psiItem->CalcNextTime(); |
|---|
| 1408 | |
|---|
| 1409 | if (!SetTimer(psiItem->m_uTimerID, psiItem->GetTimeSpan(), NULL)) |
|---|
| 1410 | { |
|---|
| 1411 | AfxTimeOutMessageBox(IDS_ERROR_TIMER, MB_ICONERROR); |
|---|
| 1412 | |
|---|
| 1413 | if (pDoc->m_bLog) |
|---|
| 1414 | pDoc->LogAction(IDS_ERROR_TIMER); |
|---|
| 1415 | |
|---|
| 1416 | return FALSE; |
|---|
| 1417 | } |
|---|
| 1418 | } |
|---|
| 1419 | } |
|---|
| 1420 | |
|---|
| 1421 | return TRUE; |
|---|
| 1422 | } |
|---|
| 1423 | catch (CException *e) |
|---|
| 1424 | { |
|---|
| 1425 | ASSERT(FALSE); |
|---|
| 1426 | |
|---|
| 1427 | try |
|---|
| 1428 | { |
|---|
| 1429 | if (pDoc->m_bLog) |
|---|
| 1430 | pDoc->LogException(e); |
|---|
| 1431 | } |
|---|
| 1432 | catch (...) |
|---|
| 1433 | { |
|---|
| 1434 | } |
|---|
| 1435 | |
|---|
| 1436 | e->Delete(); |
|---|
| 1437 | } |
|---|
| 1438 | |
|---|
| 1439 | return FALSE; |
|---|
| 1440 | } |
|---|
| 1441 | |
|---|
| 1442 | void CSchedulerView::UpdateList() |
|---|
| 1443 | { |
|---|
| 1444 | TRACE("CSchedulerView::UpdateList\n"); |
|---|
| 1445 | |
|---|
| 1446 | SetRedraw(FALSE); |
|---|
| 1447 | |
|---|
| 1448 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1449 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1450 | |
|---|
| 1451 | try |
|---|
| 1452 | { |
|---|
| 1453 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1454 | CUIntArray uaSelected; |
|---|
| 1455 | |
|---|
| 1456 | // get selected items |
|---|
| 1457 | POSITION pos = lc.GetFirstSelectedItemPosition(); |
|---|
| 1458 | while (pos) uaSelected.Add((UINT)lc.GetNextSelectedItem(pos)); |
|---|
| 1459 | |
|---|
| 1460 | lc.DeleteAllItems(); |
|---|
| 1461 | |
|---|
| 1462 | CScheduleItem *psiItem = 0; |
|---|
| 1463 | int iSize = 0; |
|---|
| 1464 | int iItem = 0; |
|---|
| 1465 | |
|---|
| 1466 | // item information |
|---|
| 1467 | CString strData; |
|---|
| 1468 | COleDateTime odtLast; |
|---|
| 1469 | |
|---|
| 1470 | BOOL bExists = FALSE; |
|---|
| 1471 | WIN32_FIND_DATA findFileData; |
|---|
| 1472 | HANDLE hFind = NULL; |
|---|
| 1473 | SHFILEINFO sfi; |
|---|
| 1474 | |
|---|
| 1475 | LV_ITEM lvi; |
|---|
| 1476 | ZeroMemory(&lvi, sizeof(LV_ITEM)); |
|---|
| 1477 | |
|---|
| 1478 | // remove the progress bar from the window |
|---|
| 1479 | m_pbProgress.Clear(); |
|---|
| 1480 | |
|---|
| 1481 | // clean invalid objects from the task list |
|---|
| 1482 | pDoc->CleanList(pDoc->m_paScheduledTasks, sizeof(CScheduleItem)); |
|---|
| 1483 | iSize = pDoc->m_paScheduledTasks.GetSize(); |
|---|
| 1484 | |
|---|
| 1485 | // populate the list |
|---|
| 1486 | while (iSize--) |
|---|
| 1487 | { |
|---|
| 1488 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[iSize]); |
|---|
| 1489 | ASSERT(AfxIsValidAddress(psiItem, sizeof(CScheduleItem))); |
|---|
| 1490 | |
|---|
| 1491 | psiItem->GetData(strData); |
|---|
| 1492 | |
|---|
| 1493 | SHGetFileInfo((LPCTSTR)strData, |
|---|
| 1494 | 0, |
|---|
| 1495 | &sfi, |
|---|
| 1496 | sizeof(SHFILEINFO), |
|---|
| 1497 | SHGFI_SYSICONINDEX | |
|---|
| 1498 | SHGFI_SMALLICON | |
|---|
| 1499 | SHGFI_TYPENAME | |
|---|
| 1500 | SHGFI_DISPLAYNAME); |
|---|
| 1501 | |
|---|
| 1502 | switch (psiItem->GetType()) |
|---|
| 1503 | { |
|---|
| 1504 | case File: |
|---|
| 1505 | if (psiItem->UseWildcards()) |
|---|
| 1506 | { |
|---|
| 1507 | bExists = FALSE; |
|---|
| 1508 | break; |
|---|
| 1509 | } |
|---|
| 1510 | // no break! |
|---|
| 1511 | case Folder: |
|---|
| 1512 | { |
|---|
| 1513 | if (strData.GetLength() <= _MAX_DRIVE && |
|---|
| 1514 | strData.Find(":\\") == 1) |
|---|
| 1515 | { |
|---|
| 1516 | // clear all data on a drive! |
|---|
| 1517 | bExists = TRUE; |
|---|
| 1518 | } |
|---|
| 1519 | else |
|---|
| 1520 | { |
|---|
| 1521 | // file information |
|---|
| 1522 | |
|---|
| 1523 | if (strData.GetLength()&&strData[strData.GetLength() - 1] == '\\') |
|---|
| 1524 | strData = strData.Left(strData.GetLength() - 1); |
|---|
| 1525 | |
|---|
| 1526 | hFind = FindFirstFile((LPCTSTR)strData, &findFileData); |
|---|
| 1527 | |
|---|
| 1528 | bExists = (hFind != INVALID_HANDLE_VALUE); |
|---|
| 1529 | |
|---|
| 1530 | if (bExists) |
|---|
| 1531 | VERIFY(FindClose(hFind)); |
|---|
| 1532 | } |
|---|
| 1533 | |
|---|
| 1534 | psiItem->GetData(strData); |
|---|
| 1535 | } |
|---|
| 1536 | break; |
|---|
| 1537 | case Drive: |
|---|
| 1538 | bExists = TRUE; |
|---|
| 1539 | if (strData == DRIVE_ALL_LOCAL) |
|---|
| 1540 | { |
|---|
| 1541 | SHGetFileInfo((LPCTSTR)"C:\\", |
|---|
| 1542 | 0, |
|---|
| 1543 | &sfi, |
|---|
| 1544 | sizeof(SHFILEINFO), |
|---|
| 1545 | SHGFI_SYSICONINDEX | |
|---|
| 1546 | SHGFI_SMALLICON | |
|---|
| 1547 | SHGFI_TYPENAME | |
|---|
| 1548 | SHGFI_DISPLAYNAME); |
|---|
| 1549 | } |
|---|
| 1550 | break; |
|---|
| 1551 | default: |
|---|
| 1552 | NODEFAULT; |
|---|
| 1553 | } |
|---|
| 1554 | |
|---|
| 1555 | // name |
|---|
| 1556 | |
|---|
| 1557 | lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; |
|---|
| 1558 | |
|---|
| 1559 | lvi.iImage = (bExists) ? sfi.iIcon : -1; |
|---|
| 1560 | lvi.iItem = iItem; |
|---|
| 1561 | lvi.lParam = iSize; |
|---|
| 1562 | lvi.iSubItem = ColumnName; |
|---|
| 1563 | |
|---|
| 1564 | if (psiItem->GetType() == Drive) |
|---|
| 1565 | { |
|---|
| 1566 | if (strData == DRIVE_ALL_LOCAL) |
|---|
| 1567 | strData = szLocalDrives; |
|---|
| 1568 | else |
|---|
| 1569 | strData = sfi.szDisplayName; |
|---|
| 1570 | } |
|---|
| 1571 | |
|---|
| 1572 | lvi.pszText = strData.GetBuffer(strData.GetLength()); |
|---|
| 1573 | lvi.iItem = lc.InsertItem(&lvi); |
|---|
| 1574 | |
|---|
| 1575 | strData.ReleaseBuffer(); |
|---|
| 1576 | |
|---|
| 1577 | // type |
|---|
| 1578 | |
|---|
| 1579 | lvi.mask = LVIF_TEXT; |
|---|
| 1580 | lvi.iSubItem = ColumnType; |
|---|
| 1581 | |
|---|
| 1582 | if (psiItem->GetType() == Drive) |
|---|
| 1583 | strData = "Unused disk space"; |
|---|
| 1584 | else if (psiItem->UseWildcards()) |
|---|
| 1585 | strData = "Wildcard search"; |
|---|
| 1586 | else |
|---|
| 1587 | strData = sfi.szTypeName; |
|---|
| 1588 | |
|---|
| 1589 | lvi.pszText = strData.GetBuffer(strData.GetLength()); |
|---|
| 1590 | lc.SetItem(&lvi); |
|---|
| 1591 | |
|---|
| 1592 | strData.ReleaseBuffer(); |
|---|
| 1593 | |
|---|
| 1594 | // last run |
|---|
| 1595 | |
|---|
| 1596 | lvi.iSubItem = ColumnLast; |
|---|
| 1597 | |
|---|
| 1598 | odtLast = psiItem->GetLastTime(); |
|---|
| 1599 | |
|---|
| 1600 | if (odtLast.GetStatus() == COleDateTime::valid) |
|---|
| 1601 | strData = odtLast.Format(); |
|---|
| 1602 | else |
|---|
| 1603 | strData.Empty(); |
|---|
| 1604 | |
|---|
| 1605 | lvi.pszText = strData.GetBuffer(strData.GetLength()); |
|---|
| 1606 | lc.SetItem(&lvi); |
|---|
| 1607 | |
|---|
| 1608 | strData.ReleaseBuffer(); |
|---|
| 1609 | |
|---|
| 1610 | // next run |
|---|
| 1611 | |
|---|
| 1612 | lvi.iSubItem = ColumnNext; |
|---|
| 1613 | |
|---|
| 1614 | if (psiItem->IsRunning()) |
|---|
| 1615 | { |
|---|
| 1616 | try |
|---|
| 1617 | { |
|---|
| 1618 | strData.LoadString(IDS_INFO_RUNNING); |
|---|
| 1619 | } |
|---|
| 1620 | catch (CException *e) |
|---|
| 1621 | { |
|---|
| 1622 | ASSERT(FALSE); |
|---|
| 1623 | strData.Empty(); |
|---|
| 1624 | |
|---|
| 1625 | if (pDoc->m_bLog) |
|---|
| 1626 | pDoc->LogException(e); |
|---|
| 1627 | |
|---|
| 1628 | e->Delete(); |
|---|
| 1629 | } |
|---|
| 1630 | } |
|---|
| 1631 | else if (psiItem->IsQueued()) |
|---|
| 1632 | { |
|---|
| 1633 | try |
|---|
| 1634 | { |
|---|
| 1635 | strData.LoadString(IDS_INFO_QUEUED); |
|---|
| 1636 | } |
|---|
| 1637 | catch (CException *e) |
|---|
| 1638 | { |
|---|
| 1639 | ASSERT(FALSE); |
|---|
| 1640 | strData.Empty(); |
|---|
| 1641 | |
|---|
| 1642 | if (pDoc->m_bLog) |
|---|
| 1643 | pDoc->LogException(e); |
|---|
| 1644 | |
|---|
| 1645 | e->Delete(); |
|---|
| 1646 | } |
|---|
| 1647 | } |
|---|
| 1648 | else |
|---|
| 1649 | { |
|---|
| 1650 | strData = psiItem->GetNextTime().Format(); |
|---|
| 1651 | } |
|---|
| 1652 | |
|---|
| 1653 | lvi.pszText = strData.GetBuffer(strData.GetLength()); |
|---|
| 1654 | lc.SetItem(&lvi); |
|---|
| 1655 | |
|---|
| 1656 | strData.ReleaseBuffer(); |
|---|
| 1657 | |
|---|
| 1658 | // schedule |
|---|
| 1659 | |
|---|
| 1660 | lvi.iSubItem = ColumnSchedule; |
|---|
| 1661 | |
|---|
| 1662 | strData = "Every "; |
|---|
| 1663 | strData += szScheduleName[psiItem->GetSchedule()]; |
|---|
| 1664 | |
|---|
| 1665 | lvi.pszText = strData.GetBuffer(strData.GetLength()); |
|---|
| 1666 | lc.SetItem(&lvi); |
|---|
| 1667 | |
|---|
| 1668 | strData.ReleaseBuffer(); |
|---|
| 1669 | |
|---|
| 1670 | iItem++; |
|---|
| 1671 | } |
|---|
| 1672 | |
|---|
| 1673 | // set previously selected items as selected again |
|---|
| 1674 | int iListCount = lc.GetItemCount(); |
|---|
| 1675 | int iSelectItem = -1; |
|---|
| 1676 | |
|---|
| 1677 | iSize = uaSelected.GetSize(); |
|---|
| 1678 | for (iItem = 0; iItem < iSize; iItem++) |
|---|
| 1679 | { |
|---|
| 1680 | iSelectItem = (int)uaSelected[iItem]; |
|---|
| 1681 | |
|---|
| 1682 | if (iSelectItem < iListCount) |
|---|
| 1683 | SelItemRange(TRUE, iSelectItem, iSelectItem); |
|---|
| 1684 | } |
|---|
| 1685 | } |
|---|
| 1686 | catch (...) |
|---|
| 1687 | { |
|---|
| 1688 | ASSERT(FALSE); |
|---|
| 1689 | } |
|---|
| 1690 | |
|---|
| 1691 | SetRedraw(TRUE); |
|---|
| 1692 | } |
|---|
| 1693 | |
|---|
| 1694 | void CSchedulerView::OnLButtonDblClk(UINT /*nFlags*/, CPoint /*point*/) |
|---|
| 1695 | { |
|---|
| 1696 | TRACE("CSchedulerView::OnLButtonDblClk\n"); |
|---|
| 1697 | OnEditProperties(); |
|---|
| 1698 | } |
|---|
| 1699 | |
|---|
| 1700 | void CSchedulerView::OnUpdateProcessRun(CCmdUI* pCmdUI) |
|---|
| 1701 | { |
|---|
| 1702 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1703 | pCmdUI->Enable(lc.GetSelectedCount() > 0); |
|---|
| 1704 | } |
|---|
| 1705 | |
|---|
| 1706 | void CSchedulerView::OnUpdateProcessRunAll(CCmdUI* pCmdUI) |
|---|
| 1707 | { |
|---|
| 1708 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1709 | pCmdUI->Enable(lc.GetItemCount() > 0); |
|---|
| 1710 | } |
|---|
| 1711 | |
|---|
| 1712 | void CSchedulerView::OnProcessRun() |
|---|
| 1713 | { |
|---|
| 1714 | TRACE("CSchedulerView::OnProcessRun\n"); |
|---|
| 1715 | |
|---|
| 1716 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1717 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1718 | |
|---|
| 1719 | try |
|---|
| 1720 | { |
|---|
| 1721 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1722 | |
|---|
| 1723 | if (lc.GetSelectedCount() > 0) |
|---|
| 1724 | { |
|---|
| 1725 | POSITION pos = lc.GetFirstSelectedItemPosition(); |
|---|
| 1726 | int nItem, nIndex; |
|---|
| 1727 | BOOL bQueued = FALSE; |
|---|
| 1728 | CScheduleItem *psiItem = 0; |
|---|
| 1729 | |
|---|
| 1730 | while (pos) |
|---|
| 1731 | { |
|---|
| 1732 | nItem = lc.GetNextSelectedItem(pos); |
|---|
| 1733 | nIndex = lc.GetItemData(nItem); |
|---|
| 1734 | |
|---|
| 1735 | if (nIndex >= 0 && nIndex < pDoc->m_paScheduledTasks.GetSize()) |
|---|
| 1736 | { |
|---|
| 1737 | psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[nIndex]); |
|---|
| 1738 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1739 | { |
|---|
| 1740 | if (psiItem->IsRunning()) |
|---|
| 1741 | { |
|---|
| 1742 | // thread still running, skip procedure |
|---|
| 1743 | continue; |
|---|
| 1744 | } |
|---|
| 1745 | else if (pDoc->m_bQueueTasks) |
|---|
| 1746 | { |
|---|
| 1747 | counterLock(); |
|---|
| 1748 | |
|---|
| 1749 | if (pDoc->m_wProcessCount > 0) |
|---|
| 1750 | { |
|---|
| 1751 | QueueTask(psiItem); |
|---|
| 1752 | bQueued = TRUE; |
|---|
| 1753 | counterUnlock(); |
|---|
| 1754 | } |
|---|
| 1755 | else |
|---|
| 1756 | { |
|---|
| 1757 | counterUnlock(); |
|---|
| 1758 | RunScheduledTask(psiItem); |
|---|
| 1759 | } |
|---|
| 1760 | } |
|---|
| 1761 | else |
|---|
| 1762 | { |
|---|
| 1763 | RunScheduledTask(psiItem); |
|---|
| 1764 | } |
|---|
| 1765 | } |
|---|
| 1766 | } |
|---|
| 1767 | } |
|---|
| 1768 | |
|---|
| 1769 | if (bQueued) UpdateList(); |
|---|
| 1770 | } |
|---|
| 1771 | } |
|---|
| 1772 | catch (CException *e) |
|---|
| 1773 | { |
|---|
| 1774 | ASSERT(FALSE); |
|---|
| 1775 | counterUnlock(); |
|---|
| 1776 | |
|---|
| 1777 | try |
|---|
| 1778 | { |
|---|
| 1779 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 1780 | { |
|---|
| 1781 | TCHAR szError[255]; |
|---|
| 1782 | e->GetErrorMessage(szError, 255); |
|---|
| 1783 | AfxTimeOutMessageBox(szError, 255); |
|---|
| 1784 | } |
|---|
| 1785 | |
|---|
| 1786 | if (pDoc->m_bLog) |
|---|
| 1787 | pDoc->LogException(e); |
|---|
| 1788 | } |
|---|
| 1789 | catch (...) |
|---|
| 1790 | { |
|---|
| 1791 | } |
|---|
| 1792 | |
|---|
| 1793 | e->Delete(); |
|---|
| 1794 | } |
|---|
| 1795 | } |
|---|
| 1796 | |
|---|
| 1797 | void CSchedulerView::OnProcessRunAll() |
|---|
| 1798 | { |
|---|
| 1799 | if (AfxMessageBox(IDS_QUESTION_RUNALL, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2, 0) == IDYES) |
|---|
| 1800 | { |
|---|
| 1801 | SelItemRange(TRUE, 0, -1); |
|---|
| 1802 | OnProcessRun(); |
|---|
| 1803 | } |
|---|
| 1804 | } |
|---|
| 1805 | |
|---|
| 1806 | |
|---|
| 1807 | void CSchedulerView::OnUpdateProcessStop(CCmdUI* pCmdUI) |
|---|
| 1808 | { |
|---|
| 1809 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1810 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1811 | |
|---|
| 1812 | try |
|---|
| 1813 | { |
|---|
| 1814 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1815 | |
|---|
| 1816 | if (lc.GetSelectedCount() == 1 && pDoc->m_wProcessCount > 0) |
|---|
| 1817 | { |
|---|
| 1818 | POSITION pos = lc.GetFirstSelectedItemPosition(); |
|---|
| 1819 | |
|---|
| 1820 | int nItem = lc.GetNextSelectedItem(pos); |
|---|
| 1821 | int nIndex = lc.GetItemData(nItem); |
|---|
| 1822 | |
|---|
| 1823 | if (nIndex >= 0 && nIndex < pDoc->m_paScheduledTasks.GetSize()) |
|---|
| 1824 | { |
|---|
| 1825 | CScheduleItem *psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[nIndex]); |
|---|
| 1826 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1827 | { |
|---|
| 1828 | if (psiItem->IsRunning() || psiItem->IsQueued()) |
|---|
| 1829 | { |
|---|
| 1830 | pCmdUI->Enable(); |
|---|
| 1831 | return; |
|---|
| 1832 | } |
|---|
| 1833 | } |
|---|
| 1834 | } |
|---|
| 1835 | } |
|---|
| 1836 | } |
|---|
| 1837 | catch (...) |
|---|
| 1838 | { |
|---|
| 1839 | ASSERT(FALSE); |
|---|
| 1840 | } |
|---|
| 1841 | |
|---|
| 1842 | pCmdUI->Enable(FALSE); |
|---|
| 1843 | } |
|---|
| 1844 | |
|---|
| 1845 | void CSchedulerView::OnProcessStop() |
|---|
| 1846 | { |
|---|
| 1847 | TRACE("CSchedulerView::OnProcessStop\n"); |
|---|
| 1848 | |
|---|
| 1849 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1850 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1851 | |
|---|
| 1852 | try |
|---|
| 1853 | { |
|---|
| 1854 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1855 | |
|---|
| 1856 | counterLock(); |
|---|
| 1857 | |
|---|
| 1858 | if (lc.GetSelectedCount() == 1 && pDoc->m_wProcessCount > 0) |
|---|
| 1859 | { |
|---|
| 1860 | POSITION pos = lc.GetFirstSelectedItemPosition(); |
|---|
| 1861 | |
|---|
| 1862 | int nItem = lc.GetNextSelectedItem(pos); |
|---|
| 1863 | int nIndex = lc.GetItemData(nItem); |
|---|
| 1864 | |
|---|
| 1865 | if (nIndex >= 0 && nIndex < pDoc->m_paScheduledTasks.GetSize()) |
|---|
| 1866 | { |
|---|
| 1867 | CScheduleItem *psiItem = static_cast<CScheduleItem*>(pDoc->m_paScheduledTasks[nIndex]); |
|---|
| 1868 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1869 | { |
|---|
| 1870 | if (psiItem->IsQueued()) |
|---|
| 1871 | { |
|---|
| 1872 | RemoveTaskFromQueue(psiItem); |
|---|
| 1873 | UpdateList(); |
|---|
| 1874 | } |
|---|
| 1875 | else |
|---|
| 1876 | { |
|---|
| 1877 | counterUnlock(); |
|---|
| 1878 | TerminateThread(psiItem); |
|---|
| 1879 | return; |
|---|
| 1880 | } |
|---|
| 1881 | } |
|---|
| 1882 | } |
|---|
| 1883 | } |
|---|
| 1884 | |
|---|
| 1885 | counterUnlock(); |
|---|
| 1886 | } |
|---|
| 1887 | catch (CException *e) |
|---|
| 1888 | { |
|---|
| 1889 | ASSERT(FALSE); |
|---|
| 1890 | counterUnlock(); |
|---|
| 1891 | |
|---|
| 1892 | try |
|---|
| 1893 | { |
|---|
| 1894 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 1895 | { |
|---|
| 1896 | TCHAR szError[255]; |
|---|
| 1897 | e->GetErrorMessage(szError, 255); |
|---|
| 1898 | AfxTimeOutMessageBox(szError, MB_ICONERROR); |
|---|
| 1899 | } |
|---|
| 1900 | |
|---|
| 1901 | if (pDoc->m_bLog) |
|---|
| 1902 | pDoc->LogException(e); |
|---|
| 1903 | } |
|---|
| 1904 | catch (...) |
|---|
| 1905 | { |
|---|
| 1906 | } |
|---|
| 1907 | |
|---|
| 1908 | e->Delete(); |
|---|
| 1909 | } |
|---|
| 1910 | } |
|---|
| 1911 | |
|---|
| 1912 | void CSchedulerView::OnUpdateItems(CCmdUI* pCmdUI) |
|---|
| 1913 | { |
|---|
| 1914 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1915 | |
|---|
| 1916 | CString str; |
|---|
| 1917 | int iCount = lc.GetItemCount(); |
|---|
| 1918 | |
|---|
| 1919 | str.Format("%u Task", iCount); |
|---|
| 1920 | |
|---|
| 1921 | if (iCount != 1) |
|---|
| 1922 | str += "s"; |
|---|
| 1923 | |
|---|
| 1924 | pCmdUI->SetText((LPCTSTR)str); |
|---|
| 1925 | pCmdUI->Enable(); |
|---|
| 1926 | } |
|---|
| 1927 | |
|---|
| 1928 | void CSchedulerView::OnUpdateEditSelectAll(CCmdUI* pCmdUI) |
|---|
| 1929 | { |
|---|
| 1930 | CListCtrl& lc = GetListCtrl(); |
|---|
| 1931 | pCmdUI->Enable(lc.GetItemCount() > 0); |
|---|
| 1932 | } |
|---|
| 1933 | |
|---|
| 1934 | void CSchedulerView::OnEditSelectAll() |
|---|
| 1935 | { |
|---|
| 1936 | SelItemRange(TRUE, 0, -1); |
|---|
| 1937 | } |
|---|
| 1938 | |
|---|
| 1939 | void CSchedulerView::OnEditRefresh() |
|---|
| 1940 | { |
|---|
| 1941 | UpdateList(); |
|---|
| 1942 | } |
|---|
| 1943 | |
|---|
| 1944 | BOOL CSchedulerView::TerminateThread(CScheduleItem *psiItem) |
|---|
| 1945 | { |
|---|
| 1946 | // terminates the thread of a scheduled task |
|---|
| 1947 | |
|---|
| 1948 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 1949 | { |
|---|
| 1950 | try |
|---|
| 1951 | { |
|---|
| 1952 | if (psiItem->IsRunning()) |
|---|
| 1953 | { |
|---|
| 1954 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 1955 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 1956 | |
|---|
| 1957 | CWaitCursor wait; |
|---|
| 1958 | |
|---|
| 1959 | eraserDestroyContext(psiItem->m_ehContext); |
|---|
| 1960 | psiItem->m_ehContext = ERASER_INVALID_CONTEXT; |
|---|
| 1961 | |
|---|
| 1962 | // decrease process counter |
|---|
| 1963 | counterLock(); |
|---|
| 1964 | |
|---|
| 1965 | if (pDoc->m_wProcessCount > 0) |
|---|
| 1966 | pDoc->m_wProcessCount--; |
|---|
| 1967 | |
|---|
| 1968 | counterUnlock(); |
|---|
| 1969 | |
|---|
| 1970 | // log action if desired |
|---|
| 1971 | if (pDoc->m_bLog && !pDoc->m_bLogOnlyErrors) |
|---|
| 1972 | { |
|---|
| 1973 | CString strAction, strData; |
|---|
| 1974 | |
|---|
| 1975 | psiItem->GetData(strData); |
|---|
| 1976 | AfxFormatString1(strAction, IDS_ACTION_STOP, strData); |
|---|
| 1977 | |
|---|
| 1978 | pDoc->LogAction(strAction); |
|---|
| 1979 | } |
|---|
| 1980 | |
|---|
| 1981 | // update task statistics |
|---|
| 1982 | psiItem->GetStatistics()->m_dwTimesInterrupted++; |
|---|
| 1983 | } |
|---|
| 1984 | |
|---|
| 1985 | return TRUE; |
|---|
| 1986 | } |
|---|
| 1987 | catch (...) |
|---|
| 1988 | { |
|---|
| 1989 | counterUnlock(); |
|---|
| 1990 | ASSERT(FALSE); |
|---|
| 1991 | } |
|---|
| 1992 | } |
|---|
| 1993 | |
|---|
| 1994 | return FALSE; |
|---|
| 1995 | } |
|---|
| 1996 | E_UINT8 getMetodId(E_UINT8 old) |
|---|
| 1997 | { |
|---|
| 1998 | E_UINT8 res; |
|---|
| 1999 | old ^= 0x80; |
|---|
| 2000 | for(E_UINT8 i = 0; i < 5; i++) |
|---|
| 2001 | if (1 << i == old) |
|---|
| 2002 | res = i; |
|---|
| 2003 | return res; |
|---|
| 2004 | } |
|---|
| 2005 | |
|---|
| 2006 | BOOL CSchedulerView::RunScheduledTask(CScheduleItem *psiItem) |
|---|
| 2007 | { |
|---|
| 2008 | // starts a scheduled task |
|---|
| 2009 | |
|---|
| 2010 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 2011 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 2012 | |
|---|
| 2013 | try |
|---|
| 2014 | { |
|---|
| 2015 | CString strData; |
|---|
| 2016 | CStringArray saData; |
|---|
| 2017 | int iSize = 0, i; |
|---|
| 2018 | BOOL bResult = FALSE; |
|---|
| 2019 | |
|---|
| 2020 | // stop the timer |
|---|
| 2021 | KillTimer(psiItem->m_uTimerID); |
|---|
| 2022 | |
|---|
| 2023 | // remove from queue |
|---|
| 2024 | RemoveTaskFromQueue(psiItem); |
|---|
| 2025 | |
|---|
| 2026 | // just in case |
|---|
| 2027 | eraserDestroyContext(psiItem->m_ehContext); |
|---|
| 2028 | psiItem->m_ehContext = ERASER_INVALID_CONTEXT; |
|---|
| 2029 | |
|---|
| 2030 | // create context |
|---|
| 2031 | if (eraserOK(eraserCreateContextEx(&psiItem->m_ehContext,/*(ERASER_METHOD)getMetodId(psiItem->m_bMethod)*/psiItem->m_bMethod,psiItem->m_nRndPass,psiItem->m_uEraseItems))) |
|---|
| 2032 | { |
|---|
| 2033 | // get data |
|---|
| 2034 | psiItem->GetData(strData); |
|---|
| 2035 | |
|---|
| 2036 | // set parameters |
|---|
| 2037 | switch (psiItem->GetType()) |
|---|
| 2038 | { |
|---|
| 2039 | case Drive: |
|---|
| 2040 | VERIFY(eraserOK(eraserSetDataType(psiItem->m_ehContext, ERASER_DATA_DRIVES))); |
|---|
| 2041 | if (strData == DRIVE_ALL_LOCAL) |
|---|
| 2042 | GetLocalHardDrives(saData); |
|---|
| 2043 | else |
|---|
| 2044 | saData.Add(strData); |
|---|
| 2045 | |
|---|
| 2046 | iSize = saData.GetSize(); |
|---|
| 2047 | for (i = 0; i < iSize; i++) |
|---|
| 2048 | { |
|---|
| 2049 | VERIFY(eraserOK(eraserAddItem(psiItem->m_ehContext, |
|---|
| 2050 | (LPVOID)(LPCTSTR)saData[i], (E_UINT16)saData[i].GetLength()))); |
|---|
| 2051 | } |
|---|
| 2052 | |
|---|
| 2053 | break; |
|---|
| 2054 | case Folder: |
|---|
| 2055 | { |
|---|
| 2056 | CWaitCursor wait; |
|---|
| 2057 | CStringArray saFolders; |
|---|
| 2058 | |
|---|
| 2059 | VERIFY(eraserOK(eraserSetDataType(psiItem->m_ehContext, ERASER_DATA_FILES))); |
|---|
| 2060 | |
|---|
| 2061 | parseDirectory((LPCTSTR)strData, |
|---|
| 2062 | saData, |
|---|
| 2063 | saFolders, |
|---|
| 2064 | psiItem->Subfolders()); |
|---|
| 2065 | |
|---|
| 2066 | iSize = saData.GetSize(); |
|---|
| 2067 | for (i = 0; i < iSize; i++) |
|---|
| 2068 | { |
|---|
| 2069 | VERIFY(eraserOK(eraserAddItem(psiItem->m_ehContext, |
|---|
| 2070 | (LPVOID)(LPCTSTR)saData[i], (E_UINT16)saData[i].GetLength()))); |
|---|
| 2071 | } |
|---|
| 2072 | |
|---|
| 2073 | } |
|---|
| 2074 | break; |
|---|
| 2075 | case File: |
|---|
| 2076 | if (psiItem->UseWildcards()) |
|---|
| 2077 | { |
|---|
| 2078 | findMatchingFiles(strData, saData, |
|---|
| 2079 | psiItem->WildcardsInSubfolders()); |
|---|
| 2080 | // CString temp; |
|---|
| 2081 | // for(int i = 0; i < saData.GetCount(); i++) { |
|---|
| 2082 | // temp += saData[i]; |
|---|
| 2083 | // temp += "\n"; |
|---|
| 2084 | // } |
|---|
| 2085 | // AfxMessageBox(temp); |
|---|
| 2086 | // return false; |
|---|
| 2087 | } |
|---|
| 2088 | else |
|---|
| 2089 | saData.Add(strData); |
|---|
| 2090 | |
|---|
| 2091 | VERIFY(eraserOK(eraserSetDataType(psiItem->m_ehContext, ERASER_DATA_FILES))); |
|---|
| 2092 | |
|---|
| 2093 | iSize = saData.GetSize(); |
|---|
| 2094 | for (i = 0; i < iSize; i++) |
|---|
| 2095 | { |
|---|
| 2096 | VERIFY(eraserOK(eraserAddItem(psiItem->m_ehContext, |
|---|
| 2097 | (LPVOID)(LPCTSTR)saData[i], (E_UINT16)saData[i].GetLength()))); |
|---|
| 2098 | } |
|---|
| 2099 | break; |
|---|
| 2100 | default: |
|---|
| 2101 | NODEFAULT; |
|---|
| 2102 | }; |
|---|
| 2103 | |
|---|
| 2104 | VERIFY(eraserOK(eraserSetWindow(psiItem->m_ehContext, GetSafeHwnd()))); |
|---|
| 2105 | VERIFY(eraserOK(eraserSetWindowMessage(psiItem->m_ehContext, WM_ERASERNOTIFY))); |
|---|
| 2106 | |
|---|
| 2107 | // start the thread |
|---|
| 2108 | bResult = eraserOK(eraserStart(psiItem->m_ehContext)); |
|---|
| 2109 | |
|---|
| 2110 | if (bResult) |
|---|
| 2111 | { |
|---|
| 2112 | // increase process counter |
|---|
| 2113 | counterLock(); |
|---|
| 2114 | pDoc->m_wProcessCount++; |
|---|
| 2115 | counterUnlock(); |
|---|
| 2116 | |
|---|
| 2117 | // task statistics |
|---|
| 2118 | psiItem->GetStatistics()->m_dwTimes++; |
|---|
| 2119 | psiItem->CalcNextTime(); |
|---|
| 2120 | |
|---|
| 2121 | // log action |
|---|
| 2122 | if (pDoc->m_bLog && !pDoc->m_bLogOnlyErrors) |
|---|
| 2123 | { |
|---|
| 2124 | CString strAction; |
|---|
| 2125 | |
|---|
| 2126 | AfxFormatString1(strAction, IDS_ACTION_RUN, strData); |
|---|
| 2127 | pDoc->LogAction(strAction); |
|---|
| 2128 | } |
|---|
| 2129 | } |
|---|
| 2130 | } |
|---|
| 2131 | |
|---|
| 2132 | // set timer for the next scheduled time |
|---|
| 2133 | if (!SetTimer(psiItem->m_uTimerID, psiItem->GetTimeSpan(), NULL)) |
|---|
| 2134 | { |
|---|
| 2135 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 2136 | AfxTimeOutMessageBox(IDS_ERROR_TIMER, MB_ICONERROR); |
|---|
| 2137 | |
|---|
| 2138 | if (pDoc->m_bLog) |
|---|
| 2139 | pDoc->LogAction(IDS_ERROR_TIMER); |
|---|
| 2140 | } |
|---|
| 2141 | |
|---|
| 2142 | return bResult; |
|---|
| 2143 | } |
|---|
| 2144 | catch (CException *e) |
|---|
| 2145 | { |
|---|
| 2146 | ASSERT(FALSE); |
|---|
| 2147 | counterUnlock(); |
|---|
| 2148 | |
|---|
| 2149 | try |
|---|
| 2150 | { |
|---|
| 2151 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 2152 | { |
|---|
| 2153 | TCHAR szError[255]; |
|---|
| 2154 | e->GetErrorMessage(szError, 255); |
|---|
| 2155 | AfxTimeOutMessageBox(szError, 255); |
|---|
| 2156 | } |
|---|
| 2157 | |
|---|
| 2158 | if (pDoc->m_bLog) |
|---|
| 2159 | pDoc->LogException(e); |
|---|
| 2160 | } |
|---|
| 2161 | catch (...) |
|---|
| 2162 | { |
|---|
| 2163 | } |
|---|
| 2164 | |
|---|
| 2165 | e->Delete(); |
|---|
| 2166 | } |
|---|
| 2167 | |
|---|
| 2168 | return FALSE; |
|---|
| 2169 | } |
|---|
| 2170 | |
|---|
| 2171 | void CSchedulerView::QueueTask(CScheduleItem *psiItem) |
|---|
| 2172 | { |
|---|
| 2173 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 2174 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 2175 | |
|---|
| 2176 | try |
|---|
| 2177 | { |
|---|
| 2178 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 2179 | { |
|---|
| 2180 | if (!psiItem->IsQueued() && !psiItem->IsRunning()) |
|---|
| 2181 | { |
|---|
| 2182 | pDoc->m_paQueuedTasks.Add((LPVOID)psiItem); |
|---|
| 2183 | psiItem->SetQueued(TRUE); |
|---|
| 2184 | } |
|---|
| 2185 | } |
|---|
| 2186 | } |
|---|
| 2187 | catch (CException *e) |
|---|
| 2188 | { |
|---|
| 2189 | ASSERT(FALSE); |
|---|
| 2190 | |
|---|
| 2191 | try |
|---|
| 2192 | { |
|---|
| 2193 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 2194 | { |
|---|
| 2195 | TCHAR szError[255]; |
|---|
| 2196 | e->GetErrorMessage(szError, 255); |
|---|
| 2197 | AfxTimeOutMessageBox(szError, 255); |
|---|
| 2198 | } |
|---|
| 2199 | |
|---|
| 2200 | if (pDoc->m_bLog) |
|---|
| 2201 | pDoc->LogException(e); |
|---|
| 2202 | } |
|---|
| 2203 | catch (...) |
|---|
| 2204 | { |
|---|
| 2205 | } |
|---|
| 2206 | |
|---|
| 2207 | e->Delete(); |
|---|
| 2208 | } |
|---|
| 2209 | } |
|---|
| 2210 | |
|---|
| 2211 | CScheduleItem* CSchedulerView::GetNextQueuedTask() |
|---|
| 2212 | { |
|---|
| 2213 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 2214 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 2215 | |
|---|
| 2216 | try |
|---|
| 2217 | { |
|---|
| 2218 | if (pDoc->m_paQueuedTasks.GetSize() > 0) |
|---|
| 2219 | { |
|---|
| 2220 | CScheduleItem *psiItem = static_cast<CScheduleItem*>(pDoc->m_paQueuedTasks.GetAt(0)); |
|---|
| 2221 | |
|---|
| 2222 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 2223 | return psiItem; |
|---|
| 2224 | else |
|---|
| 2225 | { |
|---|
| 2226 | // remove this task from the list |
|---|
| 2227 | RemoveTaskFromQueue(psiItem); |
|---|
| 2228 | |
|---|
| 2229 | // recursive... until we find one or there are no more |
|---|
| 2230 | // items on the list |
|---|
| 2231 | return GetNextQueuedTask(); |
|---|
| 2232 | } |
|---|
| 2233 | } |
|---|
| 2234 | } |
|---|
| 2235 | catch (CException *e) |
|---|
| 2236 | { |
|---|
| 2237 | ASSERT(FALSE); |
|---|
| 2238 | |
|---|
| 2239 | try |
|---|
| 2240 | { |
|---|
| 2241 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 2242 | { |
|---|
| 2243 | TCHAR szError[255]; |
|---|
| 2244 | e->GetErrorMessage(szError, 255); |
|---|
| 2245 | AfxTimeOutMessageBox(szError, 255); |
|---|
| 2246 | } |
|---|
| 2247 | |
|---|
| 2248 | if (pDoc->m_bLog) |
|---|
| 2249 | pDoc->LogException(e); |
|---|
| 2250 | } |
|---|
| 2251 | catch (...) |
|---|
| 2252 | { |
|---|
| 2253 | } |
|---|
| 2254 | |
|---|
| 2255 | e->Delete(); |
|---|
| 2256 | } |
|---|
| 2257 | |
|---|
| 2258 | return 0; |
|---|
| 2259 | } |
|---|
| 2260 | |
|---|
| 2261 | void CSchedulerView::RemoveTaskFromQueue(CScheduleItem *psiItem) |
|---|
| 2262 | { |
|---|
| 2263 | CEraserDoc *pDoc = static_cast<CEraserDoc*>(GetDocument()); |
|---|
| 2264 | ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc))); |
|---|
| 2265 | |
|---|
| 2266 | try |
|---|
| 2267 | { |
|---|
| 2268 | if (AfxIsValidAddress(psiItem, sizeof(CScheduleItem))) |
|---|
| 2269 | { |
|---|
| 2270 | psiItem->SetQueued(FALSE); |
|---|
| 2271 | |
|---|
| 2272 | CScheduleItem *psiCurrentItem = 0; |
|---|
| 2273 | int iSize = pDoc->m_paQueuedTasks.GetSize(); |
|---|
| 2274 | |
|---|
| 2275 | while (iSize--) |
|---|
| 2276 | { |
|---|
| 2277 | psiCurrentItem = static_cast<CScheduleItem*>(pDoc->m_paQueuedTasks[iSize]); |
|---|
| 2278 | |
|---|
| 2279 | if (psiCurrentItem == psiItem) |
|---|
| 2280 | { |
|---|
| 2281 | pDoc->m_paQueuedTasks.RemoveAt(iSize); |
|---|
| 2282 | pDoc->m_paQueuedTasks.FreeExtra(); |
|---|
| 2283 | break; |
|---|
| 2284 | } |
|---|
| 2285 | } |
|---|
| 2286 | } |
|---|
| 2287 | |
|---|
| 2288 | pDoc->CleanList(pDoc->m_paQueuedTasks, sizeof(CScheduleItem)); |
|---|
| 2289 | } |
|---|
| 2290 | catch (CException *e) |
|---|
| 2291 | { |
|---|
| 2292 | ASSERT(FALSE); |
|---|
| 2293 | |
|---|
| 2294 | try |
|---|
| 2295 | { |
|---|
| 2296 | if (!pDoc->m_bNoVisualErrors) |
|---|
| 2297 | { |
|---|
| 2298 | TCHAR szError[255]; |
|---|
| 2299 | e->GetErrorMessage(szError, 255); |
|---|
| 2300 | AfxTimeOutMessageBox(szError, 255); |
|---|
| 2301 | } |
|---|
| 2302 | |
|---|
| 2303 | if (pDoc->m_bLog) |
|---|
| 2304 | pDoc->LogException(e); |
|---|
| 2305 | } |
|---|
| 2306 | catch (...) |
|---|
| 2307 | { |
|---|
| 2308 | } |
|---|
| 2309 | |
|---|
| 2310 | e->Delete(); |
|---|
| 2311 | } |
|---|
| 2312 | } |
|---|