From 61fff1350263207c15ad96e85735a2600d750ea7 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 11 Oct 2023 13:25:24 -0400 Subject: [PATCH] Move launcher settings to its own class, simplify LauncherCore --- launcher/CMakeLists.txt | 2 + launcher/include/launchercore.h | 71 +------- launcher/include/launchersettings.h | 83 +++++++++ launcher/src/account.cpp | 6 +- launcher/src/assetupdater.cpp | 16 +- launcher/src/launchercore.cpp | 193 +++------------------ launcher/src/launchersettings.cpp | 169 ++++++++++++++++++ launcher/src/patcher.cpp | 2 +- launcher/src/squareboot.cpp | 8 +- launcher/src/squarelauncher.cpp | 8 +- launcher/ui/Main.qml | 4 +- launcher/ui/Pages/MainPage.qml | 6 +- launcher/ui/Settings/DeveloperSettings.qml | 28 +-- launcher/ui/Settings/GeneralSettings.qml | 16 +- launcher/ui/Settings/SettingsPage.qml | 2 +- 15 files changed, 332 insertions(+), 282 deletions(-) create mode 100644 launcher/include/launchersettings.h create mode 100644 launcher/src/launchersettings.cpp diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index d876dba..176a026 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -49,6 +49,7 @@ target_sources(astra PRIVATE include/gameinstaller.h include/headline.h include/launchercore.h + include/launchersettings.h include/logger.h include/patcher.h include/processlogger.h @@ -67,6 +68,7 @@ target_sources(astra PRIVATE src/encryptedarg.cpp src/gameinstaller.cpp src/launchercore.cpp + src/launchersettings.cpp src/logger.cpp src/main.cpp src/patcher.cpp diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index a20fd7f..087461f 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -10,8 +10,8 @@ #include #include "accountmanager.h" -#include "config.h" #include "headline.h" +#include "launchersettings.h" #include "profile.h" #include "profilemanager.h" #include "squareboot.h" @@ -62,20 +62,10 @@ class LauncherCore : public QObject Q_PROPERTY(bool hasAccount READ hasAccount NOTIFY accountChanged) Q_PROPERTY(bool isSteam READ isSteam CONSTANT) Q_PROPERTY(bool isSteamDeck READ isSteamDeck CONSTANT) + Q_PROPERTY(LauncherSettings *settings READ settings CONSTANT) Q_PROPERTY(SquareBoot *squareBoot MEMBER m_squareBoot) Q_PROPERTY(ProfileManager *profileManager READ profileManager CONSTANT) Q_PROPERTY(AccountManager *accountManager READ accountManager CONSTANT) - Q_PROPERTY(bool closeWhenLaunched READ closeWhenLaunched WRITE setCloseWhenLaunched NOTIFY closeWhenLaunchedChanged) - Q_PROPERTY(bool showNews READ showNews WRITE setShowNews NOTIFY showNewsChanged) - Q_PROPERTY(bool showDevTools READ showDevTools WRITE setShowDevTools NOTIFY showDevToolsChanged) - Q_PROPERTY(bool keepPatches READ keepPatches WRITE setKeepPatches NOTIFY keepPatchesChanged) - Q_PROPERTY(QString dalamudDistribServer READ dalamudDistribServer WRITE setDalamudDistribServer NOTIFY dalamudDistribServerChanged) - Q_PROPERTY(QString squareEnixServer READ squareEnixServer WRITE setSquareEnixServer NOTIFY squareEnixServerChanged) - Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged) - Q_PROPERTY(QString xivApiServer READ xivApiServer WRITE setXivApiServer NOTIFY xivApiServerChanged) - Q_PROPERTY(QString preferredProtocol READ preferredProtocol WRITE setPreferredProtocol NOTIFY preferredProtocolChanged) - Q_PROPERTY(QString screenshotDir READ screenshotDir WRITE setScreenshotDir NOTIFY screenshotDirChanged) - Q_PROPERTY(bool argumentsEncrypted READ argumentsEncrypted WRITE setArgumentsEncrypted NOTIFY encryptedArgumentsChanged) Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged) Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged) Q_PROPERTY(Profile *autoLoginProfile READ autoLoginProfile WRITE setAutoLoginProfile NOTIFY autoLoginProfileChanged) @@ -85,6 +75,7 @@ public: QNetworkAccessManager *mgr; + LauncherSettings *settings(); ProfileManager *profileManager(); AccountManager *accountManager(); @@ -125,43 +116,6 @@ public: void readInitialInformation(); - [[nodiscard]] bool closeWhenLaunched() const; - void setCloseWhenLaunched(bool value); - - [[nodiscard]] bool showNews() const; - void setShowNews(bool value); - - [[nodiscard]] bool showDevTools() const; - void setShowDevTools(bool value); - - [[nodiscard]] bool keepPatches() const; - void setKeepPatches(bool value); - - [[nodiscard]] QString dalamudDistribServer() const; - void setDalamudDistribServer(const QString &value); - - [[nodiscard]] QString squareEnixServer() const; - void setSquareEnixServer(const QString &value); - - [[nodiscard]] QString squareEnixLoginServer() const; - void setSquareEnixLoginServer(const QString &value); - - [[nodiscard]] QString xivApiServer() const; - void setXivApiServer(const QString &value); - - [[nodiscard]] QString preferredProtocol() const; - void setPreferredProtocol(const QString &value); - - [[nodiscard]] QString screenshotDir() const; - void setScreenshotDir(const QString &value); - - [[nodiscard]] bool argumentsEncrypted() const; - void setArgumentsEncrypted(bool value); - - [[nodiscard]] QString autoLoginProfileName() const; - [[nodiscard]] Profile *autoLoginProfile() const; - void setAutoLoginProfile(Profile *value); - Q_INVOKABLE GameInstaller *createInstaller(Profile *profile); Q_INVOKABLE CompatibilityToolInstaller *createCompatInstaller(); @@ -178,24 +132,15 @@ public: Q_INVOKABLE void clearAvatarCache(); + [[nodiscard]] QString autoLoginProfileName() const; + [[nodiscard]] Profile *autoLoginProfile() const; + void setAutoLoginProfile(Profile *value); + signals: void loadingFinished(); - void gameInstallationChanged(); void accountChanged(); - void settingsChanged(); void successfulLaunch(); void gameClosed(); - void closeWhenLaunchedChanged(); - void showNewsChanged(); - void showDevToolsChanged(); - void keepPatchesChanged(); - void dalamudDistribServerChanged(); - void squareEnixServerChanged(); - void squareEnixLoginServerChanged(); - void xivApiServerChanged(); - void preferredProtocolChanged(); - void screenshotDirChanged(); - void encryptedArgumentsChanged(); void loginError(QString message); void dalamudError(QString message); void stageChanged(QString message); @@ -246,7 +191,7 @@ private: SquareLauncher *m_squareLauncher = nullptr; Headline *m_headline = nullptr; - Config *m_config = nullptr; + LauncherSettings *m_settings = nullptr; int m_currentProfileIndex = 0; }; diff --git a/launcher/include/launchersettings.h b/launcher/include/launchersettings.h new file mode 100644 index 0000000..cefdd10 --- /dev/null +++ b/launcher/include/launchersettings.h @@ -0,0 +1,83 @@ +// SPDX-FileCopyrightText: 2023 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include +#include + +#include "config.h" +#include "profile.h" + +class LauncherSettings : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("Use LauncherCore.settings") + + Q_PROPERTY(bool closeWhenLaunched READ closeWhenLaunched WRITE setCloseWhenLaunched NOTIFY closeWhenLaunchedChanged) + Q_PROPERTY(bool showNews READ showNews WRITE setShowNews NOTIFY showNewsChanged) + Q_PROPERTY(bool showDevTools READ showDevTools WRITE setShowDevTools NOTIFY showDevToolsChanged) + Q_PROPERTY(bool keepPatches READ keepPatches WRITE setKeepPatches NOTIFY keepPatchesChanged) + Q_PROPERTY(QString dalamudDistribServer READ dalamudDistribServer WRITE setDalamudDistribServer NOTIFY dalamudDistribServerChanged) + Q_PROPERTY(QString squareEnixServer READ squareEnixServer WRITE setSquareEnixServer NOTIFY squareEnixServerChanged) + Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged) + Q_PROPERTY(QString xivApiServer READ xivApiServer WRITE setXivApiServer NOTIFY xivApiServerChanged) + Q_PROPERTY(QString preferredProtocol READ preferredProtocol WRITE setPreferredProtocol NOTIFY preferredProtocolChanged) + Q_PROPERTY(QString screenshotDir READ screenshotDir WRITE setScreenshotDir NOTIFY screenshotDirChanged) + Q_PROPERTY(bool argumentsEncrypted READ argumentsEncrypted WRITE setArgumentsEncrypted NOTIFY encryptedArgumentsChanged) + +public: + explicit LauncherSettings(QObject *parent = nullptr); + + [[nodiscard]] bool closeWhenLaunched() const; + void setCloseWhenLaunched(bool value); + + [[nodiscard]] bool showNews() const; + void setShowNews(bool value); + + [[nodiscard]] bool showDevTools() const; + void setShowDevTools(bool value); + + [[nodiscard]] bool keepPatches() const; + void setKeepPatches(bool value); + + [[nodiscard]] QString dalamudDistribServer() const; + void setDalamudDistribServer(const QString &value); + + [[nodiscard]] QString squareEnixServer() const; + void setSquareEnixServer(const QString &value); + + [[nodiscard]] QString squareEnixLoginServer() const; + void setSquareEnixLoginServer(const QString &value); + + [[nodiscard]] QString xivApiServer() const; + void setXivApiServer(const QString &value); + + [[nodiscard]] QString preferredProtocol() const; + void setPreferredProtocol(const QString &value); + + [[nodiscard]] QString screenshotDir() const; + void setScreenshotDir(const QString &value); + + [[nodiscard]] bool argumentsEncrypted() const; + void setArgumentsEncrypted(bool value); + + Config *config(); + +Q_SIGNALS: + void closeWhenLaunchedChanged(); + void showNewsChanged(); + void showDevToolsChanged(); + void keepPatchesChanged(); + void dalamudDistribServerChanged(); + void squareEnixServerChanged(); + void squareEnixLoginServerChanged(); + void xivApiServerChanged(); + void preferredProtocolChanged(); + void screenshotDirChanged(); + void encryptedArgumentsChanged(); + +private: + Config *m_config = nullptr; +}; \ No newline at end of file diff --git a/launcher/src/account.cpp b/launcher/src/account.cpp index bde5af7..f814660 100644 --- a/launcher/src/account.cpp +++ b/launcher/src/account.cpp @@ -231,8 +231,8 @@ void Account::fetchAvatar() qDebug() << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from xivapi."; QUrl url; - url.setScheme(m_launcher.preferredProtocol()); - url.setHost(m_launcher.xivApiServer()); + url.setScheme(m_launcher.settings()->preferredProtocol()); + url.setHost(m_launcher.settings()->xivApiServer()); url.setPath(QStringLiteral("/character/%1").arg(lodestoneId())); QNetworkRequest request(url); @@ -310,7 +310,7 @@ void Account::updateConfig() // Ensure that the opening cutscene movie never plays, since it's broken in most versions of Wine physis_cfg_set_value(cfgFile, "CutsceneMovieOpening", "1"); - auto screenshotDir = m_launcher.screenshotDir(); + auto screenshotDir = m_launcher.settings()->screenshotDir(); if (!QDir().exists(screenshotDir)) QDir().mkpath(screenshotDir); diff --git a/launcher/src/assetupdater.cpp b/launcher/src/assetupdater.cpp index ec43150..75963d9 100644 --- a/launcher/src/assetupdater.cpp +++ b/launcher/src/assetupdater.cpp @@ -267,8 +267,8 @@ QCoro::Task AssetUpdater::installRuntime() QUrl AssetUpdater::dalamudVersionManifestUrl() const { QUrl url; - url.setScheme(launcher.preferredProtocol()); - url.setHost(launcher.dalamudDistribServer()); + url.setScheme(launcher.settings()->preferredProtocol()); + url.setHost(launcher.settings()->dalamudDistribServer()); url.setPath(QStringLiteral("/Dalamud/Release/VersionInfo")); return url; @@ -277,8 +277,8 @@ QUrl AssetUpdater::dalamudVersionManifestUrl() const QUrl AssetUpdater::dalamudAssetManifestUrl() const { QUrl url; - url.setScheme(launcher.preferredProtocol()); - url.setHost(launcher.dalamudDistribServer()); + url.setScheme(launcher.settings()->preferredProtocol()); + url.setHost(launcher.settings()->dalamudDistribServer()); url.setPath(QStringLiteral("/Dalamud/Asset/Meta")); return url; @@ -287,8 +287,8 @@ QUrl AssetUpdater::dalamudAssetManifestUrl() const QUrl AssetUpdater::dotnetRuntimePackageUrl(const QString &version) const { QUrl url; - url.setScheme(launcher.preferredProtocol()); - url.setHost(launcher.dalamudDistribServer()); + url.setScheme(launcher.settings()->preferredProtocol()); + url.setHost(launcher.settings()->dalamudDistribServer()); url.setPath(QStringLiteral("/Dalamud/Release/Runtime/DotNet/%1").arg(version)); return url; @@ -297,8 +297,8 @@ QUrl AssetUpdater::dotnetRuntimePackageUrl(const QString &version) const QUrl AssetUpdater::dotnetDesktopPackageUrl(const QString &version) const { QUrl url; - url.setScheme(launcher.preferredProtocol()); - url.setHost(launcher.dalamudDistribServer()); + url.setScheme(launcher.settings()->preferredProtocol()); + url.setHost(launcher.settings()->dalamudDistribServer()); url.setPath(QStringLiteral("/Dalamud/Release/Runtime/WindowsDesktop/%1").arg(version)); return url; diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index ef94c48..4dfbaec 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -41,7 +41,7 @@ void LauncherCore::setupIgnoreSSL(QNetworkReply *reply) { Q_ASSERT(reply != nullptr); - if (preferredProtocol() == QStringLiteral("http")) { + if (m_settings->preferredProtocol() == QStringLiteral("http")) { connect(reply, &QNetworkReply::sslErrors, this, [reply](const QList &errors) { reply->ignoreSslErrors(errors); }); @@ -236,14 +236,14 @@ QString LauncherCore::getGameArgs(const Profile &profile, const LoginAuth &auth) gameArgs.push_back({QStringLiteral("IsSteam"), QStringLiteral("1")}); } - const QString argFormat = argumentsEncrypted() ? QStringLiteral(" /%1 =%2") : QStringLiteral(" %1=%2"); + const QString argFormat = m_settings->argumentsEncrypted() ? QStringLiteral(" /%1 =%2") : QStringLiteral(" %1=%2"); QString argJoined; for (const auto &arg : gameArgs) { argJoined += argFormat.arg(arg.key, arg.value); } - return argumentsEncrypted() ? encryptGameArg(argJoined) : argJoined; + return m_settings->argumentsEncrypted() ? encryptGameArg(argJoined) : argJoined; } void LauncherCore::launchExecutable(const Profile &profile, QProcess *process, const QStringList &args, bool isGame, bool needsRegistrySetup) @@ -402,7 +402,7 @@ void LauncherCore::readInitialInformation() } // set default profile, if found - if (auto profile = m_profileManager->getProfileByUUID(m_config->currentProfile()); profile != nullptr) { + if (auto profile = m_profileManager->getProfileByUUID(m_settings->config()->currentProfile()); profile != nullptr) { setCurrentProfile(profile); } @@ -412,7 +412,7 @@ void LauncherCore::readInitialInformation() LauncherCore::LauncherCore() { - m_config = new Config(KSharedConfig::openConfig("astrarc", KConfig::SimpleConfig, QStandardPaths::AppConfigLocation)); + m_settings = new LauncherSettings(this); mgr = new QNetworkAccessManager(this); m_sapphireLauncher = new SapphireLauncher(*this, this); m_squareLauncher = new SquareLauncher(*this, this); @@ -522,186 +522,32 @@ AccountManager *LauncherCore::accountManager() return m_accountManager; } -bool LauncherCore::closeWhenLaunched() const -{ - return m_config->closeWhenLaunched(); -} - -void LauncherCore::setCloseWhenLaunched(const bool value) -{ - if (value != m_config->closeWhenLaunched()) { - m_config->setCloseWhenLaunched(value); - m_config->save(); - Q_EMIT closeWhenLaunchedChanged(); - } -} - -bool LauncherCore::showNews() const -{ - return m_config->showNews(); -} - -void LauncherCore::setShowNews(const bool value) -{ - if (value != m_config->showNews()) { - m_config->setShowNews(value); - m_config->save(); - Q_EMIT showNewsChanged(); - } -} - -bool LauncherCore::showDevTools() const -{ - return m_config->showDevTools(); -} - -void LauncherCore::setShowDevTools(const bool value) -{ - if (value != m_config->showDevTools()) { - m_config->setShowDevTools(value); - m_config->save(); - Q_EMIT showDevToolsChanged(); - } -} - -bool LauncherCore::keepPatches() const -{ - return m_config->keepPatches(); -} - -void LauncherCore::setKeepPatches(const bool value) -{ - if (value != m_config->keepPatches()) { - m_config->setKeepPatches(value); - m_config->save(); - Q_EMIT keepPatchesChanged(); - } -} - -QString LauncherCore::dalamudDistribServer() const -{ - return m_config->dalamudDistribServer(); -} - -void LauncherCore::setDalamudDistribServer(const QString &value) -{ - if (value != m_config->dalamudDistribServer()) { - m_config->setDalamudDistribServer(value); - m_config->save(); - Q_EMIT dalamudDistribServerChanged(); - } -} - -QString LauncherCore::squareEnixServer() const -{ - return m_config->squareEnixServer(); -} - -void LauncherCore::setSquareEnixServer(const QString &value) -{ - if (value != m_config->squareEnixServer()) { - m_config->setSquareEnixServer(value); - m_config->save(); - Q_EMIT squareEnixServerChanged(); - } -} - -QString LauncherCore::squareEnixLoginServer() const -{ - return m_config->squareEnixLoginServer(); -} - -void LauncherCore::setSquareEnixLoginServer(const QString &value) -{ - if (value != m_config->squareEnixLoginServer()) { - m_config->setSquareEnixLoginServer(value); - m_config->save(); - Q_EMIT squareEnixLoginServerChanged(); - } -} - -QString LauncherCore::xivApiServer() const -{ - return m_config->xivApiServer(); -} - -void LauncherCore::setXivApiServer(const QString &value) -{ - if (value != m_config->xivApiServer()) { - m_config->setXivApiServer(value); - m_config->save(); - Q_EMIT xivApiServerChanged(); - } -} - -QString LauncherCore::preferredProtocol() const -{ - return m_config->preferredProtocol(); -} - -void LauncherCore::setPreferredProtocol(const QString &value) -{ - if (value != m_config->preferredProtocol()) { - m_config->setPreferredProtocol(value); - m_config->save(); - Q_EMIT preferredProtocolChanged(); - } -} - -QString LauncherCore::screenshotDir() const -{ - return m_config->screenshotDir(); -} - -void LauncherCore::setScreenshotDir(const QString &value) -{ - if (value != m_config->screenshotDir()) { - m_config->setScreenshotDir(value); - m_config->save(); - Q_EMIT screenshotDirChanged(); - } -} - -bool LauncherCore::argumentsEncrypted() const -{ - return m_config->encryptArguments(); -} - -void LauncherCore::setArgumentsEncrypted(const bool value) -{ - if (m_config->encryptArguments() != value) { - m_config->setEncryptArguments(value); - m_config->save(); - Q_EMIT encryptedArgumentsChanged(); - } -} - [[nodiscard]] QString LauncherCore::autoLoginProfileName() const { - return m_config->autoLoginProfile(); + return m_settings->config()->autoLoginProfile(); } [[nodiscard]] Profile *LauncherCore::autoLoginProfile() const { - if (m_config->autoLoginProfile().isEmpty()) { + if (m_settings->config()->autoLoginProfile().isEmpty()) { return nullptr; } - return m_profileManager->getProfileByUUID(m_config->autoLoginProfile()); + return m_profileManager->getProfileByUUID(m_settings->config()->autoLoginProfile()); } void LauncherCore::setAutoLoginProfile(Profile *profile) { if (profile == nullptr) { - m_config->setAutoLoginProfile({}); - m_config->save(); + m_settings->config()->setAutoLoginProfile({}); + m_settings->config()->save(); Q_EMIT autoLoginProfileChanged(); return; } auto uuid = profile->uuid(); - if (uuid != m_config->autoLoginProfile()) { - m_config->setAutoLoginProfile(uuid); - m_config->save(); + if (uuid != m_settings->config()->autoLoginProfile()) { + m_settings->config()->setAutoLoginProfile(uuid); + m_settings->config()->save(); Q_EMIT autoLoginProfileChanged(); } } @@ -720,8 +566,8 @@ QCoro::Task<> LauncherCore::fetchNews() query.addQueryItem(QStringLiteral("media"), QStringLiteral("pcapp")); QUrl url; - url.setScheme(preferredProtocol()); - url.setHost(QStringLiteral("frontier.%1").arg(squareEnixServer())); + url.setScheme(m_settings->preferredProtocol()); + url.setHost(QStringLiteral("frontier.%1").arg(m_settings->squareEnixServer())); url.setPath(QStringLiteral("/news/headline.json")); url.setQuery(query); @@ -818,8 +664,8 @@ void LauncherCore::setCurrentProfile(Profile *profile) const int newIndex = m_profileManager->getProfileIndex(profile->uuid()); if (newIndex != m_currentProfileIndex) { m_currentProfileIndex = newIndex; - m_config->setCurrentProfile(profile->uuid()); - m_config->save(); + m_settings->config()->setCurrentProfile(profile->uuid()); + m_settings->config()->save(); Q_EMIT currentProfileChanged(); } } @@ -838,3 +684,8 @@ void LauncherCore::initializeSteam() m_steamApi = new SteamAPI(*this, this); m_steamApi->setLauncherMode(true); } + +LauncherSettings *LauncherCore::settings() +{ + return m_settings; +} diff --git a/launcher/src/launchersettings.cpp b/launcher/src/launchersettings.cpp new file mode 100644 index 0000000..e9bcffd --- /dev/null +++ b/launcher/src/launchersettings.cpp @@ -0,0 +1,169 @@ +// SPDX-FileCopyrightText: 2023 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "launchersettings.h" + +LauncherSettings::LauncherSettings(QObject *parent) + : QObject(parent) +{ + m_config = new Config(KSharedConfig::openConfig("astrarc", KConfig::SimpleConfig, QStandardPaths::AppConfigLocation)); +} + +bool LauncherSettings::closeWhenLaunched() const +{ + return m_config->closeWhenLaunched(); +} + +void LauncherSettings::setCloseWhenLaunched(const bool value) +{ + if (value != m_config->closeWhenLaunched()) { + m_config->setCloseWhenLaunched(value); + m_config->save(); + Q_EMIT closeWhenLaunchedChanged(); + } +} + +bool LauncherSettings::showNews() const +{ + return m_config->showNews(); +} + +void LauncherSettings::setShowNews(const bool value) +{ + if (value != m_config->showNews()) { + m_config->setShowNews(value); + m_config->save(); + Q_EMIT showNewsChanged(); + } +} + +bool LauncherSettings::showDevTools() const +{ + return m_config->showDevTools(); +} + +void LauncherSettings::setShowDevTools(const bool value) +{ + if (value != m_config->showDevTools()) { + m_config->setShowDevTools(value); + m_config->save(); + Q_EMIT showDevToolsChanged(); + } +} + +bool LauncherSettings::keepPatches() const +{ + return m_config->keepPatches(); +} + +void LauncherSettings::setKeepPatches(const bool value) +{ + if (value != m_config->keepPatches()) { + m_config->setKeepPatches(value); + m_config->save(); + Q_EMIT keepPatchesChanged(); + } +} + +QString LauncherSettings::dalamudDistribServer() const +{ + return m_config->dalamudDistribServer(); +} + +void LauncherSettings::setDalamudDistribServer(const QString &value) +{ + if (value != m_config->dalamudDistribServer()) { + m_config->setDalamudDistribServer(value); + m_config->save(); + Q_EMIT dalamudDistribServerChanged(); + } +} + +QString LauncherSettings::squareEnixServer() const +{ + return m_config->squareEnixServer(); +} + +void LauncherSettings::setSquareEnixServer(const QString &value) +{ + if (value != m_config->squareEnixServer()) { + m_config->setSquareEnixServer(value); + m_config->save(); + Q_EMIT squareEnixServerChanged(); + } +} + +QString LauncherSettings::squareEnixLoginServer() const +{ + return m_config->squareEnixLoginServer(); +} + +void LauncherSettings::setSquareEnixLoginServer(const QString &value) +{ + if (value != m_config->squareEnixLoginServer()) { + m_config->setSquareEnixLoginServer(value); + m_config->save(); + Q_EMIT squareEnixLoginServerChanged(); + } +} + +QString LauncherSettings::xivApiServer() const +{ + return m_config->xivApiServer(); +} + +void LauncherSettings::setXivApiServer(const QString &value) +{ + if (value != m_config->xivApiServer()) { + m_config->setXivApiServer(value); + m_config->save(); + Q_EMIT xivApiServerChanged(); + } +} + +QString LauncherSettings::preferredProtocol() const +{ + return m_config->preferredProtocol(); +} + +void LauncherSettings::setPreferredProtocol(const QString &value) +{ + if (value != m_config->preferredProtocol()) { + m_config->setPreferredProtocol(value); + m_config->save(); + Q_EMIT preferredProtocolChanged(); + } +} + +QString LauncherSettings::screenshotDir() const +{ + return m_config->screenshotDir(); +} + +void LauncherSettings::setScreenshotDir(const QString &value) +{ + if (value != m_config->screenshotDir()) { + m_config->setScreenshotDir(value); + m_config->save(); + Q_EMIT screenshotDirChanged(); + } +} + +bool LauncherSettings::argumentsEncrypted() const +{ + return m_config->encryptArguments(); +} + +void LauncherSettings::setArgumentsEncrypted(const bool value) +{ + if (m_config->encryptArguments() != value) { + m_config->setEncryptArguments(value); + m_config->save(); + Q_EMIT encryptedArgumentsChanged(); + } +} + +Config *LauncherSettings::config() +{ + return m_config; +} diff --git a/launcher/src/patcher.cpp b/launcher/src/patcher.cpp index aa587f6..6aee159 100644 --- a/launcher/src/patcher.cpp +++ b/launcher/src/patcher.cpp @@ -174,7 +174,7 @@ void Patcher::processPatch(const QueuedPatch &patch) void Patcher::setupDirectories() { QDir dataDir; - if (m_launcher.keepPatches()) { + if (m_launcher.settings()->keepPatches()) { dataDir.setPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); } else { dataDir.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); diff --git a/launcher/src/squareboot.cpp b/launcher/src/squareboot.cpp index 7dd0420..c387fe7 100644 --- a/launcher/src/squareboot.cpp +++ b/launcher/src/squareboot.cpp @@ -32,7 +32,7 @@ QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info) QUrl url; url.setScheme(QStringLiteral("http")); - url.setHost(QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer())); + url.setHost(QStringLiteral("patch-bootver.%1").arg(window.settings()->squareEnixServer())); url.setPath(QStringLiteral("/http/win32/ffxivneo_release_boot/%1").arg(info.profile->bootVersion())); url.setQuery(query); @@ -43,7 +43,7 @@ QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info) request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV PATCH CLIENT")); } - request.setRawHeader(QByteArrayLiteral("Host"), QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8()); + request.setRawHeader(QByteArrayLiteral("Host"), QStringLiteral("patch-bootver.%1").arg(window.settings()->squareEnixServer()).toUtf8()); Utility::printRequest(QStringLiteral("GET"), request); const auto reply = window.mgr->get(request); @@ -69,8 +69,8 @@ QCoro::Task<> SquareBoot::checkGateStatus(const LoginInformation &info) qDebug() << "Checking gate..."; QUrl url; - url.setScheme(window.preferredProtocol()); - url.setHost(QStringLiteral("frontier.%1").arg(window.squareEnixServer())); + url.setScheme(window.settings()->preferredProtocol()); + url.setHost(QStringLiteral("frontier.%1").arg(window.settings()->squareEnixServer())); url.setPath(QStringLiteral("/worldStatus/gate_status.json")); url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch())); diff --git a/launcher/src/squarelauncher.cpp b/launcher/src/squarelauncher.cpp index a4d4b78..e7bcac3 100644 --- a/launcher/src/squarelauncher.cpp +++ b/launcher/src/squarelauncher.cpp @@ -58,8 +58,8 @@ QCoro::Task> SquareLauncher::getStored } QUrl url; - url.setScheme(window.preferredProtocol()); - url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.squareEnixLoginServer())); + url.setScheme(window.settings()->preferredProtocol()); + url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.settings()->squareEnixLoginServer())); url.setPath(QStringLiteral("/oauth/ffxivarr/login/top")); url.setQuery(query); @@ -117,7 +117,7 @@ QCoro::Task<> SquareLauncher::login(const LoginInformation &info) QUrl url; url.setScheme(QStringLiteral("https")); - url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.squareEnixLoginServer())); + url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.settings()->squareEnixLoginServer())); url.setPath(QStringLiteral("/oauth/ffxivarr/login/login.send")); QNetworkRequest request(url); @@ -170,7 +170,7 @@ QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info) { QUrl url; url.setScheme(QStringLiteral("https")); - url.setHost(QStringLiteral("patch-gamever.%1").arg(window.squareEnixServer())); + url.setHost(QStringLiteral("patch-gamever.%1").arg(window.settings()->squareEnixServer())); url.setPath(QStringLiteral("/http/win32/ffxivneo_release_game/%1/%2").arg(info.profile->baseGameVersion(), SID)); auto request = QNetworkRequest(url); diff --git a/launcher/ui/Main.qml b/launcher/ui/Main.qml index ab01255..0ab56ec 100644 --- a/launcher/ui/Main.qml +++ b/launcher/ui/Main.qml @@ -87,7 +87,7 @@ Kirigami.ApplicationWindow { } function onSuccessfulLaunch() { - if (LauncherCore.closeWhenLaunched) { + if (LauncherCore.settings.closeWhenLaunched) { hide(); } else { checkSetup(); @@ -95,7 +95,7 @@ Kirigami.ApplicationWindow { } function onGameClosed() { - if (LauncherCore.closeWhenLaunched) { + if (LauncherCore.settings.closeWhenLaunched) { Qt.callLater(Qt.quit); } else { checkSetup(); diff --git a/launcher/ui/Pages/MainPage.qml b/launcher/ui/Pages/MainPage.qml index bc2b832..b4fd2e7 100644 --- a/launcher/ui/Pages/MainPage.qml +++ b/launcher/ui/Pages/MainPage.qml @@ -27,7 +27,7 @@ Kirigami.Page { spacing: Kirigami.Units.largeSpacing Loader { - active: LauncherCore.showNews + active: LauncherCore.settings.showNews Layout.fillWidth: true Layout.fillHeight: true @@ -46,8 +46,8 @@ Kirigami.Page { id: loginPage Layout.alignment: Qt.AlignTop | Qt.AlignHCenter - Layout.minimumWidth: LauncherCore.showNews ? Kirigami.Units.gridUnit * 26 : 0 - Layout.fillWidth: !LauncherCore.showNews + Layout.minimumWidth: LauncherCore.settings.showNews ? Kirigami.Units.gridUnit * 26 : 0 + Layout.fillWidth: !LauncherCore.settings.showNews } } } \ No newline at end of file diff --git a/launcher/ui/Settings/DeveloperSettings.qml b/launcher/ui/Settings/DeveloperSettings.qml index 65378ce..1fdf3fc 100644 --- a/launcher/ui/Settings/DeveloperSettings.qml +++ b/launcher/ui/Settings/DeveloperSettings.qml @@ -28,8 +28,8 @@ FormCard.FormCardPage { text: i18n("Keep Patches") description: i18n("Do not delete patches after they're used. Astra will not download patch data, if found.") - checked: LauncherCore.keepPatches - onCheckedChanged: LauncherCore.keepPatches = checked + checked: LauncherCore.settings.keepPatches + onCheckedChanged: LauncherCore.settings.keepPatches = checked } } @@ -44,8 +44,8 @@ FormCard.FormCardPage { id: encryptArgDelegate text: i18n("Encrypt Game Arguments") - checked: LauncherCore.argumentsEncrypted - onCheckedChanged: LauncherCore.argumentsEncrypted = checked + checked: LauncherCore.settings.argumentsEncrypted + onCheckedChanged: LauncherCore.settings.argumentsEncrypted = checked } } @@ -60,8 +60,8 @@ FormCard.FormCardPage { id: preferredProtocolDelegate label: i18n("Preferred Protocol") - text: LauncherCore.preferredProtocol - onTextChanged: LauncherCore.preferredProtocol = text + text: LauncherCore.settings.preferredProtocol + onTextChanged: LauncherCore.settings.preferredProtocol = text } FormCard.FormDelegateSeparator { @@ -73,8 +73,8 @@ FormCard.FormCardPage { id: dalamudServerDelegate label: i18n("Dalamud Distribution Server") - text: LauncherCore.dalamudDistribServer - onTextChanged: LauncherCore.dalamudDistribServer = text + text: LauncherCore.settings.dalamudDistribServer + onTextChanged: LauncherCore.settings.dalamudDistribServer = text } FormCard.FormDelegateSeparator { @@ -86,8 +86,8 @@ FormCard.FormCardPage { id: mainServerDelegate label: i18n("SE Main Server") - text: LauncherCore.squareEnixServer - onTextChanged: LauncherCore.squareEnixServer = text + text: LauncherCore.settings.squareEnixServer + onTextChanged: LauncherCore.settings.squareEnixServer = text } FormCard.FormDelegateSeparator { @@ -99,8 +99,8 @@ FormCard.FormCardPage { id: loginServerDelegate label: i18n("SE Login Server") - text: LauncherCore.squareEnixLoginServer - onTextChanged: LauncherCore.squareEnixLoginServer = text + text: LauncherCore.settings.squareEnixLoginServer + onTextChanged: LauncherCore.settings.squareEnixLoginServer = text } FormCard.FormDelegateSeparator { @@ -112,8 +112,8 @@ FormCard.FormCardPage { id: xivApiServerDelegate label: i18n("XIV Api Server") - text: LauncherCore.xivApiServer - onTextChanged: LauncherCore.xivApiServer = text + text: LauncherCore.settings.xivApiServer + onTextChanged: LauncherCore.settings.xivApiServer = text } } } \ No newline at end of file diff --git a/launcher/ui/Settings/GeneralSettings.qml b/launcher/ui/Settings/GeneralSettings.qml index ed1f4e7..1600c56 100644 --- a/launcher/ui/Settings/GeneralSettings.qml +++ b/launcher/ui/Settings/GeneralSettings.qml @@ -57,8 +57,8 @@ FormCard.FormCardPage { id: closeAstraDelegate text: i18n("Close Astra when game is launched") - checked: LauncherCore.closeWhenLaunched - onCheckedChanged: LauncherCore.closeWhenLaunched = checked + checked: LauncherCore.settings.closeWhenLaunched + onCheckedChanged: LauncherCore.settings.closeWhenLaunched = checked } FormCard.FormDelegateSeparator { @@ -70,8 +70,8 @@ FormCard.FormCardPage { id: showNewsDelegate text: i18n("Enable and show news") - checked: LauncherCore.showNews - onCheckedChanged: LauncherCore.showNews = checked + checked: LauncherCore.settings.showNews + onCheckedChanged: LauncherCore.settings.showNews = checked } FormCard.FormDelegateSeparator { @@ -83,8 +83,8 @@ FormCard.FormCardPage { id: showDevToolsDelegate text: i18n("Show Developer Settings") - checked: LauncherCore.showDevTools - onCheckedChanged: LauncherCore.showDevTools = checked + checked: LauncherCore.settings.showDevTools + onCheckedChanged: LauncherCore.settings.showDevTools = checked } FormCard.FormDelegateSeparator { @@ -96,9 +96,9 @@ FormCard.FormCardPage { id: screenshotsPathDelegate text: i18n("Screenshots Folder") - folder: LauncherCore.screenshotDir + folder: LauncherCore.settings.screenshotDir - onAccepted: (folder) => LauncherCore.screenshotDir = folder + onAccepted: (folder) => LauncherCore.settings.screenshotDir = folder } } diff --git a/launcher/ui/Settings/SettingsPage.qml b/launcher/ui/Settings/SettingsPage.qml index 12d67ab..df3d35b 100644 --- a/launcher/ui/Settings/SettingsPage.qml +++ b/launcher/ui/Settings/SettingsPage.qml @@ -38,7 +38,7 @@ KirigamiSettings.CategorizedSettings { text: i18n("Developer Settings") icon.name: "preferences-others" page: Qt.resolvedUrl("/qt/qml/zone/xiv/astra/ui/Settings/DeveloperSettings.qml") - visible: LauncherCore.showDevTools + visible: LauncherCore.settings.showDevTools }, KirigamiSettings.SettingAction { actionName: "about"