1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-06-08 23:17:44 +00:00

Fix steam compatibility tool, so it works when Astra is in a Flatpak

This commit is contained in:
Joshua Goins 2023-12-19 20:43:01 -05:00
parent 99575d2406
commit 2a6009914a

View file

@ -4,6 +4,7 @@
#include "compatibilitytoolinstaller.h" #include "compatibilitytoolinstaller.h"
#include <KLocalizedString> #include <KLocalizedString>
#include <KSandbox>
#include "launchercore.h" #include "launchercore.h"
@ -15,14 +16,15 @@ CompatibilityToolInstaller::CompatibilityToolInstaller(LauncherCore &launcher, Q
void CompatibilityToolInstaller::installCompatibilityTool() void CompatibilityToolInstaller::installCompatibilityTool()
{ {
const QDir appDataDir = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::GenericDataLocation)[0]; const QDir appDataDir = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::HomeLocation)[0];
const QDir steamDir = appDataDir.absoluteFilePath(QStringLiteral("Steam")); const QDir steamDir = appDataDir.absoluteFilePath(QStringLiteral(".steam"));
if (!steamDir.exists()) { const QDir steamSteamDir = steamDir.absoluteFilePath(QStringLiteral("steam"));
if (!steamSteamDir.exists()) {
Q_EMIT error(i18n("Could not find a Steam installation.")); Q_EMIT error(i18n("Could not find a Steam installation."));
return; return;
} }
const QDir compatToolDir = steamDir.absoluteFilePath(QStringLiteral("compatibilitytools.d")); const QDir compatToolDir = steamSteamDir.absoluteFilePath(QStringLiteral("compatibilitytools.d"));
const QDir astraToolDir = compatToolDir.absoluteFilePath(QStringLiteral("astra")); const QDir astraToolDir = compatToolDir.absoluteFilePath(QStringLiteral("astra"));
if (astraToolDir.exists()) { if (astraToolDir.exists()) {
Q_EMIT error(i18n("The compatibility tool is already installed.")); Q_EMIT error(i18n("The compatibility tool is already installed."));
@ -31,16 +33,31 @@ void CompatibilityToolInstaller::installCompatibilityTool()
QDir().mkpath(astraToolDir.absolutePath()); QDir().mkpath(astraToolDir.absolutePath());
} }
const QString appPath = QCoreApplication::applicationFilePath(); QString command;
QFile appFile(appPath); if (KSandbox::isFlatpak()) {
appFile.link(astraToolDir.absoluteFilePath(QStringLiteral("astra"))); QFile wrapperFile(astraToolDir.absoluteFilePath(QStringLiteral("launch.sh")));
wrapperFile.open(QIODevice::WriteOnly);
wrapperFile.write(
QByteArrayLiteral("#!/bin/bash\n"
"LD_LIBRARY_PATH= exec \"${@:1}\""));
QProcess::execute(QStringLiteral("chmod"), {QStringLiteral("+x"), astraToolDir.absoluteFilePath(QStringLiteral("launch.sh"))});
command = QStringLiteral("/launch.sh /usr/bin/flatpak run zone.xiv.astra");
} else {
const QString appPath = QCoreApplication::applicationFilePath();
QFile appFile(appPath);
appFile.link(astraToolDir.absoluteFilePath(QStringLiteral("astra")));
command = QStringLiteral("/astra");
}
const QString toolManifestContents = QStringLiteral( const QString toolManifestContents = QStringLiteral(
"\"manifest\"\n" "\"manifest\"\n"
"{\n" "{\n"
" \"version\" \"2\"\n" " \"version\" \"2\"\n"
" \"commandline\" \"/astra --steam %verb%\"\n" " \"commandline\" \"%1 --steam %verb%\"\n"
"}"); "}")
.arg(command);
QFile toolManifestFile(astraToolDir.absoluteFilePath(QStringLiteral("toolmanifest.vdf"))); QFile toolManifestFile(astraToolDir.absoluteFilePath(QStringLiteral("toolmanifest.vdf")));
toolManifestFile.open(QIODevice::WriteOnly | QIODevice::Text); toolManifestFile.open(QIODevice::WriteOnly | QIODevice::Text);
@ -73,14 +90,15 @@ void CompatibilityToolInstaller::installCompatibilityTool()
void CompatibilityToolInstaller::removeCompatibilityTool() void CompatibilityToolInstaller::removeCompatibilityTool()
{ {
const QDir appDataDir = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::GenericDataLocation)[0]; const QDir appDataDir = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::HomeLocation)[0];
const QDir steamDir = appDataDir.absoluteFilePath(QStringLiteral("Steam")); const QDir steamDir = appDataDir.absoluteFilePath(QStringLiteral(".steam"));
if (!steamDir.exists()) { const QDir steamSteamDir = steamDir.absoluteFilePath(QStringLiteral("steam"));
if (!steamSteamDir.exists()) {
Q_EMIT error(i18n("Could not find a Steam installation.")); Q_EMIT error(i18n("Could not find a Steam installation."));
return; return;
} }
const QDir compatToolDir = steamDir.absoluteFilePath(QStringLiteral("compatibilitytools.d")); const QDir compatToolDir = steamSteamDir.absoluteFilePath(QStringLiteral("compatibilitytools.d"));
QDir astraToolDir = compatToolDir.absoluteFilePath(QStringLiteral("astra")); QDir astraToolDir = compatToolDir.absoluteFilePath(QStringLiteral("astra"));
if (!astraToolDir.exists()) { if (!astraToolDir.exists()) {
Q_EMIT error(i18n("The compatibility tool is not installed.")); Q_EMIT error(i18n("The compatibility tool is not installed."));