From a55edbcd52dfdeb0dba7f338deb7388fde6111bb Mon Sep 17 00:00:00 2001 From: David Erceg Date: Sun, 11 Oct 2020 21:48:23 +1100 Subject: [PATCH] Show error message when opening item on application toolbar fails In previous versions of Explorer++, it wasn't necessary to quote a path with spaces when adding a button to the application toolbar. It now is necessary. That means that attempting to open an application toolbar item created in a previous version of Explorer++ may fail (due to an unquoted path). To help make it clearer what's going wrong when an item fails to be opened, the associated error message is now displayed. The parsed application path is also shown. This should make it more clear that quotes are required for paths with spaces. See #145. (cherry picked from commit 58e9a217e1e9f5d119eccb5c778832032bfa144e) --- Explorer++/Explorer++/ApplicationToolbar.cpp | 45 ++++++++++++------- Explorer++/Explorer++/Explorer++.rc | Bin 173802 -> 174100 bytes Explorer++/Explorer++/resource.h | 1 + 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Explorer++/Explorer++/ApplicationToolbar.cpp b/Explorer++/Explorer++/ApplicationToolbar.cpp index bfb991aebd..a3aab54ee7 100644 --- a/Explorer++/Explorer++/ApplicationToolbar.cpp +++ b/Explorer++/Explorer++/ApplicationToolbar.cpp @@ -27,7 +27,9 @@ #include "../Helper/RegistrySettings.h" #include "../Helper/ShellHelper.h" #include "../Helper/XMLSettings.h" -#include +#include +#include +#include const TCHAR ApplicationToolbarPersistentSettings::SETTING_NAME[] = _T("Name"); const TCHAR ApplicationToolbarPersistentSettings::SETTING_COMMAND[] = _T("Command"); @@ -315,27 +317,38 @@ void ApplicationToolbar::OpenItem(int iItem, std::wstring *parameters) ApplicationButton_t *button = MapToolbarButtonToItem(iItem); - if (button != nullptr) + if (!button) { - ApplicationInfo ai = ParseCommandString(button->Command); + return; + } - unique_pidl_absolute pidl; - HRESULT hr = - SHParseDisplayName(ai.application.c_str(), nullptr, wil::out_param(pidl), 0, nullptr); + ApplicationInfo ai = ParseCommandString(button->Command); - if (SUCCEEDED(hr)) - { - std::wstring combinedParameters = ai.parameters; + unique_pidl_absolute pidl; + HRESULT hr = + SHParseDisplayName(ai.application.c_str(), nullptr, wil::out_param(pidl), 0, nullptr); - if (parameters != nullptr && parameters->length() > 0) - { - combinedParameters.append(_T(" ")); - combinedParameters.append(*parameters); - } + if (FAILED(hr)) + { + std::wstring messageTemplate = + ResourceHelper::LoadString(m_hInstance, IDS_APPLICATION_TOOLBAR_OPEN_ERROR); + _com_error error(hr); + std::wstring message = + (boost::wformat(messageTemplate) % ai.application % error.ErrorMessage()).str(); - m_pexpp->OpenFileItem(pidl.get(), combinedParameters.c_str()); - } + MessageBox(m_hwnd, message.c_str(), NExplorerplusplus::APP_NAME, MB_ICONWARNING | MB_OK); + return; + } + + std::wstring combinedParameters = ai.parameters; + + if (parameters != nullptr && parameters->length() > 0) + { + combinedParameters.append(_T(" ")); + combinedParameters.append(*parameters); } + + m_pexpp->OpenFileItem(pidl.get(), combinedParameters.c_str()); } void ApplicationToolbar::ShowItemProperties(int iItem) diff --git a/Explorer++/Explorer++/Explorer++.rc b/Explorer++/Explorer++/Explorer++.rc index 625c67e23964bb9ba4bd3b5020a064d67a17266c..9046619c0008e4079cd3043fdc9e2c79d82a3c42 100644 GIT binary patch delta 120 zcmaELmTSrdu7(!IEljHxPxn~JC@|fsf=O)pp-+rL(|LX|axlhEkMv>ko*wXzkz@KX zRwfB