WinRT: Fix argument handling on Windows 10
The Windows 10 CRT does not export __getmainargs(), so we need to move to GetCommandLine like on WinCE and desktop Windows. As CommandLineToArgv is not available, the command line is split according by spaces, allowing for quotes (and quote escaping) around arguments. Change-Id: Ibc969df94ca5423a3a71d8190bbacd201189ea19 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
This commit is contained in:
parent
ecb25dac68
commit
55f3e6bc34
@ -222,11 +222,49 @@ private:
|
||||
// Main entry point for Appx containers
|
||||
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
{
|
||||
#if _MSC_VER < 1900
|
||||
int argc = 0;
|
||||
char **argv, **env;
|
||||
_startupinfo info = { _query_new_mode() };
|
||||
if (int init = __getmainargs(&argc, &argv, &env, false, &info))
|
||||
return init;
|
||||
#else
|
||||
QByteArray commandLine = QString::fromWCharArray(GetCommandLine()).toUtf8();
|
||||
QVarLengthArray<char *> args;
|
||||
args.append(commandLine.data());
|
||||
bool quote = false;
|
||||
bool escape = false;
|
||||
for (int i = 0; i < commandLine.size(); ++i) {
|
||||
switch (commandLine.at(i)) {
|
||||
case '\\':
|
||||
escape = true;
|
||||
break;
|
||||
case '"':
|
||||
if (escape) {
|
||||
escape = false;
|
||||
break;
|
||||
}
|
||||
quote = !quote;
|
||||
commandLine[i] = '\0';
|
||||
break;
|
||||
case ' ':
|
||||
if (quote)
|
||||
break;
|
||||
commandLine[i] = '\0';
|
||||
if (args.last()[0] != '\0')
|
||||
args.append(commandLine.data() + i + 1);
|
||||
// fall through
|
||||
default:
|
||||
if (args.last()[0] == '\0')
|
||||
args.last() = commandLine.data() + i;
|
||||
escape = false; // only quotes are escaped
|
||||
break;
|
||||
}
|
||||
}
|
||||
int argc = args.size();
|
||||
char **argv = args.data();
|
||||
char **env = Q_NULLPTR;
|
||||
#endif // _MSC_VER >= 1900
|
||||
|
||||
for (int i = 0; env && env[i]; ++i) {
|
||||
QByteArray var(env[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user