Changeset 55
- Timestamp:
- 10/13/2007 11:12:51 AM (6 years ago)
- Location:
- trunk/EraserDll
- Files:
-
- 2 edited
-
FileLockResolver.cpp (modified) (11 diffs)
-
FileLockResolver.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/EraserDll/FileLockResolver.cpp
r52 r55 35 35 36 36 CFileLockResolver::CFileLockResolver(BOOL askUser) 37 : m_bAskUser(askUser), m_hHandle(ERASER_INVALID_CONTEXT) 37 : m_bAskUser(askUser), m_hHandle(ERASER_INVALID_CONTEXT), 38 m_iMethod(0), m_iPasses(0) 38 39 { 39 40 … … 41 42 42 43 CFileLockResolver::CFileLockResolver(ERASER_HANDLE h, BOOL askUser) 43 : m_bAskUser(askUser) 44 : m_bAskUser(askUser), m_iMethod(0), m_iPasses(0) 44 45 { 45 46 SetHandle(h); 47 } 48 49 CFileLockResolver::~CFileLockResolver(void) 50 { 51 Close(); 46 52 } 47 53 … … 52 58 } 53 59 54 CFileLockResolver::~CFileLockResolver(void) 55 { 56 Close(); 57 } 58 59 struct PathHelper 60 { 61 CString& m_strLockFile; 62 PathHelper(CString& lockFile, bool path_only = false) 63 :m_strLockFile(lockFile) 64 { 65 char fullname[MAX_PATH]; 66 char filename[MAX_PATH]; 67 char extension[MAX_PATH]; 68 char pathname[MAX_PATH]; 69 char drive[10]; 70 71 GetModuleFileName(AfxGetInstanceHandle(),fullname,sizeof (fullname)); 72 _splitpath(fullname,drive, pathname, filename, extension); 73 74 m_strLockFile = drive; 75 m_strLockFile += pathname; 76 if (path_only ) 77 return; 78 m_strLockFile.Format("%s%s%d.%s", drive, pathname, time(0), LOCKED_FILE_LIST_NAME); 79 } 80 }; 60 CString CFileLockResolver::GetLockFilePath(bool path_only) 61 { 62 // Retrieve the path to the current binary 63 char fullname[MAX_PATH]; 64 GetModuleFileName(AfxGetInstanceHandle(), fullname, sizeof(fullname)); 65 66 // Then separate the path into its constituent parts 67 char filename[MAX_PATH]; 68 char extension[MAX_PATH]; 69 char pathname[MAX_PATH]; 70 char drive[10]; 71 _splitpath(fullname, drive, pathname, filename, extension); 72 73 // Then generate the path which we want 74 CString result; 75 if (path_only) 76 result.Format("%s%s", drive, pathname); 77 else 78 result.Format("%s%s%d.%s", drive, pathname, time(0), LOCKED_FILE_LIST_NAME); 79 return result; 80 } 81 81 82 82 struct FileData … … 91 91 92 92 FileData(const std::string& fname, int m, unsigned int pass) 93 : name(fname), method(m), passes(pass)93 : name(fname), method(m), passes(pass) 94 94 { 95 95 } … … 99 99 is >> std::noskipws; 100 100 std::getline(is, name); 101 is >> method >> passes; 101 102 } 102 103 … … 104 105 { 105 106 os << std::noskipws; 106 os << name << std::endl ;107 os << name << std::endl << method << passes; 107 108 } 108 109 }; … … 113 114 return os; 114 115 } 116 115 117 std::istream& operator>> (std::istream& is, FileData& data) 116 118 { … … 119 121 } 120 122 121 void CFileLockResolver::HandleError(LPCTSTR szFileName, DWORD dwErrorCode, int em, unsigned int passes)123 void CFileLockResolver::HandleError(LPCTSTR szFileName, DWORD dwErrorCode, int method, unsigned int passes) 122 124 { 123 125 if (ERROR_LOCK_VIOLATION == dwErrorCode … … 128 130 if (TRUE == m_bAskUser) 129 131 { 130 if (IDYES == Afx GetMainWnd()->MessageBox(CString("The file ") +132 if (IDYES == AfxMessageBox(CString("The file ") + 131 133 szFileName + "\nis locked by another process. Do you want to Erase the file after " + 132 "you restart your computer?", "File Access Denied", MB_YESNO | MB_ICONQUESTION | MB_TASKMODAL))134 "you restart your computer?", MB_YESNO | MB_ICONQUESTION)) 133 135 { 134 static PathHelper path(m_strLockFileList); 136 if (m_strLockFileList.IsEmpty()) 137 m_strLockFileList = GetLockFilePath(); 135 138 std::ofstream os(m_strLockFileList, std::ios_base::out | std::ios_base::app); 136 os << FileData(szFileName, em, passes); 139 os << FileData(szFileName, method, passes); 140 141 ASSERT(m_iMethod == 0 || m_iMethod == method); 142 ASSERT(m_iPasses == 0 || m_iPasses == passes); 143 m_iMethod = method; 144 m_iPasses = passes; 137 145 } 138 146 } … … 168 176 { 169 177 eraserSetErrorHandler(m_hHandle, NULL, NULL); 170 171 178 if (m_strLockFileList.IsEmpty()) 172 179 return; 173 180 174 CString strPath; 175 PathHelper(strPath, true); 176 strPath = CString("\"") + strPath + LAUNCHER + "\" " + szResolveLock; 177 strPath += " \"" + m_strLockFileList + "\""; 181 //Using the method and the passes, generate a command line that will do the same thing as it does now. 182 CString method; 183 switch (m_iMethod) 184 { 185 case GUTMANN_METHOD_ID: 186 method = "Gutmann"; 187 break; 188 case DOD_METHOD_ID: 189 method = "DoD"; 190 break; 191 case DOD_E_METHOD_ID: 192 method = "DoD_E"; 193 break; 194 case RANDOM_METHOD_ID: 195 method.Format("Random %d", m_iPasses); 196 break; 197 case FL2KB_METHOD_ID: 198 method = "First_Last2k"; 199 break; 200 case SCHNEIER_METHOD_ID: 201 method = "Schneider"; 202 break; 203 } 204 205 CString strPath(CString("\"") + LAUNCHER + "\" " + szResolveLock + " \"" + 206 m_strLockFileList + "\" -method " + method); 178 207 179 208 extern bool no_registry; … … 185 214 key.SetStringValue(LAUNCHER, strPath); 186 215 m_strLockFileList = ""; 216 m_iMethod = 0; 217 m_iPasses = 0; 187 218 } 188 219 } -
trunk/EraserDll/FileLockResolver.h
r35 r55 45 45 CString m_strLockFileList; 46 46 ERASER_HANDLE m_hHandle; 47 int m_iMethod; 48 unsigned m_iPasses; 47 49 private: 50 static CString GetLockFilePath(bool path_only = false); 48 51 void HandleError(LPCTSTR szFileName, DWORD dwErrorCode, int method, unsigned int passes); 49 52 static DWORD ErrorHandler(LPCTSTR szFileName, DWORD dwErrorCode, void* ctx, void* param);
Note: See TracChangeset
for help on using the changeset viewer.
