Skip to content

Commit

Permalink
Show rudimentary error info from startGame
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Apr 21, 2024
1 parent c4e4586 commit 81aa24c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ QString getGameCommand(const QString& installPath)
" --args";
}

bool startGame(const QString& commandLine)
QString startGame(const QString& commandLine)
{
if (commandLine.startsWith("/usr/bin/open ")) {
// Get the return code of `open` to see whether the app was started successfully
int ret = QProcess::execute(commandLine);
qDebug() << "/usr/bin/open returned" << ret;
return ret == 0;
return ret == 0 ? "" : QString("/usr/bin/open returned %1").arg(ret);
} else {
return QProcess::startDetached(commandLine);
return QProcess::startDetached(commandLine) ? "" : "startDetached failed";
}
}

Expand Down
7 changes: 4 additions & 3 deletions qmldownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ void QmlDownloader::startGame()
}
commandLine.replace(COMMAND_REGEX, Sys::getGameCommand(settings_.installPath()));
qDebug() << "Starting game with command line:" << commandLine;
if (Sys::startGame(commandLine)) {
QString error = Sys::startGame(commandLine);
if (error.isEmpty()) {
qDebug() << "Game started successfully";
} else {
qDebug() << "Failed to start Unvanquished process.";
qDebug() << "Failed to start Unvanquished process:" << error;
QMessageBox errorMessageBox;
errorMessageBox.setText("Failed to start Unvanquished process.");
errorMessageBox.setText("Failed to start Unvanquished process: " + error);
errorMessageBox.exec();
}
}
Expand Down
2 changes: 1 addition & 1 deletion system.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ QString updaterArchiveName();
std::string getCertStore();
QSettings* makePersistentSettings(QObject* parent);
QString getGameCommand(const QString& installPath); // Substitution for %command%
bool startGame(const QString& commandLine);
QString startGame(const QString& commandLine);

// Windows: relaunch with UAC elevation if necessary
// Other platforms always return UNNEEDED
Expand Down
10 changes: 6 additions & 4 deletions unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,25 @@ QString getGameCommand(const QString& installPath)
return QuoteQProcessCommandArgument(installPath + QDir::separator() + "daemon");
}

bool startGame(const QString& commandLine)
QString startGame(const QString& commandLine)
{
Settings settings;
settings.sync(); // since normal shutdown will be skipped
std::vector<std::string> args;
for (const QString& arg : splitArgs(commandLine)) {
args.push_back(arg.toStdString());
}
if (args.empty()) return false;
if (args.empty()) return "missing command line";
std::vector<const char*> argv;
for (const std::string& arg : args) {
argv.push_back(arg.c_str());
}
argv.push_back(nullptr);
execvp(argv[0], const_cast<char* const*>(argv.data()));
qDebug() << "execvp failed: " << strerror( errno ) << "errno =" << errno;
return false;

QString msg = QString("error %1 (%2)").arg(errno).arg(strerror(errno));
qDebug() << "execvp failed:" << msg;
return msg;
}

ElevationResult RelaunchElevated(const QString& flags)
Expand Down
9 changes: 6 additions & 3 deletions win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ QString getGameCommand(const QString& installPath)
return QuoteQProcessCommandArgument(installPath + QDir::separator() + "daemon.exe");
}

bool startGame(const QString& commandLine)
QString startGame(const QString& commandLine)
{
if (!runningAsAdmin()) {
qDebug() << "not admin, start game normally";
return QProcess::startDetached(commandLine);
return QProcess::startDetached(commandLine) ? "" : "startDetached failed";
}
std::wstring program, args;
SplitFirstArg(commandLine.toStdWString(), &program, &args);
Expand All @@ -328,7 +328,10 @@ bool startGame(const QString& commandLine)
// good anyway because Explorer creates its own dialog
// box about the failure, and we don't want to pop two dialogs.
// Strangely, ShellExecInExplorerProcess blocks until the user closes Explorer's message box in that case.
return SUCCEEDED(result);
if (SUCCEEDED(result)) {
return "";
}
return QString("error %1 while launching as non-admin").arg(result);
}

// Care should be taken when using this function to avoid any possibility of an endless restart loop.
Expand Down

0 comments on commit 81aa24c

Please sign in to comment.