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
|
// EmptyTempFolder.cpp : Implementation of CEmptyTempFolder
#include "stdafx.h"
#include "NSCmpts.h"
#include "EmptyTempFolder.h"
#include "..\common\defines.h"
#include "ProgressDlg.h"
#include "TempWarnDlg.h"
#include "TempActions.h"
#include <appmisc.h>
/////////////////////////////////////////////////////////////////////////////
// CEmptyTempFolder
STDMETHODIMP CEmptyTempFolder::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 CEmptyTempFolder::DoShutdown(long hParent, long lMode)
{
HWND hwndParent = (HWND)hParent;
bool bPrompt = lMode & nsNoPrompt ? false : true;
bool bSilent = lMode & nsQuiet ? true : false;
DWORD dwRet;
// Get Windows Temp Folder
string sWindowsTempPath;
dwRet = ::GetTempPath(MAX_PATH, sWindowsTempPath.get_buffer(MAX_PATH));
sWindowsTempPath.release_buffer();
sWindowsTempPath.make_upper();
file_path::clean_path(sWindowsTempPath);
if(dwRet == 0)
return HRESULT_FROM_WIN32(::GetLastError());
bool bDisable = false;
// Get Windows folder
string sTemp;
GetWindowsDirectory(sTemp.get_buffer(MAX_PATH), MAX_PATH);
sTemp.release_buffer();
sTemp.make_upper();
file_path::clean_path(sTemp);
// Compare Temp path against Windows folder
if(sWindowsTempPath == sTemp)
bDisable = true;
// Get System folder
GetSystemDirectory(sTemp.get_buffer(MAX_PATH), MAX_PATH);
sTemp.release_buffer();
sTemp.make_upper();
file_path::clean_path(sTemp);
// Compare Temp path against System folder
if(sWindowsTempPath == sTemp)
bDisable = true;
// Construct Root folder
sTemp = sWindowsTempPath.substr(0, 3);
file_path::clean_path(sTemp);
// Compare Temp path against root
if(sWindowsTempPath == sTemp)
bDisable = true;
if(bDisable)
{
if(bPrompt)
MessageBoxTimeout(hwndParent, _T("Can't remove temp files. The temp folder on your computer is the same as your Windows or System folder."),
_T("Empty Temp Folder"), MB_OK | MB_ICONSTOP, 15000, 5000);
m_Data.WriteInt(ENABLED_KEY, false);
return E_FAIL;
}
if(sWindowsTempPath.find(_T("TEMP")) == string::npos &&
sWindowsTempPath.find(_T("TMP")) == string::npos)
{
if(m_Data.GetInt(_T("Folder Prompt"), true))
{
if(!bPrompt)
{
bDisable = true;
}
else
{
CTempWarnDlg dlg(sWindowsTempPath);
bDisable = (dlg.DoModal(hwndParent) == IDCANCEL);
if(dlg.m_bNotAgain)
m_Data.WriteInt(_T("Folder Prompt"), false);
}
}
}
if(bDisable)
{
m_Data.WriteInt(ENABLED_KEY, false);
return E_FAIL;
}
// Create the dialog
CActionProgressDlg dlgProgress(m_spUnkSite, IDD_PROGRESSTEMP);
dlgProgress.Create(hwndParent);
dlgProgress.PlayAmination(IDR_AVITEMP);
CTempActions::DeletePrepare* pAction = new CTempActions::DeletePrepare;
pAction->Initialize(sWindowsTempPath);
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);
HRESULT hr = S_OK;
GetExitCodeThread(hThread, (LPDWORD)&hr);
dlgProgress.DestroyWindow();
return hr;
}
// XError: We should be using file_path here
/*string CEmptyTempFolder::CleanSlashes(const string& sPath)
{
string sTemp;
if(sPath.at(sPath.length() - 1) == _T('\\'))
sTemp = sPath.substr(0, sPath.length() - 1);
else
sTemp = sPath;
int nPos;
while((nPos = sTemp.find(_T("\\\\"), 2)) != string::npos)
sTemp.erase(nPos, 1);
return sTemp;
}
*/
STDMETHODIMP CEmptyTempFolder::get_Info(NightSecInfo nsItem, VARIANT* pvVal)
{
::VariantClear(pvVal);
CComBSTR bsRetVal;
switch(nsItem)
{
case nsName:
pvVal->vt = VT_BSTR;
bsRetVal.LoadString(IDS_TEMPNAME);
pvVal->bstrVal = bsRetVal.Detach();
return S_OK;
case nsHelpText:
pvVal->vt = VT_BSTR;
bsRetVal.LoadString(IDS_TEMPDESC);
pvVal->bstrVal = bsRetVal.Detach();
return S_OK;
case nsCmdLine:
pvVal->vt = VT_BSTR;
bsRetVal.LoadString(IDS_TEMPPARAM);
pvVal->bstrVal = bsRetVal.Detach();
return S_OK;
}
::VariantClear(pvVal);
return S_FALSE;
}
STDMETHODIMP CEmptyTempFolder::SetData(IUnknown* pUnk)
{
return m_Data.Initialize(pUnk);
}
|