DolphinQt: Handle non-ASCII characters in Windows cmd arguments

CommandLineParse expects UTF-8 strings. (QApplication, on the
other hand, seems to be designed so that you can pass in the
char** argv untouched on Windows and get proper Unicode handling.)
This commit is contained in:
JosJuice
2020-09-21 11:23:06 +02:00
parent 39df01434c
commit 16d2ef1ea9
4 changed files with 39 additions and 21 deletions

View File

@ -31,6 +31,7 @@
#ifdef _WIN32
#include <Windows.h>
#include <shellapi.h>
constexpr u32 CODEPAGE_SHIFT_JIS = 932;
constexpr u32 CODEPAGE_WINDOWS_1252 = 1252;
#else
@ -630,3 +631,22 @@ std::string PathToString(const std::filesystem::path& path)
#endif
}
#endif
#ifdef _WIN32
std::vector<std::string> CommandLineToUtf8Argv(const wchar_t* command_line)
{
int nargs;
LPWSTR* tokenized = CommandLineToArgvW(command_line, &nargs);
if (!tokenized)
return {};
std::vector<std::string> argv(nargs);
for (size_t i = 0; i < nargs; ++i)
{
argv[i] = WStringToUTF8(tokenized[i]);
}
LocalFree(tokenized);
return argv;
}
#endif