From 0d7374757224a4231ff85f96a2fb85d4795be649 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Sun, 16 Nov 2025 20:55:16 -0600 Subject: [PATCH] there's no way that just works, right? --- .../CmdPalModuleInterface.vcxproj | 1 + .../cmdpal/CmdPalModuleInterface/dllmain.cpp | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/modules/cmdpal/CmdPalModuleInterface/CmdPalModuleInterface.vcxproj b/src/modules/cmdpal/CmdPalModuleInterface/CmdPalModuleInterface.vcxproj index 433e7599d5..318db41ba6 100644 --- a/src/modules/cmdpal/CmdPalModuleInterface/CmdPalModuleInterface.vcxproj +++ b/src/modules/cmdpal/CmdPalModuleInterface/CmdPalModuleInterface.vcxproj @@ -58,6 +58,7 @@ $(OutDir)$(TargetName)$(TargetExt) + Shlwapi.lib;%(AdditionalDependencies) diff --git a/src/modules/cmdpal/CmdPalModuleInterface/dllmain.cpp b/src/modules/cmdpal/CmdPalModuleInterface/dllmain.cpp index 7c6a7926db..700742d7df 100644 --- a/src/modules/cmdpal/CmdPalModuleInterface/dllmain.cpp +++ b/src/modules/cmdpal/CmdPalModuleInterface/dllmain.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,29 @@ private: // Track if this is the first call to enable bool firstEnableCall = true; + static bool IsUriProtocolRegistered(const std::wstring& protocol) + { + WCHAR executable[MAX_PATH] = { 0 }; + DWORD buffer_length = MAX_PATH; + + // Query if there's an executable associated with this URI protocol + HRESULT hr = AssocQueryString(ASSOCF_INIT_IGNOREUNKNOWN, + ASSOCSTR_EXECUTABLE, + protocol.c_str(), + nullptr, + executable, + &buffer_length); + + if (SUCCEEDED(hr) && buffer_length > 0) + { + Logger::trace(L"URI protocol '{}' is registered with executable: {}", protocol, executable); + return true; + } + + Logger::trace(L"URI protocol '{}' is not registered. HRESULT: 0x{:X}", protocol, static_cast(hr)); + return false; + } + static bool LaunchApp(const std::wstring& appPath, const std::wstring& commandLineArgs, bool elevated, bool silentFail) { std::wstring dir = std::filesystem::path(appPath).parent_path(); @@ -269,6 +293,13 @@ public: return; } + // Check if x-cmdpal URI protocol handler is registered + if (!IsUriProtocolRegistered(L"x-cmdpal")) + { + Logger::error("x-cmdpal URI protocol handler is not registered. Cannot launch CmdPal."); + return; + } + if (!firstEnableCall) { Logger::trace("Not first attempt, try to launch");