Use rundll32.exe for launching URL schemes

This commit is contained in:
Yukino Song
2024-09-19 23:45:50 +08:00
parent 9f012639b3
commit 81de679fba
+5 -16
View File
@@ -785,23 +785,12 @@ namespace platf {
} }
auto raw_target = raw_cmd_parts.at(0); auto raw_target = raw_cmd_parts.at(0);
std::wstring lookup_string;
HRESULT res;
if (PathIsURLW(raw_target.c_str())) { if (PathIsURLW(raw_target.c_str())) {
std::array<WCHAR, 128> scheme; // If the target is a URL, handle it directly with rundll32.exe
std::wstring cmd = L"rundll32.exe url.dll,FileProtocolHandler " + raw_target;
DWORD out_len = scheme.size(); return cmd;
res = UrlGetPartW(raw_target.c_str(), scheme.data(), &out_len, URL_PART_SCHEME, 0);
if (res != S_OK) {
BOOST_LOG(warning) << "Failed to extract URL scheme from URL: "sv << raw_target << " ["sv << util::hex(res).to_string_view() << ']';
return from_utf8(raw_cmd);
} }
// If the target is a URL, the class is found using the URL scheme (prior to and not including the ':')
lookup_string = scheme.data();
}
else {
// If the target is not a URL, assume it's a regular file path // If the target is not a URL, assume it's a regular file path
auto extension = PathFindExtensionW(raw_target.c_str()); auto extension = PathFindExtensionW(raw_target.c_str());
if (extension == nullptr || *extension == 0) { if (extension == nullptr || *extension == 0) {
@@ -818,8 +807,8 @@ namespace platf {
} }
// For regular files, the class is found using the file extension (including the dot) // For regular files, the class is found using the file extension (including the dot)
lookup_string = extension; std::wstring lookup_string = extension;
} HRESULT res;
std::array<WCHAR, MAX_PATH> shell_command_string; std::array<WCHAR, MAX_PATH> shell_command_string;
bool needs_cmd_escaping = false; bool needs_cmd_escaping = false;