diff --git a/launcher/include/assetupdater.h b/launcher/include/assetupdater.h index d3601f8..527a3cd 100644 --- a/launcher/include/assetupdater.h +++ b/launcher/include/assetupdater.h @@ -20,15 +20,15 @@ class AssetUpdater : public QObject public: explicit AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *parent = nullptr); - QCoro::Task<> update(); + QCoro::Task update(); private: - QCoro::Task<> checkRemoteDalamudAssetVersion(); - QCoro::Task<> checkRemoteDalamudVersion(); + QCoro::Task checkRemoteDalamudAssetVersion(); + QCoro::Task checkRemoteDalamudVersion(); - QCoro::Task<> installDalamudAssets(); - QCoro::Task<> installDalamud(); - QCoro::Task<> installRuntime(); + QCoro::Task installDalamudAssets(); + QCoro::Task installDalamud(); + QCoro::Task installRuntime(); [[nodiscard]] QUrl dalamudVersionManifestUrl() const; [[nodiscard]] QUrl dalamudAssetManifestUrl() const; diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index ef1bc1a..eb7eb26 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -192,6 +192,7 @@ signals: void preferredProtocolChanged(); void encryptedArgumentsChanged(); void loginError(QString message); + void dalamudError(QString message); void stageChanged(QString message); void stageIndeterminate(); void stageDeterminate(int min, int max, int value); diff --git a/launcher/src/assetupdater.cpp b/launcher/src/assetupdater.cpp index f83253b..cd69861 100644 --- a/launcher/src/assetupdater.cpp +++ b/launcher/src/assetupdater.cpp @@ -22,13 +22,12 @@ AssetUpdater::AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *pa , chosenChannel(profile.dalamudChannel()) , m_profile(profile) { - launcher.mgr->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy); } -QCoro::Task<> AssetUpdater::update() +QCoro::Task AssetUpdater::update() { if (!m_profile.dalamudEnabled()) { - co_return; + co_return true; } qInfo(ASTRA_LOG) << "Checking for asset updates..."; @@ -47,11 +46,18 @@ QCoro::Task<> AssetUpdater::update() createIfNeeded(dalamudAssetDir); createIfNeeded(dalamudRuntimeDir); - co_await checkRemoteDalamudAssetVersion(); - co_await checkRemoteDalamudVersion(); + if (!co_await checkRemoteDalamudAssetVersion()) { + co_return false; + } + + if (!co_await checkRemoteDalamudVersion()) { + co_return false; + } + + co_return true; } -QCoro::Task<> AssetUpdater::checkRemoteDalamudAssetVersion() +QCoro::Task AssetUpdater::checkRemoteDalamudAssetVersion() { // first we want to fetch the list of assets required const QNetworkRequest request(dalamudAssetManifestUrl()); @@ -60,7 +66,11 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudAssetVersion() const auto reply = launcher.mgr->get(request); co_await reply; - // TODO: handle asset failure + if (reply->error() != QNetworkReply::NetworkError::NoError) { + Q_EMIT launcher.dalamudError(i18n("Could not check for Dalamud asset updates.\n\n%1", reply->errorString())); + co_return false; + } + const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); remoteDalamudAssetVersion = doc.object()[QLatin1String("version")].toInt(); @@ -73,11 +83,11 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudAssetVersion() if (remoteDalamudAssetVersion != m_profile.dalamudAssetVersion()) { qInfo(ASTRA_LOG) << "Dalamud assets out of date"; - co_await installDalamudAssets(); + co_return co_await installDalamudAssets(); } } -QCoro::Task<> AssetUpdater::checkRemoteDalamudVersion() +QCoro::Task AssetUpdater::checkRemoteDalamudVersion() { QUrl url(dalamudVersionManifestUrl()); @@ -94,8 +104,8 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudVersion() co_await reply; if (reply->error() != QNetworkReply::NetworkError::NoError) { - Q_EMIT launcher.loginError(i18n("Could not check for Dalamud updates.\n\n%1", reply->errorString())); - co_return; + Q_EMIT launcher.dalamudError(i18n("Could not check for Dalamud updates.\n\n%1", reply->errorString())); + co_return false; } const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); @@ -107,15 +117,21 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudVersion() qInfo(ASTRA_LOG) << "Latest available NET runtime:" << remoteRuntimeVersion; if (remoteDalamudVersion != m_profile.dalamudVersion()) { - co_await installDalamud(); + if (!co_await installDalamud()) { + co_return false; + } } if (m_profile.runtimeVersion() != remoteRuntimeVersion) { - co_await installRuntime(); + if (!co_await installRuntime()) { + co_return false; + } } + + co_return true; } -QCoro::Task<> AssetUpdater::installDalamudAssets() +QCoro::Task AssetUpdater::installDalamudAssets() { Q_EMIT launcher.stageChanged(i18n("Updating Dalamud assets...")); @@ -157,9 +173,11 @@ QCoro::Task<> AssetUpdater::installDalamudAssets() file.open(QIODevice::WriteOnly | QIODevice::Text); file.write(QString::number(remoteDalamudAssetVersion).toUtf8()); file.close(); + + co_return true; } -QCoro::Task<> AssetUpdater::installDalamud() +QCoro::Task AssetUpdater::installDalamud() { Q_EMIT launcher.stageChanged(i18n("Updating Dalamud...")); @@ -180,14 +198,17 @@ QCoro::Task<> AssetUpdater::installDalamud() !JlCompress::extractDir(tempDir.path() + QLatin1String("/latest.zip"), dalamudDir.absoluteFilePath(m_profile.dalamudChannelName())).empty(); if (!success) { - // TODO: handle failure here - qCritical(ASTRA_LOG) << "Failed to install Dalamud!"; + qCritical(ASTRA_LOG) << "Failed to install Dalamud"; + Q_EMIT launcher.dalamudError(i18n("Failed to install Dalamud.")); + co_return false; } m_profile.setDalamudVersion(remoteDalamudVersion); + + co_return true; } -QCoro::Task<> AssetUpdater::installRuntime() +QCoro::Task AssetUpdater::installRuntime() { Q_EMIT launcher.stageChanged(i18n("Updating .NET Runtime...")); @@ -227,12 +248,17 @@ QCoro::Task<> AssetUpdater::installRuntime() success |= !JlCompress::extractDir(tempDir.path() + QStringLiteral("/dotnet-desktop.zip"), dalamudRuntimeDir.absolutePath()).empty(); if (!success) { - qCritical(ASTRA_LOG) << "Failed to install dotnet!"; + qCritical(ASTRA_LOG) << "Failed to install dotnet"; + Q_EMIT launcher.dalamudError(i18n("Failed to install .NET runtime.")); + + co_return false; } else { QFile file(dalamudRuntimeDir.absoluteFilePath(QStringLiteral("runtime.ver"))); file.open(QIODevice::WriteOnly | QIODevice::Text); file.write(remoteRuntimeVersion.toUtf8()); file.close(); + + co_return true; } } diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 048529e..9ab02e1 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -77,12 +77,12 @@ void LauncherCore::launchGame(Profile &profile, const LoginAuth &auth) QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info) { auto assetUpdater = new AssetUpdater(*info.profile, *this, this); - co_await assetUpdater->update(); - - if (info.profile->account()->isSapphire()) { - m_sapphireLauncher->login(info.profile->account()->lobbyUrl(), info); - } else { - m_squareBoot->checkGateStatus(info); + if (co_await assetUpdater->update()) { + if (info.profile->account()->isSapphire()) { + m_sapphireLauncher->login(info.profile->account()->lobbyUrl(), info); + } else { + m_squareBoot->checkGateStatus(info); + } } assetUpdater->deleteLater(); diff --git a/launcher/ui/Pages/StatusPage.qml b/launcher/ui/Pages/StatusPage.qml index 1f80ccd..a18a6e5 100644 --- a/launcher/ui/Pages/StatusPage.qml +++ b/launcher/ui/Pages/StatusPage.qml @@ -31,6 +31,20 @@ Kirigami.Page { onRejected: applicationWindow().pageStack.layers.pop() } + Kirigami.PromptDialog { + id: dalamudErrorDialog + title: i18n("Dalamud Error") + + showCloseButton: false + standardButtons: Kirigami.Dialog.Yes | Kirigami.Dialog.Cancel + + onAccepted: { + LauncherCore.currentProfile.dalamudEnabled = false; + applicationWindow().pageStack.layers.pop() + } + onRejected: applicationWindow().pageStack.layers.pop() + } + Connections { target: LauncherCore @@ -53,5 +67,10 @@ Kirigami.Page { errorDialog.subtitle = message errorDialog.open() } + + function onDalamudError(message) { + dalamudErrorDialog.subtitle = i18n("An error occured while updating Dalamud:\n\n%1.\n\nWould you like to disable Dalamud?", message); + dalamudErrorDialog.open(); + } } } \ No newline at end of file