From 02beef81ce8fdf6f081f7e0eeea8fcdb2a086209 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 27 Jan 2022 10:46:22 -0500 Subject: [PATCH] Update Dalamud automatically --- src/assetupdater.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- src/assetupdater.h | 6 +++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/assetupdater.cpp b/src/assetupdater.cpp index 20b2dec..cc058da 100644 --- a/src/assetupdater.cpp +++ b/src/assetupdater.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include @@ -10,6 +12,7 @@ const QString dalamudRemotePath = "https://goatcorp.github.io/dalamud-distrib/"; const QString dalamudVersion = "latest"; +const QString dalamudVersionPath = dalamudRemotePath + "/version"; const QString nativeLauncherRemotePath = "https://github.com/redstrate/nativelauncher/releases/download/"; const QString nativeLauncherVersion = "v1.0.0"; @@ -25,8 +28,38 @@ void AssetUpdater::update(const ProfileSettings& profile) { const bool hasDalamud = QFile::exists(dataDir + "/NativeLauncher.exe") && QFile::exists(dataDir + "/Dalamud"); + bool isDalamudUpdated = false; + if(hasDalamud) { + if(remoteDalamudVersion.isEmpty()) { + QNetworkRequest request(dalamudVersionPath); + + auto reply = launcher.mgr->get(request); + reply->setObjectName("DalamudVersionCheck"); + currentSettings = &profile; // TODO: this is dirty, should change + + return; + } else { + if(QFile::exists(dataDir + "/Dalamud/Dalamud.deps.json")) { + QFile depsJson(dataDir + "/Dalamud/Dalamud.deps.json"); + depsJson.open(QFile::ReadOnly); + QJsonDocument doc = QJsonDocument::fromJson(depsJson.readAll()); + + // TODO: UGLY + QString versionString = doc["targets"].toObject()[".NETCoreApp,Version=v5.0"].toObject().keys().filter("Dalamud")[0]; + versionString = versionString.remove("Dalamud/"); + + if(versionString != remoteDalamudVersion) { + isDalamudUpdated = false; + } else { + isDalamudUpdated = true; + } + } + } + } + + // first we determine if we need dalamud - const bool needsDalamud = profile.enableDalamud && !hasDalamud; + const bool needsDalamud = profile.enableDalamud && (!hasDalamud || !isDalamudUpdated); if(needsDalamud) { // download nativelauncher release (needed to launch the game with fixed ACLs) { @@ -70,6 +103,12 @@ void AssetUpdater::finishDownload(QNetworkReply* reply) { file.close(); checkIfFinished(); + } else if(reply->objectName() == "DalamudVersionCheck") { + QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); + remoteDalamudVersion = doc["AssemblyVersion"].toString(); + + update(*currentSettings); + currentSettings = nullptr; } } @@ -84,4 +123,4 @@ void AssetUpdater::beginInstall() { } else { // STUB: install failure } -} \ No newline at end of file +} diff --git a/src/assetupdater.h b/src/assetupdater.h index 443dabc..1ad6b4c 100644 --- a/src/assetupdater.h +++ b/src/assetupdater.h @@ -22,5 +22,9 @@ signals: private: LauncherCore& launcher; + const ProfileSettings* currentSettings = nullptr; + + QString remoteDalamudVersion; + QTemporaryDir tempDir; -}; \ No newline at end of file +};