source: trunk/Eraser.cpp @ 3

Revision 3, 10.9 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// Eraser.cpp
2//
3// Eraser. Secure data removal. For Windows.
4// Copyright © 1997-2001  Sami Tolvanen (sami@tolvanen.com).
5// Copyright © 2002 Garrett Trant (support@heidi.ie).
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 "Eraser.h"
24
25#include "MainFrm.h"
26#include "EraserDoc.h"
27#include "EraserView.h"
28#include "Windows.h"
29
30#include "EraserDll\EraserDll.h"
31#include "shared\HyperLink.h"
32#include "version.h"
33#include "EraserDll\SecurityManager.h"
34
35#ifdef _DEBUG
36#define new DEBUG_NEW
37#undef THIS_FILE
38static char THIS_FILE[] = __FILE__;
39#endif
40
41/////////////////////////////////////////////////////////////////////////////
42// CEraserApp
43
44BEGIN_MESSAGE_MAP(CEraserApp, CWinApp)
45    //{{AFX_MSG_MAP(CEraserApp)
46    ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
47        // NOTE - the ClassWizard will add and remove mapping macros here.
48        //    DO NOT EDIT what you see in these blocks of generated code!
49    //}}AFX_MSG_MAP
50    // Standard file based document commands
51    ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
52    ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
53END_MESSAGE_MAP()
54
55/////////////////////////////////////////////////////////////////////////////
56// CEraserApp construction
57
58CEraserApp::CEraserApp() :
59m_pDoc(0)
60{
61    _set_se_translator(SeTranslator);
62}
63
64/////////////////////////////////////////////////////////////////////////////
65// The one and only CEraserApp object
66
67CEraserApp theApp;
68
69/////////////////////////////////////////////////////////////////////////////
70// CEraserApp initialization
71
72// Add a static BOOL that indicates whether the class was
73// registered so that we can unregister it in ExitInstance
74static BOOL bClassRegistered = FALSE;
75
76BOOL CEraserApp::FirstInstance()
77{
78    CWnd *pWndPrev = CWnd::FindWindow(szEraserClassName, NULL);
79    CWnd *pWndChild;
80
81    // Determine if another window with our class name exists...
82    if (pWndPrev)
83    {
84        // if so, does it have any popups?
85        pWndChild = pWndPrev->GetLastActivePopup();
86
87        // If iconic, restore the main window
88        if (!pWndPrev->IsWindowVisible() || pWndPrev->IsIconic())
89            pWndPrev->ShowWindow(SW_RESTORE);
90
91        // Bring the main window or its popup to
92        // the foreground
93        pWndChild->SetForegroundWindow();
94
95        // and we are done activating the previous one.
96        return FALSE;
97    }
98    // First instance. Proceed as normal.
99    else
100        return TRUE;
101}
102
103__declspec(dllimport) bool no_registry;
104
105BOOL CEraserApp::InitInstance()
106{
107    // If a previous instance of the application is already running,
108    // then activate it and return FALSE from InitInstance to
109    // end the execution of this instance.
110
111    {
112        char temp[512];
113        ::GetModuleFileName(NULL, temp, sizeof(temp));
114        ::PathStripToRoot(temp);
115        switch(::GetDriveType(temp)) {
116        case DRIVE_UNKNOWN:
117        case DRIVE_NO_ROOT_DIR:
118        case DRIVE_FIXED:
119        default:
120            no_registry = false;
121            break;
122        case DRIVE_REMOVABLE:
123        case DRIVE_REMOTE:
124        case DRIVE_CDROM:
125        case DRIVE_RAMDISK:
126            no_registry = true;
127            break;
128        }
129    }
130//  no_registry = true;
131    if (no_registry) {
132        char temp[512];
133        ::GetModuleFileName(NULL, temp, sizeof(temp));
134        ::PathRemoveFileSpec(temp);
135        ::PathAppend(temp, "eraser.ini");
136        m_pszProfileName = strdup(temp);
137    }
138
139    if (!CheckAccess())
140        return false;
141
142    if (!FirstInstance())
143        return FALSE;
144
145    eraserInit();
146
147    // Register our unique class name that we wish to use
148    WNDCLASS wndcls;
149    ZeroMemory(&wndcls, sizeof(WNDCLASS));   // start with NULL
150
151    // defaults
152    wndcls.style            = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
153    wndcls.lpfnWndProc      = ::DefWindowProc;
154    wndcls.hInstance        = AfxGetInstanceHandle();
155    wndcls.hIcon            = LoadIcon(IDR_MAINFRAME); // or load a different icon
156    wndcls.hCursor          = LoadCursor(IDC_ARROW);
157    wndcls.hbrBackground    = (HBRUSH) (COLOR_WINDOW + 1);
158    wndcls.lpszMenuName     = NULL;
159
160    // Specify our own class name for using FindWindow later
161    wndcls.lpszClassName = szEraserClassName;
162
163    // Register new class and exit if it fails
164    if (!AfxRegisterClass(&wndcls))
165    {
166        AfxMessageBox("Class Registration Failed");
167        return FALSE;
168    }
169
170    bClassRegistered = TRUE;
171
172    // Initialize OLE libraries
173    if (!AfxOleInit())
174    {
175        AfxMessageBox("OLE initialization failed.");
176        return FALSE;
177    }
178
179    // Standard initialization
180    // If you are not using these features and wish to reduce the size
181    //  of your final executable, you should remove from the following
182    //  the specific initialization routines you do not need.
183
184#ifdef _AFXDLL
185    Enable3dControls();         // Call this when using MFC in a shared DLL
186#else
187    Enable3dControlsStatic();   // Call this when linking to MFC statically
188#endif
189
190    // Change the registry key under which our settings are stored.
191    if (!no_registry)
192        SetRegistryKey(_T("Heidi Computers Ltd\\Eraser\\5.5"));
193
194    LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)
195
196    // Register the application's document templates.  Document templates
197    //  serve as the connection between documents, frame windows and views.
198
199    CSingleDocTemplate* pDocTemplate;
200    pDocTemplate = new CSingleDocTemplate(
201        IDR_MAINFRAME,
202        RUNTIME_CLASS(CEraserDoc),
203        RUNTIME_CLASS(CMainFrame),       // main SDI frame window
204        NULL);  // we create views by ourselves; no default view here
205    AddDocTemplate(pDocTemplate);
206
207    // Enable DDE Execute open
208    EnableShellOpen();
209    RegisterShellFileTypes(TRUE);
210
211    CString str(m_lpCmdLine);
212    BOOL bHide = (str.Find(NOWINDOW_PARAMETER) != -1);
213
214    if (bHide)
215        m_nCmdShow = SW_HIDE;
216
217    // Parse command line for standard shell commands, DDE, file open
218    CCommandLineInfo cmdInfo;
219    ParseCommandLine(cmdInfo);
220
221    // Dispatch commands specified on the command line
222    if (!ProcessShellCommand(cmdInfo))
223        return FALSE;
224
225    EnableHtmlHelp();
226    int helpfilelen = strlen(m_pszHelpFilePath);
227    if((helpfilelen >= 4) && !stricmp(&m_pszHelpFilePath[helpfilelen - 4], ".hlp"))
228        strcpy((char *)&m_pszHelpFilePath[helpfilelen - 4], ".chm");
229
230    // The one and only window has been initialized, so show and update it.
231
232    m_pMainWnd->ShowWindow((bHide) ? SW_HIDE : SW_SHOW);
233    m_pMainWnd->UpdateWindow();
234
235    return TRUE;
236}
237
238
239/////////////////////////////////////////////////////////////////////////////
240// CAboutDlg dialog used for App About
241
242class CAboutDlg : public CDialog
243{
244public:
245    CAboutDlg();
246
247// Dialog Data
248    //{{AFX_DATA(CAboutDlg)
249    enum { IDD = IDD_ABOUTBOX };
250    CHyperLink  m_hlMail;
251    CHyperLink  m_hlLink;
252    CString m_strVersion;
253    //}}AFX_DATA
254
255    // ClassWizard generated virtual function overrides
256    //{{AFX_VIRTUAL(CAboutDlg)
257    protected:
258    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
259    //}}AFX_VIRTUAL
260
261// Implementation
262protected:
263    //{{AFX_MSG(CAboutDlg)
264    virtual BOOL OnInitDialog();
265    //}}AFX_MSG
266    DECLARE_MESSAGE_MAP()
267};
268
269CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
270{
271    //{{AFX_DATA_INIT(CAboutDlg)
272    m_strVersion = _T("Eraser Version 5.8.1");
273    //}}AFX_DATA_INIT
274}
275
276void CAboutDlg::DoDataExchange(CDataExchange* pDX)
277{
278    CDialog::DoDataExchange(pDX);
279    //{{AFX_DATA_MAP(CAboutDlg)
280    DDX_Control(pDX, IDC_HYPERLINK_MAIL, m_hlMail);
281    DDX_Control(pDX, IDC_HYPERLINK, m_hlLink);
282    DDX_Text(pDX, IDC_STATIC_VERSION, m_strVersion);
283    //}}AFX_DATA_MAP
284}
285
286BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
287    //{{AFX_MSG_MAP(CAboutDlg)
288    //}}AFX_MSG_MAP
289END_MESSAGE_MAP()
290
291// App command to run the dialog
292void CEraserApp::OnAppAbout()
293{
294    CAboutDlg aboutDlg;
295    //aboutDlg.m_strVersion.Format("Eraser Version %s",GetVersionInfoFromModule( TRUE )); // Show four-digit version info
296    aboutDlg.m_strVersion.Format("Eraser Version %s",VERSION_NUMBER_STRING); 
297    aboutDlg.DoModal();
298}
299LPCTSTR  CEraserApp::GetVersionInfoFromModule( BOOL boolFourDigitString )
300{
301 // From: Chris Copenhaver <ccopenhaver@documentsolutions.com>
302 
303 // This method reads information from the Version resource.
304
305    char  szFullPath[MAX_PATH];
306    DWORD dwVerHnd;
307    DWORD dwVerInfoSize;
308
309    // Get version information from the application
310    ::GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
311
312    dwVerInfoSize = ::GetFileVersionInfoSize(szFullPath, &dwVerHnd);
313    if (dwVerInfoSize)
314    {
315        char* pVersionInfo = new char[dwVerInfoSize];
316        if(pVersionInfo)
317        {
318            BOOL bRet = ::GetFileVersionInfo((LPTSTR)szFullPath,
319                                             (DWORD)dwVerHnd,
320                                             (DWORD)dwVerInfoSize,
321                                             (LPVOID)pVersionInfo);
322            char* szVer = NULL;
323            UINT uVerLength;
324            if(bRet)
325            {
326                bRet = ::VerQueryValue(pVersionInfo,
327
328TEXT("\\StringFileInfo\\040904b0\\FileVersion"),
329                                       (LPVOID*)&szVer,
330                                       &uVerLength);
331                if (bRet)
332                {
333                    // Now return the file version...
334                 CString strVersion = szVer;
335                 if ( !boolFourDigitString )
336                 {
337   int posComma = strVersion.ReverseFind( ',' );
338   strVersion = strVersion.Left( posComma );
339                 }
340                 
341                    return strVersion;
342                }
343            }
344            delete pVersionInfo;
345        }
346    }
347
348 return "";
349}
350
351/////////////////////////////////////////////////////////////////////////////
352// CEraserApp message handlers
353
354
355int CEraserApp::ExitInstance()
356{
357    try
358    {
359        if (AfxIsValidAddress(m_pDoc, sizeof(CEraserDoc)))
360            delete m_pDoc;
361
362        m_pDoc = 0;
363    }
364    catch (CException *e)
365    {
366        ASSERT(FALSE);
367        REPORT_ERROR(e);
368        e->Delete();
369    }
370
371    if (bClassRegistered)
372        ::UnregisterClass(szEraserClassName, AfxGetInstanceHandle());
373
374    eraserEnd();
375
376    return CWinApp::ExitInstance();
377}
378
379BOOL CAboutDlg::OnInitDialog()
380{
381    //m_strVersion.Format("Eraser %u.%u  (Build %u)", MAJOR_NUMBER, MINOR_NUMBER, BUILD_NUMBER);
382   
383    m_hlLink.SetURL(ERASER_URL_HOMEPAGE);
384    m_hlMail.SetURL(ERASER_URL_EMAIL);
385
386    CDialog::OnInitDialog();
387
388    return TRUE;  // return TRUE unless you set the focus to a control
389                  // EXCEPTION: OCX Property Pages should return FALSE
390}
391
Note: See TracBrowser for help on using the repository browser.