From 81aa24c67f126db2d962fc6223391470eabe9499 Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 15 Apr 2024 00:34:10 -0500 Subject: [PATCH] Show rudimentary error info from startGame --- osx.cpp | 6 +++--- qmldownloader.cpp | 7 ++++--- system.h | 2 +- unix.cpp | 10 ++++++---- win.cpp | 9 ++++++--- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/osx.cpp b/osx.cpp index e27fe3b..ce6c745 100644 --- a/osx.cpp +++ b/osx.cpp @@ -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"; } } diff --git a/qmldownloader.cpp b/qmldownloader.cpp index 0031330..d53ce29 100644 --- a/qmldownloader.cpp +++ b/qmldownloader.cpp @@ -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(); } } diff --git a/system.h b/system.h index 61cac2f..a74d0cd 100644 --- a/system.h +++ b/system.h @@ -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 diff --git a/unix.cpp b/unix.cpp index 7143b28..ede05b9 100644 --- a/unix.cpp +++ b/unix.cpp @@ -255,7 +255,7 @@ 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 @@ -263,15 +263,17 @@ bool startGame(const QString& commandLine) 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 argv; for (const std::string& arg : args) { argv.push_back(arg.c_str()); } argv.push_back(nullptr); execvp(argv[0], const_cast(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) diff --git a/win.cpp b/win.cpp index 691d211..47715da 100644 --- a/win.cpp +++ b/win.cpp @@ -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); @@ -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.