// 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; }