Skip to content

Commit

Permalink
Windows: really honor connect URL on self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed May 19, 2024
1 parent 54ada3f commit 3395698
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gamelauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down

0 comments on commit 3395698

Please sign in to comment.