From a2bb741c72c413741af3bcfcabc5a4b858095a59 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 9 Apr 2022 17:53:43 -0400 Subject: [PATCH] Fix "Configure Wine" menu item not working if game is not installed Now there is a dedicated way to launch an external tool, that does not wrap in gamescope (if enabled) and not in the game's working directory. --- include/launchercore.h | 7 +++++- src/launchercore.cpp | 53 ++++++++++++++++++++++++++---------------- src/launcherwindow.cpp | 2 +- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/include/launchercore.h b/include/launchercore.h index 4ff5db0..74cbf1e 100755 --- a/include/launchercore.h +++ b/include/launchercore.h @@ -126,7 +126,12 @@ public: /* * This just wraps it in wine if needed. */ - void launchExecutable(const ProfileSettings& settings, QProcess* process, QStringList args); + void launchExecutable(const ProfileSettings& settings, QProcess* process, QStringList args, bool isGame); + + /* + * Launches an external tool. Gamescope for example is intentionally excluded. + */ + void launchExternalTool(const ProfileSettings& settings, QStringList args); void buildRequest(const ProfileSettings& settings, QNetworkRequest& request); void setSSL(QNetworkRequest& request); diff --git a/src/launchercore.cpp b/src/launchercore.cpp index 6930f96..5383690 100755 --- a/src/launchercore.cpp +++ b/src/launchercore.cpp @@ -170,7 +170,7 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au auto list = dalamudProcess->processEnvironment().toStringList(); - launchExecutable(profile, dalamudProcess, {dataDir + "/Dalamud/" + "Dalamud.Injector.exe", QString::number(exitCode), argsEncoded}); + launchExecutable(profile, dalamudProcess, {dataDir + "/Dalamud/" + "Dalamud.Injector.exe", QString::number(exitCode), argsEncoded}, false); connection->close(); socket->close(); @@ -189,7 +189,13 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au void LauncherCore::launchExecutable(const ProfileSettings& profile, const QStringList args) { auto process = new QProcess(this); process->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); - launchExecutable(profile, process, args); + launchExecutable(profile, process, args, true); +} + +void LauncherCore::launchExternalTool(const ProfileSettings& profile, const QStringList args) { + auto process = new QProcess(this); + process->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); + launchExecutable(profile, process, args, false); } void LauncherCore::launchGameExecutable(const ProfileSettings& profile, QProcess* process, const QStringList args) { @@ -197,35 +203,40 @@ void LauncherCore::launchGameExecutable(const ProfileSettings& profile, QProcess arguments.append(args); - launchExecutable(profile, process, arguments); + launchExecutable(profile, process, arguments, true); } -void LauncherCore::launchExecutable(const ProfileSettings& profile, QProcess* process, const QStringList args) { +void LauncherCore::launchExecutable(const ProfileSettings& profile, QProcess* process, const QStringList args, bool isGame) { QList arguments; auto env = process->processEnvironment(); #if defined(Q_OS_LINUX) - if(profile.useGamescope) { - arguments.push_back("gamescope"); + if (isGame) { + if (profile.useGamescope) { + arguments.push_back("gamescope"); - if(profile.gamescope.fullscreen) - arguments.push_back("-f"); + if (profile.gamescope.fullscreen) + arguments.push_back("-f"); - if(profile.gamescope.borderless) - arguments.push_back("-b"); + if (profile.gamescope.borderless) + arguments.push_back("-b"); - if(profile.gamescope.width > 0) - arguments.push_back("-w " + QString::number(profile.gamescope.width)); + if (profile.gamescope.width > 0) + arguments.push_back("-w " + + QString::number(profile.gamescope.width)); - if(profile.gamescope.height > 0) - arguments.push_back("-h " + QString::number(profile.gamescope.height)); + if (profile.gamescope.height > 0) + arguments.push_back("-h " + + QString::number(profile.gamescope.height)); - if(profile.gamescope.refreshRate > 0) - arguments.push_back("-r " + QString::number(profile.gamescope.refreshRate)); + if (profile.gamescope.refreshRate > 0) + arguments.push_back( + "-r " + QString::number(profile.gamescope.refreshRate)); + } + + if (profile.useGamemode) + arguments.push_back("gamemoderun"); } - - if(profile.useGamemode) - arguments.push_back("gamemoderun"); #endif #if defined(Q_OS_LINUX) @@ -247,7 +258,9 @@ void LauncherCore::launchExecutable(const ProfileSettings& profile, QProcess* pr auto executable = arguments[0]; arguments.removeFirst(); - process->setWorkingDirectory(profile.gamePath + "/game/"); + if (isGame) + process->setWorkingDirectory(profile.gamePath + "/game/"); + process->setProcessEnvironment(env); qDebug() << "launching " << executable << " with args" << arguments; diff --git a/src/launcherwindow.cpp b/src/launcherwindow.cpp index b153516..841df81 100644 --- a/src/launcherwindow.cpp +++ b/src/launcherwindow.cpp @@ -74,7 +74,7 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo wineCfg = fileMenu->addAction("Configure Wine..."); wineCfg->setIcon(QIcon::fromTheme("settings")); connect(wineCfg, &QAction::triggered, [=] { - this->core.launchExecutable(currentProfile(), {"winecfg.exe"}); + this->core.launchExternalTool(currentProfile(), {"winecfg.exe"}); }); #endif