| 1 | // WipeProgDlg.cpp |
|---|
| 2 | // |
|---|
| 3 | // Eraser. Secure data removal. For Windows. |
|---|
| 4 | // Copyright © 1997-2001 Sami Tolvanen (sami@tolvanen.com). |
|---|
| 5 | // |
|---|
| 6 | // This program is free software; you can redistribute it and/or |
|---|
| 7 | // modify it under the terms of the GNU General Public License |
|---|
| 8 | // as published by the Free Software Foundation; either version 2 |
|---|
| 9 | // of the License, or (at your option) any later version. |
|---|
| 10 | // |
|---|
| 11 | // This program is distributed in the hope that it will be useful, |
|---|
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | // GNU General Public License for more details. |
|---|
| 15 | // |
|---|
| 16 | // You should have received a copy of the GNU General Public License |
|---|
| 17 | // along with this program; if not, write to the Free Software |
|---|
| 18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|---|
| 19 | // 02111-1307, USA. |
|---|
| 20 | |
|---|
| 21 | #include "stdafx.h" |
|---|
| 22 | #include "Erasext.h" |
|---|
| 23 | #include "..\EraserDll\eraserdll.h" |
|---|
| 24 | #include "..\shared\FitFileNameToScrn.h" |
|---|
| 25 | #include "..\shared\key.h" |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | #include "resource.h" |
|---|
| 29 | #include "WipeProgDlg.h" |
|---|
| 30 | |
|---|
| 31 | #ifdef _DEBUG |
|---|
| 32 | #define new DEBUG_NEW |
|---|
| 33 | #undef THIS_FILE |
|---|
| 34 | static char THIS_FILE[] = __FILE__; |
|---|
| 35 | #endif |
|---|
| 36 | |
|---|
| 37 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 38 | // CEraserDlg dialog |
|---|
| 39 | |
|---|
| 40 | // General Preferences |
|---|
| 41 | static BOOL getAskUserParam() |
|---|
| 42 | { |
|---|
| 43 | BOOL bResolveAskUser = TRUE; |
|---|
| 44 | CKey kReg; |
|---|
| 45 | if (kReg.Open(HKEY_CURRENT_USER, ERASER_REGISTRY_BASE)) |
|---|
| 46 | { |
|---|
| 47 | kReg.GetValue(bResolveAskUser, "EraserResolveLockAskUser", TRUE); |
|---|
| 48 | kReg.Close(); |
|---|
| 49 | } |
|---|
| 50 | return bResolveAskUser; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | CEraserDlg::CEraserDlg(CWnd* pParent /*=NULL*/) : |
|---|
| 54 | CDialog(CEraserDlg::IDD, pParent), |
|---|
| 55 | m_hAccel(NULL), |
|---|
| 56 | m_bUseFiles(TRUE), |
|---|
| 57 | m_bMove(FALSE), |
|---|
| 58 | m_bShowResults(TRUE), |
|---|
| 59 | m_ehContext(ERASER_INVALID_CONTEXT), |
|---|
| 60 | m_LockResolver(getAskUserParam()) |
|---|
| 61 | { |
|---|
| 62 | //{{AFX_DATA_INIT(CEraserDlg) |
|---|
| 63 | m_strPercent = _T("0%"); |
|---|
| 64 | m_strPercentTotal = _T("0%"); |
|---|
| 65 | m_strData = _T(""); |
|---|
| 66 | m_strErasing = _T(""); |
|---|
| 67 | m_strPass = _T(""); |
|---|
| 68 | m_strTime = _T(""); |
|---|
| 69 | m_strMessage = _T(""); |
|---|
| 70 | m_bResults = FALSE; |
|---|
| 71 | //}}AFX_DATA_INIT |
|---|
| 72 | |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | void CEraserDlg::DoDataExchange(CDataExchange* pDX) |
|---|
| 77 | { |
|---|
| 78 | CDialog::DoDataExchange(pDX); |
|---|
| 79 | //{{AFX_DATA_MAP(CEraserDlg) |
|---|
| 80 | DDX_Control(pDX, IDC_PROGRESS, m_pcProgress); |
|---|
| 81 | DDX_Control(pDX, IDC_PROGRESS_TOTAL, m_pcProgressTotal); |
|---|
| 82 | DDX_Text(pDX, IDC_STATIC_PERCENT, m_strPercent); |
|---|
| 83 | DDX_Text(pDX, IDC_STATIC_PERCENT_TOTAL, m_strPercentTotal); |
|---|
| 84 | DDX_Text(pDX, IDC_STATIC_DATA, m_strData); |
|---|
| 85 | DDX_Text(pDX, IDC_STATIC_ERASING, m_strErasing); |
|---|
| 86 | DDX_Text(pDX, IDC_STATIC_PASS, m_strPass); |
|---|
| 87 | DDX_Text(pDX, IDC_STATIC_TIME, m_strTime); |
|---|
| 88 | DDX_Text(pDX, IDC_STATIC_MESSAGE, m_strMessage); |
|---|
| 89 | DDX_Check(pDX, IDC_CHECK_RESULTS, m_bResults); |
|---|
| 90 | //}}AFX_DATA_MAP |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | BEGIN_MESSAGE_MAP(CEraserDlg, CDialog) |
|---|
| 95 | //{{AFX_MSG_MAP(CEraserDlg) |
|---|
| 96 | ON_WM_DESTROY() |
|---|
| 97 | ON_BN_CLICKED(IDC_CHECK_RESULTS, OnCheckResults) |
|---|
| 98 | //}}AFX_MSG_MAP |
|---|
| 99 | ON_MESSAGE(WM_ERASERNOTIFY, OnEraserNotify) |
|---|
| 100 | END_MESSAGE_MAP() |
|---|
| 101 | |
|---|
| 102 | ///////////////////////////////////////////////////////////////////////////// |
|---|
| 103 | // CEraserDlg message handlers |
|---|
| 104 | |
|---|
| 105 | BOOL CEraserDlg::OnInitDialog() |
|---|
| 106 | { |
|---|
| 107 | CDialog::OnInitDialog(); |
|---|
| 108 | |
|---|
| 109 | CKey kReg; |
|---|
| 110 | |
|---|
| 111 | if (kReg.Open(HKEY_CURRENT_USER, ERASER_REGISTRY_BASE)) |
|---|
| 112 | { |
|---|
| 113 | kReg.GetValue(m_bResults, ERASEXT_REGISTRY_RESULTS, TRUE); |
|---|
| 114 | kReg.GetValue(m_bResultsForFiles, ERASER_REGISTRY_RESULTS_FILES, TRUE); |
|---|
| 115 | kReg.GetValue(m_bResultsForUnusedSpace, ERASER_REGISTRY_RESULTS_UNUSEDSPACE, TRUE); |
|---|
| 116 | kReg.GetValue(m_bResultsOnlyWhenFailed, ERASER_REGISTRY_RESULTS_WHENFAILED, TRUE); |
|---|
| 117 | kReg.Close(); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | if (!m_bShowResults) |
|---|
| 121 | { |
|---|
| 122 | m_bResults = FALSE; |
|---|
| 123 | GetDlgItem(IDC_CHECK_RESULTS)->ShowWindow(SW_HIDE); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | UpdateData(FALSE); |
|---|
| 127 | |
|---|
| 128 | m_hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR_PROG)); |
|---|
| 129 | |
|---|
| 130 | m_pcProgress.SetRange(0, 100); |
|---|
| 131 | m_pcProgress.SetStep(1); |
|---|
| 132 | m_pcProgress.SetPos(0); |
|---|
| 133 | |
|---|
| 134 | m_pcProgressTotal.SetRange(0, 100); |
|---|
| 135 | m_pcProgressTotal.SetStep(1); |
|---|
| 136 | m_pcProgressTotal.SetPos(0); |
|---|
| 137 | |
|---|
| 138 | // starts the thread |
|---|
| 139 | Erase(); |
|---|
| 140 | |
|---|
| 141 | return TRUE; // return TRUE unless you set the focus to a control |
|---|
| 142 | // EXCEPTION: OCX Property Pages should return FALSE |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | void CEraserDlg::Erase() |
|---|
| 146 | { |
|---|
| 147 | if (eraserError(eraserIsValidContext(m_ehContext)) && m_saData.GetSize() > 0) |
|---|
| 148 | { |
|---|
| 149 | if (eraserOK(eraserCreateContext(&m_ehContext))) |
|---|
| 150 | { |
|---|
| 151 | m_LockResolver.SetHandle(m_ehContext); |
|---|
| 152 | |
|---|
| 153 | if (m_bUseFiles) |
|---|
| 154 | VERIFY(eraserOK(eraserSetDataType(m_ehContext, ERASER_DATA_FILES))); |
|---|
| 155 | else |
|---|
| 156 | VERIFY(eraserOK(eraserSetDataType(m_ehContext, ERASER_DATA_DRIVES))); |
|---|
| 157 | |
|---|
| 158 | int iSize = m_saData.GetSize(); |
|---|
| 159 | for (int i = 0; i < iSize; i++) |
|---|
| 160 | { |
|---|
| 161 | VERIFY(eraserOK(eraserAddItem(m_ehContext, |
|---|
| 162 | (LPVOID)(LPCTSTR)m_saData[i], (E_UINT16)m_saData[i].GetLength()))); |
|---|
| 163 | } |
|---|
| 164 | m_saData.RemoveAll(); |
|---|
| 165 | |
|---|
| 166 | // set notification window & message |
|---|
| 167 | VERIFY(eraserOK(eraserSetWindow(m_ehContext, GetSafeHwnd()))); |
|---|
| 168 | VERIFY(eraserOK(eraserSetWindowMessage(m_ehContext, WM_ERASERNOTIFY))); |
|---|
| 169 | |
|---|
| 170 | // start erasing (the library will launch a new thread for this) |
|---|
| 171 | VERIFY(eraserOK(eraserStart(m_ehContext))); |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | LRESULT CEraserDlg::OnEraserNotify(WPARAM wParam, LPARAM) |
|---|
| 177 | { |
|---|
| 178 | switch (wParam) |
|---|
| 179 | { |
|---|
| 180 | case ERASER_WIPE_BEGIN: |
|---|
| 181 | EraserWipeBegin(); |
|---|
| 182 | break; |
|---|
| 183 | case ERASER_WIPE_UPDATE: |
|---|
| 184 | EraserWipeUpdate(); |
|---|
| 185 | break; |
|---|
| 186 | case ERASER_WIPE_DONE: |
|---|
| 187 | EraserWipeDone(); |
|---|
| 188 | break; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | return TRUE; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | BOOL CEraserDlg::EraserWipeBegin() |
|---|
| 195 | { |
|---|
| 196 | UpdateData(TRUE); |
|---|
| 197 | |
|---|
| 198 | if (m_bUseFiles) |
|---|
| 199 | { |
|---|
| 200 | if (!m_bMove) |
|---|
| 201 | m_strErasing = "Files"; |
|---|
| 202 | else |
|---|
| 203 | m_strErasing = "Source Files"; |
|---|
| 204 | } |
|---|
| 205 | else |
|---|
| 206 | m_strErasing = "Unused disk space"; |
|---|
| 207 | |
|---|
| 208 | TCHAR szValue[255]; |
|---|
| 209 | E_UINT16 uSize = 255; |
|---|
| 210 | E_UINT8 uValue = 0; |
|---|
| 211 | |
|---|
| 212 | // data |
|---|
| 213 | if (eraserOK(eraserProgGetCurrentDataString(m_ehContext, (LPVOID)szValue, &uSize))) |
|---|
| 214 | m_strData = szValue; |
|---|
| 215 | fitFileNameToScrn(GetDlgItem(IDC_STATIC_DATA), m_strData); |
|---|
| 216 | |
|---|
| 217 | // message |
|---|
| 218 | if (eraserOK(eraserProgGetMessage(m_ehContext, (LPVOID)szValue, &uSize))) |
|---|
| 219 | m_strMessage = szValue; |
|---|
| 220 | |
|---|
| 221 | // progress |
|---|
| 222 | if (eraserOK(eraserDispFlags(m_ehContext, &uValue))) |
|---|
| 223 | { |
|---|
| 224 | if (bitSet(uValue, eraserDispInit)) |
|---|
| 225 | { |
|---|
| 226 | m_pcProgress.SetPos(0); |
|---|
| 227 | m_strPercent = "0%"; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | // pass |
|---|
| 231 | if (!bitSet(uValue, eraserDispPass)) |
|---|
| 232 | m_strPass.Empty(); |
|---|
| 233 | |
|---|
| 234 | // time |
|---|
| 235 | if (!bitSet(uValue, eraserDispTime)) |
|---|
| 236 | m_strTime.Empty(); |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | UpdateData(FALSE); |
|---|
| 240 | |
|---|
| 241 | return TRUE; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | BOOL CEraserDlg::EraserWipeUpdate() |
|---|
| 245 | { |
|---|
| 246 | TCHAR szValue[255]; |
|---|
| 247 | E_UINT16 uSize = 255; |
|---|
| 248 | E_UINT8 uValue = 0; |
|---|
| 249 | CString strPercent, strPercentTotal, strTime, strPass, strMessage; |
|---|
| 250 | |
|---|
| 251 | UpdateData(TRUE); |
|---|
| 252 | |
|---|
| 253 | // percent |
|---|
| 254 | if (eraserOK(eraserProgGetPercent(m_ehContext, &uValue))) |
|---|
| 255 | { |
|---|
| 256 | strPercent.Format("%u%%", uValue); |
|---|
| 257 | m_pcProgress.SetPos(uValue); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | // total percent |
|---|
| 261 | if (eraserOK(eraserProgGetTotalPercent(m_ehContext, &uValue))) |
|---|
| 262 | { |
|---|
| 263 | strPercentTotal.Format("%u%%", uValue); |
|---|
| 264 | m_pcProgressTotal.SetPos(uValue); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | // pass |
|---|
| 268 | if (eraserOK(eraserDispFlags(m_ehContext, &uValue))) |
|---|
| 269 | { |
|---|
| 270 | if (bitSet(uValue, eraserDispPass)) |
|---|
| 271 | { |
|---|
| 272 | E_UINT16 current = 0, passes = 0; |
|---|
| 273 | if (eraserOK(eraserProgGetCurrentPass(m_ehContext, ¤t)) && |
|---|
| 274 | eraserOK(eraserProgGetPasses(m_ehContext, &passes))) |
|---|
| 275 | { |
|---|
| 276 | strPass.Format("%u of %u", current, passes); |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | // show time? |
|---|
| 281 | if (bitSet(uValue, eraserDispTime)) |
|---|
| 282 | { |
|---|
| 283 | // time left |
|---|
| 284 | E_UINT32 uTimeLeft = 0; |
|---|
| 285 | if (eraserOK(eraserProgGetTimeLeft(m_ehContext, &uTimeLeft))) |
|---|
| 286 | { |
|---|
| 287 | if (uTimeLeft > 120) |
|---|
| 288 | { |
|---|
| 289 | uTimeLeft = (uTimeLeft / 60) + 1; |
|---|
| 290 | strTime.Format("%u minutes left", uTimeLeft); |
|---|
| 291 | } |
|---|
| 292 | else if (uTimeLeft > 0) |
|---|
| 293 | { |
|---|
| 294 | if (uTimeLeft % 5) |
|---|
| 295 | strTime = m_strTime; |
|---|
| 296 | else |
|---|
| 297 | strTime.Format("%u seconds left", uTimeLeft); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | // message |
|---|
| 304 | if (eraserOK(eraserProgGetMessage(m_ehContext, (LPVOID)szValue, &uSize))) |
|---|
| 305 | strMessage = szValue; |
|---|
| 306 | |
|---|
| 307 | // update only if necessary to minimize flickering |
|---|
| 308 | if (m_strPercent != strPercent || m_strPercentTotal != strPercentTotal || |
|---|
| 309 | m_strPass != strPass || m_strTime != strTime || m_strMessage != strMessage) |
|---|
| 310 | { |
|---|
| 311 | m_strPercent = strPercent; |
|---|
| 312 | m_strPercentTotal = strPercentTotal; |
|---|
| 313 | m_strPass = strPass; |
|---|
| 314 | m_strTime = strTime; |
|---|
| 315 | m_strMessage = strMessage; |
|---|
| 316 | |
|---|
| 317 | UpdateData(FALSE); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | return TRUE; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | BOOL CEraserDlg::EraserWipeDone() |
|---|
| 324 | { |
|---|
| 325 | // clear display |
|---|
| 326 | m_strMessage.Empty(); |
|---|
| 327 | m_strPercent.Empty(); |
|---|
| 328 | m_strPercentTotal.Empty(); |
|---|
| 329 | m_strPass.Empty(); |
|---|
| 330 | m_strTime.Empty(); |
|---|
| 331 | m_strData.Empty(); |
|---|
| 332 | m_pcProgress.SetPos(0); |
|---|
| 333 | m_pcProgressTotal.SetPos(0); |
|---|
| 334 | UpdateData(FALSE); |
|---|
| 335 | |
|---|
| 336 | // show results |
|---|
| 337 | E_UINT32 uFailed = 0; |
|---|
| 338 | E_UINT16 uErrors = 0; |
|---|
| 339 | eraserFailedCount(m_ehContext, &uFailed); |
|---|
| 340 | eraserErrorStringCount(m_ehContext, &uErrors); |
|---|
| 341 | |
|---|
| 342 | if (m_bResults) |
|---|
| 343 | { |
|---|
| 344 | if (((m_bUseFiles && m_bResultsForFiles) || |
|---|
| 345 | (!m_bUseFiles && m_bResultsForUnusedSpace)) && |
|---|
| 346 | (!m_bResultsOnlyWhenFailed || (uFailed > 0 || uErrors > 0))) |
|---|
| 347 | { |
|---|
| 348 | eraserShowReport(m_ehContext, GetSafeHwnd()); |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | // success |
|---|
| 353 | E_UINT8 uSuccess = 0; |
|---|
| 354 | if (eraserOK(eraserCompleted(m_ehContext, &uSuccess)) && uSuccess) |
|---|
| 355 | CDialog::OnOK(); |
|---|
| 356 | else |
|---|
| 357 | CDialog::OnCancel(); |
|---|
| 358 | |
|---|
| 359 | return TRUE; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | void CEraserDlg::OnDestroy() |
|---|
| 364 | { |
|---|
| 365 | UpdateData(TRUE); |
|---|
| 366 | |
|---|
| 367 | if (m_bShowResults) |
|---|
| 368 | { |
|---|
| 369 | CKey kReg; |
|---|
| 370 | |
|---|
| 371 | if (kReg.Open(HKEY_CURRENT_USER, ERASER_REGISTRY_BASE)) |
|---|
| 372 | { |
|---|
| 373 | kReg.SetValue(m_bResults, ERASEXT_REGISTRY_RESULTS); |
|---|
| 374 | kReg.Close(); |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | m_LockResolver.Close(); |
|---|
| 379 | |
|---|
| 380 | eraserDestroyContext(m_ehContext); |
|---|
| 381 | m_ehContext = ERASER_INVALID_CONTEXT; |
|---|
| 382 | |
|---|
| 383 | CDialog::OnDestroy(); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | BOOL CEraserDlg::PreTranslateMessage(MSG* pMsg) |
|---|
| 387 | { |
|---|
| 388 | if (TranslateAccelerator(GetSafeHwnd(), m_hAccel, pMsg)) |
|---|
| 389 | return TRUE; |
|---|
| 390 | |
|---|
| 391 | return CDialog::PreTranslateMessage(pMsg); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | void CEraserDlg::OnCancel() |
|---|
| 395 | { |
|---|
| 396 | m_strMessage = "Terminating..."; |
|---|
| 397 | m_strPercent.Empty(); |
|---|
| 398 | m_strPercentTotal.Empty(); |
|---|
| 399 | m_strPass.Empty(); |
|---|
| 400 | m_strTime.Empty(); |
|---|
| 401 | m_strData.Empty(); |
|---|
| 402 | m_pcProgress.SetPos(0); |
|---|
| 403 | m_pcProgressTotal.SetPos(0); |
|---|
| 404 | UpdateData(FALSE); |
|---|
| 405 | |
|---|
| 406 | GetDlgItem(IDCANCEL)->EnableWindow(FALSE); |
|---|
| 407 | eraserStop(m_ehContext); |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | void CEraserDlg::OnCheckResults() |
|---|
| 411 | { |
|---|
| 412 | UpdateData(TRUE); |
|---|
| 413 | } |
|---|