Merge pull request 'Switch the precheck to use the release.json method of version fetching' (#77) from DrakiaXYZ/SPT-AKI-Installer:fix-release-fetch into master

Reviewed-on: CWX/SPT-AKI-Installer#77
This commit is contained in:
chomp 2024-04-26 16:55:44 +00:00
commit 1c595fc239
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) }; 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 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() public static string GetCacheSizeText()
{ {

View File

@ -5,7 +5,7 @@ using SPTInstaller.Models;
using System.Threading.Tasks; using System.Threading.Tasks;
using SPTInstaller.Helpers; using SPTInstaller.Helpers;
using Newtonsoft.Json; using Newtonsoft.Json;
using SPTInstaller.Models.Releases; using SPTInstaller.Models.ReleaseInfo;
namespace SPTInstaller.Installer_Tasks; namespace SPTInstaller.Installer_Tasks;
@ -27,7 +27,7 @@ public class ReleaseCheckTask : InstallerTaskBase
SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate); SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate);
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)); });
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) if (akiReleaseInfoFile == null)
{ {
return Result.FromError("Failed to download release metadata"); 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; namespace SPTInstaller.Models;
@ -32,7 +32,7 @@ public class InternalData
/// <summary> /// <summary>
/// The release information from release.json /// The release information from release.json
/// </summary> /// </summary>
public ReleaseInfo ReleaseInfo { get; set; } public ReleaseInfo.ReleaseInfo ReleaseInfo { get; set; }
/// <summary> /// <summary>
/// The release download link for the patcher mirror list /// 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 DialogHostAvalonia;
using Gitea.Api; using Gitea.Api;
using Gitea.Client; using Gitea.Client;
using Newtonsoft.Json;
using ReactiveUI; using ReactiveUI;
using Serilog; using Serilog;
using SPTInstaller.Controllers; using SPTInstaller.Controllers;
@ -14,6 +15,7 @@ using SPTInstaller.CustomControls;
using SPTInstaller.CustomControls.Dialogs; using SPTInstaller.CustomControls.Dialogs;
using SPTInstaller.Helpers; using SPTInstaller.Helpers;
using SPTInstaller.Models; using SPTInstaller.Models;
using SPTInstaller.Models.ReleaseInfo;
namespace SPTInstaller.ViewModels; namespace SPTInstaller.ViewModels;
@ -268,26 +270,24 @@ public class PreChecksViewModel : ViewModelBase
InstallButtonText = "Getting latest release ..."; InstallButtonText = "Getting latest release ...";
InstallButtonCheckState = StatusSpinner.SpinnerState.Running; InstallButtonCheckState = StatusSpinner.SpinnerState.Running;
var repo = new RepositoryApi(Configuration.Default); var progress = new Progress<double>((d) => { });
var akiRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Stable-releases"); var akiReleaseInfoFile = await DownloadCacheHelper.DownloadFileAsync("release.json", DownloadCacheHelper.ReleaseMirrorUrl, progress);
if (akiReleaseInfoFile == null)
if (akiRepoReleases == null || akiRepoReleases.Count == 0)
{ {
InstallButtonText = "Could not get SPT releases from repo"; InstallButtonText = "Could not get SPT release metadata";
InstallButtonCheckState = StatusSpinner.SpinnerState.Error; InstallButtonCheckState = StatusSpinner.SpinnerState.Error;
return; return;
} }
var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0]; var akiReleaseInfo = JsonConvert.DeserializeObject<ReleaseInfo>(File.ReadAllText(akiReleaseInfoFile.FullName));
if (akiReleaseInfo == null)
if (latestAkiRelease == null)
{ {
InstallButtonText = "Could not find the latest SPT release"; InstallButtonText = "Could not parse latest SPT release";
InstallButtonCheckState = StatusSpinner.SpinnerState.Error; InstallButtonCheckState = StatusSpinner.SpinnerState.Error;
return; return;
} }
InstallButtonText = $"Start Install: SPT v{latestAkiRelease.TagName}"; InstallButtonText = $"Start Install: SPT v{akiReleaseInfo.AkiVersion}";
InstallButtonCheckState = StatusSpinner.SpinnerState.OK; InstallButtonCheckState = StatusSpinner.SpinnerState.OK;
AllowDetailsButton = true; AllowDetailsButton = true;