summaryrefslogtreecommitdiff
path: root/NSCmpts/Encrypt.cpp
blob: 617dc696504b643ec9262f14667e922cfcd1b273 (plain)
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
// Encrypt.cpp : Implementation of CEncrypt
#include "stdafx.h"
#include "NSCmpts.h"
#include "Encrypt.h"
#include "ProgressDlg.h"
#include <appmisc.h>
#include <commisc.h>

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