void CDirstatDoc::PerformUserDefinedCleanup(const USERDEFINEDCLEANUP *udc, CItem *item) throw(CException *) { CWaitCursor wc; CString path= item->GetPath(); bool isDirectory= item->GetType() == IT_DRIVE || item->GetType() == IT_DIRECTORY || item->GetType() == IT_FILESFOLDER; // Verify that path still exists if (isDirectory) { if (!FolderExists(path) && !DriveExists(path)) MdThrowStringExceptionF(IDS_THEDIRECTORYsDOESNOTEXIST, path); } else { ASSERT(item->GetType() == IT_FILE); if (!FileExists(path)) MdThrowStringExceptionF(IDS_THEFILEsDOESNOTEXIST, path); } if (udc->recurseIntoSubdirectories && item->GetType() != IT_FILESFOLDER) { ASSERT(item->GetType() == IT_DRIVE || item->GetType() == IT_DIRECTORY); RecursiveUserDefinedCleanup(udc, path, path); } else { CallUserDefinedCleanup(isDirectory, udc->commandLine, path, path, udc->showConsoleWindow, udc->waitForCompletion); } }
void MyShellExecute(HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd) throw (CException *) { CWaitCursor wc; UINT h= (UINT)ShellExecute(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd); if (h <= 32) MdThrowStringExceptionF(_T("ShellExecute failed: %1!s!"), GetShellExecuteError(h)); }
void CSetupApp::CreateShortcutInSpecialFolder(int csidl) { #ifdef TESTSLEEP Sleep(2000); #endif CShFolderApi shf; if (!shf.IsSupported()) { MdThrowStringExceptionF(IDS_CANNOTCREATESHORTCUT); } CString path; HRESULT hr= shf.SHGetFolderPath(NULL, csidl, NULL, 0, path.GetBuffer(_MAX_PATH)); path.ReleaseBuffer(); if (hr != S_OK) MdThrowStringExceptionF(IDS_SHGETFOLDERPATHdFAILEDs, csidl, MdGetWinerrorText(hr)); path+= _T("\\WinDirStat.lnk"); CreateLink(GetDestExecutable(), path, _T("WinDirStat")); }
void CDirstatDoc::CallUserDefinedCleanup(bool isDirectory, const CString& format, const CString& rootPath, const CString& currentPath, bool showConsoleWindow, bool wait) { CString userCommandLine = BuildUserDefinedCleanupCommandLine(format, rootPath, currentPath); CString app = GetCOMSPEC(); CString cmdline; cmdline.Format(_T("%s /C %s"), GetBaseNameFromPath(app), userCommandLine); CString directory = isDirectory ? currentPath : GetFolderNameFromPath(currentPath); STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = showConsoleWindow ? SW_SHOWNORMAL : SW_HIDE; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); BOOL b = CreateProcess( app, cmdline.GetBuffer(), NULL, NULL, false, 0, NULL, directory, &si, &pi ); cmdline.ReleaseBuffer(); if(!b) { MdThrowStringExceptionF(IDS_COULDNOTCREATEPROCESSssss, app, cmdline, directory, MdGetWinErrorText(::GetLastError()) ); return; } CloseHandle(pi.hThread); if(wait) { WaitForHandleWithRepainting(pi.hProcess); } CloseHandle(pi.hProcess); }
void ShellExecuteWithAssocDialog(HWND hwnd, LPCTSTR filename) { CWaitCursor wc; BOOL bExecuted = ShellExecuteNoThrow(hwnd, NULL, filename, NULL, NULL, SW_SHOWNORMAL); if((!bExecuted) && (ERROR_NO_ASSOCIATION == ::GetLastError())) { // Q192352 CString sysDir; //-- Get the system directory so that we know where Rundll32.exe resides. ::GetSystemDirectory(sysDir.GetBuffer(_MAX_PATH), _MAX_PATH); sysDir.ReleaseBuffer(); CString parameters = _T("shell32.dll,OpenAs_RunDLL "); bExecuted = ShellExecuteNoThrow(hwnd, _T("open"), _T("RUNDLL32.EXE"), parameters + filename, sysDir, SW_SHOWNORMAL); } if(!bExecuted) { MdThrowStringExceptionF(_T("ShellExecute failed: %1!s!"), MdGetWinErrorText(::GetLastError())); } }