source: trunk/TaskDataPage.cpp @ 47

Revision 47, 14.3 KB checked in by lowjoel, 7 years ago (diff)

Removed the Erase Files in Mask option.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1// TaskDataPage.cpp
2//
3// Eraser. Secure data removal. For Windows.
4// Copyright © 1997-2001  Sami Tolvanen (sami@tolvanen.com).
5// Copyright © 2007 The Eraser Project
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation; either version 2
10// of the License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20// 02111-1307, USA.
21
22#include "stdafx.h"
23#include "resource.h"
24#include "EraserUI\DirDialog.h"
25#include "EraserUI\NewDialog.h"
26#include "TaskDataPage.h"
27#include ".\taskdatapage.h"
28
29#ifdef _DEBUG
30#undef THIS_FILE
31static char BASED_CODE THIS_FILE[] = __FILE__;
32#endif
33
34IMPLEMENT_DYNCREATE(CTaskDataPage, CPropertyPage)
35IMPLEMENT_DYNCREATE(CTaskSchedulePage, CPropertyPage)
36IMPLEMENT_DYNCREATE(CTaskStatisticsPage, CPropertyPage)
37
38
39/////////////////////////////////////////////////////////////////////////////
40// CTaskDataPage property page
41
42CTaskDataPage::CTaskDataPage() :
43CPropertyPage(CTaskDataPage::IDD),
44m_tType(Drive),
45m_bShowPersistent(FALSE)
46, m_dwFinishAction(0)
47,m_iFinishActionInd(0)
48{
49    //{{AFX_DATA_INIT(CTaskDataPage)
50    m_strFolder = _T("");
51    m_strFile = _T("");
52    m_bRemoveOnlySub = FALSE;
53    m_bSubfolders = FALSE;
54    m_bRemoveFolder = FALSE;
55    m_bPersistent = FALSE;
56    m_bUseWildCards = FALSE;
57    m_bWildCardsInSubfolders = FALSE;
58    //}}AFX_DATA_INIT
59}
60
61CTaskDataPage::~CTaskDataPage()
62{
63}
64
65void CTaskDataPage::DoDataExchange(CDataExchange* pDX)
66{
67    CPropertyPage::DoDataExchange(pDX);
68    //{{AFX_DATA_MAP(CTaskDataPage)
69    DDX_Control(pDX, IDC_COMBO_DRIVES, m_comboDrives);
70    DDX_Text(pDX, IDC_EDIT_FOLDER, m_strFolder);
71    DDX_Text(pDX, IDC_EDIT_FILE, m_strFile);
72    DDX_Check(pDX, IDC_CHECK_ONLYSUB, m_bRemoveOnlySub);
73    DDX_Check(pDX, IDC_CHECK_SUBFOLDERS, m_bSubfolders);
74    DDX_Check(pDX, IDC_CHECK_FOLDER, m_bRemoveFolder);
75    DDX_Control(pDX, IDC_RADIO_DISK, m_buRadioDisk);
76    DDX_Control(pDX, IDC_RADIO_FILES, m_buRadioFiles);
77    DDX_Control(pDX, IDC_RADIO_FILE, m_buRadioFile);
78    DDX_Check(pDX, IDC_PERSISTENT_CHECK, m_bPersistent);
79    DDX_Check(pDX, IDC_CHECK_WILDCARDS, m_bUseWildCards);
80    DDX_Check(pDX, IDC_CHECK_WILDCARDS_SF, m_bWildCardsInSubfolders);
81    //}}AFX_DATA_MAP
82   
83    DDX_CBIndex(pDX, IDC_COMBO_WHENFINISH, m_iFinishActionInd);
84    if (-1 !=m_iFinishActionInd && pDX->m_bSaveAndValidate)
85    {
86
87        CComboBox* finish_action  = (CComboBox* )GetDlgItem(IDC_COMBO_WHENFINISH);
88        m_dwFinishAction = finish_action->GetItemData(m_iFinishActionInd) ;
89       
90    }
91}
92
93
94BEGIN_MESSAGE_MAP(CTaskDataPage, CPropertyPage)
95    //{{AFX_MSG_MAP(CTaskDataPage)
96    ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnBrowse)
97    ON_BN_CLICKED(IDC_BUTTON_BROWSE_FILES, OnBrowseFiles)
98    ON_BN_CLICKED(IDC_CHECK_FOLDER, OnRemoveFolder)
99    ON_BN_CLICKED(IDC_RADIO_DISK, OnRadioDisk)
100    ON_BN_CLICKED(IDC_RADIO_FILES, OnRadioFiles)
101    ON_BN_CLICKED(IDC_RADIO_FILE, OnRadioFile)
102    ON_BN_CLICKED(IDC_CHECK_WILDCARDS, OnCheckWildcards)
103    //}}AFX_MSG_MAP
104END_MESSAGE_MAP()
105
106
107/////////////////////////////////////////////////////////////////////////////
108// CTaskSchedulePage property page
109
110CTaskSchedulePage::CTaskSchedulePage() :
111CPropertyPage(CTaskSchedulePage::IDD),
112m_b24Hour(TRUE)
113{
114    //{{AFX_DATA_INIT(CTaskSchedulePage)
115    m_bPM = FALSE;
116    m_iWhen = Day;
117    //}}AFX_DATA_INIT
118}
119
120CTaskSchedulePage::~CTaskSchedulePage()
121{
122}
123
124void CTaskSchedulePage::DoDataExchange(CDataExchange* pDX)
125{
126    CPropertyPage::DoDataExchange(pDX);
127    //{{AFX_DATA_MAP(CTaskSchedulePage)
128    DDX_Control(pDX, IDC_EDIT_TIME, m_editTime);
129    DDX_Check(pDX, IDC_CHECK_PM, m_bPM);
130    DDX_CBIndex(pDX, IDC_COMBO_WHEN, m_iWhen);
131    //}}AFX_DATA_MAP
132}
133
134
135BEGIN_MESSAGE_MAP(CTaskSchedulePage, CPropertyPage)
136    //{{AFX_MSG_MAP(CTaskSchedulePage)
137    //}}AFX_MSG_MAP
138END_MESSAGE_MAP()
139
140
141/////////////////////////////////////////////////////////////////////////////
142// CTaskSchedulePage property page
143
144CTaskStatisticsPage::CTaskStatisticsPage() :
145CPropertyPage(CTaskStatisticsPage::IDD),
146m_lpts(0)
147{
148    //{{AFX_DATA_INIT(CTaskStatisticsPage)
149    m_strStatistics = _T("");
150    //}}AFX_DATA_INIT
151}
152
153CTaskStatisticsPage::~CTaskStatisticsPage()
154{
155}
156
157void CTaskStatisticsPage::DoDataExchange(CDataExchange* pDX)
158{
159    CPropertyPage::DoDataExchange(pDX);
160    //{{AFX_DATA_MAP(CTaskStatisticsPage)
161    DDX_Text(pDX, IDC_EDIT_STATISTICS, m_strStatistics);
162    //}}AFX_DATA_MAP
163}
164
165
166BEGIN_MESSAGE_MAP(CTaskStatisticsPage, CPropertyPage)
167    //{{AFX_MSG_MAP(CTaskStatisticsPage)
168    ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
169    //}}AFX_MSG_MAP
170END_MESSAGE_MAP()
171
172
173
174void CTaskDataPage::OnBrowse()
175{
176    UpdateData(TRUE);
177
178    //CDirectoryDialog dd;
179    //dd.DoModal(m_strFolder, "Select Folder to be Erased.");
180
181    CNewDialog dd;
182    if (dd.DoModal() == IDOK) {
183        m_strFolder = dd.m_sPath;
184    }
185   
186    UpdateData(FALSE);
187}
188
189void CTaskDataPage::OnBrowseFiles()
190{
191    UpdateData(TRUE);
192    CNewDialog fdlg;
193    if (fdlg.DoModal() == IDOK)
194    {
195        m_strFile = fdlg.m_sPath;
196        UpdateData(FALSE);
197    }
198}
199
200void CTaskDataPage::OnRemoveFolder()
201{
202    UpdateData(TRUE);
203
204    // if the user wants to remove the specified folder, we
205    // must remove the subfolders as well
206
207    if (m_bRemoveFolder)
208    {
209        m_bSubfolders = TRUE;
210        GetDlgItem(IDC_CHECK_SUBFOLDERS)->EnableWindow(FALSE);
211        GetDlgItem(IDC_CHECK_ONLYSUB)->EnableWindow(TRUE);
212    }
213    else
214    {
215        GetDlgItem(IDC_CHECK_SUBFOLDERS)->EnableWindow(TRUE);
216        GetDlgItem(IDC_CHECK_ONLYSUB)->EnableWindow(FALSE);
217    }
218
219    UpdateData(FALSE);
220}
221
222void CTaskDataPage::OnRadioDisk()
223{
224    // enable disk section
225    GetDlgItem(IDC_COMBO_DRIVES)->EnableWindow(TRUE);
226
227    // disable other sections
228    GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
229    GetDlgItem(IDC_EDIT_FOLDER)->EnableWindow(FALSE);
230    GetDlgItem(IDC_CHECK_FOLDER)->EnableWindow(FALSE);
231    GetDlgItem(IDC_CHECK_SUBFOLDERS)->EnableWindow(FALSE);
232    GetDlgItem(IDC_CHECK_ONLYSUB)->EnableWindow(FALSE);
233
234    GetDlgItem(IDC_BUTTON_BROWSE_FILES)->EnableWindow(FALSE);
235    GetDlgItem(IDC_EDIT_FILE)->EnableWindow(FALSE);
236    GetDlgItem(IDC_CHECK_WILDCARDS)->EnableWindow(FALSE);
237    GetDlgItem(IDC_CHECK_WILDCARDS_SF)->EnableWindow(FALSE);
238}
239
240void CTaskDataPage::OnRadioFiles()
241{
242    // enable folder section
243    GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(TRUE);
244    GetDlgItem(IDC_EDIT_FOLDER)->EnableWindow(TRUE);
245    GetDlgItem(IDC_CHECK_FOLDER)->EnableWindow(TRUE);
246    GetDlgItem(IDC_CHECK_SUBFOLDERS)->EnableWindow(!m_bRemoveFolder);
247    GetDlgItem(IDC_CHECK_ONLYSUB)->EnableWindow(m_bRemoveFolder);
248
249    // disable other sections
250    GetDlgItem(IDC_COMBO_DRIVES)->EnableWindow(FALSE);
251
252    GetDlgItem(IDC_BUTTON_BROWSE_FILES)->EnableWindow(FALSE);
253    GetDlgItem(IDC_EDIT_FILE)->EnableWindow(FALSE);
254    GetDlgItem(IDC_CHECK_WILDCARDS)->EnableWindow(FALSE);
255    GetDlgItem(IDC_CHECK_WILDCARDS_SF)->EnableWindow(FALSE);
256}
257
258void CTaskDataPage::OnRadioFile()
259{
260    // enable file section
261    GetDlgItem(IDC_BUTTON_BROWSE_FILES)->EnableWindow(TRUE);
262    GetDlgItem(IDC_EDIT_FILE)->EnableWindow(TRUE);
263    ((CEdit*)GetDlgItem(IDC_EDIT_FILE))->SetReadOnly(!m_bUseWildCards);
264    GetDlgItem(IDC_CHECK_WILDCARDS)->EnableWindow(TRUE);
265    GetDlgItem(IDC_CHECK_WILDCARDS_SF)->EnableWindow(m_bUseWildCards);
266
267    // disable other sections
268    GetDlgItem(IDC_COMBO_DRIVES)->EnableWindow(FALSE);
269    GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
270    GetDlgItem(IDC_EDIT_FOLDER)->EnableWindow(FALSE);
271    GetDlgItem(IDC_CHECK_FOLDER)->EnableWindow(FALSE);
272    GetDlgItem(IDC_CHECK_SUBFOLDERS)->EnableWindow(FALSE);
273    GetDlgItem(IDC_CHECK_ONLYSUB)->EnableWindow(FALSE);
274
275}
276
277void CTaskDataPage::OnCheckWildcards()
278{
279    UpdateData(TRUE);
280    ((CEdit*)GetDlgItem(IDC_EDIT_FILE))->SetReadOnly(!m_bUseWildCards);
281    GetDlgItem(IDC_CHECK_WILDCARDS_SF)->EnableWindow(m_bUseWildCards);
282}
283
284BOOL CTaskDataPage::OnInitDialog()
285{
286    CPropertyPage::OnInitDialog();
287
288    BOOL bDrive     = (m_tType == Drive);
289    BOOL bFolder    = (m_tType == Folder);
290    BOOL bFile      = (m_tType == File);
291
292    m_comboDrives.FillDrives();
293
294    if (!m_strSelectedDrive.IsEmpty())
295        m_comboDrives.SelectDrive(m_strSelectedDrive);
296
297    m_buRadioDisk.SetCheck(bDrive);
298    m_buRadioFiles.SetCheck(bFolder);
299    m_buRadioFile.SetCheck(bFile);
300
301    // drive
302    GetDlgItem(IDC_COMBO_DRIVES)->EnableWindow(bDrive);
303
304    // folder
305    GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(bFolder);
306    GetDlgItem(IDC_EDIT_FOLDER)->EnableWindow(bFolder);
307    GetDlgItem(IDC_CHECK_FOLDER)->EnableWindow(bFolder);
308    GetDlgItem(IDC_CHECK_SUBFOLDERS)->EnableWindow(bFolder && !m_bRemoveFolder);
309    GetDlgItem(IDC_CHECK_ONLYSUB)->EnableWindow(bFolder && m_bRemoveFolder);
310
311    // file
312    GetDlgItem(IDC_BUTTON_BROWSE_FILES)->EnableWindow(bFile);
313    GetDlgItem(IDC_EDIT_FILE)->EnableWindow(bFile);
314    ((CEdit*)GetDlgItem(IDC_EDIT_FILE))->SetReadOnly(!m_bUseWildCards);
315    GetDlgItem(IDC_CHECK_WILDCARDS)->EnableWindow(bFile);
316    GetDlgItem(IDC_CHECK_WILDCARDS_SF)->EnableWindow(bFile && m_bUseWildCards);
317
318    if (!m_bShowPersistent)
319        GetDlgItem(IDC_PERSISTENT_CHECK)->ShowWindow(SW_HIDE);
320
321    CComboBox* finish_action  = (CComboBox*)GetDlgItem(IDC_COMBO_WHENFINISH);
322    int selstr;
323    finish_action->SetItemDataPtr(selstr = finish_action->AddString("None"), NULL);
324    finish_action->SetItemData(finish_action->AddString("Shutdown system"), EWX_SHUTDOWN);
325    finish_action->SetItemData(finish_action->AddString("Restart"), EWX_REBOOT);
326    finish_action->SetItemData(finish_action->AddString("Sleep"), -1);
327
328    finish_action->SetCurSel(m_iFinishActionInd);
329   
330
331    UpdateData(FALSE);
332    return TRUE;  // return TRUE unless you set the focus to a control
333                  // EXCEPTION: OCX Property Pages should return FALSE
334}
335
336void CTaskDataPage::OnOK()
337{
338    UpdateData(TRUE);
339
340    if (m_buRadioDisk.GetCheck())
341        m_tType = Drive;
342    else if (m_buRadioFiles.GetCheck())
343        m_tType = Folder;
344    else
345        m_tType = File;
346
347    if (m_tType == Drive)
348        m_comboDrives.GetSelectedDrive(m_strSelectedDrive);
349    else if (m_tType == Folder && !m_strFolder.IsEmpty())
350    {
351        if (m_strFolder[m_strFolder.GetLength() - 1] != '\\')
352            m_strFolder += "\\";
353    }
354
355    CPropertyPage::OnOK();
356}
357
358void CTaskSchedulePage::OnOK()
359{
360    CPropertyPage::OnOK();
361
362    UpdateData(TRUE);
363
364    m_odtTime = m_editTime.GetTime();
365
366    if (!m_b24Hour)
367    {
368        // 12-hour clock
369
370        int iHour = m_odtTime.GetHour();
371        COleDateTimeSpan odtSpan(0, 12, 0, 0);
372
373        if ((iHour < 12 && m_bPM) ||
374            (iHour == 12 && !m_bPM))
375        {
376            m_odtTime += odtSpan;
377        }
378    }
379}
380
381BOOL CTaskSchedulePage::OnInitDialog()
382{
383    CPropertyPage::OnInitDialog();
384
385    TCHAR szLocale[2] = { 0, 0 };
386
387    if (GetLocaleInfo(LOCALE_USER_DEFAULT,
388                      LOCALE_ITIME,
389                      szLocale, 2))
390    {
391        // 0 -> 12-hour clock
392        // 1 -> 24-hour clock
393
394        m_b24Hour = (szLocale[0] != '0');
395    }
396
397    if (!m_b24Hour)
398    {
399        // 12-hour clock requires some special arrangements
400        int iHour;
401        CString str;
402
403        m_editTime.SetHours(12);
404        m_editTime.SetMinHours(1);
405
406        GetDlgItem(IDC_CHECK_PM)->ShowWindow(SW_SHOW);
407
408        iHour = m_odtTime.GetHour();
409
410        // 12 - 11 PM == 12 - 23
411        // 12 - 11 AM == 00 - 11
412
413        if (iHour < 1)
414        {
415            // 00 == 12 AM
416            iHour = 12;
417            m_bPM = FALSE;
418        }
419        else if (iHour > 12)
420        {
421            // 13 - 23 == 01 - 11 PM
422            iHour -= 12;
423            m_bPM = TRUE;
424        }
425        else if (iHour == 12)
426        {
427            // 12 == 12 PM
428            m_bPM = TRUE;
429        }
430        else
431        {
432            // 01 - 11 == 01 - 11 AM
433            m_bPM = FALSE;
434        }
435
436        str.Format("%.2d:%.2d", iHour, m_odtTime.GetMinute());
437        m_editTime.SetTime(str);
438    }
439    else
440    {
441        // 24-hour clock
442        m_editTime.SetTime(m_odtTime);
443    }
444
445    UpdateData(FALSE);
446
447    return TRUE;  // return TRUE unless you set the focus to a control
448                  // EXCEPTION: OCX Property Pages should return FALSE
449}
450
451BOOL CTaskStatisticsPage::OnInitDialog()
452{
453    UpdateStatistics();
454    CPropertyPage::OnInitDialog();
455
456    return TRUE;  // return TRUE unless you set the focus to a control
457                  // EXCEPTION: OCX Property Pages should return FALSE
458}
459
460void CTaskStatisticsPage::OnButtonReset()
461{
462    if (m_lpts)
463    {
464        m_lpts->Reset();
465        UpdateStatistics();
466        UpdateData(FALSE);
467    }
468}
469
470void CTaskStatisticsPage::UpdateStatistics()
471{
472    if (m_lpts)
473    {
474        CString strTemp;
475        double dTime;
476
477        // report header
478        m_strStatistics = "Task Report:\r\n\r\n";
479        // run
480        strTemp.Format("    Processed\t\t=  %u times\r\n", m_lpts->m_dwTimes);
481        m_strStatistics += strTemp;
482        // successful
483        strTemp.Format("    Successful\t\t=  %u times\r\n", m_lpts->m_dwTimesSuccess);
484        m_strStatistics += strTemp;
485        // terminated
486        strTemp.Format("    Terminated\t\t=  %u times\r\n", m_lpts->m_dwTimesInterrupted);
487        m_strStatistics += strTemp;
488        // failure
489        strTemp.Format("    Possible failure\t\t=  %u times\r\n",
490                        m_lpts->m_dwTimes - m_lpts->m_dwTimesSuccess - m_lpts->m_dwTimesInterrupted);
491        m_strStatistics += strTemp;
492
493        // statistics header
494        m_strStatistics += "\r\nStatistics (average):\r\n\r\n";
495        // erased area
496        strTemp.Format("    Erased area\t\t=  %u %s\r\n", m_lpts->m_dwAveArea, "kB");
497        m_strStatistics += strTemp;
498        // written
499        strTemp.Format("    Data written\t\t=  %u %s\r\n", m_lpts->m_dwAveWritten, "kB");
500        m_strStatistics += strTemp;
501        // time
502        dTime = (double)m_lpts->m_dwAveTime / 1000.0f;
503        strTemp.Format("    Write time\t\t=  %.2f %s", dTime, "s");
504        m_strStatistics += strTemp;
505        // speed
506        if (dTime > 0)
507        {
508            strTemp.Format("\r\n    Write speed\t\t=  %u %s", (DWORD)((double)m_lpts->m_dwAveWritten /
509                dTime), "kB/s");
510            m_strStatistics += strTemp;
511        }
512
513        UpdateData(FALSE);
514    }
515}
516
Note: See TracBrowser for help on using the repository browser.