virtual /* [local] */ HRESULT STDMETHODCALLTYPE Initialize( /* [in] */ HKEY hkRegKey, /* [in] */ LPCWSTR pcwszVolume, /* [out] */ LPWSTR *ppwszDisplayName, /* [out] */ LPWSTR *ppwszDescription, /* [out] */ DWORD *pdwFlags) = 0; virtual HRESULT STDMETHODCALLTYPE GetSpaceUsed( /* [out] */ DWORDLONG *pdwlSpaceUsed, /* [in] */ IEmptyVolumeCacheCallBack *picb) = 0; virtual HRESULT STDMETHODCALLTYPE ShowProperties( /* [in] */ HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE Purge( /* [in] */ DWORDLONG dwlSpaceToFree, /* [in] */ IEmptyVolumeCacheCallBack *picb) = 0; virtual HRESULT STDMETHODCALLTYPE Deactivate( /* [out] */ DWORD *pdwFlags) = 0; |
virtual /* [local] */ HRESULT STDMETHODCALLTYPE InitializeEx( /* [in] */ HKEY hkRegKey, /* [in] */ LPCWSTR pcwszVolume, /* [in] */ LPCWSTR pcwszKeyName, /* [out] */ LPWSTR *ppwszDisplayName, /* [out] */ LPWSTR *ppwszDescription, /* [out] */ LPWSTR *ppwszBtnText, /* [out] */ DWORD *pdwFlags) = 0; |
EVCF_OUTOFDISKSPACE EVCF_SETTINGSMODE EVCF_DONTSHOWIFZERO EVCF_ENABLEBYDEFAULT EVCF_ENABLEBYDEFAULT_AUTO EVCF_HASSETTINGS EVCF_REMOVEFROMLIST |
// 储存扫描出文件的大小 DWORDLONG m_dwlFileSize; // 储存根目录 WCHAR m_strRootDir[MAX_PATH]; // 储存扫描出文件列表 std::vector<WCHAR *> m_lstFilesToDel; |
HRESULT CCleanSimpleHandler::InitializeEx (HKEY hKey, LPCWSTR pcwszVolume, LPCWSTR pcwszKeyName, LPWSTR *ppwszDisplayName, LPWSTR *ppwszDescription, LPWSTR *ppwszBtnText, DWORD *pdwFlags) { HRESULT hr = Initialize (hKey, pcwszVolume, ppwszDisplayName, ppwszDescription, pdwFlags); *ppwszBtnText = (LPWSTR) CoTaskMemAlloc (64 * sizeof (WCHAR)); StrCpyW(*ppwszBtnText, L"View files"); return hr; } HRESULT CCleanSimpleHandler::Initialize (HKEY hKey, LPCWSTR pcwszVolume, LPWSTR *ppwszDisplayName, LPWSTR *ppwszDescription, DWORD *pdwFlags) { StrCpyW(m_strRootDir, pcwszVolume); *ppwszDisplayName = (LPWSTR) CoTaskMemAlloc(256 * sizeof (WCHAR)); StrCpyW(*ppwszDisplayName, L"*.TMP files"); *ppwszDescription = (LPWSTR) CoTaskMemAlloc (256 * sizeof (WCHAR)); StrCpyW(*ppwszDescription, L"Temporary files - *.TMP"); *pdwFlags = EVCF_HASSETTINGS | EVCF_ENABLEBYDEFAULT; m_dwlFileSize = 0; return S_OK; } |
HRESULT CCleanSimpleHandler::GetSpaceUsed (DWORDLONG *pdwSpaceUsed, IEmptyVolumeCacheCallBack *picb) { m_dwlFileSize = 0; ScanDir(m_strRootDir, picb); picb->ScanProgress(m_dwlFileSize, EVCCBF_LASTNOTIFICATION ,NULL); *pdwSpaceUsed = m_dwlFileSize; return S_OK; } bool CCleanSimpleHandler::ScanDir(WCHAR * szDir, IEmptyVolumeCacheCallBack *pcib) { WCHAR strPath[MAX_PATH]; WCHAR* pchPathFileName; bool cancelled = false; WIN32_FIND_DATAW fd; HANDLE hFind; if (cancelled = FAILED(pcib->ScanProgress(m_dwlFileSize, NULL, NULL))) return false; StrCpyW(strPath,szDir); PathAppendW(strPath, L"*"); pchPathFileName = strPath+lstrlenW(strPath)-1; hFind = FindFirstFileW(strPath, &fd); if (hFind == INVALID_HANDLE_VALUE) // E.g. Due to security issues return true; do { StrCpyW(pchPathFileName, fd.cFileName); if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (fd.cFileName[0] != '.') { if (cancelled = !ScanDir(strPath, pcib)) break; } } else { WCHAR* pchExt = PathFindExtensionW(strPath); if ( StrCmpIW(pchExt, L".tmp") == 0 ) { m_dwlFileSize += ((DWORDLONG)fd.nFileSizeHigh)*4294967295+fd.nFileSizeLow; WCHAR* filename = (WCHAR *)CoTaskMemAlloc((lstrlenW(strPath)+1)*sizeof(WCHAR)); StrCpyW(filename, strPath); m_lstFilesToDel.push_back(filename); } } } while (FindNextFileW(hFind, &fd) != NULL); FindClose(hFind); return !cancelled; } |
HRESULT CCleanSimpleHandler::Purge (DWORDLONG dwSpaceToFree, IEmptyVolumeCacheCallBack *picb) { for (unsigned int i=0; i < m_lstFilesToDel.size(); ++i) DeleteFileW(m_lstFilesToDel[i]); return S_OK; } HRESULT CCleanSimpleHandler::ShowProperties (HWND hWnd) { for (unsigned int i=0; i < m_lstFilesToDel.size(); ++i) if (MessageBoxW(hWnd, m_lstFilesToDel[i], L"View files", MB_OKCANCEL|MB_ICONINFORMATION)==IDCANCEL) break; return S_OK; } HRESULT CCleanSimpleHandler::Deactivate (LPDWORD pdwFlags) { for (unsigned int i=0; i < m_lstFilesToDel.size(); ++i) CoTaskMemFree(m_lstFilesToDel[i]); m_lstFilesToDel.clear(); *pdwFlags = 0; return S_OK; |