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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
// NightSecError.cpp : Implementation of CNSCmptsApp and DLL registration.
#include "stdafx.h"
#include "NSCmpts.h"
#include "NightSecError.h"
/////////////////////////////////////////////////////////////////////////////
// Set the current error to
void CBaseErrorImpl::SetError(const string& sDesc, HRESULT hRes,
LPCTSTR szHelpFile /*= _T("")*/, long lHelpContext /*= 0*/)
{
// Initialize Other Stuff
m_hRes = hRes;
m_bsDescription = sDesc;
m_bsHelpFile = szHelpFile;
m_lHelpContext = lHelpContext;
}
/*void CActionErrorImpl::SetError(CAction* pAction, const string& sDesc, HRESULT hRes,
LPCTSTR szHelpFile, long lHelpContext)
{
// Attach to Action
m_pAction = pAction;
pAction->addref();
CBaseErrorImpl::SetError(sDesc, hRes, szHelpFile, lHelpContext);
}
*/
void CActionErrorImpl::Attach(CAction* pAction)
{
// Attach to Action
ASSERT(pAction);
m_pAction = pAction;
pAction->addref();
}
//////////////////////////////////////////////////////////////////////////
// Fix the error
STDMETHODIMP CActionErrorImpl::Fix()
{
// Sanity Checks
ASSERT(m_pAction);
ASSERT(m_pAction->IsFixable(m_hRes));
if(!m_pAction)
return E_UNEXPECTED;
if(!m_pAction->IsFixable(m_hRes))
return E_FAIL;
// Fix it
try
{
m_pAction->Fix(m_hRes);
// Clear error information
m_bsDescription = _T("Fixed Successfully");
m_hRes = S_OK;
m_lHelpContext = 0;
}
catch(CActionError& err)
{
// Set new error information
m_hRes = err.m_hRes;
m_bsDescription = err.m_sDesc;
m_lHelpContext = 0;
}
return m_hRes;
}
///////////////////////////////////////////////////////////////////
// Check if fixable
STDMETHODIMP CActionErrorImpl::get_Fixable(/*[out, retval]*/ BOOL* pbRet)
{
ASSERT(m_pAction);
if(!m_pAction)
return E_UNEXPECTED;
*pbRet = m_pAction->IsFixable(m_hRes) ? TRUE : FALSE;
return S_OK;
}
////////////////////////////////////////////////////////////////////
// Retry the action
STDMETHODIMP CActionErrorImpl::Retry()
{
// Sanity Checks
ASSERT(m_pAction);
ASSERT(m_pAction->IsRetryable());
if(!m_pAction)
return E_UNEXPECTED;
if(!m_pAction->IsRetryable())
return E_FAIL;
// Do it Again
try
{
m_pAction->Do(NULL, NULL);
// Clear error Information
m_hRes = S_OK;
m_bsDescription = _T("Completed Successfully");
m_lHelpContext = 0;
}
catch(CActionError& err)
{
// Set New Error Information
m_hRes = err.m_hRes;
m_bsDescription = err.m_sDesc;
m_lHelpContext = 0;
}
return m_hRes;
}
/////////////////////////////////////////////////////////////////////
// Check if retryable
STDMETHODIMP CActionErrorImpl::get_Retryable(/*[out, retval]*/ BOOL* pbRet)
{
ASSERT(m_pAction);
if(!m_pAction)
return E_UNEXPECTED;
*pbRet = m_pAction->IsRetryable() ? TRUE : FALSE;
return S_OK;
}
void CNightSecErrorImpl::Attach(ISecureShutdownWin* pShutdown)
{
// Attach to Secure Shutdown
ASSERT(pShutdown);
m_pShutdown = pShutdown;
m_pShutdown->AddRef();
}
////////////////////////////////////////////////////////////////////
// Retry the action
STDMETHODIMP CNightSecErrorImpl::Retry()
{
// Sanity Checks
ASSERT(m_pShutdown);
if(!m_pShutdown)
return E_UNEXPECTED;
// Do it Again
HRESULT hr = m_pShutdown->DoShutdown(NULL, 0);
if(SUCCEEDED(hr))
{
// Clear error Information
m_hRes = S_OK;
m_bsDescription = _T("Completed Successfully");
m_lHelpContext = 0;
}
// Otherwise it should have filled us up with new error info
return m_hRes;
}
|