From 275b48ebf1fc75731b4a79bad8c1e75984e2e0f9 Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Mon, 25 Mar 2013 22:47:59 -0600 Subject: [PATCH] FileView: Fixed crash when using the Open command. --- Plugins/PluginFileView/PluginFileView.cpp | 25 ++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Plugins/PluginFileView/PluginFileView.cpp b/Plugins/PluginFileView/PluginFileView.cpp index de5f7d3c..7944adea 100644 --- a/Plugins/PluginFileView/PluginFileView.cpp +++ b/Plugins/PluginFileView/PluginFileView.cpp @@ -49,7 +49,7 @@ void GetFolderInfo(std::queue& folderQueue, std::wstring& folder, void GetIcon(std::wstring filePath, const std::wstring& iconPath, IconSize iconSize); HRESULT SaveIcon(HICON hIcon, FILE* fp); -std::vector g_ParentMeasures; +static std::vector g_ParentMeasures; static CRITICAL_SECTION g_CriticalSection; BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -496,6 +496,23 @@ PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args) return; } + auto runFile = [&](std::wstring& filename, std::wstring& dir) + { + CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + + std::wstring file = dir + filename; + SHELLEXECUTEINFO si = {sizeof(SHELLEXECUTEINFO)}; + + si.lpVerb = L"open"; + si.lpFile = file.c_str(); + si.nShow = SW_SHOWNORMAL; + si.lpDirectory = dir.c_str(); + si.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_ASYNCOK; + + ShellExecuteEx(&si); + CoUninitialize(); + }; + if (parent->ownerChild == child) { if (parent->files.size() > parent->count) @@ -591,8 +608,7 @@ PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args) { if (_wcsicmp(args, L"OPEN") == 0) { - std::wstring file = parent->files[trueIndex].path + parent->files[trueIndex].fileName; - ShellExecute(nullptr, nullptr, file.c_str(), nullptr, parent->files[trueIndex].path.c_str(), SW_SHOW); + runFile(parent->files[trueIndex].fileName, parent->files[trueIndex].path); } else if (parent->recursiveType != RECURSIVE_FULL && _wcsicmp(args, L"FOLLOWPATH") == 0) { @@ -631,8 +647,7 @@ PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args) } else { - std::wstring file = parent->path + parent->files[trueIndex].fileName; - ShellExecute(nullptr, nullptr, file.c_str(), nullptr, parent->path.c_str(), SW_SHOW); + runFile(parent->files[trueIndex].fileName, parent->files[trueIndex].path); } }