From c486bae62f1f9beb57e85e8f57d1d8758a3dc5d3 Mon Sep 17 00:00:00 2001 From: Michael Guntsche Date: Tue, 9 Jul 2019 14:29:44 +0200 Subject: [PATCH] Make opening the settings file more robust (#1841) * Make opening the settings file more robust This fixes two issues. * Opens the assigned default application regardless of its configuration. Gvim for example only reacts to the "edit" verb so when selected as default application won't open. Using nullptr results in using the first specified application. This fixes #1789 * If no application is assigned for json files fall back to notepad See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea for more details especially why the result code checking is so horrific. * Fix c-style cast --- src/cascadia/TerminalApp/App.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/App.cpp b/src/cascadia/TerminalApp/App.cpp index e8d374fe64b..24f42ed5791 100644 --- a/src/cascadia/TerminalApp/App.cpp +++ b/src/cascadia/TerminalApp/App.cpp @@ -445,7 +445,12 @@ namespace winrt::TerminalApp::implementation co_await winrt::resume_background(); const auto settingsPath = CascadiaSettings::GetSettingsPath(); - ShellExecute(nullptr, L"open", settingsPath.c_str(), nullptr, nullptr, SW_SHOW); + + HINSTANCE res = ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW); + if (static_cast(reinterpret_cast(res)) <= 32) + { + ShellExecute(nullptr, nullptr, L"notepad", settingsPath.c_str(), nullptr, SW_SHOW); + } } // Method Description: