From f0d1e1bcbe016da5b16603b44e5f7bc3f581a884 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 11 Oct 2023 13:34:43 -0400 Subject: [PATCH] Move LauncherCore::mgr to private, add accessor function instead --- launcher/include/launchercore.h | 4 ++-- launcher/src/account.cpp | 4 ++-- launcher/src/assetupdater.cpp | 12 ++++++------ launcher/src/gameinstaller.cpp | 2 +- launcher/src/launchercore.cpp | 9 +++++++-- launcher/src/patcher.cpp | 2 +- launcher/src/sapphirelauncher.cpp | 4 ++-- launcher/src/squareboot.cpp | 4 ++-- launcher/src/squarelauncher.cpp | 6 +++--- 9 files changed, 26 insertions(+), 21 deletions(-) diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index 23d9600..5c87061 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -73,8 +73,7 @@ class LauncherCore : public QObject public: LauncherCore(); - QNetworkAccessManager *mgr; - + QNetworkAccessManager *mgr(); LauncherSettings *settings(); ProfileManager *profileManager(); AccountManager *accountManager(); @@ -190,6 +189,7 @@ private: SquareBoot *m_squareBoot = nullptr; SquareLauncher *m_squareLauncher = nullptr; + QNetworkAccessManager *m_mgr = nullptr; Headline *m_headline = nullptr; LauncherSettings *m_settings = nullptr; diff --git a/launcher/src/account.cpp b/launcher/src/account.cpp index f814660..702cef1 100644 --- a/launcher/src/account.cpp +++ b/launcher/src/account.cpp @@ -238,14 +238,14 @@ void Account::fetchAvatar() QNetworkRequest request(url); Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = m_launcher.mgr->get(request); + const auto reply = m_launcher.mgr()->get(request); connect(reply, &QNetworkReply::finished, [this, filename, reply] { auto document = QJsonDocument::fromJson(reply->readAll()); if (document.isObject()) { const QNetworkRequest avatarRequest(document.object()[QLatin1String("Character")].toObject()[QLatin1String("Avatar")].toString()); Utility::printRequest(QStringLiteral("GET"), avatarRequest); - auto avatarReply = m_launcher.mgr->get(avatarRequest); + auto avatarReply = m_launcher.mgr()->get(avatarRequest); QObject::connect(avatarReply, &QNetworkReply::finished, [this, filename, avatarReply] { QFile file(filename); file.open(QIODevice::ReadWrite); diff --git a/launcher/src/assetupdater.cpp b/launcher/src/assetupdater.cpp index 75963d9..1f850c5 100644 --- a/launcher/src/assetupdater.cpp +++ b/launcher/src/assetupdater.cpp @@ -63,7 +63,7 @@ QCoro::Task AssetUpdater::checkRemoteDalamudAssetVersion() const QNetworkRequest request(dalamudAssetManifestUrl()); Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = launcher.mgr->get(request); + const auto reply = launcher.mgr()->get(request); co_await reply; if (reply->error() != QNetworkReply::NetworkError::NoError) { @@ -102,7 +102,7 @@ QCoro::Task AssetUpdater::checkRemoteDalamudVersion() remoteDalamudVersion.clear(); remoteRuntimeVersion.clear(); - const auto reply = launcher.mgr->get(request); + const auto reply = launcher.mgr()->get(request); co_await reply; if (reply->error() != QNetworkReply::NetworkError::NoError) { @@ -143,7 +143,7 @@ QCoro::Task AssetUpdater::installDalamudAssets() const QNetworkRequest assetRequest(assetObject.toObject()[QLatin1String("url")].toString()); Utility::printRequest(QStringLiteral("GET"), assetRequest); - const auto assetReply = launcher.mgr->get(assetRequest); + const auto assetReply = launcher.mgr()->get(assetRequest); const auto future = QtFuture::connect(assetReply, &QNetworkReply::finished).then([this, assetReply, assetObject] { const QString fileName = assetObject.toObject()[QLatin1String("fileName")].toString(); @@ -186,7 +186,7 @@ QCoro::Task AssetUpdater::installDalamud() const QNetworkRequest request(remoteDalamudDownloadUrl); Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = launcher.mgr->get(request); + const auto reply = launcher.mgr()->get(request); co_await reply; qInfo(ASTRA_LOG) << "Finished downloading Dalamud"; @@ -219,7 +219,7 @@ QCoro::Task AssetUpdater::installRuntime() const QNetworkRequest request(dotnetRuntimePackageUrl(remoteRuntimeVersion)); Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = launcher.mgr->get(request); + const auto reply = launcher.mgr()->get(request); co_await reply; qInfo(ASTRA_LOG) << "Finished downloading Dotnet-core"; @@ -235,7 +235,7 @@ QCoro::Task AssetUpdater::installRuntime() const QNetworkRequest request(dotnetDesktopPackageUrl(remoteRuntimeVersion)); Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = launcher.mgr->get(request); + const auto reply = launcher.mgr()->get(request); co_await reply; qInfo(ASTRA_LOG) << "Finished downloading Dotnet-desktop"; diff --git a/launcher/src/gameinstaller.cpp b/launcher/src/gameinstaller.cpp index 583b8d8..25a2073 100644 --- a/launcher/src/gameinstaller.cpp +++ b/launcher/src/gameinstaller.cpp @@ -30,7 +30,7 @@ void GameInstaller::installGame() QNetworkRequest request((QUrl(installerUrl))); - auto reply = m_launcher.mgr->get(request); + auto reply = m_launcher.mgr()->get(request); Utility::printRequest(QStringLiteral("GET"), request); QObject::connect(reply, &QNetworkReply::finished, [this, reply, installDirectory] { diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index d5598ef..11e3da8 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -413,7 +413,7 @@ void LauncherCore::readInitialInformation() LauncherCore::LauncherCore() { m_settings = new LauncherSettings(this); - mgr = new QNetworkAccessManager(this); + m_mgr = new QNetworkAccessManager(this); m_sapphireLauncher = new SapphireLauncher(*this, this); m_squareLauncher = new SquareLauncher(*this, this); m_squareBoot = new SquareBoot(*this, *m_squareLauncher, this); @@ -580,7 +580,7 @@ QCoro::Task<> LauncherCore::fetchNews() .toUtf8()); Utility::printRequest(QStringLiteral("GET"), request); - auto reply = mgr->get(request); + auto reply = mgr()->get(request); co_await reply; auto document = QJsonDocument::fromJson(reply->readAll()); @@ -689,3 +689,8 @@ LauncherSettings *LauncherCore::settings() { return m_settings; } + +QNetworkAccessManager *LauncherCore::mgr() +{ + return m_mgr; +} diff --git a/launcher/src/patcher.cpp b/launcher/src/patcher.cpp index 6aee159..972e857 100644 --- a/launcher/src/patcher.cpp +++ b/launcher/src/patcher.cpp @@ -84,7 +84,7 @@ QCoro::Task Patcher::patch(const PatchList &patchList) const auto patchRequest = QNetworkRequest(patch.url); Utility::printRequest(QStringLiteral("GET"), patchRequest); - auto patchReply = m_launcher.mgr->get(patchRequest); + auto patchReply = m_launcher.mgr()->get(patchRequest); connect(patchReply, &QNetworkReply::downloadProgress, this, [this, queuedPatch](int received, int total) { Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nDownloading %2", getBaseString(), queuedPatch.getVersion())); diff --git a/launcher/src/sapphirelauncher.cpp b/launcher/src/sapphirelauncher.cpp index c02efc7..737d827 100644 --- a/launcher/src/sapphirelauncher.cpp +++ b/launcher/src/sapphirelauncher.cpp @@ -25,7 +25,7 @@ void SapphireLauncher::login(const QString &lobbyUrl, const LoginInformation &in request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/x-www-form-urlencoded")); Utility::printRequest(QStringLiteral("POST"), request); - const auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact)); + const auto reply = window.mgr()->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact)); connect(reply, &QNetworkReply::finished, [this, reply, &info] { if (reply->error() != QNetworkReply::NetworkError::NoError) { @@ -58,7 +58,7 @@ void SapphireLauncher::registerAccount(const QString &lobbyUrl, const LoginInfor Utility::printRequest(QStringLiteral("POST"), request); - const auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact)); + const auto reply = window.mgr()->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact)); connect(reply, &QNetworkReply::finished, [&] { const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); diff --git a/launcher/src/squareboot.cpp b/launcher/src/squareboot.cpp index c387fe7..52b6bf2 100644 --- a/launcher/src/squareboot.cpp +++ b/launcher/src/squareboot.cpp @@ -46,7 +46,7 @@ QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info) 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); + const auto reply = window.mgr()->get(request); co_await reply; const QString patchList = reply->readAll(); @@ -81,7 +81,7 @@ QCoro::Task<> SquareBoot::checkGateStatus(const LoginInformation &info) Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = window.mgr->get(request); + const auto reply = window.mgr()->get(request); window.setupIgnoreSSL(reply); co_await reply; diff --git a/launcher/src/squarelauncher.cpp b/launcher/src/squarelauncher.cpp index e7bcac3..610e4c8 100644 --- a/launcher/src/squarelauncher.cpp +++ b/launcher/src/squarelauncher.cpp @@ -68,7 +68,7 @@ QCoro::Task> SquareLauncher::getStored Utility::printRequest(QStringLiteral("GET"), request); - const auto reply = window.mgr->get(request); + const auto reply = window.mgr()->get(request); co_await reply; const QString str = reply->readAll(); @@ -128,7 +128,7 @@ QCoro::Task<> SquareLauncher::login(const LoginInformation &info) Utility::printRequest(QStringLiteral("POST"), request); - const auto reply = window.mgr->post(request, postData.toString(QUrl::FullyEncoded).toUtf8()); + const auto reply = window.mgr()->post(request, postData.toString(QUrl::FullyEncoded).toUtf8()); window.setupIgnoreSSL(reply); co_await reply; @@ -190,7 +190,7 @@ QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info) Utility::printRequest(QStringLiteral("POST"), request); - const auto reply = window.mgr->post(request, report.toUtf8()); + const auto reply = window.mgr()->post(request, report.toUtf8()); co_await reply; if (reply->error() == QNetworkReply::NoError) {