fix: Opening files with unicode names through the command line

This commit is contained in:
WerWolv
2022-10-07 10:14:24 +02:00
parent 210106901e
commit 484481f886
3 changed files with 26 additions and 2 deletions

View File

@@ -11,6 +11,12 @@
#include <nlohmann/json.hpp>
#if defined(OS_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#endif
namespace hex {
namespace ImHexApi::Common {
@@ -399,6 +405,21 @@ namespace hex {
return impl::s_programArguments;
}
std::optional<std::u8string> getProgramArgument(int index) {
if (index >= impl::s_programArguments.argc) {
return std::nullopt;
}
#if defined(OS_WINDOWS)
std::wstring wideArg = ::CommandLineToArgvW(::GetCommandLineW(), &impl::s_programArguments.argc)[index];
std::string byteArg = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(wideArg);
return std::u8string(byteArg.begin(), byteArg.end());
#else
return std::u8string(reinterpret_cast<const char8_t *>(impl::s_programArguments.argv[index]));
#endif
}
static float s_targetFPS = 60.0F;