1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// ShutdownApp.cpp: implementation of the CShutdownApp class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ShutdownApp.h"
#include <mystring.h>
#include "batchfilecmpt.h"
#include <appmisc.h>
#include "itemdlg.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CShutdownApp::CShutdownApp()
: CNightSecApp(_T("Secure Shutdown"), _T("NightSecurity.SecureShutdown.{2ED9B360-F6EF-11d2-A5A1-0020182B97FC}"))
{ }
CShutdownApp::~CShutdownApp()
{ }
bool CShutdownApp::InitInstance()
{
// If more than one instance bail out early
if(m_oneInstance.IsAlreadyLoaded())
{
m_oneInstance.FindAndActivate(_T("#32770"), _T("Secure Shutdown"));
return false;
}
if(!CNightSecApp::InitInstance())
return false;
// If the checklist hasn't been run all the way through yet
// then...
if(!m_settings.GetInt(IS_SETUP_KEY, 0))
{
// Ask if they'd like to fill it out
if(::MessageBox(NULL, _T("You haven't filled out the Night Security checklist yet. Would you like to do that now?."), _T("Secure Shutdown"), MB_ICONQUESTION | MB_YESNO) == IDYES)
{
// Start the Checklist Program
if(ShellExecute(NULL, _T("open"), string(GetProgramFolder(_Module.m_hInst) + _T("Checklist.exe")), NULL, "", SW_SHOWNORMAL) <= (HINSTANCE)32)
::MessageBox(NULL, _T("Couldn't start Night Security Checklist. Make sure it's installed properly."), _T("Secure Shutdown"), MB_ICONSTOP);
return false;
}
// Only ask'm once. If they answer 'no' then don't bother'm
// again
m_settings.WriteInt(IS_SETUP_KEY, 1);
}
g_site.SetSite();
// Do the actual shutdown
DoShutdown(NULL);
// If any components changed data
g_aComponents.SaveComponentData();
g_site.ClearSite();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return false;
}
HRESULT CShutdownApp::DoShutdown(HWND hwndParent, long lOptions)
{
// ... Add Entry for Batchfile Creation Components (host based)
// into array
g_aComponents.push_back(new CBatchFileCmpt);
// Create Progress Dialog
g_site.m_dlgItems.Create(NULL);
g_site.m_log.Init(g_site.m_dlgItems);
// Now comes the real stuff
HRESULT hr = S_OK;
MSG msg;
int nCurPos = 0;
// Call Do Shutdown for All Windows Components
for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
{
// If it's a Windows Component
if(g_aComponents[nCnt]->GetType() == COMPONENT_WIN)
{
// If it's currently active
if(g_aComponents[nCnt]->IsEnabled())
{
// Make Entry Active
g_site.m_dlgItems.SetCurrentItem(nCurPos);
PEEK_ALL_MESSAGES(msg);
// Call Shutdown
hr = g_aComponents[nCnt]->DoShutdown(lOptions, g_site.m_dlgItems);
// Was Component Cancelled?
// All nicely behaved components return E_ABORT
// on cancel
if(hr == E_ABORT)
return E_ABORT;
// Check it off
// (Check it with a false if failed)
g_site.m_dlgItems.CheckOffItem(nCurPos, SUCCEEDED(hr));
PEEK_ALL_MESSAGES(msg);
// Is Dialog Cancelled?
if(g_site.m_dlgItems.IsCancelled())
return E_ABORT;
nCurPos++;
}
}
}
return S_OK;
}
|