summaryrefslogtreecommitdiff
path: root/Source/Core/Common/StringUtil.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2020-09-21 11:23:06 +0200
committerJosJuice <josjuice@gmail.com>2020-09-21 17:26:29 +0200
commit16d2ef1ea9bc35e0a30806e1406a9aa6be9d409f (patch)
treee8d4c872b3466c46276f43d87bec8c12c30e6575 /Source/Core/Common/StringUtil.cpp
parent39df01434c3a6f444e658d1bea660ff2a6badcef (diff)
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.)
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
-rw-r--r--Source/Core/Common/StringUtil.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp
index bbc281460c..5ef8b01d24 100644
--- a/Source/Core/Common/StringUtil.cpp
+++ b/Source/Core/Common/StringUtil.cpp
@@ -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