correctly handle unicode args on win32

Fixes #1810
This commit is contained in:
itsmattkc
2021-12-29 00:12:23 -08:00
parent e902507e47
commit 82df30586d
5 changed files with 26 additions and 8 deletions
+3 -1
View File
@@ -162,7 +162,9 @@ else()
endif()
endif()
if (APPLE)
if (WIN32)
list(APPEND OLIVE_DEFINITIONS "-DUNICODE -D_UNICODE")
elseif (APPLE)
list(APPEND OLIVE_LIBRARIES "-framework IOKit")
elseif(UNIX)
list(APPEND OLIVE_LIBRARIES Qt5::DBus)
+4 -4
View File
@@ -52,16 +52,16 @@ const CommandLineParser::PositionalArgument *CommandLineParser::AddPositionalArg
return a;
}
void CommandLineParser::Process(int argc, char **argv)
void CommandLineParser::Process(const QVector<QString> &argv)
{
int positional_index = 0;
for (int i=1; i<argc; i++) {
for (int i=1; i<argv.size(); i++) {
if (argv[i][0] == '-') {
// Must be an option
// Skip past first dashes
const char* arg_basename = &argv[i][1];
QString arg_basename = argv[i].mid(1);
bool matched_known = false;
@@ -73,7 +73,7 @@ void CommandLineParser::Process(int argc, char **argv)
// Flag discovered!
o.option->Set();
if (o.takes_arg && i+1 < argc) {
if (o.takes_arg && i+1 < argv.size()) {
o.option->SetSetting(argv[i+1]);
i++;
}
+1 -1
View File
@@ -91,7 +91,7 @@ public:
const PositionalArgument* AddPositionalArgument(const QString& name, const QString& description, bool required = false);
void Process(int argc, char** argv);
void Process(const QVector<QString> &argv);
void PrintHelp(const char* filename);
+17 -1
View File
@@ -71,6 +71,22 @@ int main(int argc, char *argv[])
// Parse command line arguments
//
QVector<QString> args;
#if defined(_WIN32) && defined(UNICODE)
int wargc;
LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
args.resize(wargc);
for (int i=0; i<wargc; i++) {
args[i] = QString::fromWCharArray(wargv[i]);
}
LocalFree(wargv);
#else
args.resize(argc);
for (int i=0; i<argc; i++) {
args[i] = QString::fromLocal8Bit(argv[i]);
}
#endif
olive::Core::CoreParams startup_params;
CommandLineParser parser;
@@ -130,7 +146,7 @@ int main(int argc, char *argv[])
// Hidden crash option for debugging the crash handling
auto crash_option = parser.AddOption({QStringLiteral("-crash")}, QString(), true, QString(), true);
parser.Process(argc, argv);
parser.Process(args);
if (help_option->IsSet()) {
// Show help
+1 -1
View File
@@ -47,7 +47,7 @@ MainWindow::MainWindow(QWidget *parent) :
#ifdef Q_OS_WINDOWS
// Set up taskbar button progress bar (used for some modal tasks like exporting)
taskbar_btn_id_ = RegisterWindowMessage("TaskbarButtonCreated");
taskbar_btn_id_ = RegisterWindowMessage(TEXT("TaskbarButtonCreated"));
taskbar_interface_ = nullptr;
#endif