2023-08-05 22:14:05 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-11-23 14:37:37 -05:00
|
|
|
#include "assetupdater.h"
|
2023-10-08 18:54:03 -04:00
|
|
|
#include "astra_log.h"
|
2023-10-08 18:02:02 -04:00
|
|
|
#include "utility.h"
|
2021-11-23 14:37:37 -05:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
#include <KLocalizedString>
|
2023-12-20 18:00:40 -05:00
|
|
|
#include <KTar>
|
|
|
|
#include <KZip>
|
2021-11-23 14:37:37 -05:00
|
|
|
#include <QFile>
|
2022-01-27 10:46:22 -05:00
|
|
|
#include <QJsonDocument>
|
2022-02-23 19:05:53 -05:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QStandardPaths>
|
2023-09-17 18:43:58 -04:00
|
|
|
#include <qcorofuture.h>
|
|
|
|
#include <qcoronetworkreply.h>
|
2021-11-23 14:37:37 -05:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
#include <QtConcurrentRun>
|
2021-11-23 14:37:37 -05:00
|
|
|
|
2023-12-17 12:01:28 -05:00
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
AssetUpdater::AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, launcher(launcher)
|
|
|
|
, m_profile(profile)
|
|
|
|
{
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::update()
|
2023-09-17 18:43:58 -04:00
|
|
|
{
|
2023-12-20 18:00:40 -05:00
|
|
|
qInfo(ASTRA_LOG) << "Checking for compatibility tool updates...";
|
|
|
|
|
|
|
|
m_dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
|
2024-05-18 14:26:33 -04:00
|
|
|
if (LauncherCore::needsCompatibilityTool()) {
|
|
|
|
const QDir compatibilityToolDir = m_dataDir.absoluteFilePath(QStringLiteral("tool"));
|
|
|
|
m_wineDir = compatibilityToolDir.absoluteFilePath(QStringLiteral("wine"));
|
|
|
|
m_dxvkDir = compatibilityToolDir.absoluteFilePath(QStringLiteral("dxvk"));
|
2023-12-20 18:00:40 -05:00
|
|
|
|
2024-05-18 14:26:33 -04:00
|
|
|
Utility::createPathIfNeeded(m_wineDir);
|
|
|
|
Utility::createPathIfNeeded(m_dxvkDir);
|
2023-12-20 18:00:40 -05:00
|
|
|
|
2024-05-18 14:26:33 -04:00
|
|
|
if (m_profile.wineType() == Profile::WineType::BuiltIn && !co_await checkRemoteCompatibilityToolVersion()) {
|
|
|
|
co_return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: should DXVK be tied to this setting...?
|
|
|
|
if (m_profile.wineType() == Profile::WineType::BuiltIn && !co_await checkRemoteDxvkVersion()) {
|
|
|
|
co_return false;
|
|
|
|
}
|
2023-12-20 20:19:48 -05:00
|
|
|
}
|
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
if (!m_profile.dalamudEnabled()) {
|
2023-10-08 19:07:34 -04:00
|
|
|
co_return true;
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Checking for asset updates...";
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
m_dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
m_dalamudDir = m_dataDir.absoluteFilePath(QStringLiteral("dalamud"));
|
|
|
|
m_dalamudAssetDir = m_dalamudDir.absoluteFilePath(QStringLiteral("assets"));
|
|
|
|
m_dalamudRuntimeDir = m_dalamudDir.absoluteFilePath(QStringLiteral("runtime"));
|
2023-08-18 14:52:06 -04:00
|
|
|
|
2023-12-17 12:01:28 -05:00
|
|
|
Utility::createPathIfNeeded(m_dalamudDir);
|
|
|
|
Utility::createPathIfNeeded(m_dalamudAssetDir);
|
|
|
|
Utility::createPathIfNeeded(m_dalamudRuntimeDir);
|
2023-09-17 18:43:58 -04:00
|
|
|
|
2024-06-29 19:33:39 -04:00
|
|
|
if (m_profile.dalamudChannel() != Profile::DalamudChannel::Local) {
|
|
|
|
if (!co_await checkRemoteDalamudAssetVersion()) {
|
|
|
|
co_return false;
|
|
|
|
}
|
2023-10-08 19:07:34 -04:00
|
|
|
|
2024-06-29 19:33:39 -04:00
|
|
|
if (!co_await checkRemoteDalamudVersion()) {
|
|
|
|
co_return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qInfo(ASTRA_LOG) << "Using a local Dalamud installation, skipping version checks!";
|
2023-10-08 19:07:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
co_return true;
|
2021-11-23 14:37:37 -05:00
|
|
|
}
|
|
|
|
|
2023-12-20 18:00:40 -05:00
|
|
|
QCoro::Task<bool> AssetUpdater::checkRemoteCompatibilityToolVersion()
|
|
|
|
{
|
|
|
|
// TODO: hardcoded for now
|
|
|
|
m_remoteCompatibilityToolVersion = QStringLiteral("wine-xiv-staging-fsync-git-8.5.r4.g4211bac7");
|
|
|
|
|
|
|
|
qInfo(ASTRA_LOG) << "Compatibility tool remote version" << m_remoteCompatibilityToolVersion;
|
|
|
|
|
|
|
|
// TODO: this version should not be profile specific
|
|
|
|
if (m_remoteCompatibilityToolVersion != m_profile.compatibilityToolVersion()) {
|
|
|
|
qInfo(ASTRA_LOG) << "Compatibility tool out of date";
|
|
|
|
|
|
|
|
co_return co_await installCompatibilityTool();
|
|
|
|
}
|
|
|
|
|
|
|
|
co_return true;
|
|
|
|
}
|
|
|
|
|
2023-12-20 20:19:48 -05:00
|
|
|
QCoro::Task<bool> AssetUpdater::checkRemoteDxvkVersion()
|
|
|
|
{
|
|
|
|
// TODO: hardcoded for now
|
|
|
|
m_remoteDxvkToolVersion = QStringLiteral("dxvk-2.3");
|
|
|
|
|
|
|
|
qInfo(ASTRA_LOG) << "DXVK remote version" << m_remoteDxvkToolVersion;
|
|
|
|
|
|
|
|
QString localDxvkVersion;
|
|
|
|
const QString dxvkVer = m_dxvkDir.absoluteFilePath(QStringLiteral("dxvk.ver"));
|
|
|
|
if (QFile::exists(dxvkVer)) {
|
2023-12-21 20:28:41 -05:00
|
|
|
localDxvkVersion = Utility::readVersion(dxvkVer);
|
2023-12-20 20:19:48 -05:00
|
|
|
qInfo(ASTRA_LOG) << "Local DXVK version:" << localDxvkVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this version should not be profile specific
|
|
|
|
if (m_remoteDxvkToolVersion != localDxvkVersion) {
|
|
|
|
qInfo(ASTRA_LOG) << "DXVK tool out of date";
|
|
|
|
|
|
|
|
co_return co_await installDxvkTool();
|
|
|
|
}
|
|
|
|
|
|
|
|
co_return true;
|
|
|
|
}
|
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::checkRemoteDalamudAssetVersion()
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
2023-09-17 18:43:58 -04:00
|
|
|
// first we want to fetch the list of assets required
|
|
|
|
const QNetworkRequest request(dalamudAssetManifestUrl());
|
2023-10-08 18:02:02 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
2021-11-23 14:37:37 -05:00
|
|
|
|
2023-10-11 13:34:43 -04:00
|
|
|
const auto reply = launcher.mgr()->get(request);
|
2023-09-17 18:43:58 -04:00
|
|
|
co_await reply;
|
2022-02-23 19:05:53 -05:00
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
|
2022-02-25 18:08:57 -05:00
|
|
|
|
2023-12-17 12:01:28 -05:00
|
|
|
m_remoteDalamudAssetVersion = doc.object()["version"_L1].toInt();
|
2024-02-24 11:48:02 -05:00
|
|
|
m_remoteDalamudAssetPackageUrl = doc.object()["packageUrl"_L1].toString();
|
2023-12-17 12:01:28 -05:00
|
|
|
m_remoteDalamudAssetArray = doc.object()["assets"_L1].toArray();
|
2022-02-25 18:08:57 -05:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Dalamud asset remote version" << m_remoteDalamudAssetVersion;
|
2023-10-08 18:54:03 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Dalamud asset local version" << m_profile.dalamudAssetVersion();
|
2022-02-25 18:08:57 -05:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
// dalamud assets
|
2023-10-11 13:39:10 -04:00
|
|
|
if (m_remoteDalamudAssetVersion != m_profile.dalamudAssetVersion()) {
|
2023-10-08 18:54:03 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Dalamud assets out of date";
|
2022-02-25 20:06:29 -05:00
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
co_return co_await installDalamudAssets();
|
2021-11-23 14:37:37 -05:00
|
|
|
}
|
2023-10-11 12:59:15 -04:00
|
|
|
|
|
|
|
co_return true;
|
2021-11-23 14:37:37 -05:00
|
|
|
}
|
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::checkRemoteDalamudVersion()
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
2023-10-08 18:54:03 -04:00
|
|
|
QUrl url(dalamudVersionManifestUrl());
|
|
|
|
|
|
|
|
QUrlQuery query;
|
|
|
|
query.addQueryItem(QStringLiteral("track"), m_profile.dalamudChannelName());
|
|
|
|
|
2024-07-01 23:05:46 -04:00
|
|
|
url.setQuery(query);
|
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
const QNetworkRequest request(url);
|
2023-10-08 18:02:02 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
2022-02-25 20:06:29 -05:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
m_remoteDalamudVersion.clear();
|
|
|
|
m_remoteRuntimeVersion.clear();
|
2022-02-25 20:06:29 -05:00
|
|
|
|
2023-10-11 13:34:43 -04:00
|
|
|
const auto reply = launcher.mgr()->get(request);
|
2023-09-17 18:43:58 -04:00
|
|
|
co_await reply;
|
2022-02-25 20:06:29 -05:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
2023-10-08 19:07:34 -04:00
|
|
|
Q_EMIT launcher.dalamudError(i18n("Could not check for Dalamud updates.\n\n%1", reply->errorString()));
|
|
|
|
co_return false;
|
2022-02-25 20:06:29 -05:00
|
|
|
}
|
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
|
2023-12-17 12:01:28 -05:00
|
|
|
m_remoteDalamudVersion = doc["assemblyVersion"_L1].toString();
|
|
|
|
m_remoteRuntimeVersion = doc["runtimeVersion"_L1].toString();
|
|
|
|
m_remoteDalamudDownloadUrl = doc["downloadUrl"_L1].toString();
|
2022-03-13 20:48:43 -04:00
|
|
|
|
2024-06-27 16:38:18 -04:00
|
|
|
// TODO: Also check supportedGameVer as a fallback
|
|
|
|
m_profile.setDalamudApplicable(doc["isApplicableForCurrentGameVer"_L1].toBool());
|
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Latest available Dalamud version:" << m_remoteDalamudVersion << "local:" << m_profile.dalamudVersion();
|
|
|
|
qInfo(ASTRA_LOG) << "Latest available NET runtime:" << m_remoteRuntimeVersion;
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
if (m_remoteDalamudVersion != m_profile.dalamudVersion()) {
|
2023-10-08 19:07:34 -04:00
|
|
|
if (!co_await installDalamud()) {
|
|
|
|
co_return false;
|
|
|
|
}
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
if (m_profile.runtimeVersion() != m_remoteRuntimeVersion) {
|
2023-10-08 19:07:34 -04:00
|
|
|
if (!co_await installRuntime()) {
|
|
|
|
co_return false;
|
|
|
|
}
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
2023-10-08 19:07:34 -04:00
|
|
|
|
|
|
|
co_return true;
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-08-22 21:02:23 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::installCompatibilityTool() const
|
2023-12-20 18:00:40 -05:00
|
|
|
{
|
|
|
|
Q_EMIT launcher.stageChanged(i18n("Updating compatibility tool..."));
|
|
|
|
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto request = QNetworkRequest(QUrl(m_remoteCompatibilityToolUrl));
|
2023-12-20 18:00:40 -05:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
|
|
|
|
|
|
|
const auto reply = launcher.mgr()->get(request);
|
|
|
|
co_await reply;
|
|
|
|
|
2024-04-01 14:56:58 -04:00
|
|
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
|
|
|
Q_EMIT launcher.miscError(i18n("Could not update compatibility tool:\n\n%1", reply->errorString()));
|
|
|
|
co_return false;
|
|
|
|
}
|
|
|
|
|
2023-12-20 18:00:40 -05:00
|
|
|
qInfo(ASTRA_LOG) << "Finished downloading compatibility tool";
|
|
|
|
|
2023-12-20 20:19:48 -05:00
|
|
|
QFile file(m_tempDir.filePath(QStringLiteral("wine.tar.xz")));
|
2023-12-20 18:00:40 -05:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
|
2023-12-20 20:19:48 -05:00
|
|
|
KTar archive(m_tempDir.filePath(QStringLiteral("wine.tar.xz")));
|
2023-12-20 18:00:40 -05:00
|
|
|
if (!archive.open(QIODevice::ReadOnly)) {
|
|
|
|
qCritical(ASTRA_LOG) << "Failed to install compatibility tool";
|
2024-04-01 14:56:58 -04:00
|
|
|
Q_EMIT launcher.miscError(i18n("Failed to install compatibility tool."));
|
2023-12-20 18:00:40 -05:00
|
|
|
co_return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the first directory is the same as the version we download
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto *root = dynamic_cast<const KArchiveDirectory *>(archive.directory()->entry(m_remoteCompatibilityToolVersion));
|
|
|
|
Q_UNUSED(root->copyTo(m_wineDir.absolutePath(), true))
|
2023-12-20 18:00:40 -05:00
|
|
|
|
|
|
|
archive.close();
|
|
|
|
|
2023-12-21 20:28:41 -05:00
|
|
|
Utility::writeVersion(m_wineDir.absoluteFilePath(QStringLiteral("wine.ver")), m_remoteCompatibilityToolVersion);
|
2023-12-20 18:00:40 -05:00
|
|
|
|
|
|
|
m_profile.setCompatibilityToolVersion(m_remoteCompatibilityToolVersion);
|
|
|
|
|
|
|
|
co_return true;
|
|
|
|
}
|
|
|
|
|
2024-08-22 21:02:23 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::installDxvkTool() const
|
2023-12-20 20:19:48 -05:00
|
|
|
{
|
|
|
|
Q_EMIT launcher.stageChanged(i18n("Updating DXVK..."));
|
|
|
|
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto request = QNetworkRequest(QUrl(m_remoteDxvkToolUrl));
|
2023-12-20 20:19:48 -05:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
|
|
|
|
|
|
|
const auto reply = launcher.mgr()->get(request);
|
|
|
|
co_await reply;
|
|
|
|
|
|
|
|
qInfo(ASTRA_LOG) << "Finished downloading DXVK";
|
|
|
|
|
2024-04-01 14:56:58 -04:00
|
|
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
|
|
|
Q_EMIT launcher.miscError(i18n("Could not update DXVK:\n\n%1", reply->errorString()));
|
|
|
|
co_return false;
|
|
|
|
}
|
|
|
|
|
2023-12-20 20:19:48 -05:00
|
|
|
QFile file(m_tempDir.filePath(QStringLiteral("dxvk.tar.xz")));
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
KTar archive(m_tempDir.filePath(QStringLiteral("dxvk.tar.xz")));
|
|
|
|
if (!archive.open(QIODevice::ReadOnly)) {
|
|
|
|
qCritical(ASTRA_LOG) << "Failed to install DXVK";
|
2024-04-01 14:56:58 -04:00
|
|
|
Q_EMIT launcher.miscError(i18n("Failed to install DXVK."));
|
2023-12-20 20:19:48 -05:00
|
|
|
co_return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the first directory is the same as the version we download
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto *root = dynamic_cast<const KArchiveDirectory *>(archive.directory()->entry(m_remoteDxvkToolVersion));
|
|
|
|
Q_UNUSED(root->copyTo(m_dxvkDir.absolutePath(), true))
|
2023-12-20 20:19:48 -05:00
|
|
|
|
|
|
|
archive.close();
|
|
|
|
|
2023-12-21 20:28:41 -05:00
|
|
|
Utility::writeVersion(m_dxvkDir.absoluteFilePath(QStringLiteral("dxvk.ver")), m_remoteDxvkToolVersion);
|
2023-12-20 20:19:48 -05:00
|
|
|
|
|
|
|
co_return true;
|
|
|
|
}
|
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::installDalamudAssets()
|
2023-09-17 18:43:58 -04:00
|
|
|
{
|
|
|
|
Q_EMIT launcher.stageChanged(i18n("Updating Dalamud assets..."));
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto request = QNetworkRequest(QUrl(m_remoteDalamudAssetPackageUrl));
|
2024-02-24 11:48:02 -05:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-02-24 11:48:02 -05:00
|
|
|
const auto reply = launcher.mgr()->get(request);
|
|
|
|
co_await reply;
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-02-24 11:48:02 -05:00
|
|
|
qInfo(ASTRA_LOG) << "Finished downloading Dalamud assets";
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-02-24 11:48:02 -05:00
|
|
|
QFile file(m_tempDir.filePath(QStringLiteral("dalamud-assets.zip")));
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-02-24 11:48:02 -05:00
|
|
|
if (!extractZip(m_tempDir.filePath(QStringLiteral("dalamud-assets.zip")), m_dalamudAssetDir.absolutePath())) {
|
|
|
|
qCritical(ASTRA_LOG) << "Failed to install Dalamud assets";
|
|
|
|
Q_EMIT launcher.dalamudError(i18n("Failed to install Dalamud assets."));
|
|
|
|
co_return false;
|
2022-03-13 20:44:57 -04:00
|
|
|
}
|
|
|
|
|
2024-02-24 11:48:02 -05:00
|
|
|
// TODO: check for file hashes
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
m_profile.setDalamudAssetVersion(m_remoteDalamudAssetVersion);
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-12-21 20:28:41 -05:00
|
|
|
Utility::writeVersion(m_dalamudAssetDir.absoluteFilePath(QStringLiteral("asset.ver")), QString::number(m_remoteDalamudAssetVersion));
|
2023-10-08 19:07:34 -04:00
|
|
|
|
|
|
|
co_return true;
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::installDalamud()
|
2023-09-17 18:43:58 -04:00
|
|
|
{
|
|
|
|
Q_EMIT launcher.stageChanged(i18n("Updating Dalamud..."));
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2024-07-04 20:53:06 -04:00
|
|
|
const auto request = QNetworkRequest(QUrl(m_remoteDalamudDownloadUrl));
|
2023-10-08 18:02:02 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:34:43 -04:00
|
|
|
const auto reply = launcher.mgr()->get(request);
|
2023-09-17 18:43:58 -04:00
|
|
|
co_await reply;
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Finished downloading Dalamud";
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-12-04 17:44:48 -05:00
|
|
|
QFile file(m_tempDir.filePath(QStringLiteral("latest.zip")));
|
2023-09-17 18:43:58 -04:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-12-20 18:00:40 -05:00
|
|
|
if (!extractZip(m_tempDir.filePath(QStringLiteral("latest.zip")), m_dalamudDir.absoluteFilePath(m_profile.dalamudChannelName()))) {
|
2023-10-08 19:07:34 -04:00
|
|
|
qCritical(ASTRA_LOG) << "Failed to install Dalamud";
|
|
|
|
Q_EMIT launcher.dalamudError(i18n("Failed to install Dalamud."));
|
|
|
|
co_return false;
|
2022-03-13 20:44:57 -04:00
|
|
|
}
|
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
m_profile.setDalamudVersion(m_remoteDalamudVersion);
|
2023-10-08 19:07:34 -04:00
|
|
|
|
|
|
|
co_return true;
|
2023-09-17 18:43:58 -04:00
|
|
|
}
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-08 19:07:34 -04:00
|
|
|
QCoro::Task<bool> AssetUpdater::installRuntime()
|
2023-09-17 18:43:58 -04:00
|
|
|
{
|
|
|
|
Q_EMIT launcher.stageChanged(i18n("Updating .NET Runtime..."));
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
// core
|
|
|
|
{
|
2023-10-11 13:39:10 -04:00
|
|
|
const QNetworkRequest request(dotnetRuntimePackageUrl(m_remoteRuntimeVersion));
|
2023-10-08 18:02:02 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:34:43 -04:00
|
|
|
const auto reply = launcher.mgr()->get(request);
|
2023-09-17 18:43:58 -04:00
|
|
|
co_await reply;
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Finished downloading Dotnet-core";
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
QFile file(m_tempDir.filePath(QStringLiteral("dotnet-core.zip")));
|
2023-09-17 18:43:58 -04:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
}
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
// desktop
|
|
|
|
{
|
2023-10-11 13:39:10 -04:00
|
|
|
const QNetworkRequest request(dotnetDesktopPackageUrl(m_remoteRuntimeVersion));
|
2023-10-08 18:02:02 -04:00
|
|
|
Utility::printRequest(QStringLiteral("GET"), request);
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:34:43 -04:00
|
|
|
const auto reply = launcher.mgr()->get(request);
|
2023-09-17 18:43:58 -04:00
|
|
|
co_await reply;
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
qInfo(ASTRA_LOG) << "Finished downloading Dotnet-desktop";
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-10-11 13:39:10 -04:00
|
|
|
QFile file(m_tempDir.filePath(QStringLiteral("dotnet-desktop.zip")));
|
2023-09-17 18:43:58 -04:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
}
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-12-20 18:00:40 -05:00
|
|
|
bool success = extractZip(m_tempDir.filePath(QStringLiteral("dotnet-core.zip")), m_dalamudRuntimeDir.absolutePath());
|
|
|
|
success |= extractZip(m_tempDir.filePath(QStringLiteral("dotnet-desktop.zip")), m_dalamudRuntimeDir.absolutePath());
|
2022-03-13 20:44:57 -04:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
if (!success) {
|
2023-10-08 19:07:34 -04:00
|
|
|
qCritical(ASTRA_LOG) << "Failed to install dotnet";
|
|
|
|
Q_EMIT launcher.dalamudError(i18n("Failed to install .NET runtime."));
|
|
|
|
|
|
|
|
co_return false;
|
2023-09-17 18:43:58 -04:00
|
|
|
} else {
|
2023-12-21 20:28:41 -05:00
|
|
|
Utility::writeVersion(m_dalamudRuntimeDir.absoluteFilePath(QStringLiteral("runtime.ver")), m_remoteRuntimeVersion);
|
2023-10-08 19:07:34 -04:00
|
|
|
|
|
|
|
co_return true;
|
2022-03-13 20:44:57 -04:00
|
|
|
}
|
2022-02-25 18:08:57 -05:00
|
|
|
}
|
2023-08-18 21:36:29 -04:00
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
QUrl AssetUpdater::dalamudVersionManifestUrl() const
|
|
|
|
{
|
|
|
|
QUrl url;
|
2023-10-11 13:25:24 -04:00
|
|
|
url.setScheme(launcher.settings()->preferredProtocol());
|
|
|
|
url.setHost(launcher.settings()->dalamudDistribServer());
|
2023-10-08 18:54:03 -04:00
|
|
|
url.setPath(QStringLiteral("/Dalamud/Release/VersionInfo"));
|
2023-08-18 21:36:29 -04:00
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl AssetUpdater::dalamudAssetManifestUrl() const
|
2023-08-18 21:36:29 -04:00
|
|
|
{
|
|
|
|
QUrl url;
|
2023-10-11 13:25:24 -04:00
|
|
|
url.setScheme(launcher.settings()->preferredProtocol());
|
|
|
|
url.setHost(launcher.settings()->dalamudDistribServer());
|
2023-10-08 18:54:03 -04:00
|
|
|
url.setPath(QStringLiteral("/Dalamud/Asset/Meta"));
|
2023-08-18 21:36:29 -04:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
QUrl AssetUpdater::dotnetRuntimePackageUrl(const QString &version) const
|
2023-08-18 21:36:29 -04:00
|
|
|
{
|
|
|
|
QUrl url;
|
2023-10-11 13:25:24 -04:00
|
|
|
url.setScheme(launcher.settings()->preferredProtocol());
|
|
|
|
url.setHost(launcher.settings()->dalamudDistribServer());
|
2023-10-08 18:54:03 -04:00
|
|
|
url.setPath(QStringLiteral("/Dalamud/Release/Runtime/DotNet/%1").arg(version));
|
2023-08-18 21:36:29 -04:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:54:03 -04:00
|
|
|
QUrl AssetUpdater::dotnetDesktopPackageUrl(const QString &version) const
|
2023-08-18 21:36:29 -04:00
|
|
|
{
|
|
|
|
QUrl url;
|
2023-10-11 13:25:24 -04:00
|
|
|
url.setScheme(launcher.settings()->preferredProtocol());
|
|
|
|
url.setHost(launcher.settings()->dalamudDistribServer());
|
2023-10-08 18:54:03 -04:00
|
|
|
url.setPath(QStringLiteral("/Dalamud/Release/Runtime/WindowsDesktop/%1").arg(version));
|
2023-08-18 21:36:29 -04:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
2023-12-17 11:12:13 -05:00
|
|
|
|
2023-12-20 18:00:40 -05:00
|
|
|
bool AssetUpdater::extractZip(const QString &filePath, const QString &directory)
|
|
|
|
{
|
|
|
|
KZip archive(filePath);
|
|
|
|
if (!archive.open(QIODevice::ReadOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KArchiveDirectory *root = archive.directory();
|
|
|
|
if (!root->copyTo(directory, true)) {
|
|
|
|
archive.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
archive.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-17 11:12:13 -05:00
|
|
|
#include "moc_assetupdater.cpp"
|