From 3395698527e3875aea2c21e9e6b85923afbf0c7a Mon Sep 17 00:00:00 2001 From: slipher Date: Sun, 19 May 2024 02:21:03 -0300 Subject: [PATCH] Windows: really honor connect URL on self-update --- gamelauncher.cpp | 2 +- linux.cpp | 2 +- osx.cpp | 2 +- system.h | 4 +++- win.cpp | 6 ++++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gamelauncher.cpp b/gamelauncher.cpp index 3366aec..7c1f14d 100644 --- a/gamelauncher.cpp +++ b/gamelauncher.cpp @@ -59,7 +59,7 @@ void GameLauncher::startGame(bool useConnectUrl, bool failIfWindowsAdmin) commandLine.replace(COMMAND_REGEX, gameCommand); } qDebug() << "Starting game with command line:" << commandLine; - QString error = Sys::startGame(commandLine, failIfWindowsAdmin); + QString error = Sys::startGame(commandLine, failIfWindowsAdmin, connectUrl_); if (error.isEmpty()) { qDebug() << "Game started successfully"; } else { diff --git a/linux.cpp b/linux.cpp index da6618b..733ae0e 100644 --- a/linux.cpp +++ b/linux.cpp @@ -281,7 +281,7 @@ QString getGameCommand(const QString& installPath) return QuoteQProcessCommandArgument(installPath + QDir::separator() + "daemon"); } -QString startGame(const QString& commandLine, bool) +QString startGame(const QString& commandLine, bool, const QString&) { QString error = DoExecvp(splitArgs(commandLine)); QString msg = QString("error %1 (%2)").arg(errno).arg(strerror(errno)); diff --git a/osx.cpp b/osx.cpp index 5102178..5895778 100644 --- a/osx.cpp +++ b/osx.cpp @@ -187,7 +187,7 @@ QString getGameCommand(const QString& installPath) " --args"; } -QString startGame(const QString& commandLine, bool) +QString startGame(const QString& commandLine, bool, const QString&) { if (commandLine.startsWith("/usr/bin/open ")) { // Get the return code of `open` to see whether the app was started successfully diff --git a/system.h b/system.h index f0df9c1..53b34f8 100644 --- a/system.h +++ b/system.h @@ -34,7 +34,9 @@ QString updaterArchiveName(); std::string getCertStore(); QSettings* makePersistentSettings(QObject* parent); QString getGameCommand(const QString& installPath); // Substitution for %command% -QString startGame(const QString& commandLine, bool failIfWindowsAdmin); +// A connect URL is already included in command line but on Windows if the updater has to restart to +// lose admin elevation, it uses connectUrlForRestart +QString startGame(const QString& commandLine, bool failIfWindowsAdmin, const QString& connectUrlForRestart); // Windows: relaunch with UAC elevation if necessary // Other platforms always return UNNEEDED diff --git a/win.cpp b/win.cpp index 822a4ba..4fe8e92 100644 --- a/win.cpp +++ b/win.cpp @@ -324,7 +324,7 @@ static void setGraphicsPreference() setRegistryKey(HKEY_CURRENT_USER, key, path, "GpuPreference=2;"); } -QString startGame(const QString& commandLine, bool failIfWindowsAdmin) +QString startGame(const QString& commandLine, bool failIfWindowsAdmin, const QString& connectUrlForRestart) { if (!runningAsAdmin()) { qDebug() << "not admin, start game normally"; @@ -338,9 +338,11 @@ QString startGame(const QString& commandLine, bool failIfWindowsAdmin) } // Relaunch the updater without elevation so that the graphics preference can be set. - // TODO: propagate connect URL in this case std::wstring program = QCoreApplication::applicationFilePath().toStdWString(); std::wstring args = L"--internalcommand playnow"; + if (!connectUrlForRestart.isEmpty()) { + args += L" -- " + connectUrlForRestart.toStdWString(); + } qDebug() << "restarting de-elevated: program =" << program << "args =" << args; HRESULT result = ShellExecInExplorerProcess(program.c_str(), args.c_str()); qDebug() << "HRESULT:" << result;