Merge pull request #10500 from shuffle2/master

windows: wrap all main funcs with utf8 conversions
This commit is contained in:
Jordan Woyak 2022-03-08 01:54:41 -06:00 committed by GitHub
commit 58c02e6b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 16 deletions

View File

@ -149,6 +149,10 @@ static std::unique_ptr<Platform> GetPlatform(const optparse::Values& options)
return nullptr; return nullptr;
} }
#ifdef _WIN32
#define main app_main
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::OmitGUIOptions); auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::OmitGUIOptions);
@ -275,3 +279,18 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
#ifdef _WIN32
int wmain(int, wchar_t*[], wchar_t*[])
{
std::vector<std::string> args = CommandLineToUtf8Argv(GetCommandLineW());
const int argc = static_cast<int>(args.size());
std::vector<char*> argv(args.size());
for (size_t i = 0; i < args.size(); ++i)
argv[i] = args[i].data();
return main(argc, argv.data());
}
#undef main
#endif

View File

@ -98,18 +98,13 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
return false; return false;
} }
#ifndef _WIN32 #ifdef _WIN32
#define main app_main
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
#else #ifdef _WIN32
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
std::vector<std::string> utf8_args = CommandLineToUtf8Argv(GetCommandLineW());
const int utf8_argc = static_cast<int>(utf8_args.size());
std::vector<char*> utf8_argv(utf8_args.size());
for (size_t i = 0; i < utf8_args.size(); ++i)
utf8_argv[i] = utf8_args[i].data();
const bool console_attached = AttachConsole(ATTACH_PARENT_PROCESS) != FALSE; const bool console_attached = AttachConsole(ATTACH_PARENT_PROCESS) != FALSE;
HANDLE stdout_handle = ::GetStdHandle(STD_OUTPUT_HANDLE); HANDLE stdout_handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
if (console_attached && stdout_handle) if (console_attached && stdout_handle)
@ -134,12 +129,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
#endif #endif
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::IncludeGUIOptions); auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::IncludeGUIOptions);
const optparse::Values& options = const optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
#ifdef _WIN32
CommandLineParse::ParseArguments(parser.get(), utf8_argc, utf8_argv.data());
#else
CommandLineParse::ParseArguments(parser.get(), argc, argv);
#endif
const std::vector<std::string> args = parser->args(); const std::vector<std::string> args = parser->args();
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@ -300,3 +290,18 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
return retval; return retval;
} }
#ifdef _WIN32
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int)
{
std::vector<std::string> args = CommandLineToUtf8Argv(GetCommandLineW());
const int argc = static_cast<int>(args.size());
std::vector<char*> argv(args.size());
for (size_t i = 0; i < args.size(); ++i)
argv[i] = args[i].data();
return main(argc, argv.data());
}
#undef main
#endif

View File

@ -20,6 +20,10 @@ static int PrintUsage(int code)
return code; return code;
} }
#ifdef _WIN32
#define main app_main
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (argc < 2) if (argc < 2)
@ -43,3 +47,18 @@ int main(int argc, char* argv[])
return command->Main(args); return command->Main(args);
} }
#ifdef _WIN32
int wmain(int, wchar_t*[], wchar_t*[])
{
std::vector<std::string> args = CommandLineToUtf8Argv(GetCommandLineW());
const int argc = static_cast<int>(args.size());
std::vector<char*> argv(args.size());
for (size_t i = 0; i < args.size(); ++i)
argv[i] = args[i].data();
return main(argc, argv.data());
}
#undef main
#endif