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:
parent
0e909c6670
commit
b17dcaf0b2
5 changed files with 77 additions and 31 deletions
|
@ -20,15 +20,15 @@ class AssetUpdater : public QObject
|
||||||
public:
|
public:
|
||||||
explicit AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *parent = nullptr);
|
explicit AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *parent = nullptr);
|
||||||
|
|
||||||
QCoro::Task<> update();
|
QCoro::Task<bool> update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCoro::Task<> checkRemoteDalamudAssetVersion();
|
QCoro::Task<bool> checkRemoteDalamudAssetVersion();
|
||||||
QCoro::Task<> checkRemoteDalamudVersion();
|
QCoro::Task<bool> checkRemoteDalamudVersion();
|
||||||
|
|
||||||
QCoro::Task<> installDalamudAssets();
|
QCoro::Task<bool> installDalamudAssets();
|
||||||
QCoro::Task<> installDalamud();
|
QCoro::Task<bool> installDalamud();
|
||||||
QCoro::Task<> installRuntime();
|
QCoro::Task<bool> installRuntime();
|
||||||
|
|
||||||
[[nodiscard]] QUrl dalamudVersionManifestUrl() const;
|
[[nodiscard]] QUrl dalamudVersionManifestUrl() const;
|
||||||
[[nodiscard]] QUrl dalamudAssetManifestUrl() const;
|
[[nodiscard]] QUrl dalamudAssetManifestUrl() const;
|
||||||
|
|
|
@ -192,6 +192,7 @@ signals:
|
||||||
void preferredProtocolChanged();
|
void preferredProtocolChanged();
|
||||||
void encryptedArgumentsChanged();
|
void encryptedArgumentsChanged();
|
||||||
void loginError(QString message);
|
void loginError(QString message);
|
||||||
|
void dalamudError(QString message);
|
||||||
void stageChanged(QString message);
|
void stageChanged(QString message);
|
||||||
void stageIndeterminate();
|
void stageIndeterminate();
|
||||||
void stageDeterminate(int min, int max, int value);
|
void stageDeterminate(int min, int max, int value);
|
||||||
|
|
|
@ -22,13 +22,12 @@ AssetUpdater::AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *pa
|
||||||
, chosenChannel(profile.dalamudChannel())
|
, chosenChannel(profile.dalamudChannel())
|
||||||
, m_profile(profile)
|
, m_profile(profile)
|
||||||
{
|
{
|
||||||
launcher.mgr->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> AssetUpdater::update()
|
QCoro::Task<bool> AssetUpdater::update()
|
||||||
{
|
{
|
||||||
if (!m_profile.dalamudEnabled()) {
|
if (!m_profile.dalamudEnabled()) {
|
||||||
co_return;
|
co_return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
qInfo(ASTRA_LOG) << "Checking for asset updates...";
|
qInfo(ASTRA_LOG) << "Checking for asset updates...";
|
||||||
|
@ -47,11 +46,18 @@ QCoro::Task<> AssetUpdater::update()
|
||||||
createIfNeeded(dalamudAssetDir);
|
createIfNeeded(dalamudAssetDir);
|
||||||
createIfNeeded(dalamudRuntimeDir);
|
createIfNeeded(dalamudRuntimeDir);
|
||||||
|
|
||||||
co_await checkRemoteDalamudAssetVersion();
|
if (!co_await checkRemoteDalamudAssetVersion()) {
|
||||||
co_await checkRemoteDalamudVersion();
|
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
|
// first we want to fetch the list of assets required
|
||||||
const QNetworkRequest request(dalamudAssetManifestUrl());
|
const QNetworkRequest request(dalamudAssetManifestUrl());
|
||||||
|
@ -60,7 +66,11 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudAssetVersion()
|
||||||
const auto reply = launcher.mgr->get(request);
|
const auto reply = launcher.mgr->get(request);
|
||||||
co_await reply;
|
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());
|
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
|
||||||
remoteDalamudAssetVersion = doc.object()[QLatin1String("version")].toInt();
|
remoteDalamudAssetVersion = doc.object()[QLatin1String("version")].toInt();
|
||||||
|
@ -73,11 +83,11 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudAssetVersion()
|
||||||
if (remoteDalamudAssetVersion != m_profile.dalamudAssetVersion()) {
|
if (remoteDalamudAssetVersion != m_profile.dalamudAssetVersion()) {
|
||||||
qInfo(ASTRA_LOG) << "Dalamud assets out of date";
|
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());
|
QUrl url(dalamudVersionManifestUrl());
|
||||||
|
|
||||||
|
@ -94,8 +104,8 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudVersion()
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
||||||
Q_EMIT launcher.loginError(i18n("Could not check for Dalamud updates.\n\n%1", reply->errorString()));
|
Q_EMIT launcher.dalamudError(i18n("Could not check for Dalamud updates.\n\n%1", reply->errorString()));
|
||||||
co_return;
|
co_return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
|
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
@ -107,15 +117,21 @@ QCoro::Task<> AssetUpdater::checkRemoteDalamudVersion()
|
||||||
qInfo(ASTRA_LOG) << "Latest available NET runtime:" << remoteRuntimeVersion;
|
qInfo(ASTRA_LOG) << "Latest available NET runtime:" << remoteRuntimeVersion;
|
||||||
|
|
||||||
if (remoteDalamudVersion != m_profile.dalamudVersion()) {
|
if (remoteDalamudVersion != m_profile.dalamudVersion()) {
|
||||||
co_await installDalamud();
|
if (!co_await installDalamud()) {
|
||||||
|
co_return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_profile.runtimeVersion() != remoteRuntimeVersion) {
|
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..."));
|
Q_EMIT launcher.stageChanged(i18n("Updating Dalamud assets..."));
|
||||||
|
|
||||||
|
@ -157,9 +173,11 @@ QCoro::Task<> AssetUpdater::installDalamudAssets()
|
||||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
file.write(QString::number(remoteDalamudAssetVersion).toUtf8());
|
file.write(QString::number(remoteDalamudAssetVersion).toUtf8());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
co_return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> AssetUpdater::installDalamud()
|
QCoro::Task<bool> AssetUpdater::installDalamud()
|
||||||
{
|
{
|
||||||
Q_EMIT launcher.stageChanged(i18n("Updating Dalamud..."));
|
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();
|
!JlCompress::extractDir(tempDir.path() + QLatin1String("/latest.zip"), dalamudDir.absoluteFilePath(m_profile.dalamudChannelName())).empty();
|
||||||
|
|
||||||
if (!success) {
|
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);
|
m_profile.setDalamudVersion(remoteDalamudVersion);
|
||||||
|
|
||||||
|
co_return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> AssetUpdater::installRuntime()
|
QCoro::Task<bool> AssetUpdater::installRuntime()
|
||||||
{
|
{
|
||||||
Q_EMIT launcher.stageChanged(i18n("Updating .NET Runtime..."));
|
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();
|
success |= !JlCompress::extractDir(tempDir.path() + QStringLiteral("/dotnet-desktop.zip"), dalamudRuntimeDir.absolutePath()).empty();
|
||||||
|
|
||||||
if (!success) {
|
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 {
|
} else {
|
||||||
QFile file(dalamudRuntimeDir.absoluteFilePath(QStringLiteral("runtime.ver")));
|
QFile file(dalamudRuntimeDir.absoluteFilePath(QStringLiteral("runtime.ver")));
|
||||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||||
file.write(remoteRuntimeVersion.toUtf8());
|
file.write(remoteRuntimeVersion.toUtf8());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
co_return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,13 +77,13 @@ void LauncherCore::launchGame(Profile &profile, const LoginAuth &auth)
|
||||||
QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info)
|
QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info)
|
||||||
{
|
{
|
||||||
auto assetUpdater = new AssetUpdater(*info.profile, *this, this);
|
auto assetUpdater = new AssetUpdater(*info.profile, *this, this);
|
||||||
co_await assetUpdater->update();
|
if (co_await assetUpdater->update()) {
|
||||||
|
|
||||||
if (info.profile->account()->isSapphire()) {
|
if (info.profile->account()->isSapphire()) {
|
||||||
m_sapphireLauncher->login(info.profile->account()->lobbyUrl(), info);
|
m_sapphireLauncher->login(info.profile->account()->lobbyUrl(), info);
|
||||||
} else {
|
} else {
|
||||||
m_squareBoot->checkGateStatus(info);
|
m_squareBoot->checkGateStatus(info);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assetUpdater->deleteLater();
|
assetUpdater->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,20 @@ Kirigami.Page {
|
||||||
onRejected: applicationWindow().pageStack.layers.pop()
|
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 {
|
Connections {
|
||||||
target: LauncherCore
|
target: LauncherCore
|
||||||
|
|
||||||
|
@ -53,5 +67,10 @@ Kirigami.Page {
|
||||||
errorDialog.subtitle = message
|
errorDialog.subtitle = message
|
||||||
errorDialog.open()
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue