1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-23 04:57:44 +00:00

Add native launcher update support

When updating to this new commit, you will download the 1.1.0 release
automatically since we create a new version file.

This commit also fixes a bug where in certain cases the asset updating
process could end early.

The native launcher version is also visible from the settings window!
This commit is contained in:
Joshua Goins 2022-04-08 19:34:51 -04:00
parent dbbcb67134
commit 50ad93ee8f
6 changed files with 74 additions and 22 deletions

View file

@ -33,13 +33,14 @@ private:
QString remoteDalamudVersion;
QString remoteRuntimeVersion;
QString remoteNativeLauncherVersion;
QTemporaryDir tempDir;
bool doneDownloadingDalamud = true;
bool doneDownloadingNativelauncher = true;
bool doneDownloadingRuntimeCore = true;
bool doneDownloadingRuntimeDesktop = true;
bool doneDownloadingDalamud = false;
bool doneDownloadingNativelauncher = false;
bool doneDownloadingRuntimeCore = false;
bool doneDownloadingRuntimeDesktop = false;
bool needsRuntimeInstall = false;
bool needsDalamudInstall = false;
bool needsNativeInstall = false;

View file

@ -142,6 +142,7 @@ public:
QString dalamudVersion;
int dalamudAssetVersion = -1;
QString runtimeVersion;
QString nativeLauncherVersion;
int defaultProfileIndex = 0;
signals:

View file

@ -55,6 +55,7 @@ private:
QCheckBox* enableDalamudBox = nullptr;
QLabel* dalamudVersionLabel = nullptr;
QLabel* dalamudAssetVersionLabel = nullptr;
QLabel* nativeLauncherVersionLabel = nullptr;
QCheckBox* dalamudOptOutBox = nullptr;
bool currentlyReloadingControls = false;

View file

@ -21,9 +21,10 @@ const QString baseDalamudAssetDistribution = baseGoatDomain + "/DalamudAssets";
const QString dalamudAssetManifestURL = baseDalamudAssetDistribution + "/asset.json";
const QString baseNativeLauncherDistribution =
"https://github.com/redstrate/nativelauncher/releases/download/";
"https://xiv.zone/astra-distrib/nativelauncher";
const QString nativeLauncherLatestPackageURL =
baseNativeLauncherDistribution + "/latest/NativeLauncher.exe";
baseNativeLauncherDistribution + "/NativeLauncher.exe";
const QString nativeLauncherVersionManifestURL = baseNativeLauncherDistribution + "/version";
const QString dotnetRuntimePackageURL =
"https://dotnetcli.azureedge.net/dotnet/Runtime/%1/dotnet-runtime-%1-win-x64.zip";
@ -80,6 +81,24 @@ void AssetUpdater::update(const ProfileSettings& profile) {
});
}
// native launcher
{
QNetworkRequest request(nativeLauncherVersionManifestURL);
remoteNativeLauncherVersion.clear();
auto reply = launcher.mgr->get(request);
connect(reply, &QNetworkReply::finished, [this, profile, reply] {
dialog->setLabelText("Checking for native launcher updates...");
remoteNativeLauncherVersion = reply->readAll().trimmed();
qInfo() << "Latest native launcher version reported: " << remoteNativeLauncherVersion;
checkIfCheckingIsDone();
});
}
// dalamud injector / net runtime / nativelauncher
// they're all updated in unison, so there's no reason to have multiple checks
{
@ -123,17 +142,32 @@ void AssetUpdater::beginInstall() {
if(!success) {
// TODO: handle failure here
qInfo() << "Failed to install Dalamud!";
} else {
needsDalamudInstall = false;
}
}
if(needsNativeInstall) {
QFile::copy(tempDir.path() + "/NativeLauncher.exe",
qInfo() << "Installing native launcher...";
if(QFile::exists(dataDir + "/NativeLauncher.exe"))
QFile::remove(dataDir + "/NativeLauncher.exe");
bool success = QFile::copy(tempDir.path() + "/NativeLauncher.exe",
dataDir + "/NativeLauncher.exe");
if(!success) {
qInfo() << "Failed to install native launcher!";
} else {
QFile file(dataDir + "/nativelauncher.ver");
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.write(remoteNativeLauncherVersion.toUtf8());
file.close();
needsNativeInstall = false;
}
}
if(needsRuntimeInstall) {
bool success = !JlCompress::extractDir(tempDir.path() + "/dotnet-core.zip",
@ -145,7 +179,7 @@ void AssetUpdater::beginInstall() {
.empty();
if(!success) {
// TODO: handle failure here
qInfo() << "Failed to install dotnet!";
} else {
QFile file(dataDir + "/DalamudRuntime/runtime.ver");
file.open(QIODevice::WriteOnly | QIODevice::Text);
@ -201,7 +235,7 @@ void AssetUpdater::checkIfCheckingIsDone() {
if(dialog->wasCanceled())
return;
if(remoteDalamudVersion.isEmpty() || remoteRuntimeVersion.isEmpty() || remoteDalamudAssetVersion == -1) {
if(remoteDalamudVersion.isEmpty() || remoteRuntimeVersion.isEmpty() || remoteDalamudAssetVersion == -1 || remoteNativeLauncherVersion.isEmpty()) {
return;
}
@ -212,8 +246,6 @@ void AssetUpdater::checkIfCheckingIsDone() {
// dalamud injector / net runtime
if(launcher.runtimeVersion != remoteRuntimeVersion) {
doneDownloadingRuntimeCore = false;
doneDownloadingRuntimeDesktop = false;
needsRuntimeInstall = true;
// core
@ -267,7 +299,7 @@ void AssetUpdater::checkIfCheckingIsDone() {
if(remoteDalamudVersion != launcher.dalamudVersion) {
qInfo() << "Downloading Dalamud...";
doneDownloadingDalamud = false;
needsDalamudInstall = true;
QNetworkRequest request(dalamudLatestPackageURL);
@ -346,14 +378,11 @@ void AssetUpdater::checkIfCheckingIsDone() {
checkIfFinished();
}
// nativelauncher
const bool hasNative = QFile::exists(dataDir + "/NativeLauncher.exe");
if (!hasNative) {
// download nativelauncher release (needed to launch the game with fixed
// ACLs)
if(remoteNativeLauncherVersion != launcher.nativeLauncherVersion) {
qInfo() << "Native launcher out of date.";
dialog->setLabelText("Updating native launcher...");
qInfo() << "Downloading NativeLauncher...";
doneDownloadingNativelauncher = false;
needsNativeInstall = true;
QNetworkRequest request(nativeLauncherLatestPackageURL);
@ -362,8 +391,6 @@ void AssetUpdater::checkIfCheckingIsDone() {
connect(reply, &QNetworkReply::finished, [this, reply] {
qInfo() << "NativeLauncher finished downloading!";
dialog->setLabelText("Updating Nativelauncher...");
QFile file(tempDir.path() + "/NativeLauncher.exe");
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
@ -373,5 +400,11 @@ void AssetUpdater::checkIfCheckingIsDone() {
checkIfFinished();
});
} else {
qInfo() << "Native launcher up to date.";
doneDownloadingNativelauncher = true;
checkIfFinished();
}
}

View file

@ -305,6 +305,13 @@ void LauncherCore::readInitialInformation() {
}
}
if(QFile::exists(dataDir + "/nativelauncher.ver")) {
QFile nativeVer(dataDir + "/nativelauncher.ver");
nativeVer.open(QFile::ReadOnly | QFile::Text);
nativeLauncherVersion = QString(nativeVer.readAll());
}
auto profiles = settings.childGroups();
// create the Default profile if it doesnt exist

View file

@ -373,6 +373,9 @@ SettingsWindow::SettingsWindow(int defaultTab, LauncherWindow& window, LauncherC
dalamudAssetVersionLabel = new QLabel();
dalamudBoxLayout->addRow("Dalamud Asset Version", dalamudAssetVersionLabel);
nativeLauncherVersionLabel = new QLabel();
dalamudBoxLayout->addRow("Native Launcher Version", nativeLauncherVersionLabel);
}
tabWidget->setCurrentIndex(defaultTab);
@ -493,6 +496,12 @@ void SettingsWindow::reloadControls() {
dalamudAssetVersionLabel->setText(QString::number(core.dalamudAssetVersion));
}
if(core.nativeLauncherVersion.isEmpty()) {
nativeLauncherVersionLabel->setText("Native launcher is not installed.");
} else {
nativeLauncherVersionLabel->setText(core.nativeLauncherVersion);
}
dalamudOptOutBox->setChecked(profile.dalamud.optOutOfMbCollection);
window.reloadControls();