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
This commit is contained in:
DrakiaXYZ 2024-04-26 09:52:41 -07:00
parent 058c086c51
commit ac95894967
6 changed files with 32 additions and 15 deletions

View File

@ -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()
{

View File

@ -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<double>((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");

View File

@ -1,4 +1,4 @@
using SPTInstaller.Models.Releases;
using SPTInstaller.Models.ReleaseInfo;
namespace SPTInstaller.Models;
@ -32,7 +32,7 @@ public class InternalData
/// <summary>
/// The release information from release.json
/// </summary>
public ReleaseInfo ReleaseInfo { get; set; }
public ReleaseInfo.ReleaseInfo ReleaseInfo { get; set; }
/// <summary>
/// The release download link for the patcher mirror list

View File

@ -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<ReleaseInfoMirror> Mirrors { get; set; }
}

View File

@ -0,0 +1,6 @@
namespace SPTInstaller.Models.ReleaseInfo;
public class ReleaseInfoMirror
{
public string DownloadUrl { get; set; }
public string Hash { get; set; }
}

View File

@ -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<double>((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<ReleaseInfo>(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;