diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index c1df648..ef1bc1a 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -87,7 +87,7 @@ public: ProfileManager *profileManager(); AccountManager *accountManager(); - void setIsSteam(bool isSteam); + void initializeSteam(); /* * Begins the login process, and may call SquareBoot or SapphireLauncher depending on the profile type. diff --git a/launcher/include/steamapi.h b/launcher/include/steamapi.h index 654b865..5446e46 100644 --- a/launcher/include/steamapi.h +++ b/launcher/include/steamapi.h @@ -11,6 +11,7 @@ class SteamAPI : public QObject { public: explicit SteamAPI(LauncherCore &core, QObject *parent = nullptr); + ~SteamAPI(); void setLauncherMode(bool isLauncher); diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index e28faf7..889346f 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -65,7 +65,9 @@ void LauncherCore::buildRequest(const Profile &settings, QNetworkRequest &reques void LauncherCore::launchGame(Profile &profile, const LoginAuth &auth) { - m_steamApi->setLauncherMode(false); + if (m_steamApi != nullptr) { + m_steamApi->setLauncherMode(false); + } beginGameExecutable(profile, auth); } @@ -397,13 +399,10 @@ LauncherCore::LauncherCore() m_sapphireLauncher = new SapphireLauncher(*this, this); m_squareLauncher = new SquareLauncher(*this, this); m_squareBoot = new SquareBoot(*this, *m_squareLauncher, this); - m_steamApi = new SteamAPI(*this, this); m_profileManager = new ProfileManager(*this, this); m_accountManager = new AccountManager(*this, this); readInitialInformation(); - - m_steamApi->setLauncherMode(true); } bool LauncherCore::checkIfInPath(const QString &program) @@ -765,12 +764,11 @@ bool LauncherCore::isSteam() const bool LauncherCore::isSteamDeck() const { - return m_steamApi->isDeck(); -} - -void LauncherCore::setIsSteam(bool isSteam) -{ - m_isSteam = isSteam; + if (m_steamApi != nullptr) { + return m_steamApi->isDeck(); + } else { + return false; + } } Profile *LauncherCore::currentProfile() const @@ -797,3 +795,10 @@ void LauncherCore::clearAvatarCache() QDir(cacheLocation).removeRecursively(); } } + +void LauncherCore::initializeSteam() +{ + m_isSteam = true; + m_steamApi = new SteamAPI(*this, this); + m_steamApi->setLauncherMode(true); +} diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index bc8ab47..bb861e1 100755 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -67,24 +68,37 @@ int main(int argc, char *argv[]) parser.parse(QCoreApplication::arguments()); about.processCommandLine(&parser); -#ifdef ENABLE_STEAM + // We must handle these manually, since we use parse() and not process() + if (parser.isSet("help")) { + parser.showHelp(); + } + + if (parser.isSet("version")) { + parser.showVersion(); + } + if (parser.isSet(steamOption)) { +#ifndef ENABLE_STEAM + QMessageBox::warning(nullptr, + i18n("Warning"), + i18n("You somehow launched Astra through Steam, despite it not being compiled with Steam support. Some features may not work!")); +#endif + const QStringList args = parser.positionalArguments(); // Steam tries to use as a compatibility tool, running installation scripts (like DirectX), so try to ignore it. - if (!args[0].contains(QLatin1String("ffxivboot.exe"))) { + if (!args.empty() && !args[0].contains(QLatin1String("ffxivboot.exe"))) { return 0; } } -#endif QCoro::Qml::registerTypes(); QQmlApplicationEngine engine; -#ifdef ENABLE_STEAM auto core = engine.singletonInstance(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore")); - core->setIsSteam(parser.isSet(steamOption)); -#endif + if (parser.isSet(steamOption)) { + core->initializeSteam(); + } engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit); diff --git a/launcher/src/steamapi.cpp b/launcher/src/steamapi.cpp index 87980c2..03e8fe3 100644 --- a/launcher/src/steamapi.cpp +++ b/launcher/src/steamapi.cpp @@ -24,12 +24,15 @@ SteamAPI::SteamAPI(LauncherCore &core, QObject *parent) #endif } +SteamAPI::~SteamAPI() +{ + SteamAPI_Shutdown(); +} + void SteamAPI::setLauncherMode(bool isLauncher) { #ifdef ENABLE_STEAM - if (core.isSteam()) { - SteamUtils()->SetGameLauncherMode(isLauncher); - } + SteamUtils()->SetGameLauncherMode(isLauncher); #else Q_UNUSED(isLauncher) #endif @@ -38,11 +41,7 @@ void SteamAPI::setLauncherMode(bool isLauncher) bool SteamAPI::isDeck() const { #ifdef ENABLE_STEAM - if (core.isSteam()) { - return SteamUtils()->IsSteamRunningOnSteamDeck(); - } else { - return false; - } + return SteamUtils()->IsSteamRunningOnSteamDeck(); #else return false; #endif