From abadb7f80f041f6d23db3ad2d9d70789664e1c1b Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 24 Jul 2023 00:48:35 +1000 Subject: [PATCH] GSRunner: Fix Unicode command line on Win32 --- pcsx2-gsrunner/Main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pcsx2-gsrunner/Main.cpp b/pcsx2-gsrunner/Main.cpp index b2dd53926f..9f7e4fb81d 100644 --- a/pcsx2-gsrunner/Main.cpp +++ b/pcsx2-gsrunner/Main.cpp @@ -644,6 +644,11 @@ void GSRunner::DumpStats() Console.WriteLn("============================================"); } +#ifdef _WIN32 +// We can't handle unicode in filenames if we don't use wmain on Win32. +#define main real_main +#endif + int main(int argc, char* argv[]) { GSRunner::InitializeConsole(); @@ -808,4 +813,20 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return DefWindowProcW(hwnd, msg, wParam, lParam); } +int wmain(int argc, wchar_t** argv) +{ + std::vector u8_args; + u8_args.reserve(static_cast(argc)); + for (int i = 0; i < argc; i++) + u8_args.push_back(StringUtil::WideStringToUTF8String(argv[i])); + + std::vector u8_argptrs; + u8_argptrs.reserve(u8_args.size()); + for (int i = 0; i < argc; i++) + u8_argptrs.push_back(u8_args[i].data()); + u8_argptrs.push_back(nullptr); + + return real_main(argc, u8_argptrs.data()); +} + #endif // _WIN32