2021-11-23 14:37:37 -05:00
|
|
|
#include "assetupdater.h"
|
|
|
|
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
|
|
#include <quazip/JlCompress.h>
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
#include "launchercore.h"
|
2021-11-23 14:37:37 -05:00
|
|
|
|
|
|
|
const QString dalamudRemotePath = "https://goatcorp.github.io/dalamud-distrib/";
|
|
|
|
const QString dalamudVersion = "latest";
|
|
|
|
|
|
|
|
const QString nativeLauncherRemotePath = "https://github.com/redstrate/nativelauncher/releases/download/";
|
|
|
|
const QString nativeLauncherVersion = "v1.0.0";
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
AssetUpdater::AssetUpdater(LauncherCore &launcher) : launcher(launcher) {
|
2021-11-23 14:37:37 -05:00
|
|
|
connect(launcher.mgr, &QNetworkAccessManager::finished, this, &AssetUpdater::finishDownload);
|
|
|
|
|
|
|
|
launcher.mgr->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
|
|
|
|
}
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
void AssetUpdater::update(const ProfileSettings& profile) {
|
2021-11-23 14:37:37 -05:00
|
|
|
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
|
|
|
|
const bool hasDalamud = QFile::exists(dataDir + "/NativeLauncher.exe") && QFile::exists(dataDir + "/Dalamud");
|
|
|
|
|
|
|
|
// first we determine if we need dalamud
|
2021-11-23 15:34:23 -05:00
|
|
|
const bool needsDalamud = profile.enableDalamud && !hasDalamud;
|
2021-11-23 14:37:37 -05:00
|
|
|
if(needsDalamud) {
|
|
|
|
// download nativelauncher release (needed to launch the game with fixed ACLs)
|
|
|
|
{
|
|
|
|
QNetworkRequest request(nativeLauncherRemotePath + nativeLauncherVersion + "/NativeLauncher.exe");
|
|
|
|
|
|
|
|
auto reply = launcher.mgr->get(request);
|
|
|
|
reply->setObjectName("NativeLauncher");
|
|
|
|
}
|
|
|
|
|
|
|
|
// download dalamud (... duh)
|
|
|
|
{
|
|
|
|
QNetworkRequest request(dalamudRemotePath + dalamudVersion + ".zip");
|
|
|
|
|
|
|
|
auto reply = launcher.mgr->get(request);
|
|
|
|
reply->setObjectName("Dalamud");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// non-dalamud users can bypass this process since it's not needed
|
|
|
|
finishedUpdating();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssetUpdater::finishDownload(QNetworkReply* reply) {
|
|
|
|
const auto checkIfFinished = [=] {
|
|
|
|
if(QFile::exists(tempDir.path() + "/NativeLauncher.exe") && QFile::exists(tempDir.path() + "/latest.zip")) {
|
|
|
|
beginInstall();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(reply->objectName() == "Dalamud") {
|
|
|
|
QFile file(tempDir.path() + "/latest.zip");
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
checkIfFinished();
|
|
|
|
} else if(reply->objectName() == "NativeLauncher") {
|
|
|
|
QFile file(tempDir.path() + "/NativeLauncher.exe");
|
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(reply->readAll());
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
checkIfFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssetUpdater::beginInstall() {
|
|
|
|
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
|
|
|
|
bool success = !JlCompress::extractDir(tempDir.path() + "/latest.zip", dataDir + "/Dalamud").empty();
|
|
|
|
if(success) {
|
|
|
|
QFile::copy(tempDir.path() + "/NativeLauncher.exe", dataDir + "/NativeLauncher.exe");
|
|
|
|
|
|
|
|
finishedUpdating();
|
|
|
|
} else {
|
|
|
|
// STUB: install failure
|
|
|
|
}
|
|
|
|
}
|