From dade93c9a711513e2a5ca0b9e7c79f167fa1e808 Mon Sep 17 00:00:00 2001 From: SupSuper Date: Mon, 19 Apr 2021 19:51:27 +0100 Subject: [PATCH] Fix ShellExecute return --- src/Engine/CrossPlatform.cpp | 8 +++++--- src/Engine/Unicode.h | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Engine/CrossPlatform.cpp b/src/Engine/CrossPlatform.cpp index 7d13dcc785..3ae08dda05 100644 --- a/src/Engine/CrossPlatform.cpp +++ b/src/Engine/CrossPlatform.cpp @@ -32,6 +32,7 @@ #include "Logger.h" #include "Exception.h" #include "Options.h" +#include "Unicode.h" #ifdef _WIN32 #ifndef NOMINMAX #define NOMINMAX @@ -1185,11 +1186,12 @@ void crashDump(void *ex, const std::string &err) bool openExplorer(const std::string &url) { #ifdef _WIN32 - HINSTANCE ret = ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL); + HINSTANCE ret = ShellExecuteW(NULL, L"open", Unicode::convMbToWc(url, CP_UTF8).c_str(), NULL, NULL, SW_SHOWNORMAL); // The return value is not a true HINSTANCE. If the function succeeds, it returns a value greater than 32. - return ((int)ret > 32); + return (static_cast(reinterpret_cast(ret)) > 32); #elif __APPLE__ - return false; + std::string cmd = "open \"" + url + "\""; + return (system(cmd.c_str()) == 0); #else std::string cmd = "xdg-open \"" + url + "\""; return (system(cmd.c_str()) == 0); diff --git a/src/Engine/Unicode.h b/src/Engine/Unicode.h index c689fb48d0..fac8942a91 100644 --- a/src/Engine/Unicode.h +++ b/src/Engine/Unicode.h @@ -61,6 +61,10 @@ namespace Unicode UString convUtf8ToUtf32(const std::string &src); /// Converts a UTF-32 string to UTF-8. std::string convUtf32ToUtf8(const UString &src); + /// Converts a wide-char string to multi-byte. + std::string convWcToMb(const std::wstring &src, unsigned int cp = 0); + /// Converts a multi-byte string to wide-char. + std::wstring convMbToWc(const std::string &src, unsigned int cp = 0); /// Converts a path to a UTF-8 string. std::string convPathToUtf8(const std::string &src); /// Converts a UTF-8 string to a path.