source: trunk/PreferencesPage.cpp @ 28

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

-Fixed a warning of unused variables in ShellListView?.cpp
-In the Preferences page the Minimize to tray option should be DISABLED when the tray icon is disabled

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