From b642c493d78db1ac5188d6fbfcd892c89072a962 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 27 Jun 2024 23:12:20 +0200 Subject: [PATCH] fix: Opening files with unicode paths in external program/explorer not working --- lib/libimhex/source/helpers/fs.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 50de4f63d..9bbe7dc0c 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -32,6 +32,9 @@ #include #include +#include +#include + namespace hex::fs { static AutoReset> s_fileBrowserErrorCallback; @@ -48,7 +51,7 @@ namespace hex::fs { #if defined(OS_WINDOWS) hex::unused( - ShellExecute(nullptr, "open", wolv::util::toUTF8String(filePath).c_str(), nullptr, nullptr, SW_SHOWNORMAL) + ShellExecuteW(nullptr, L"open", filePath.c_str(), nullptr, nullptr, SW_SHOWNORMAL) ); #elif defined(OS_MACOS) hex::unused(system( @@ -66,9 +69,8 @@ namespace hex::fs { } #if defined(OS_WINDOWS) - hex::unused(system( - hex::format("explorer.exe {}", wolv::util::toUTF8String(dirPath)).c_str() - )); + auto args = fmt::format(L"\"{}\"", dirPath.c_str()); + ShellExecuteW(nullptr, L"open", L"explorer.exe", args.c_str(), nullptr, SW_SHOWNORMAL); #elif defined(OS_MACOS) hex::unused(system( hex::format("open {}", wolv::util::toUTF8String(dirPath)).c_str() @@ -85,9 +87,8 @@ namespace hex::fs { } #if defined(OS_WINDOWS) - hex::unused(system( - hex::format(R"(explorer.exe /select,"{}")", wolv::util::toUTF8String(selectedFilePath)).c_str() - )); + auto args = fmt::format(L"/select,\"{}\"", selectedFilePath.c_str()); + ShellExecuteW(nullptr, L"open", L"explorer.exe", args.c_str(), nullptr, SW_SHOWNORMAL); #elif defined(OS_MACOS) hex::unused(system( hex::format(