diff options
Diffstat (limited to 'NSCmpts/WipefreeSpace.cpp')
-rw-r--r-- | NSCmpts/WipefreeSpace.cpp | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/NSCmpts/WipefreeSpace.cpp b/NSCmpts/WipefreeSpace.cpp new file mode 100644 index 0000000..72bc199 --- /dev/null +++ b/NSCmpts/WipefreeSpace.cpp @@ -0,0 +1,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; +} |