summaryrefslogtreecommitdiff
path: root/NSCmpts/Backup.cpp
blob: 5f108bd4d08e7ca432d43b4ff55254b58421bcab (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
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
177
// Backup.cpp : Implementation of CBackup

#include "stdafx.h"
#include "NSCmpts.h"
#include "Backup.h"
#include "ProgressDlg.h"
#include <appmisc.h>

/////////////////////////////////////////////////////////////////////////////
// CBackup

STDMETHODIMP CBackup::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;
}

ATL_PROPMAP_ENTRY* CBackup::GetPropertyMap()
{
	// Depending on the mode of the wizard
	// return a different set of property papges

	// This is the Normal set without the advanced page
	static ATL_PROPMAP_ENTRY pNormalPropMap[] = 
	{
		PROP_PAGE(CLSID_BackupSourceProp)
		PROP_PAGE(CLSID_BackupDestProp)
		{NULL, 0, NULL, &IID_NULL, 0, 0, 0}
	};

	// All the property pages
	static ATL_PROPMAP_ENTRY pAdvancedPropMap[] = 
	{
		PROP_PAGE(CLSID_BackupSourceProp)
		PROP_PAGE(CLSID_BackupDestProp)
		PROP_PAGE(CLSID_BackupAdvancedProp)
		{NULL, 0, NULL, &IID_NULL, 0, 0, 0}
	};

	// Try and see which mode the wizard is in
	INightSecSiteInfoPtr pInfo = (IUnknown*)m_spUnkSite;
	if(pInfo)
	{
		// Get the Info from the Site
		CComVariant var;
		pInfo->get_Info(nsAdvanced, &var);

		if(var.vt == VT_BOOL && var.bVal == TRUE)
			return pAdvancedPropMap;
	}

	return pNormalPropMap;
}

/*static DWORD CALLBACK BackupProc(LPVOID lpParam)
{
	CActionEngine* pEngine = (CActionEngine*)lpParam;
	return pEngine->Start();
}
*/

STDMETHODIMP CBackup::DoShutdown(long hParent, long lMode)
{
	// Whether or not to show prompts
	bool bPrompt = lMode & nsNoPrompt ? false : true;

	// We don't support this option yet
	//	bool bSilent = lMode & nsQuiet ? true : false;

	// Create the dialog
	CActionProgressDlg dlgProgress(m_spUnkSite, IDD_PROGRESSBACKUP);
	dlgProgress.Create((HWND)hParent);
	dlgProgress.PlayAmination(IDR_AVIBACKUP);

	// Create the first Action
	string sTemp = m_Data.GetString(NS_BACKUP_REG_ENGINE, _T("Archive"));

	HRESULT hr = S_OK;

	// Date based backup
	if(sTemp == _T("Date"))
	{
		CBackupActions::DatePrepare* pAction = new CBackupActions::DatePrepare;
		hr = pAction->Initialize(m_Data);
		m_Engine.Add(pAction);
	}
	// Archive Based Backup
	else
	{
		CBackupActions::ArchivePrepare* pAction = new CBackupActions::ArchivePrepare;
		hr = pAction->Initialize(m_Data);
		m_Engine.Add(pAction);
	}

	if(FAILED(hr))
	{
		if(bPrompt)
			MessageBoxTimeout((HWND)hParent, _T("The backup options aren't set up correctly. \n\nRun Night Security Checklist to set the options."), _T("Night Security Backup"), MB_OK | MB_ICONWARNING, 15000, 5000);

		dlgProgress.DestroyWindow();
		return E_INVALIDARG;
	}

	// Init the update_monitor
	m_Engine.SetUpdates(dlgProgress, dlgProgress);

	// start the backup
	HANDLE hThread = m_Engine.StartThread();

	// Wait for the Thread
	WaitForAndIdle(1, &hThread, INFINITE);

	// Get the HRESULT from the Thread
	GetExitCodeThread(hThread, (LPDWORD)&hr);

	// Close Dialog
	dlgProgress.DestroyWindow();

	return hr;
}

// Gets Miscellaneous Info about the Object
STDMETHODIMP CBackup::get_Info(NightSecInfo nsItem, VARIANT* pvVal)
{
	::VariantClear(pvVal);

	CComBSTR bsRetVal;

	switch(nsItem)
	{
	case nsName:
		pvVal->vt = VT_BSTR;
		bsRetVal.LoadString(IDS_BACKUPNAME);
		pvVal->bstrVal = bsRetVal;
		return S_OK;
	case nsHelpText:
		pvVal->vt = VT_BSTR;
		bsRetVal.LoadString(IDS_BACKUPDESC);
		pvVal->bstrVal = bsRetVal;
		return S_OK;
	case nsCmdLine:
		pvVal->vt = VT_BSTR;
		bsRetVal.LoadString(IDS_BACKUPPARAM);
		pvVal->bstrVal = bsRetVal;
		return S_OK;
	case nsForceShow:			// We have to have our pages shown
		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 CBackup::SetData(IUnknown* pUnk)
{
	return m_Data.Initialize(pUnk);
}

/*UINT CBackup::LoadPaths()
{
	m_destPath = m_Data.GetString(NS_BACKUP_REG_DEST, _T(""));
	return m_Data.GetStringSet(NS_BACKUP_REG_SOURCE, m_srcPaths);
}
*/