From ac95894967f7ecfe4bfeb09699c038097d293d8f Mon Sep 17 00:00:00 2001 From: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:52:41 -0700 Subject: [PATCH] Switch the precheck to use the release.json method of version fetching - Removes another hit to the Gitea API - Renamed 'Models/Releases' to 'Models/ReleaseInfo' to avoid a .gitignore hit, this adds the missing files - Moved the definition for the release.json URL to DownloadCacheHelper for now --- SPTInstaller/Helpers/DownloadCacheHelper.cs | 1 + .../Installer Tasks/ReleaseCheckTask.cs | 4 ++-- SPTInstaller/Models/InternalData.cs | 4 ++-- .../Models/ReleaseInfo/ReleaseInfo.cs | 10 +++++++++ .../Models/ReleaseInfo/ReleaseInfoMirror.cs | 6 +++++ SPTInstaller/ViewModels/PreChecksViewModel.cs | 22 +++++++++---------- 6 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 SPTInstaller/Models/ReleaseInfo/ReleaseInfo.cs create mode 100644 SPTInstaller/Models/ReleaseInfo/ReleaseInfoMirror.cs diff --git a/SPTInstaller/Helpers/DownloadCacheHelper.cs b/SPTInstaller/Helpers/DownloadCacheHelper.cs index 533dc7e..4a850ac 100644 --- a/SPTInstaller/Helpers/DownloadCacheHelper.cs +++ b/SPTInstaller/Helpers/DownloadCacheHelper.cs @@ -10,6 +10,7 @@ public static class DownloadCacheHelper private static HttpClient _httpClient = new() { Timeout = TimeSpan.FromHours(1) }; public static string CachePath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "spt-installer/cache"); + public static string ReleaseMirrorUrl = "https://spt-releases.modd.in/release.json"; public static string GetCacheSizeText() { diff --git a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs index f30211d..f1f9f81 100644 --- a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs +++ b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs @@ -5,7 +5,7 @@ using SPTInstaller.Models; using System.Threading.Tasks; using SPTInstaller.Helpers; using Newtonsoft.Json; -using SPTInstaller.Models.Releases; +using SPTInstaller.Models.ReleaseInfo; namespace SPTInstaller.Installer_Tasks; @@ -27,7 +27,7 @@ public class ReleaseCheckTask : InstallerTaskBase SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate); var progress = new Progress((d) => { SetStatus(null, null, (int)Math.Floor(d)); }); - var akiReleaseInfoFile = await DownloadCacheHelper.DownloadFileAsync("release.json", "https://spt-releases.modd.in/release.json", progress); + var akiReleaseInfoFile = await DownloadCacheHelper.DownloadFileAsync("release.json", DownloadCacheHelper.ReleaseMirrorUrl, progress); if (akiReleaseInfoFile == null) { return Result.FromError("Failed to download release metadata"); diff --git a/SPTInstaller/Models/InternalData.cs b/SPTInstaller/Models/InternalData.cs index 3ceffb6..9a8f21b 100644 --- a/SPTInstaller/Models/InternalData.cs +++ b/SPTInstaller/Models/InternalData.cs @@ -1,4 +1,4 @@ -using SPTInstaller.Models.Releases; +using SPTInstaller.Models.ReleaseInfo; namespace SPTInstaller.Models; @@ -32,7 +32,7 @@ public class InternalData /// /// The release information from release.json /// - public ReleaseInfo ReleaseInfo { get; set; } + public ReleaseInfo.ReleaseInfo ReleaseInfo { get; set; } /// /// The release download link for the patcher mirror list diff --git a/SPTInstaller/Models/ReleaseInfo/ReleaseInfo.cs b/SPTInstaller/Models/ReleaseInfo/ReleaseInfo.cs new file mode 100644 index 0000000..5566242 --- /dev/null +++ b/SPTInstaller/Models/ReleaseInfo/ReleaseInfo.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace SPTInstaller.Models.ReleaseInfo; +public class ReleaseInfo +{ + public string AkiVersion { get; set; } + public string ClientVersion { get; set; } + public List Mirrors { get; set; } +} + diff --git a/SPTInstaller/Models/ReleaseInfo/ReleaseInfoMirror.cs b/SPTInstaller/Models/ReleaseInfo/ReleaseInfoMirror.cs new file mode 100644 index 0000000..506d52e --- /dev/null +++ b/SPTInstaller/Models/ReleaseInfo/ReleaseInfoMirror.cs @@ -0,0 +1,6 @@ +namespace SPTInstaller.Models.ReleaseInfo; +public class ReleaseInfoMirror +{ + public string DownloadUrl { get; set; } + public string Hash { get; set; } +} diff --git a/SPTInstaller/ViewModels/PreChecksViewModel.cs b/SPTInstaller/ViewModels/PreChecksViewModel.cs index 12f4724..7006536 100644 --- a/SPTInstaller/ViewModels/PreChecksViewModel.cs +++ b/SPTInstaller/ViewModels/PreChecksViewModel.cs @@ -7,6 +7,7 @@ using Avalonia.Threading; using DialogHostAvalonia; using Gitea.Api; using Gitea.Client; +using Newtonsoft.Json; using ReactiveUI; using Serilog; using SPTInstaller.Controllers; @@ -14,6 +15,7 @@ using SPTInstaller.CustomControls; using SPTInstaller.CustomControls.Dialogs; using SPTInstaller.Helpers; using SPTInstaller.Models; +using SPTInstaller.Models.ReleaseInfo; namespace SPTInstaller.ViewModels; @@ -267,27 +269,25 @@ public class PreChecksViewModel : ViewModelBase // get latest spt version InstallButtonText = "Getting latest release ..."; InstallButtonCheckState = StatusSpinner.SpinnerState.Running; - - var repo = new RepositoryApi(Configuration.Default); - var akiRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Stable-releases"); - if (akiRepoReleases == null || akiRepoReleases.Count == 0) + var progress = new Progress((d) => { }); + var akiReleaseInfoFile = await DownloadCacheHelper.DownloadFileAsync("release.json", DownloadCacheHelper.ReleaseMirrorUrl, progress); + if (akiReleaseInfoFile == null) { - InstallButtonText = "Could not get SPT releases from repo"; + InstallButtonText = "Could not get SPT release metadata"; InstallButtonCheckState = StatusSpinner.SpinnerState.Error; return; } - - var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0]; - if (latestAkiRelease == null) + var akiReleaseInfo = JsonConvert.DeserializeObject(File.ReadAllText(akiReleaseInfoFile.FullName)); + if (akiReleaseInfo == null) { - InstallButtonText = "Could not find the latest SPT release"; + InstallButtonText = "Could not parse latest SPT release"; InstallButtonCheckState = StatusSpinner.SpinnerState.Error; return; } - - InstallButtonText = $"Start Install: SPT v{latestAkiRelease.TagName}"; + + InstallButtonText = $"Start Install: SPT v{akiReleaseInfo.AkiVersion}"; InstallButtonCheckState = StatusSpinner.SpinnerState.OK; AllowDetailsButton = true;