From e3226c3a6703ad3e134af44f8b37beca32ae47e0 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 31 Dec 2011 01:18:48 +0100 Subject: [PATCH] deduplicate CreateProcess code Signed-off-by: Sven Strickroth --- src/TortoiseShell/ContextMenu.cpp | 30 +++++++++++++----------------- src/TortoiseShell/ShellExt.h | 1 + 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/TortoiseShell/ContextMenu.cpp b/src/TortoiseShell/ContextMenu.cpp index a99913454..5b0cb9413 100644 --- a/src/TortoiseShell/ContextMenu.cpp +++ b/src/TortoiseShell/ContextMenu.cpp @@ -25,6 +25,7 @@ //#include "GitProperties.h" #include "GitStatus.h" #include "TGitPath.h" +#include "CreateProcessHelper.h" #include "FormatMessageWrapper.h" #define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0]) @@ -1246,11 +1247,6 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) std::map::const_iterator id_it = myIDMap.lower_bound(idCmd); if (id_it != myIDMap.end() && id_it->first == idCmd) { - STARTUPINFO startup; - PROCESS_INFORMATION process; - memset(&startup, 0, sizeof(startup)); - startup.cb = sizeof(startup); - memset(&process, 0, sizeof(process)); CRegStdString tortoiseProcPath(_T("Software\\TortoiseGit\\ProcPath"), _T("TortoiseProc.exe"), false, HKEY_LOCAL_MACHINE); CRegStdString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T("TortoiseMerge.exe"), false, HKEY_LOCAL_MACHINE); @@ -1831,12 +1827,7 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) myIDMap.clear(); myVerbsIDMap.clear(); myVerbsMap.clear(); - if (CreateProcess(((stdstring)tortoiseMergePath).c_str(), const_cast(gitCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0) - { - MessageBox(NULL, CFormatMessageWrapper(), _T("TortoiseMerge launch failed"), MB_OK | MB_ICONINFORMATION ); - } - CloseHandle(process.hThread); - CloseHandle(process.hProcess); + RunCommand(tortoiseMergePath, gitCmd, _T("TortoiseMerge launch failed")); return NOERROR; break; case ShellMenuProperties: @@ -1967,12 +1958,7 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) myIDMap.clear(); myVerbsIDMap.clear(); myVerbsMap.clear(); - if (CreateProcess(((stdstring)tortoiseProcPath).c_str(), const_cast(gitCmd.c_str()), NULL, NULL, FALSE, 0, 0, 0, &startup, &process)==0) - { - MessageBox(NULL, CFormatMessageWrapper(), _T("TortoiseProc Launch failed"), MB_OK | MB_ICONINFORMATION ); - } - CloseHandle(process.hThread); - CloseHandle(process.hProcess); + RunCommand(tortoiseProcPath, gitCmd, _T("TortoiseProc launch failed")); hr = NOERROR; } // if (id_it != myIDMap.end() && id_it->first == idCmd) } // if ((files_.size() > 0)||(folder_.size() > 0)) @@ -2636,3 +2622,13 @@ HRESULT CShellExt::ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, return hr; } +void CShellExt::RunCommand(const tstring& path, const tstring& command, LPCTSTR errorMessage) +{ + if (CCreateProcessHelper::CreateProcessDetached(path.c_str(), const_cast(command.c_str()))) + { + // process started - exit + return; + } + + MessageBox(NULL, CFormatMessageWrapper(), errorMessage, MB_OK | MB_ICONINFORMATION); +} diff --git a/src/TortoiseShell/ShellExt.h b/src/TortoiseShell/ShellExt.h index 64fd6ca91..6118e7c7c 100644 --- a/src/TortoiseShell/ShellExt.h +++ b/src/TortoiseShell/ShellExt.h @@ -129,6 +129,7 @@ private: HBITMAP IconToBitmap(UINT uIcon); STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu); bool IsIllegalFolder(std::wstring folder, int * cslidarray); + static void RunCommand(const tstring& path, const tstring& command, LPCTSTR errorMessage); HBITMAP IconToBitmapPARGB32(UINT uIcon); HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp); HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon); -- 2.11.4.GIT