From bc2f077c37c2f8ef6d62026debc9d5f1ad8e62e7 Mon Sep 17 00:00:00 2001 From: Hashim Khan <64767361+Hashim1999164@users.noreply.github.com> Date: Mon, 17 Aug 2026 01:13:12 +0500 Subject: [PATCH] launcher: quote emulator paths that contain spaces (#244) * launcher: quote emulator paths that contain spaces Run the Linux helper script as a bash file argument instead of bash -c, and build a properly quoted cmd.exe /K command on Windows so install folders like "Sony Playstation 5" still launch. Fixes #179. * launcher: fix cmd command quoting --------- Co-authored-by: nmzik --- src/launcher/src/mainDialog.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/launcher/src/mainDialog.cpp b/src/launcher/src/mainDialog.cpp index 38f12f103..af3ef37b9 100644 --- a/src/launcher/src/mainDialog.cpp +++ b/src/launcher/src/mainDialog.cpp @@ -335,6 +335,23 @@ static bool FindTerminal(QString* program, QStringList* prefix) { } #endif +#if defined(_WIN32) +// Quote one token for cmd.exe so paths with spaces survive /K parsing. +static QString WinCmdQuote(QString value) { + value.replace(QLatin1Char('"'), QStringLiteral("\\\"")); + return QLatin1Char('"') + value + QLatin1Char('"'); +} + +static QString BuildWinCmdKCommand(const QString& interpreter, const QStringList& args) { + QString command = WinCmdQuote(QDir::toNativeSeparators(interpreter)); + for (const auto& arg: args) { + command += QLatin1Char(' '); + command += WinCmdQuote(arg); + } + return command; +} +#endif + void MainDialog::RunInterpreter(QProcess* process, const Configuration& info) { const auto& interpreter = m_p->GetInterpreter(); @@ -359,22 +376,23 @@ void MainDialog::RunInterpreter(QProcess* process, const Configuration& info) { { QString terminal; QStringList terminal_prefix; + // Pass the script as a file argument (not bash -c) so paths with spaces work. if (FindTerminal(&terminal, &terminal_prefix)) { process->setProgram(terminal); - process->setArguments(terminal_prefix + QStringList {"bash", "-c", bash_file_name}); + process->setArguments(terminal_prefix + QStringList {"bash", bash_file_name}); } else { // Run without a terminal as a fallback. process->setProgram(QStringLiteral("bash")); - process->setArguments({QStringLiteral("-c"), bash_file_name}); + process->setArguments({bash_file_name}); } } #elif defined(_WIN32) { + // Use nativeArguments so Qt does not re-quote the /K command string. process->setProgram(CMD_EXE); - QStringList process_args; - process_args << QStringLiteral("/K") << interpreter; - process_args += args; - process->setArguments(process_args); + process->setArguments({}); + process->setNativeArguments(QStringLiteral("/K \"") + + BuildWinCmdKCommand(interpreter, args) + QLatin1Char('"')); } #else process->setProgram(interpreter);