summaryrefslogtreecommitdiff
path: root/NSCmpts/EmptyTempFolder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NSCmpts/EmptyTempFolder.cpp')
-rw-r--r--NSCmpts/EmptyTempFolder.cpp197
1 files changed, 197 insertions, 0 deletions
diff --git a/NSCmpts/EmptyTempFolder.cpp b/NSCmpts/EmptyTempFolder.cpp
new file mode 100644
index 0000000..cfd0510
--- /dev/null
+++ b/NSCmpts/EmptyTempFolder.cpp
@@ -0,0 +1,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);
+}
+
+
+
+
+