source: trunk/PreferencesPage.cpp @ 30

Revision 30, 9.6 KB checked in by lowjoel, 7 years ago (diff)

The PreferencesPage?.cpp file should have the minimize to try disabled if the tray icon is disabled

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