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:
commit
058c086c51
@ -83,6 +83,24 @@ public class DownloadTask : InstallerTaskBase
|
||||
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()
|
||||
{
|
||||
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);
|
||||
|
||||
_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();
|
||||
return await DownloadSptAkiFromMirrors(progress);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using SPTInstaller.Models.Releases;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
@ -24,21 +26,25 @@ public class ReleaseCheckTask : InstallerTaskBase
|
||||
|
||||
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);
|
||||
|
||||
var patchRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Downgrade-Patches");
|
||||
|
||||
var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0];
|
||||
var latestAkiVersion = latestAkiRelease.Name.Replace('(', ' ').Replace(')', ' ').Split(' ')[3];
|
||||
var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(_data.OriginalGameVersion) && x.Name.Contains(latestAkiVersion));
|
||||
var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(_data.OriginalGameVersion) && x.Name.Contains(akiReleaseInfo.ClientVersion));
|
||||
|
||||
_data.PatcherMirrorsLink = comparePatchToAki?.Assets[0].BrowserDownloadUrl;
|
||||
_data.AkiReleaseDownloadLink = latestAkiRelease.Assets[0].BrowserDownloadUrl;
|
||||
_data.AkiReleaseHash = FileHashHelper.GetGiteaReleaseHash(latestAkiRelease);
|
||||
_data.ReleaseInfo = akiReleaseInfo;
|
||||
|
||||
int IntAkiVersion = int.Parse(latestAkiVersion);
|
||||
int IntAkiVersion = int.Parse(akiReleaseInfo.ClientVersion);
|
||||
int IntGameVersion = int.Parse(_data.OriginalGameVersion);
|
||||
bool patchNeedCheck = false;
|
||||
|
||||
@ -65,7 +71,7 @@ public class ReleaseCheckTask : InstallerTaskBase
|
||||
|
||||
_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);
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using SPTInstaller.Models.Mirrors;
|
||||
using SPTInstaller.Models.Releases;
|
||||
|
||||
namespace SPTInstaller.Models;
|
||||
|
||||
@ -31,14 +30,9 @@ public class InternalData
|
||||
public FileInfo AkiZipInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The release download link for SPT-AKI
|
||||
/// The release information from release.json
|
||||
/// </summary>
|
||||
public string AkiReleaseDownloadLink { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The release zip hash
|
||||
/// </summary>
|
||||
public string AkiReleaseHash { get; set; } = null;
|
||||
public ReleaseInfo ReleaseInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The release download link for the patcher mirror list
|
||||
|
Loading…
x
Reference in New Issue
Block a user