summaryrefslogtreecommitdiff
path: root/NSCmpts/WipefreeSpace.cpp
blob: 72bc1998a89755a43d89cb4569689684cec8f8c2 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// WipefreeSpace.cpp : Implementation of CWipefreeSpace
#include "stdafx.h"
#include "NSCmpts.h"
#include "WipefreeSpace.h"

/////////////////////////////////////////////////////////////////////////////
// CWipefreeSpace

STDMETHODIMP CWipefreeSpace::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_ISecureShutdownDOS,
	};
	for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

///////////////////////////////////////////////////////////////////////////////
// Called to get text for Batch File

STDMETHODIMP CWipefreeSpace::GetBatchText(BSTR* psText)
{
	string sRetVal;
	string sTemp;

	// Get Property
	string sDrivesToWipe = m_Data.GetString(_T("Drives"), _T("!!!"));

	// Only wipe individually selected drives if the user has 
	// modified the default othwise wipe all
	m_bCustomDrives = (sDrivesToWipe != _T("!!!"));

	if(!m_bCustomDrives) 
	{
		string sDrives;
		::GetLogicalDriveStrings(220, sDrives.get_buffer(220));
		sDrives.release_buffer();

		LPCTSTR szCurDrive = sDrives;

		// Add each fixed drive to the wipe string
		while(szCurDrive[0] != _T('\0'))
		{
			if(GetDriveType(szCurDrive) == DRIVE_FIXED)
				sTemp += string(szCurDrive[0]) + _T(": ");

			szCurDrive += _tcslen(szCurDrive) + 1;
		}

	}
	// Wipe Just the ones the user has selected
	else 
	{
		// Add each drive to the wipe string
		for(int nCnt = 0; nCnt < sDrivesToWipe.length(); nCnt++)
			sTemp += sDrivesToWipe[nCnt] + string(_T(": "));

	}


	// We installed Wiper to the Windows Folder so look for it there
	string sWinFolder;
	if(!GetWindowsDirectory(sWinFolder.get_buffer(MAX_PATH), MAX_PATH))
		sWinFolder = _T("C:\\WINDOWS");

	sWinFolder.release_buffer();

	// Should turn out something like C:\WINNT\WIPER C: D:
	sRetVal.format(IDS_WIPEFREE_BATCHTEXT, (LPCTSTR)sWinFolder, (LPCTSTR)sTemp);
	
	CComBSTR bsRet(sRetVal);
	*psText = bsRet.Detach();

	return S_OK;
}

///////////////////////////////////////////////////////////////////////////////
// Returns info about the object

STDMETHODIMP CWipefreeSpace::get_Info(NightSecInfo nsItem, VARIANT* pvVal)
{
	::VariantClear(pvVal);

	CComBSTR bsRetVal;

	switch(nsItem)
	{
	case nsName:
		pvVal->vt = VT_BSTR;
		bsRetVal.LoadString(IDS_WIPEFREE_NAME);
		pvVal->bstrVal = bsRetVal.Detach();
		return S_OK;
	case nsHelpText:
		pvVal->vt = VT_BSTR;
		bsRetVal.LoadString(IDS_WIPEFREE_DESC);
		pvVal->bstrVal = bsRetVal.Detach();
		return S_OK;
	}

	::VariantClear(pvVal);
	return S_FALSE;
}


STDMETHODIMP CWipefreeSpace::SetData(IUnknown* pUnk)
{
	return m_Data.Initialize(pUnk);
}

///////////////////////////////////////////////////////////////////////////////
// Property Sheet Stuff

STDMETHODIMP CWipefreeSpace::Apply()
{
	ATLTRACE(_T("CClearInetCache::Apply\n"));
 
	string sTemp;
	string sDrives;

	// If the user has selected just some drives then
	// save them individually
	if(m_bCustomDrives) 
	{
		for(int nCnt = 0; nCnt < m_nDrives; nCnt++) 
		{
			// Loop through check boxes
			if(IsDlgButtonChecked(IDC_FIRST_DRIVE + nCnt))
			{
				// Get Label of Checked Button
				::GetWindowText(GetDlgItem(IDC_FIRST_DRIVE + nCnt), sTemp.get_buffer(10), 10);
				sTemp.release_buffer();

				// Label should be "Drive C" (C is the 7th Char)
				sDrives += sTemp[6];

			}

		}
	}
	// All Drives 
	else
		sDrives = _T("!!!");

	m_bDirty = FALSE;
	return m_Data.WriteString(_T("Drives"), sDrives);

}

LRESULT CWipefreeSpace::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	string sDrives;
	string sTemp;

	// Get Property
	string sSelectedDrives = m_Data.GetString(_T("Drives"), _T("!!!"));

	// Has the User Changed the Defaults?
	m_bCustomDrives = (sSelectedDrives != _T("!!!"));
	
	::GetLogicalDriveStrings(220, sDrives.get_buffer(220));
	sDrives.release_buffer();

	sSelectedDrives.make_upper();

	LPCTSTR szCurDrive = sDrives;	// Pointer to Current Drive in sDrives
	int nCnt = 0;					// Current Drive Num (for interface)


	// Loop Through Drives
	while(szCurDrive[0] != _T('\0'))
	{
		// We're only interested in fixed drives
		if(GetDriveType(szCurDrive) == DRIVE_FIXED)
		{
			sTemp = szCurDrive;
			sTemp.make_upper();
	
			// Due to interface limitations we only support 15 drives (MAX_DRIVES)
			if(nCnt < MAX_DRIVES) 
			{
				// Give the Window the Appropriate Label
				SetDlgItemText(IDC_FIRST_DRIVE + nCnt,  (string)(_T("Drive ") + string(sTemp[0])));

				// Since it's hidden in the dialog template, show it
				::ShowWindow(GetDlgItem(IDC_FIRST_DRIVE + nCnt), SW_SHOW);

				// Check it if the user has selected it or if we are going for all of'm
				CheckDlgButton(IDC_FIRST_DRIVE + nCnt, (!m_bCustomDrives) || ((sSelectedDrives.find(sTemp[0]) != string::npos)));

				nCnt++;
			}


		}

		// Next Drive
		szCurDrive += _tcslen(szCurDrive) + 1; // ???? Later: What does this do
	}

	// Counter for Apply()
	m_nDrives = nCnt;

	return false;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

LRESULT CWipefreeSpace::OnDrivesChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	// User is overriding the default
	m_bCustomDrives = true;
	return 0;
}