1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00

Improve asset updater error handling, allow disabling Dalamud

In the rare situation where the goatcorp servers are offline, they
shouldn't prevent a profile from launching. This adds an option to
quickly disable Dalamud if needed.
This commit is contained in:
Joshua Goins 2023-10-08 19:07:34 -04:00
parent 0e909c6670
commit b17dcaf0b2
5 changed files with 77 additions and 31 deletions

View file

@ -20,15 +20,15 @@ class AssetUpdater : public QObject
public:
explicit AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *parent = nullptr);
QCoro::Task<> update();
QCoro::Task<bool> update();
private:
QCoro::Task<> checkRemoteDalamudAssetVersion();
QCoro::Task<> checkRemoteDalamudVersion();
QCoro::Task<bool> checkRemoteDalamudAssetVersion();
QCoro::Task<bool> checkRemoteDalamudVersion();
QCoro::Task<> installDalamudAssets();
QCoro::Task<> installDalamud();
QCoro::Task<> installRuntime();
QCoro::Task<bool> installDalamudAssets();
QCoro::Task<bool> installDalamud();
QCoro::Task<bool> installRuntime();
[[nodiscard]] QUrl dalamudVersionManifestUrl() const;
[[nodiscard]] QUrl dalamudAssetManifestUrl() const;

View file

@ -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);

View file

@ -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<bool> 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;
}
QCoro::Task<> AssetUpdater::checkRemoteDalamudAssetVersion()
if (!co_await checkRemoteDalamudVersion()) {
co_return false;
}
co_return true;
}
QCoro::Task<bool> 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<bool> 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;
}
}
QCoro::Task<> AssetUpdater::installDalamudAssets()
co_return true;
}
QCoro::Task<bool> 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<bool> 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<bool> 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;
}
}

View file

@ -77,13 +77,13 @@ 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 (co_await assetUpdater->update()) {
if (info.profile->account()->isSapphire()) {
m_sapphireLauncher->login(info.profile->account()->lobbyUrl(), info);
} else {
m_squareBoot->checkGateStatus(info);
}
}
assetUpdater->deleteLater();
}

View file

@ -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();
}
}
}