Changeset 61 for trunk/Launcher/Launcher.cpp
- Timestamp:
- 10/15/2007 11:18:28 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/Launcher/Launcher.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Launcher/Launcher.cpp
r53 r61 289 289 ///////////////////////////////////////////////////////////////////////////// 290 290 // CLauncherApp initialization 291 void ShowHelp(const CString& message = "") 292 { 293 CString msg; 294 msg.LoadString(AfxGetInstanceHandle(), IDS_CMDLINE_INCORRECT); 295 AfxMessageBox(message + msg, MB_ICONERROR, 0); 296 } 291 297 292 298 BOOL CLauncherApp::InitInstance() … … 294 300 // Standard initialization 295 301 // If you are not using these features and wish to reduce the size 296 // of your final executable, you should remove from the following297 // the specific initialization routines you do not need.302 // of your final executable, you should remove from the following 303 // the specific initialization routines you do not need. 298 304 eraserInit(); 299 305 … … 301 307 CString strCurrentParameter; 302 308 303 BOOL bIncorrectParameter = FALSE;304 309 BOOL bSilent = FALSE; 305 310 BOOL bResults = -1; … … 321 326 E_UINT16 uPasses = 1; 322 327 323 if (!strCmdLine.IsEmpty()) 328 // Declare an "Invalid command line" exception 329 class InvalidCommandLineException : public std::exception 324 330 { 325 while (GetNextParameter(strCmdLine, strCurrentParameter)) 326 { 327 if (strCurrentParameter.CompareNoCase(szFile) == 0 && 328 strData.IsEmpty()) 331 public: 332 InvalidCommandLineException(const CString& msg) 333 : Message(msg) 334 { 335 chrBuf = NULL; 336 } 337 338 ~InvalidCommandLineException() 339 { 340 delete[] chrBuf; 341 } 342 343 virtual const char* what() const 344 { 345 if (!chrBuf) 329 346 { 330 // file 331 332 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 333 bIncorrectParameter = TRUE; 334 else 335 { 336 strData = strCurrentParameter; 337 bFiles = TRUE; 338 } 347 CString msg = Message; 348 chrBuf = new char[msg.GetLength()]; 349 strcpy(chrBuf, msg.GetBuffer()); 350 msg.ReleaseBuffer(); 339 351 } 340 else if (strCurrentParameter.CompareNoCase(szResolveLock) == 0 && 341 strData.IsEmpty()) 352 return chrBuf; 353 } 354 355 private: 356 mutable char* chrBuf; 357 CString Message; 358 }; 359 360 try 361 { 362 if (!strCmdLine.IsEmpty()) 363 { 364 while (GetNextParameter(strCmdLine, strCurrentParameter)) 342 365 { 343 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 344 bIncorrectParameter = TRUE; 345 else 346 { 347 strData = strCurrentParameter; 348 bResolveLock = TRUE; 349 } 350 } 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]); 366 if (strCurrentParameter.CompareNoCase(szFile) == 0 && 367 strData.IsEmpty()) 368 { 369 // file 370 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 371 throw InvalidCommandLineException("-file was specified but no file name was given."); 381 372 else 373 { 382 374 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) 375 bFiles = TRUE; 376 } 377 } 378 else if (strCurrentParameter.CompareNoCase(szResolveLock) == 0 && 379 strData.IsEmpty()) 380 { 381 // resolve locked files 382 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 383 throw InvalidCommandLineException("-rl was specified but no file name was given."); 384 else 410 385 { 411 emMethod = ERASER_METHOD_PSEUDORANDOM; 412 413 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 414 bIncorrectParameter = TRUE; 386 strData = strCurrentParameter; 387 bResolveLock = TRUE; 388 } 389 } 390 else if (strCurrentParameter.CompareNoCase(szFolder) == 0 && 391 strData.IsEmpty()) 392 { 393 // folder 394 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 395 throw InvalidCommandLineException("-folder was specified but no folder name was given."); 396 else 397 { 398 strData = strCurrentParameter; 399 bFiles = TRUE; 400 bFolders = TRUE; 401 402 if (strData[strData.GetLength() - 1] != '\\') 403 strData += "\\"; 404 } 405 } 406 else if (strCurrentParameter.CompareNoCase(szDisk) == 0 && 407 strData.IsEmpty()) 408 { 409 // unused disk space 410 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 411 throw InvalidCommandLineException("-disk was specified but no file name was given."); 412 else 413 { 414 bDrive = TRUE; 415 416 if (strCurrentParameter != szDiskAll) 417 strData.Format("%c:\\", strCurrentParameter[0]); 415 418 else 419 strData = strCurrentParameter; 420 } 421 } 422 else if (strCurrentParameter.CompareNoCase(szRecycled) == 0) 423 { 424 bRecycled = TRUE; 425 bFiles = TRUE; 426 bFolders = FALSE; 427 } 428 else if (strCurrentParameter.CompareNoCase(szMethod) == 0) 429 { 430 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 431 throw InvalidCommandLineException("-method was specified but no method name was given."); 432 else 433 { 434 if (strCurrentParameter.CompareNoCase(szMethodLibrary) == 0) 435 emMethod = ERASER_METHOD_LIBRARY; 436 else if (strCurrentParameter.CompareNoCase(szMethodGutmann) == 0) 437 emMethod = ERASER_METHOD_GUTMANN; 438 else if (strCurrentParameter.CompareNoCase(szMethodDoD) == 0) 439 emMethod = ERASER_METHOD_DOD; 440 else if (strCurrentParameter.CompareNoCase(szMethodDoD_E) == 0) 441 emMethod = ERASER_METHOD_DOD_E; 442 else if (strCurrentParameter.CompareNoCase(szMethodFL2K) == 0) 443 emMethod = ERASER_METHOD_FIRST_LAST_2KB; 444 else if (strCurrentParameter.CompareNoCase(szSchneier) == 0) 445 emMethod = ERASER_METHOD_SCHNEIER; 446 else if (strCurrentParameter.CompareNoCase(szMethodRandom) == 0) 416 447 { 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; 448 emMethod = ERASER_METHOD_PSEUDORANDOM; 449 450 if (!GetNextParameter(strCmdLine, strCurrentParameter)) 451 throw InvalidCommandLineException("-method Random was specified but no number of passes was specified."); 452 else 453 { 454 char *sztmp = 0; 455 E_UINT32 uCurrentParameter = strtoul((LPCTSTR)strCurrentParameter, &sztmp, 10); 456 457 if (*sztmp != '\0' || uCurrentParameter > (E_UINT16)-1) { 458 throw InvalidCommandLineException("-method Random was specified an invalid number of passes was specified."); 459 } else { 460 uPasses = (E_UINT16)uCurrentParameter; 461 } 424 462 } 425 463 } 464 else 465 throw InvalidCommandLineException("Unrecognized method name '" + strCurrentParameter + "'"); 426 466 } 427 else 428 bIncorrectParameter = TRUE; 429 } 467 } 468 else if (strCurrentParameter.CompareNoCase(szSubFolders) == 0) 469 bSubFolders = TRUE; 470 else if (strCurrentParameter.CompareNoCase(szKeepFolder) == 0) 471 bKeepFolder = TRUE; 472 else if (strCurrentParameter.CompareNoCase(szSilent) == 0) 473 bSilent = TRUE; 474 else if (strCurrentParameter.CompareNoCase(szResults) == 0) 475 bResults = TRUE; 476 else if (strCurrentParameter.CompareNoCase(szResultsOnError) == 0) 477 { 478 bResults = TRUE; 479 bResultsOnError = TRUE; 480 } 481 else if (strCurrentParameter.CompareNoCase(szOptions) == 0) 482 bOptions = TRUE; 483 else if (strCurrentParameter.CompareNoCase(szQueue) == 0) 484 bQueue = TRUE; 485 else 486 throw InvalidCommandLineException("Unrecognized parameter '" + strCurrentParameter + "'"); 430 487 } 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 // is the user naive enough to select the first/last 2KB pass with free space? 469 if (emMethod == ERASER_METHOD_FIRST_LAST_2KB && bDrive) 470 { 471 AfxMessageBox("The first/last 2KB erase cannot be used with Free Space erases.", MB_ICONERROR); 472 return FALSE; 473 } 474 475 //Now that the command line has been passed, check if we should display the 476 //results dialog (because it may not be overridde by the user) 477 CKey kReg; 478 if (kReg.Open(HKEY_CURRENT_USER, ERASER_REGISTRY_BASE)) 479 { 480 if (bResults == -1) 481 kReg.GetValue(bResults, ERASER_REGISTRY_RESULTS_FILES, TRUE); 482 if (bResultsOnError == -1) 483 kReg.GetValue(bResultsOnError, ERASER_REGISTRY_RESULTS_WHENFAILED, FALSE); 484 kReg.Close(); 485 } 486 487 try 488 { 488 } 489 else 490 { 491 throw InvalidCommandLineException("Invalid command line."); 492 } 493 494 // conflicting command line parameters ? 495 if (((!bOptions && !bRecycled) && strData.IsEmpty())) 496 throw InvalidCommandLineException("No data to erase."); 497 if (!bFolders && bKeepFolder) 498 throw InvalidCommandLineException("Data to erase is not a folder, -keepfolder has no effect."); 499 if (bSilent && bResults) 500 throw InvalidCommandLineException("-silent and -results are mutually exclusive."); 501 if (bOptions && bQueue) 502 throw InvalidCommandLineException("The help command cannot be queued."); 503 504 // is the user naive enough to select the first/last 2KB pass with free space? 505 if (emMethod == ERASER_METHOD_FIRST_LAST_2KB && bDrive) 506 { 507 AfxMessageBox("The first/last 2KB erase cannot be used with Free Space erases.", MB_ICONERROR); 508 return FALSE; 509 } 510 511 //Now that the command line has been passed, check if we should display the 512 //results dialog (because it may not be overridde by the user) 513 CKey kReg; 514 if (kReg.Open(HKEY_CURRENT_USER, ERASER_REGISTRY_BASE)) 515 { 516 if (bResults == -1) 517 kReg.GetValue(bResults, ERASER_REGISTRY_RESULTS_FILES, TRUE); 518 if (bResultsOnError == -1) 519 kReg.GetValue(bResultsOnError, ERASER_REGISTRY_RESULTS_WHENFAILED, FALSE); 520 kReg.Close(); 521 } 522 489 523 m_pdlgEraser = new CLauncherDlg(); 490 524 m_pMainWnd = m_pdlgEraser; … … 569 603 } 570 604 } 605 } 606 catch (InvalidCommandLineException& e) 607 { 608 ShowHelp(CString(e.what()) + "\n\n"); 571 609 } 572 610 catch (CException *e)
Note: See TracChangeset
for help on using the changeset viewer.
