source: trunk/PreferencesPage.cpp @ 3

Revision 3, 10.0 KB checked in by lowjoel, 7 years ago (diff)

Added the source files from root (SVN migration commit 1)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1// PreferencesPage.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 "resource.h"
23#include "EraserDoc.h"
24#include "PreferencesPage.h"
25#include "EraserDll\SecurityManager.h"
26#include "HotKeyDlg.h"
27
28#include <winsvc.h>
29
30
31#ifdef _DEBUG
32#undef THIS_FILE
33static char BASED_CODE THIS_FILE[] = __FILE__;
34#endif
35
36IMPLEMENT_DYNCREATE(CEraserPreferencesPage, CPropertyPage)
37IMPLEMENT_DYNCREATE(CSchedulerPreferencesPage, CPropertyPage)
38
39
40/////////////////////////////////////////////////////////////////////////////
41// CEraserPreferencesPage property page
42
43CEraserPreferencesPage::CEraserPreferencesPage() :
44CPropertyPage(CEraserPreferencesPage::IDD)
45, m_bResolveLock(TRUE)
46, m_bResolveAskUser(TRUE)
47{
48    //{{AFX_DATA_INIT(CEraserPreferencesPage)
49    m_bClearSwap = FALSE;
50    m_bShellextResults = FALSE;
51    m_bResultsForFiles = FALSE;
52    m_bResultsForUnusedSpace = FALSE;
53    m_bResultsOnlyWhenFailed = FALSE;
54    m_bErasextEnabled = FALSE;
55    m_bEnableSlowPoll = FALSE;
56    //}}AFX_DATA_INIT
57}
58
59CEraserPreferencesPage::~CEraserPreferencesPage()
60{
61}
62void CEraserPreferencesPage::OnOK()
63{
64    //CFrameWnd* frame = (CFrameWnd*) AfxGetMainWnd();
65    //CEraserDoc* doc = (CEraserDoc*) frame->GetActiveDocument();
66    CPropertyPage::OnOK();
67}
68void CEraserPreferencesPage::DoDataExchange(CDataExchange* pDX)
69{
70    CPropertyPage::DoDataExchange(pDX);
71    //{{AFX_DATA_MAP(CEraserPreferencesPage)
72    DDX_Check(pDX, IDC_CHECK_CLEAR_SWAP, m_bClearSwap);
73    DDX_Check(pDX, IDC_CHECK_SHELLEXT_RESULTS, m_bShellextResults);
74    DDX_Check(pDX, IDC_CHECK_RESULTS_FOR_FILES, m_bResultsForFiles);
75    DDX_Check(pDX, IDC_CHECK_RESULTS_FOR_UNUSED_SPACE, m_bResultsForUnusedSpace);
76    DDX_Check(pDX, IDC_CHECK_RESULTSONLYWHENFAILED, m_bResultsOnlyWhenFailed);
77    DDX_Check(pDX, IDC_CHECK_ERASEXT_ENABLE, m_bErasextEnabled);
78    DDX_Check(pDX, IDC_CHECK_PRNG_SLOWPOLL, m_bEnableSlowPoll);
79    //}}AFX_DATA_MAP
80    DDX_Check(pDX, IDC_CHECK_RESOLVE_LOCK, m_bResolveLock);
81    DDX_Check(pDX, IDC_CHECK_RESOLVE_ASK_USR, m_bResolveAskUser);
82}
83
84
85BEGIN_MESSAGE_MAP(CEraserPreferencesPage, CPropertyPage)
86    //{{AFX_MSG_MAP(CEraserPreferencesPage)
87    ON_BN_CLICKED(IDC_CHECK_RESULTS_FOR_UNUSED_SPACE, OnCheckResultsForUnusedSpace)
88    ON_BN_CLICKED(IDC_CHECK_RESULTS_FOR_FILES, OnCheckResultsForFiles)
89    //}}AFX_MSG_MAP
90    ON_BN_CLICKED(IDC_BUTTON_PROTECTION, OnBnClickedButtonProtection)
91    ON_BN_CLICKED(IDC_BUTTON_HOTKEYS, OnBnClickedButtonHotkeys)
92END_MESSAGE_MAP()
93
94
95/////////////////////////////////////////////////////////////////////////////
96// CSchedulerPreferencesPage property page
97
98CSchedulerPreferencesPage::CSchedulerPreferencesPage() : CPropertyPage(CSchedulerPreferencesPage::IDD)
99{
100    //{{AFX_DATA_INIT(CSchedulerPreferencesPage)
101    m_bLog = FALSE;
102    m_bStartup = FALSE;
103    m_bNoVisualErrors = FALSE;
104    m_bLogOnlyErrors = FALSE;
105    m_dwMaxLogSize = 0;
106    m_bNoTrayIcon = FALSE;
107    m_bQueueTasks = FALSE;
108    m_bEnabled = FALSE;
109    m_bHideOnMinimize = FALSE;
110    //}}AFX_DATA_INIT
111}
112
113CSchedulerPreferencesPage::~CSchedulerPreferencesPage()
114{
115}
116
117void CSchedulerPreferencesPage::DoDataExchange(CDataExchange* pDX)
118{
119    CPropertyPage::DoDataExchange(pDX);
120    //{{AFX_DATA_MAP(CSchedulerPreferencesPage)
121    DDX_Control(pDX, IDC_SPIN_LIMIT, m_sbLimitSize);
122    DDX_Check(pDX, IDC_CHECK_LOG, m_bLog);
123    DDX_Check(pDX, IDC_CHECK_STARTUP, m_bStartup);
124    DDX_Check(pDX, IDC_CHECK_NOVISUALERRORS, m_bNoVisualErrors);
125    DDX_Check(pDX, IDC_CHECK_LOG_ONLYERRORS, m_bLogOnlyErrors);
126    DDX_Text(pDX, IDC_EDIT_LIMIT, m_dwMaxLogSize);
127    DDX_Check(pDX, IDC_CHECK_NOTRAYICON, m_bNoTrayIcon);
128    DDX_Check(pDX, IDC_CHECK_QUEUE, m_bQueueTasks);
129    DDX_Check(pDX, IDC_CHECK_ENABLE, m_bEnabled);
130    DDX_Check(pDX, IDC_CHECK_HIDEONMINIMIZE, m_bHideOnMinimize);
131    //}}AFX_DATA_MAP
132}
133
134
135BEGIN_MESSAGE_MAP(CSchedulerPreferencesPage, CPropertyPage)
136    //{{AFX_MSG_MAP(CSchedulerPreferencesPage)
137    ON_BN_CLICKED(IDC_CHECK_LOG_LIMITSIZE, OnCheckLogLimitsize)
138    ON_BN_CLICKED(IDC_CHECK_LOG, OnCheckLog)
139    ON_BN_CLICKED(IDC_CHECK_NOTRAYICON, OnCheckNotrayicon)
140    //}}AFX_MSG_MAP
141END_MESSAGE_MAP()
142
143
144static inline BOOL IsAdminOnNT()
145{
146    SC_HANDLE hSC;
147
148    // Try an Admin Privileged API - if it works return
149    // TRUE - else FALSE
150
151    hSC = OpenSCManager(NULL, NULL,
152                        GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
153
154    if (hSC == NULL)
155        return FALSE;
156
157    CloseServiceHandle(hSC);
158    return TRUE;
159}
160
161BOOL CEraserPreferencesPage::OnInitDialog()
162{
163    CPropertyPage::OnInitDialog();
164
165    // Clearing Paging file is a Windows NT security
166    // feature and not available on Windows 9x
167
168    OSVERSIONINFO ov;
169
170    ZeroMemory(&ov, sizeof(OSVERSIONINFO));
171    ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
172
173    VERIFY(GetVersionEx(&ov));
174
175    CButton *pButtonSwap = (CButton*)GetDlgItem(IDC_CHECK_CLEAR_SWAP);
176
177    if (ov.dwPlatformId == VER_PLATFORM_WIN32_NT)
178    {
179        if (IsAdminOnNT())
180        {
181            pButtonSwap->EnableWindow(TRUE);
182        }
183    }
184    else
185    {
186        m_bClearSwap = FALSE;
187        pButtonSwap->SetCheck(0);
188    }
189
190
191    BOOL bEnable = (m_bResultsForFiles || m_bResultsForUnusedSpace);
192
193    GetDlgItem(IDC_CHECK_RESULTSONLYWHENFAILED)->EnableWindow(bEnable);
194    GetDlgItem(IDC_CHECK_SHELLEXT_RESULTS)->EnableWindow(bEnable);
195   
196
197    CString strButtonTitle;
198    strButtonTitle.LoadString(CSecurityManager::IsProtected() ? IDS_CLEAR_PROTECTION : IDS_SET_PROTECTION);
199
200    GetDlgItem(IDC_BUTTON_PROTECTION)->SetWindowText(strButtonTitle);
201
202
203    return TRUE;  // return TRUE unless you set the focus to a control
204                  // EXCEPTION: OCX Property Pages should return FALSE
205}
206
207void CSchedulerPreferencesPage::OnCheckLogLimitsize()
208{
209    CButton *pCheck = static_cast<CButton*>(GetDlgItem(IDC_CHECK_LOG_LIMITSIZE));
210
211    if (pCheck->GetCheck())
212    {
213        GetDlgItem(IDC_EDIT_LIMIT)->EnableWindow(TRUE);
214        m_sbLimitSize.EnableWindow(TRUE);
215    }
216    else
217    {
218        GetDlgItem(IDC_EDIT_LIMIT)->EnableWindow(FALSE);
219        m_sbLimitSize.EnableWindow(FALSE);
220    }
221}
222
223void CSchedulerPreferencesPage::OnCheckLog()
224{
225    UpdateData(TRUE);
226    GetDlgItem(IDC_CHECK_LOG_ONLYERRORS)->EnableWindow(m_bLog);
227
228    CButton *pCheck = static_cast<CButton*>(GetDlgItem(IDC_CHECK_LOG_LIMITSIZE));
229
230    GetDlgItem(IDC_EDIT_LIMIT)->EnableWindow(pCheck->GetCheck() && m_bLog);
231    m_sbLimitSize.EnableWindow(pCheck->GetCheck() && m_bLog);
232
233    pCheck->EnableWindow(m_bLog);
234    GetDlgItem(IDC_STATIC_KB)->EnableWindow(m_bLog);
235}
236
237BOOL CSchedulerPreferencesPage::OnInitDialog()
238{
239    CPropertyPage::OnInitDialog();
240
241    GetDlgItem(IDC_CHECK_LOG_ONLYERRORS)->EnableWindow(m_bLog);
242
243    m_sbLimitSize.SetBase(10);
244    m_sbLimitSize.SetRange(1, 1024);
245    m_sbLimitSize.SetPos(m_dwMaxLogSize);
246    m_sbLimitSize.SetBuddy(GetDlgItem(IDC_EDIT_LIMIT));
247
248    CButton *pCheck = static_cast<CButton*>(GetDlgItem(IDC_CHECK_LOG_LIMITSIZE));
249
250    if (m_dwMaxLogSize < 1)
251    {
252        m_dwMaxLogSize = 1;
253        pCheck->SetCheck(0);
254    }
255    else
256    {
257        pCheck->SetCheck(1);
258    }
259
260    GetDlgItem(IDC_EDIT_LIMIT)->EnableWindow(pCheck->GetCheck() && m_bLog);
261    m_sbLimitSize.EnableWindow(pCheck->GetCheck() && m_bLog);
262
263    pCheck->EnableWindow(m_bLog);
264    GetDlgItem(IDC_STATIC_KB)->EnableWindow(m_bLog);
265
266    if (!m_bNoTrayIcon)
267    {
268        m_bHideOnMinimize = FALSE;
269        GetDlgItem(IDC_CHECK_HIDEONMINIMIZE)->EnableWindow(FALSE);
270    }
271
272
273   
274       
275    UpdateData(FALSE);
276
277    return TRUE;  // return TRUE unless you set the focus to a control
278                  // EXCEPTION: OCX Property Pages should return FALSE
279}
280
281void CSchedulerPreferencesPage::OnOK()
282{
283    CPropertyPage::OnOK();
284
285    CButton *pCheck = static_cast<CButton*>(GetDlgItem(IDC_CHECK_LOG_LIMITSIZE));
286
287    if (!pCheck->GetCheck())
288        m_dwMaxLogSize = 0;
289}
290
291void CEraserPreferencesPage::OnCheckResultsForUnusedSpace()
292{
293    UpdateData(TRUE);
294    BOOL bEnable = (m_bResultsForFiles || m_bResultsForUnusedSpace);
295
296    GetDlgItem(IDC_CHECK_RESULTSONLYWHENFAILED)->EnableWindow(bEnable);
297    GetDlgItem(IDC_CHECK_SHELLEXT_RESULTS)->EnableWindow(bEnable);
298    if (!bEnable)
299    {
300        CButton* btn = (CButton*)GetDlgItem(IDC_CHECK_RESULTSONLYWHENFAILED);
301        btn->SetCheck(BST_UNCHECKED);
302        btn = (CButton*)GetDlgItem(IDC_CHECK_SHELLEXT_RESULTS);
303        btn->SetCheck(BST_UNCHECKED);   
304    }
305}
306
307void CEraserPreferencesPage::OnCheckResultsForFiles()
308{
309    UpdateData(TRUE);
310    BOOL bEnable = (m_bResultsForFiles || m_bResultsForUnusedSpace);
311
312    GetDlgItem(IDC_CHECK_RESULTSONLYWHENFAILED)->EnableWindow(bEnable);
313    GetDlgItem(IDC_CHECK_SHELLEXT_RESULTS)->EnableWindow(bEnable);
314    if (!bEnable)
315    {
316        CButton* btn = (CButton*)GetDlgItem(IDC_CHECK_RESULTSONLYWHENFAILED);
317        btn->SetCheck(BST_UNCHECKED);
318        btn = (CButton*)GetDlgItem(IDC_CHECK_SHELLEXT_RESULTS);
319        btn->SetCheck(BST_UNCHECKED);
320    }
321}
322
323void CSchedulerPreferencesPage::OnCheckNotrayicon() 
324{
325    UpdateData(TRUE);
326    GetDlgItem(IDC_CHECK_HIDEONMINIMIZE)->EnableWindow(m_bNoTrayIcon);
327}
328
329void CEraserPreferencesPage::OnBnClickedButtonProtection()
330{
331    bool res;
332    CString strButtonTitle;
333       
334    if (CSecurityManager::IsProtected())
335    {
336        res = ClearProtection();
337        strButtonTitle.LoadString(IDS_SET_PROTECTION);
338    }
339    else
340    {
341        res = SetProtection();
342        strButtonTitle.LoadString(IDS_CLEAR_PROTECTION);
343    }
344
345    if (res)
346    {
347        GetDlgItem(IDC_BUTTON_PROTECTION)->SetWindowText(strButtonTitle);
348    }
349}
350
351void CEraserPreferencesPage::OnBnClickedButtonHotkeys()
352{
353    // TODO: Add your control notification handler code here
354    CHotKeyDlg dlg;
355    if (IDOK != dlg.DoModal()) return;
356}
Note: See TracBrowser for help on using the repository browser.