Changeset 34
- Timestamp:
- 10/11/2007 12:33:16 PM (6 years ago)
- Location:
- trunk/Launcher
- Files:
-
- 2 edited
-
Launcher.cpp (modified) (4 diffs)
-
Launcher.vcproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Launcher/Launcher.cpp
r23 r34 24 24 #include "stdafx.h" 25 25 #include "..\EraserDll\EraserDll.h" 26 #include "..\EraserDll\FileLockResolver.h" 26 27 #include "..\EraserUI\DriveCombo.h" 28 #include "..\EraserUI\VisualStyles.h" 27 29 #include "..\shared\FileHelper.h" 28 30 #include "..\shared\UserInfo.h" 29 #include "..\EraserDll\FileLockResolver.h" 31 #include "..\shared\Key.h" 32 30 33 #include "Launcher.h" 31 34 #include "ConfirmDialog.h" 32 35 #include "LauncherDlg.h" 36 33 37 #include <exception> 34 38 #ifdef _DEBUG … … 288 292 BOOL CLauncherApp::InitInstance() 289 293 { 290 // Standard initialization291 // If you are not using these features and wish to reduce the size292 // of your final executable, you should remove from the following293 // the specific initialization routines you do not need.294 eraserInit();295 296 CString strCmdLine(m_lpCmdLine);297 CString strCurrentParameter;298 299 BOOL bIncorrectParameter = FALSE;300 BOOL bSilent = FALSE;301 BOOL bResults = FALSE;302 BOOL bResultsOnError = FALSE;303 BOOL bOptions = FALSE;304 BOOL bQueue = FALSE;305 306 CString strData;307 CStringArray saFiles;308 BOOL bFiles = FALSE;309 BOOL bFolders = FALSE;310 BOOL bSubFolders = FALSE;311 BOOL bKeepFolder = FALSE;312 BOOL bDrive = FALSE;313 BOOL bRecycled = FALSE;294 // Standard initialization 295 // If you are not using these features and wish to reduce the size 296 // of your final executable, you should remove from the following 297 // the specific initialization routines you do not need. 298 eraserInit(); 299 300 CString strCmdLine(m_lpCmdLine); 301 CString strCurrentParameter; 302 303 BOOL bIncorrectParameter = FALSE; 304 BOOL bSilent = FALSE; 305 BOOL bResults = -1; 306 BOOL bResultsOnError = -1; 307 BOOL bOptions = FALSE; 308 BOOL bQueue = FALSE; 309 310 CString strData; 311 CStringArray saFiles; 312 BOOL bFiles = FALSE; 313 BOOL bFolders = FALSE; 314 BOOL bSubFolders = FALSE; 315 BOOL bKeepFolder = FALSE; 316 BOOL bDrive = FALSE; 317 BOOL bRecycled = FALSE; 314 318 BOOL bResolveLock = FALSE; 315 319 316 ERASER_METHOD emMethod = ERASER_METHOD_PSEUDORANDOM /*ERASER_METHOD_LIBRARY*/; 317 E_UINT16 uPasses = 1; 318 319 if (!strCmdLine.IsEmpty()) 320 { 321 while (GetNextParameter(strCmdLine, strCurrentParameter)) 322 { 323 if (strCurrentParameter.CompareNoCase(szFile) == 0 && 324 strData.IsEmpty()) 325 { 326 // file 327 328 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 329 bIncorrectParameter = TRUE; 330 else 331 { 332 strData = strCurrentParameter; 333 bFiles = TRUE; 334 } 335 } 336 else if (strCurrentParameter.CompareNoCase(szResolveLock) == 0 && 320 ERASER_METHOD emMethod = ERASER_METHOD_PSEUDORANDOM /*ERASER_METHOD_LIBRARY*/; 321 E_UINT16 uPasses = 1; 322 323 if (!strCmdLine.IsEmpty()) 324 { 325 while (GetNextParameter(strCmdLine, strCurrentParameter)) 326 { 327 if (strCurrentParameter.CompareNoCase(szFile) == 0 && 337 328 strData.IsEmpty()) 338 329 { 330 // file 331 339 332 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 340 333 bIncorrectParameter = TRUE; … … 342 335 { 343 336 strData = strCurrentParameter; 337 bFiles = TRUE; 338 } 339 } 340 else if (strCurrentParameter.CompareNoCase(szResolveLock) == 0 && 341 strData.IsEmpty()) 342 { 343 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 344 bIncorrectParameter = TRUE; 345 else 346 { 347 strData = strCurrentParameter; 344 348 bResolveLock = TRUE; 345 349 } 346 350 } 347 else if (strCurrentParameter.CompareNoCase(szFolder) == 0 && 348 strData.IsEmpty()) 349 { 350 // folder 351 352 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 353 bIncorrectParameter = TRUE; 354 else 355 { 356 strData = strCurrentParameter; 357 bFiles = TRUE; 358 bFolders = TRUE; 359 360 if (strData[strData.GetLength() - 1] != '\\') 361 strData += "\\"; 362 } 363 } 364 else if (strCurrentParameter.CompareNoCase(szDisk) == 0 && 365 strData.IsEmpty()) 366 { 367 // unused disk space 368 369 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 370 bIncorrectParameter = TRUE; 371 else 372 { 373 bDrive = TRUE; 374 375 if (strCurrentParameter != szDiskAll) 376 strData.Format("%c:\\", strCurrentParameter[0]); 377 else 378 strData = strCurrentParameter; 379 } 380 } 381 else if (strCurrentParameter.CompareNoCase(szRecycled) == 0) 382 { 383 bRecycled = TRUE; 384 bFiles = TRUE; 385 bFolders = FALSE; 386 } 387 else if (strCurrentParameter.CompareNoCase(szMethod) == 0) 388 { 389 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 390 bIncorrectParameter = TRUE; 391 else 392 { 393 if (strCurrentParameter.CompareNoCase(szMethodLibrary) == 0) 394 emMethod = ERASER_METHOD_LIBRARY; 395 else if (strCurrentParameter.CompareNoCase(szMethodGutmann) == 0) 396 emMethod = ERASER_METHOD_GUTMANN; 397 else if (strCurrentParameter.CompareNoCase(szMethodDoD) == 0) 398 emMethod = ERASER_METHOD_DOD; 399 else if (strCurrentParameter.CompareNoCase(szMethodDoD_E) == 0) 400 emMethod = ERASER_METHOD_DOD_E; 401 else if (strCurrentParameter.CompareNoCase(szMethodFL2K) == 0) 402 emMethod = ERASER_METHOD_FIRST_LAST_2KB; 403 else if (strCurrentParameter.CompareNoCase(szSchneier) == 0) 404 emMethod = ERASER_METHOD_SCHNEIER; 405 else if (strCurrentParameter.CompareNoCase(szMethodRandom) == 0) 406 { 407 emMethod = ERASER_METHOD_PSEUDORANDOM; 408 409 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 410 bIncorrectParameter = TRUE; 411 else 412 { 413 char *sztmp = 0; 414 E_UINT32 uCurrentParameter = strtoul((LPCTSTR)strCurrentParameter, &sztmp, 10); 415 416 if (*sztmp != '\0' || uCurrentParameter > (E_UINT16)-1) { 417 bIncorrectParameter = TRUE; 418 } else { 419 uPasses = (E_UINT16)uCurrentParameter; 420 } 421 } 422 } 423 else 424 bIncorrectParameter = TRUE; 425 } 426 } 427 else if (strCurrentParameter.CompareNoCase(szSubFolders) == 0) 428 bSubFolders = TRUE; 429 else if (strCurrentParameter.CompareNoCase(szKeepFolder) == 0) 430 bKeepFolder = TRUE; 431 else if (strCurrentParameter.CompareNoCase(szSilent) == 0) 432 bSilent = TRUE; 433 else if (strCurrentParameter.CompareNoCase(szResults) == 0) 434 bResults = TRUE; 435 else if (strCurrentParameter.CompareNoCase(szResultsOnError) == 0) 436 { 437 bResults = TRUE; 438 bResultsOnError = TRUE; 439 } 440 else if (strCurrentParameter.CompareNoCase(szOptions) == 0) 441 bOptions = TRUE; 442 else if (strCurrentParameter.CompareNoCase(szQueue) == 0) 443 bQueue = TRUE; 444 else 445 bIncorrectParameter = TRUE; 446 } 447 } 448 else 449 { 450 bIncorrectParameter = TRUE; 451 } 452 453 // conflicting command line parameters ? 454 455 if (((!bOptions && !bRecycled) && strData.IsEmpty()) || // no data! 456 (!bFolders && bKeepFolder) || // data not a folder 457 (bSilent && bResults) || // no windows 458 (bOptions && bQueue)) // why queue the options? 459 { 460 bIncorrectParameter = TRUE; 461 } 462 463 if (bIncorrectParameter) 464 { 465 AfxMessageBox(IDS_CMDLINE_INCORRECT, MB_ICONERROR, 0); 466 return FALSE; 467 } 468 469 try 470 { 471 m_pdlgEraser = new CLauncherDlg(); 472 m_pMainWnd = m_pdlgEraser; 473 474 if (!m_pdlgEraser->Create(IDD_LAUNCHER_DIALOG)) 475 { 476 AfxMessageBox(IDS_ERROR_DIALOG, MB_ICONERROR, 0); 477 return FALSE; 478 } 479 480 if (bOptions) 481 { 482 m_pdlgEraser->Options(); 483 return FALSE; 484 } 485 else 486 { 487 HandleQueue(bQueue); 351 else if (strCurrentParameter.CompareNoCase(szFolder) == 0 && 352 strData.IsEmpty()) 353 { 354 // folder 355 356 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 357 bIncorrectParameter = TRUE; 358 else 359 { 360 strData = strCurrentParameter; 361 bFiles = TRUE; 362 bFolders = TRUE; 363 364 if (strData[strData.GetLength() - 1] != '\\') 365 strData += "\\"; 366 } 367 } 368 else if (strCurrentParameter.CompareNoCase(szDisk) == 0 && 369 strData.IsEmpty()) 370 { 371 // unused disk space 372 373 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 374 bIncorrectParameter = TRUE; 375 else 376 { 377 bDrive = TRUE; 378 379 if (strCurrentParameter != szDiskAll) 380 strData.Format("%c:\\", strCurrentParameter[0]); 381 else 382 strData = strCurrentParameter; 383 } 384 } 385 else if (strCurrentParameter.CompareNoCase(szRecycled) == 0) 386 { 387 bRecycled = TRUE; 388 bFiles = TRUE; 389 bFolders = FALSE; 390 } 391 else if (strCurrentParameter.CompareNoCase(szMethod) == 0) 392 { 393 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 394 bIncorrectParameter = TRUE; 395 else 396 { 397 if (strCurrentParameter.CompareNoCase(szMethodLibrary) == 0) 398 emMethod = ERASER_METHOD_LIBRARY; 399 else if (strCurrentParameter.CompareNoCase(szMethodGutmann) == 0) 400 emMethod = ERASER_METHOD_GUTMANN; 401 else if (strCurrentParameter.CompareNoCase(szMethodDoD) == 0) 402 emMethod = ERASER_METHOD_DOD; 403 else if (strCurrentParameter.CompareNoCase(szMethodDoD_E) == 0) 404 emMethod = ERASER_METHOD_DOD_E; 405 else if (strCurrentParameter.CompareNoCase(szMethodFL2K) == 0) 406 emMethod = ERASER_METHOD_FIRST_LAST_2KB; 407 else if (strCurrentParameter.CompareNoCase(szSchneier) == 0) 408 emMethod = ERASER_METHOD_SCHNEIER; 409 else if (strCurrentParameter.CompareNoCase(szMethodRandom) == 0) 410 { 411 emMethod = ERASER_METHOD_PSEUDORANDOM; 412 413 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 414 bIncorrectParameter = TRUE; 415 else 416 { 417 char *sztmp = 0; 418 E_UINT32 uCurrentParameter = strtoul((LPCTSTR)strCurrentParameter, &sztmp, 10); 419 420 if (*sztmp != '\0' || uCurrentParameter > (E_UINT16)-1) { 421 bIncorrectParameter = TRUE; 422 } else { 423 uPasses = (E_UINT16)uCurrentParameter; 424 } 425 } 426 } 427 else 428 bIncorrectParameter = TRUE; 429 } 430 } 431 else if (strCurrentParameter.CompareNoCase(szSubFolders) == 0) 432 bSubFolders = TRUE; 433 else if (strCurrentParameter.CompareNoCase(szKeepFolder) == 0) 434 bKeepFolder = TRUE; 435 else if (strCurrentParameter.CompareNoCase(szSilent) == 0) 436 bSilent = TRUE; 437 else if (strCurrentParameter.CompareNoCase(szResults) == 0) 438 bResults = TRUE; 439 else if (strCurrentParameter.CompareNoCase(szResultsOnError) == 0) 440 { 441 bResults = TRUE; 442 bResultsOnError = TRUE; 443 } 444 else if (strCurrentParameter.CompareNoCase(szOptions) == 0) 445 bOptions = TRUE; 446 else if (strCurrentParameter.CompareNoCase(szQueue) == 0) 447 bQueue = TRUE; 448 else 449 bIncorrectParameter = TRUE; 450 } 451 } 452 else 453 { 454 bIncorrectParameter = TRUE; 455 } 456 457 // conflicting command line parameters ? 458 if (((!bOptions && !bRecycled) && strData.IsEmpty()) || // no data! 459 (!bFolders && bKeepFolder) || // data not a folder 460 (bSilent && bResults) || // no windows 461 (bOptions && bQueue) || // why queue the options? 462 bIncorrectParameter) 463 { 464 AfxMessageBox(IDS_CMDLINE_INCORRECT, MB_ICONERROR, 0); 465 return FALSE; 466 } 467 468 //Now that the command line has been passed, check if we should display the 469 //results dialog (because it may not be overridde by the user) 470 CKey kReg; 471 kReg.Open(HKEY_CURRENT_USER, ERASER_REGISTRY_BASE); 472 if (bResults == -1) 473 kReg.GetValue(bResults, ERASER_REGISTRY_RESULTS_FILES, TRUE); 474 if (bResultsOnError == -1) 475 kReg.GetValue(bResultsOnError, ERASER_REGISTRY_RESULTS_WHENFAILED, FALSE); 476 477 try 478 { 479 m_pdlgEraser = new CLauncherDlg(); 480 m_pMainWnd = m_pdlgEraser; 481 482 if (!m_pdlgEraser->Create(IDD_LAUNCHER_DIALOG)) 483 { 484 AfxMessageBox(IDS_ERROR_DIALOG, MB_ICONERROR, 0); 485 return FALSE; 486 } 487 488 if (bOptions) 489 { 490 m_pdlgEraser->Options(); 491 return FALSE; 492 } 493 else 494 { 495 HandleQueue(bQueue); 488 496 if (bResolveLock) 489 497 { … … 494 502 catch (const std::exception& ee) 495 503 { 496 ee.what(); 497 } 498 504 AfxMessageBox(ee.what(), MB_ICONERROR); 505 } 499 506 } 500 507 501 if (bFiles && !bFolders)502 {503 if (!bRecycled)504 findMatchingFiles(strData, saFiles, bSubFolders);505 else506 {507 LocateRecycledItems(saFiles, m_pdlgEraser->m_saFolders);508 509 if (saFiles.GetSize() > 0 && !bSilent)510 {511 CConfirmDialog cd(m_pdlgEraser);512 513 if (cd.DoModal() != IDOK)514 return FALSE;515 }516 }517 }518 else519 {520 if (bDrive || GetFileAttributes((LPCTSTR)strData) != (DWORD)-1)521 saFiles.Add(strData);522 }523 524 if (saFiles.GetSize() > 0 || m_pdlgEraser->m_saFolders.GetSize() > 0)525 {526 if (!bSilent)527 m_pdlgEraser->ShowWindow(SW_SHOW);528 else529 m_pdlgEraser->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);530 531 m_pdlgEraser->m_saFiles.Copy(saFiles);532 m_pdlgEraser->m_bResults = bResults;533 m_pdlgEraser->m_bResultsOnError = bResultsOnError;534 m_pdlgEraser->m_bUseFiles = bFiles || bResolveLock;535 m_pdlgEraser->m_bUseEmptySpace = bDrive;536 m_pdlgEraser->m_bFolders = bFolders;537 m_pdlgEraser->m_bSubFolders = bSubFolders;538 m_pdlgEraser->m_bKeepFolder = bKeepFolder;539 m_pdlgEraser->m_bRecycled = bRecycled;540 m_pdlgEraser->m_emMethod = emMethod;541 m_pdlgEraser->m_uPasses = uPasses;542 543 return m_pdlgEraser->Erase();544 }545 else if (!bSilent)546 {547 if (bRecycled)548 AfxMessageBox("Recycle Bin is empty.", MB_ICONERROR);549 else550 AfxMessageBox("File not found. Nothing to erase. (" + strData + ")", MB_ICONERROR);551 }552 }553 }554 catch (CException *e)555 {556 ASSERT(FALSE);557 e->ReportError(MB_ICONERROR);558 e->Delete();559 }560 catch (...)561 {562 ASSERT(FALSE);563 }564 565 return FALSE;508 if (bFiles && !bFolders) 509 { 510 if (!bRecycled) 511 findMatchingFiles(strData, saFiles, bSubFolders); 512 else 513 { 514 LocateRecycledItems(saFiles, m_pdlgEraser->m_saFolders); 515 516 if (saFiles.GetSize() > 0 && !bSilent) 517 { 518 CConfirmDialog cd(m_pdlgEraser); 519 520 if (cd.DoModal() != IDOK) 521 return FALSE; 522 } 523 } 524 } 525 else 526 { 527 if (bDrive || GetFileAttributes((LPCTSTR)strData) != (DWORD)-1) 528 saFiles.Add(strData); 529 } 530 531 if (saFiles.GetSize() > 0 || m_pdlgEraser->m_saFolders.GetSize() > 0) 532 { 533 if (!bSilent) 534 m_pdlgEraser->ShowWindow(SW_SHOW); 535 else 536 m_pdlgEraser->GetDlgItem(IDCANCEL)->EnableWindow(FALSE); 537 538 m_pdlgEraser->m_saFiles.Copy(saFiles); 539 m_pdlgEraser->m_bResults = bResults; 540 m_pdlgEraser->m_bResultsOnError = bResultsOnError; 541 m_pdlgEraser->m_bUseFiles = bFiles || bResolveLock; 542 m_pdlgEraser->m_bUseEmptySpace = bDrive; 543 m_pdlgEraser->m_bFolders = bFolders; 544 m_pdlgEraser->m_bSubFolders = bSubFolders; 545 m_pdlgEraser->m_bKeepFolder = bKeepFolder; 546 m_pdlgEraser->m_bRecycled = bRecycled; 547 m_pdlgEraser->m_emMethod = emMethod; 548 m_pdlgEraser->m_uPasses = uPasses; 549 550 return m_pdlgEraser->Erase(); 551 } 552 else if (!bSilent) 553 { 554 if (bRecycled) 555 AfxMessageBox("Recycle Bin is empty.", MB_ICONERROR); 556 else 557 AfxMessageBox("File not found. Nothing to erase. (" + strData + ")", MB_ICONERROR); 558 } 559 } 560 } 561 catch (CException *e) 562 { 563 ASSERT(FALSE); 564 e->ReportError(MB_ICONERROR); 565 e->Delete(); 566 } 567 catch (...) 568 { 569 ASSERT(FALSE); 570 } 571 572 return FALSE; 566 573 } 567 574 -
trunk/Launcher/Launcher.vcproj
r24 r34 488 488 </File> 489 489 <File 490 RelativePath="..\shared\key.cpp" 491 > 492 </File> 493 <File 490 494 RelativePath="Launcher.cpp" 491 495 >
Note: See TracChangeset
for help on using the changeset viewer.
