// Encrypt.cpp : Implementation of CEncrypt #include "stdafx.h" #include "NSCmpts.h" #include "Encrypt.h" #include "ProgressDlg.h" #include #include ///////////////////////////////////////////////////////////////////////////// // CEncrypt STDMETHODIMP CEncrypt::InterfaceSupportsErrorInfo(REFIID riid) { static const IID* arr[] = { &IID_ISecureShutdownWin }; for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++) { if (InlineIsEqualGUID(*arr[i],riid)) return S_OK; } return S_FALSE; } STDMETHODIMP CEncrypt::DoShutdown(long hParent, long lMode) { bool bPrompt = lMode & nsNoPrompt ? false : true; // bool bSilent = lMode & nsQuiet ? true : false; // Put it out here so it'll stay in scope m_bDisablePassword = m_Data.GetInt(NS_ENCRYPT_REG_DISABLE, false) ? true : false; try { // Ask for Password here if(m_xpyPass == NULL) try_(m_xpyPass.CreateInstance(__uuidof(XpyEx))); VARIANT_BOOL vbEnabled = m_xpyPass->Enabled[xpyMainPass]; if(!vbEnabled && bPrompt) m_xpyPass->Prompt(hParent, xpyuiMainPassword); vbEnabled = m_xpyPass->Enabled[xpyMainPass]; if(!vbEnabled) return XPY_E_NO_PASSWORD; } catch(_com_error& e) { // These are big errors and means something's not // set up properly. Make sure it gets user's attention // can't just go into the log window if(bPrompt) { string sMessage; IErrorInfo* pError; if(pError = e.ErrorInfo()) { sMessage.format(IDS_ENCRYPT_ERR_XPY, e.Description()); pError->Release(); } else sMessage.format(IDS_ENCRYPT_ERR_XPY, e.ErrorMessage()); MessageBox((HWND)hParent, sMessage, _T("XPY Encryption Problem"), MB_OK | MB_ICONSTOP); } route_to_atl(e); } // Create the dialog CActionProgressDlg dlgProgress(m_spUnkSite, IDD_PROGRESSENCRYPT); dlgProgress.Create((HWND)hParent); dlgProgress.PlayAmination(IDR_AVIENCRYPT); CEncryptActions::EncryptPrepare* pAction = new CEncryptActions::EncryptPrepare; HRESULT hr = pAction->Initialize(m_Data); if(hr != S_OK) return hr; m_Engine.Add(pAction); // Create the update_monitor m_Engine.SetUpdates(dlgProgress, dlgProgress); // start the backup HANDLE hThread = m_Engine.StartThread(); WaitForAndIdle(1, &hThread, INFINITE); hr = S_OK; GetExitCodeThread(hThread, (LPDWORD)&hr); dlgProgress.DestroyWindow(); return hr; } STDMETHODIMP CEncrypt::get_Info(NightSecInfo nsItem, VARIANT* pvVal) { ::VariantClear(pvVal); CComBSTR bsRetVal; switch(nsItem) { case nsName: pvVal->vt = VT_BSTR; bsRetVal.LoadString(IDS_ENCRYPTNAME); pvVal->bstrVal = bsRetVal; return S_OK; case nsHelpText: pvVal->vt = VT_BSTR; bsRetVal.LoadString(IDS_ENCRYPTDESC); pvVal->bstrVal = bsRetVal; return S_OK; case nsCmdLine: pvVal->vt = VT_BSTR; bsRetVal.LoadString(IDS_ENCRYPTPARAM); pvVal->bstrVal = bsRetVal; return S_OK; case nsForceShow: pvVal->vt = VT_BOOL; pvVal->bVal = TRUE; return S_OK; case nsCopyAble: pvVal->vt = VT_BOOL; pvVal->bVal = TRUE; return S_OK; } return S_FALSE; } STDMETHODIMP CEncrypt::SetData(IUnknown* pUnk) { return m_Data.Initialize(pUnk); }