Merge pull request 'Utilize R2 for release downloads' (#76) from DrakiaXYZ/SPT-AKI-Installer:feat-r2-releases into master

Reviewed-on: CWX/SPT-AKI-Installer#76
This commit is contained in:
chomp 2024-04-26 10:53:46 +00:00
commit 058c086c51
3 changed files with 36 additions and 27 deletions

View File

@ -83,6 +83,24 @@ public class DownloadTask : InstallerTaskBase
return Result.FromError("Failed to download Patcher"); return Result.FromError("Failed to download Patcher");
} }
private async Task<IResult> DownloadSptAkiFromMirrors(IProgress<double> progress)
{
// Note that GetOrDownloadFileAsync handles the cached file hash check, so we don't need to check it first
foreach (var mirror in _data.ReleaseInfo.Mirrors)
{
SetStatus("Downloading SPT-AKI", mirror.DownloadUrl, progressStyle: ProgressStyle.Indeterminate);
_data.AkiZipInfo = await DownloadCacheHelper.GetOrDownloadFileAsync("sptaki", mirror.DownloadUrl, progress, mirror.Hash);
if (_data.AkiZipInfo != null)
{
return Result.FromSuccess();
}
}
return Result.FromError("Failed to download spt-aki");
}
public override async Task<IResult> TaskOperation() public override async Task<IResult> TaskOperation()
{ {
var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); }); var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
@ -106,15 +124,6 @@ public class DownloadTask : InstallerTaskBase
} }
} }
SetStatus("Downloading SPT-AKI", _data.AkiReleaseDownloadLink, 0); return await DownloadSptAkiFromMirrors(progress);
_data.AkiZipInfo = await DownloadCacheHelper.GetOrDownloadFileAsync("sptaki", _data.AkiReleaseDownloadLink, progress, _data.AkiReleaseHash);
if (_data.AkiZipInfo == null)
{
return Result.FromError("Failed to download spt-aki");
}
return Result.FromSuccess();
} }
} }

View File

@ -4,6 +4,8 @@ using SPTInstaller.Interfaces;
using SPTInstaller.Models; using SPTInstaller.Models;
using System.Threading.Tasks; using System.Threading.Tasks;
using SPTInstaller.Helpers; using SPTInstaller.Helpers;
using Newtonsoft.Json;
using SPTInstaller.Models.Releases;
namespace SPTInstaller.Installer_Tasks; namespace SPTInstaller.Installer_Tasks;
@ -24,21 +26,25 @@ public class ReleaseCheckTask : InstallerTaskBase
SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate); SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate);
var akiRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Stable-releases"); var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
var akiReleaseInfoFile = await DownloadCacheHelper.DownloadFileAsync("release.json", "https://spt-releases.modd.in/release.json", progress);
if (akiReleaseInfoFile == null)
{
return Result.FromError("Failed to download release metadata");
}
var akiReleaseInfo = JsonConvert.DeserializeObject<ReleaseInfo>(File.ReadAllText(akiReleaseInfoFile.FullName));
SetStatus("Checking for Patches", "", null, ProgressStyle.Indeterminate); SetStatus("Checking for Patches", "", null, ProgressStyle.Indeterminate);
var patchRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Downgrade-Patches"); var patchRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Downgrade-Patches");
var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0]; var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(_data.OriginalGameVersion) && x.Name.Contains(akiReleaseInfo.ClientVersion));
var latestAkiVersion = latestAkiRelease.Name.Replace('(', ' ').Replace(')', ' ').Split(' ')[3];
var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(_data.OriginalGameVersion) && x.Name.Contains(latestAkiVersion));
_data.PatcherMirrorsLink = comparePatchToAki?.Assets[0].BrowserDownloadUrl; _data.PatcherMirrorsLink = comparePatchToAki?.Assets[0].BrowserDownloadUrl;
_data.AkiReleaseDownloadLink = latestAkiRelease.Assets[0].BrowserDownloadUrl; _data.ReleaseInfo = akiReleaseInfo;
_data.AkiReleaseHash = FileHashHelper.GetGiteaReleaseHash(latestAkiRelease);
int IntAkiVersion = int.Parse(latestAkiVersion); int IntAkiVersion = int.Parse(akiReleaseInfo.ClientVersion);
int IntGameVersion = int.Parse(_data.OriginalGameVersion); int IntGameVersion = int.Parse(_data.OriginalGameVersion);
bool patchNeedCheck = false; bool patchNeedCheck = false;
@ -65,7 +71,7 @@ public class ReleaseCheckTask : InstallerTaskBase
_data.PatchNeeded = patchNeedCheck; _data.PatchNeeded = patchNeedCheck;
string status = $"Current Release: {latestAkiVersion} - {(_data.PatchNeeded ? "Patch Available" : "No Patch Needed")}"; string status = $"Current Release: {akiReleaseInfo.ClientVersion} - {(_data.PatchNeeded ? "Patch Available" : "No Patch Needed")}";
SetStatus(null, status); SetStatus(null, status);

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using SPTInstaller.Models.Releases;
using SPTInstaller.Models.Mirrors;
namespace SPTInstaller.Models; namespace SPTInstaller.Models;
@ -31,14 +30,9 @@ public class InternalData
public FileInfo AkiZipInfo { get; set; } public FileInfo AkiZipInfo { get; set; }
/// <summary> /// <summary>
/// The release download link for SPT-AKI /// The release information from release.json
/// </summary> /// </summary>
public string AkiReleaseDownloadLink { get; set; } public ReleaseInfo ReleaseInfo { get; set; }
/// <summary>
/// The release zip hash
/// </summary>
public string AkiReleaseHash { get; set; } = null;
/// <summary> /// <summary>
/// The release download link for the patcher mirror list /// The release download link for the patcher mirror list