From d840da2f474a5da7be58f30a334280796a3961f7 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 27 Apr 2024 14:51:54 -0400 Subject: [PATCH] updated the things it might even work --- SPTInstaller/Helpers/DownloadCacheHelper.cs | 1 + SPTInstaller/Helpers/FileHashHelper.cs | 24 ++-- SPTInstaller/Installer Tasks/DownloadTask.cs | 20 +--- .../Installer Tasks/ReleaseCheckTask.cs | 47 ++++---- SPTInstaller/Interfaces/IMirrorDownloader.cs | 2 +- SPTInstaller/Models/InstallerUpdateInfo.cs | 110 +++++++++--------- SPTInstaller/Models/InternalData.cs | 7 +- .../Downloaders/HttpMirrorDownloader.cs | 2 +- .../Downloaders/MegaMirrorDownloader.cs | 2 +- .../Downloaders/MirrorDownloaderBase.cs | 4 +- SPTInstaller/Models/Mirrors/PatchInfo.cs | 10 ++ .../{DownloadMirror.cs => PatchInfoMirror.cs} | 2 +- SPTInstaller/SPTInstaller.csproj | 10 +- .../ViewModels/MainWindowViewModel.cs | 3 - SPTInstaller/ViewModels/PreChecksViewModel.cs | 4 +- 15 files changed, 118 insertions(+), 130 deletions(-) create mode 100644 SPTInstaller/Models/Mirrors/PatchInfo.cs rename SPTInstaller/Models/Mirrors/{DownloadMirror.cs => PatchInfoMirror.cs} (80%) diff --git a/SPTInstaller/Helpers/DownloadCacheHelper.cs b/SPTInstaller/Helpers/DownloadCacheHelper.cs index 4a850ac..b011b1a 100644 --- a/SPTInstaller/Helpers/DownloadCacheHelper.cs +++ b/SPTInstaller/Helpers/DownloadCacheHelper.cs @@ -11,6 +11,7 @@ public static class DownloadCacheHelper 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 PatchMirrorUrl = "https://slugma.waffle-lord.net/mirrors.json"; public static string GetCacheSizeText() { diff --git a/SPTInstaller/Helpers/FileHashHelper.cs b/SPTInstaller/Helpers/FileHashHelper.cs index 0449069..0f6f2a3 100644 --- a/SPTInstaller/Helpers/FileHashHelper.cs +++ b/SPTInstaller/Helpers/FileHashHelper.cs @@ -1,24 +1,22 @@ using System.Linq; using System.Security.Cryptography; -using System.Text.RegularExpressions; -using Gitea.Model; using Serilog; namespace SPTInstaller.Helpers; public static class FileHashHelper { - public static string? GetGiteaReleaseHash(Release release) - { - var regex = Regex.Match(release.Body, @"Release Hash: (?\S+)"); - - if (regex.Success) - { - return regex.Groups["hash"].Value; - } - - return null; - } + // public static string? GetGiteaReleaseHash(Release release) + // { + // var regex = Regex.Match(release.Body, @"Release Hash: (?\S+)"); + // + // if (regex.Success) + // { + // return regex.Groups["hash"].Value; + // } + // + // return null; + // } public static bool CheckHash(FileInfo file, string expectedHash) { diff --git a/SPTInstaller/Installer Tasks/DownloadTask.cs b/SPTInstaller/Installer Tasks/DownloadTask.cs index b9e67c6..d0d96bf 100644 --- a/SPTInstaller/Installer Tasks/DownloadTask.cs +++ b/SPTInstaller/Installer Tasks/DownloadTask.cs @@ -23,29 +23,13 @@ public class DownloadTask : InstallerTaskBase private async Task BuildMirrorList() { - var progress = new Progress((d) => { SetStatus("Downloading Mirror List", "", (int)Math.Floor(d), ProgressStyle.Shown);}); - - var file = await DownloadCacheHelper.DownloadFileAsync("mirrors.json", _data.PatcherMirrorsLink, progress); - - if (file == null) - { - return Result.FromError("Failed to download mirror list"); - } - - var mirrorsList = JsonConvert.DeserializeObject>(File.ReadAllText(file.FullName)); - - if (mirrorsList == null) - { - return Result.FromError("Failed to deserialize mirrors list"); - } - - foreach (var mirror in mirrorsList) + foreach (var mirror in _data.PatchInfo.Mirrors) { _expectedPatcherHash = mirror.Hash; switch (mirror.Link) { - case string l when l.StartsWith("https://mega"): + case { } l when l.StartsWith("https://mega"): _mirrors.Add(new MegaMirrorDownloader(mirror)); break; default: diff --git a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs index f1f9f81..86842cd 100644 --- a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs +++ b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs @@ -1,10 +1,9 @@ -using Gitea.Api; -using Gitea.Client; -using SPTInstaller.Interfaces; +using SPTInstaller.Interfaces; using SPTInstaller.Models; using System.Threading.Tasks; using SPTInstaller.Helpers; using Newtonsoft.Json; +using SPTInstaller.Models.Mirrors; using SPTInstaller.Models.ReleaseInfo; namespace SPTInstaller.Installer_Tasks; @@ -22,8 +21,6 @@ public class ReleaseCheckTask : InstallerTaskBase { try { - var repo = new RepositoryApi(Configuration.Default); - SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate); var progress = new Progress((d) => { SetStatus(null, null, (int)Math.Floor(d)); }); @@ -37,34 +34,42 @@ public class ReleaseCheckTask : InstallerTaskBase SetStatus("Checking for Patches", "", null, ProgressStyle.Indeterminate); - var patchRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Downgrade-Patches"); + var akiPatchMirrorsFile = + await DownloadCacheHelper.DownloadFileAsync("mirrors.json", DownloadCacheHelper.PatchMirrorUrl, + progress); - var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(_data.OriginalGameVersion) && x.Name.Contains(akiReleaseInfo.ClientVersion)); - - _data.PatcherMirrorsLink = comparePatchToAki?.Assets[0].BrowserDownloadUrl; - _data.ReleaseInfo = akiReleaseInfo; - - int IntAkiVersion = int.Parse(akiReleaseInfo.ClientVersion); - int IntGameVersion = int.Parse(_data.OriginalGameVersion); - bool patchNeedCheck = false; - - if (IntGameVersion > IntAkiVersion) + if (akiPatchMirrorsFile == null) { - patchNeedCheck = true; + return Result.FromError("Failed to download patch mirror data"); } + + var patchMirrorInfo = JsonConvert.DeserializeObject(File.ReadAllText(akiPatchMirrorsFile.FullName)); - if (IntGameVersion < IntAkiVersion) + if (akiReleaseInfo == null || patchMirrorInfo == null) + { + return Result.FromError("An error occurred while deserializing aki or patch data"); + } + + _data.ReleaseInfo = akiReleaseInfo; + _data.PatchInfo = patchMirrorInfo; + int intAkiVersion = int.Parse(akiReleaseInfo.ClientVersion); + int intGameVersion = int.Parse(_data.OriginalGameVersion); + + // note: it's possible the game version could be lower than the aki version and still need a patch if the major version numbers change + // : it's probably a low chance though + bool patchNeedCheck = intGameVersion > intAkiVersion; + + if (intGameVersion < intAkiVersion) { return Result.FromError("Your client is outdated. Please update EFT"); - } - if (IntGameVersion == IntAkiVersion) + if (intGameVersion == intAkiVersion) { patchNeedCheck = false; } - if (comparePatchToAki == null && patchNeedCheck) + if ((intGameVersion != patchMirrorInfo.SourceClientVersion || intAkiVersion != patchMirrorInfo.TargetClientVersion) && patchNeedCheck) { return Result.FromError("No patcher available for your version.\nA patcher is usually created within 24 hours of an EFT update."); } diff --git a/SPTInstaller/Interfaces/IMirrorDownloader.cs b/SPTInstaller/Interfaces/IMirrorDownloader.cs index 1540620..95f293a 100644 --- a/SPTInstaller/Interfaces/IMirrorDownloader.cs +++ b/SPTInstaller/Interfaces/IMirrorDownloader.cs @@ -4,6 +4,6 @@ using System.Threading.Tasks; namespace SPTInstaller.Interfaces; public interface IMirrorDownloader { - public DownloadMirror MirrorInfo { get; } + public PatchInfoMirror MirrorInfo { get; } public Task Download(IProgress progress); } diff --git a/SPTInstaller/Models/InstallerUpdateInfo.cs b/SPTInstaller/Models/InstallerUpdateInfo.cs index 4116686..952b8c4 100644 --- a/SPTInstaller/Models/InstallerUpdateInfo.cs +++ b/SPTInstaller/Models/InstallerUpdateInfo.cs @@ -1,6 +1,4 @@ -using Gitea.Api; -using Gitea.Client; -using ReactiveUI; +using ReactiveUI; using Serilog; using SPTInstaller.Helpers; using System.Diagnostics; @@ -117,57 +115,57 @@ public class InstallerUpdateInfo : ReactiveObject UpdateAvailable = updateAvailable; } - public async Task CheckForUpdates(Version? currentVersion) - { - if (currentVersion == null) - return; - - UpdateInfoText = "Checking for installer updates"; - Show = true; - CheckingForUpdates = true; - - try - { - var repo = new RepositoryApi(Configuration.Default); - - var releases = await repo.RepoListReleasesAsync("CWX", "SPT-AKI-Installer"); - - if (releases == null || releases.Count == 0) - { - EndCheck("No releases available", false); - return; - } - - var latest = releases.FindAll(x => !x.Prerelease)[0]; - - if (latest == null) - { - EndCheck("could not get latest release", false); - return; - } - - var latestVersion = new Version(latest.TagName); - - if (latestVersion == null || latestVersion <= currentVersion) - { - EndCheck("No updates available", false); - return; - } - - _newVersion = latestVersion; - - NewInstallerUrl = latest.Assets[0].BrowserDownloadUrl; - - EndCheck($"Update available: v{latestVersion}", true); - - return; - } - catch (Exception ex) - { - EndCheck(ex.Message, false, false); - Log.Error(ex, "Failed to check for updates"); - } - - return; - } + // public async Task CheckForUpdates(Version? currentVersion) + // { + // if (currentVersion == null) + // return; + // + // UpdateInfoText = "Checking for installer updates"; + // Show = true; + // CheckingForUpdates = true; + // + // try + // { + // var repo = new RepositoryApi(Configuration.Default); + // + // var releases = await repo.RepoListReleasesAsync("CWX", "SPT-AKI-Installer"); + // + // if (releases == null || releases.Count == 0) + // { + // EndCheck("No releases available", false); + // return; + // } + // + // var latest = releases.FindAll(x => !x.Prerelease)[0]; + // + // if (latest == null) + // { + // EndCheck("could not get latest release", false); + // return; + // } + // + // var latestVersion = new Version(latest.TagName); + // + // if (latestVersion == null || latestVersion <= currentVersion) + // { + // EndCheck("No updates available", false); + // return; + // } + // + // _newVersion = latestVersion; + // + // NewInstallerUrl = latest.Assets[0].BrowserDownloadUrl; + // + // EndCheck($"Update available: v{latestVersion}", true); + // + // return; + // } + // catch (Exception ex) + // { + // EndCheck(ex.Message, false, false); + // Log.Error(ex, "Failed to check for updates"); + // } + // + // return; + // } } diff --git a/SPTInstaller/Models/InternalData.cs b/SPTInstaller/Models/InternalData.cs index 9a8f21b..e361be8 100644 --- a/SPTInstaller/Models/InternalData.cs +++ b/SPTInstaller/Models/InternalData.cs @@ -1,4 +1,5 @@ -using SPTInstaller.Models.ReleaseInfo; +using SPTInstaller.Models.Mirrors; +using SPTInstaller.Models.ReleaseInfo; namespace SPTInstaller.Models; @@ -33,11 +34,13 @@ public class InternalData /// The release information from release.json /// public ReleaseInfo.ReleaseInfo ReleaseInfo { get; set; } + + public PatchInfo PatchInfo { get; set; } /// /// The release download link for the patcher mirror list /// - public string PatcherMirrorsLink { get; set; } + // public string PatcherMirrorsLink { get; set; } /// /// Whether or not a patch is needed to downgrade the client files diff --git a/SPTInstaller/Models/Mirrors/Downloaders/HttpMirrorDownloader.cs b/SPTInstaller/Models/Mirrors/Downloaders/HttpMirrorDownloader.cs index 2a49364..329b322 100644 --- a/SPTInstaller/Models/Mirrors/Downloaders/HttpMirrorDownloader.cs +++ b/SPTInstaller/Models/Mirrors/Downloaders/HttpMirrorDownloader.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace SPTInstaller.Models.Mirrors.Downloaders; public class HttpMirrorDownloader : MirrorDownloaderBase { - public HttpMirrorDownloader(DownloadMirror mirror) : base(mirror) + public HttpMirrorDownloader(PatchInfoMirror mirror) : base(mirror) { } diff --git a/SPTInstaller/Models/Mirrors/Downloaders/MegaMirrorDownloader.cs b/SPTInstaller/Models/Mirrors/Downloaders/MegaMirrorDownloader.cs index 5f08e4b..109a93d 100644 --- a/SPTInstaller/Models/Mirrors/Downloaders/MegaMirrorDownloader.cs +++ b/SPTInstaller/Models/Mirrors/Downloaders/MegaMirrorDownloader.cs @@ -6,7 +6,7 @@ using Serilog; namespace SPTInstaller.Models.Mirrors.Downloaders; public class MegaMirrorDownloader : MirrorDownloaderBase { - public MegaMirrorDownloader(DownloadMirror mirrorInfo) : base(mirrorInfo) + public MegaMirrorDownloader(PatchInfoMirror mirrorInfo) : base(mirrorInfo) { } diff --git a/SPTInstaller/Models/Mirrors/Downloaders/MirrorDownloaderBase.cs b/SPTInstaller/Models/Mirrors/Downloaders/MirrorDownloaderBase.cs index 2fb6dcb..f36f205 100644 --- a/SPTInstaller/Models/Mirrors/Downloaders/MirrorDownloaderBase.cs +++ b/SPTInstaller/Models/Mirrors/Downloaders/MirrorDownloaderBase.cs @@ -4,9 +4,9 @@ using System.Threading.Tasks; namespace SPTInstaller.Models.Mirrors.Downloaders; public abstract class MirrorDownloaderBase : IMirrorDownloader { - public DownloadMirror MirrorInfo { get; private set; } + public PatchInfoMirror MirrorInfo { get; private set; } public abstract Task Download(IProgress progress); - public MirrorDownloaderBase(DownloadMirror mirrorInfo) + public MirrorDownloaderBase(PatchInfoMirror mirrorInfo) { MirrorInfo = mirrorInfo; } diff --git a/SPTInstaller/Models/Mirrors/PatchInfo.cs b/SPTInstaller/Models/Mirrors/PatchInfo.cs new file mode 100644 index 0000000..95d02f2 --- /dev/null +++ b/SPTInstaller/Models/Mirrors/PatchInfo.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace SPTInstaller.Models.Mirrors; + +public class PatchInfo +{ + public int SourceClientVersion { get; set; } + public int TargetClientVersion { get; set; } + public List Mirrors { get; set; } +} \ No newline at end of file diff --git a/SPTInstaller/Models/Mirrors/DownloadMirror.cs b/SPTInstaller/Models/Mirrors/PatchInfoMirror.cs similarity index 80% rename from SPTInstaller/Models/Mirrors/DownloadMirror.cs rename to SPTInstaller/Models/Mirrors/PatchInfoMirror.cs index b44a00a..40a7a8d 100644 --- a/SPTInstaller/Models/Mirrors/DownloadMirror.cs +++ b/SPTInstaller/Models/Mirrors/PatchInfoMirror.cs @@ -1,6 +1,6 @@ namespace SPTInstaller.Models.Mirrors; -public class DownloadMirror +public class PatchInfoMirror { public string Link { get; set; } public string Hash { get; set; } diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index aa5247a..d5e4902 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -9,8 +9,8 @@ icon.ico Assets\icon.ico Debug;Release;TEST - 2.59 - 2.59 + 2.61 + 2.61 SPT-AKI @@ -47,10 +47,4 @@ - - - - Z:\dev_stuff\EftPatchHelper\EftPatchHelper\EftPatchHelper\Resources\Gitea.dll - - diff --git a/SPTInstaller/ViewModels/MainWindowViewModel.cs b/SPTInstaller/ViewModels/MainWindowViewModel.cs index 338834e..28210ca 100644 --- a/SPTInstaller/ViewModels/MainWindowViewModel.cs +++ b/SPTInstaller/ViewModels/MainWindowViewModel.cs @@ -1,5 +1,4 @@ using Avalonia; -using Gitea.Client; using ReactiveUI; using Serilog; using System.Globalization; @@ -21,8 +20,6 @@ public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScree public MainWindowViewModel(bool debugging) { - Configuration.Default.BasePath = "https://dev.sp-tarkov.com/api/v1"; - Title = $"{(debugging ? "-debug-" : "")} SPT Installer {"v" + Assembly.GetExecutingAssembly().GetName()?.Version?.ToString() ?? "--unknown version--"}"; Log.Information($"========= {Title} Started ========="); diff --git a/SPTInstaller/ViewModels/PreChecksViewModel.cs b/SPTInstaller/ViewModels/PreChecksViewModel.cs index 7006536..a75dcab 100644 --- a/SPTInstaller/ViewModels/PreChecksViewModel.cs +++ b/SPTInstaller/ViewModels/PreChecksViewModel.cs @@ -5,8 +5,6 @@ using System.Threading.Tasks; using System.Windows.Input; using Avalonia.Threading; using DialogHostAvalonia; -using Gitea.Api; -using Gitea.Client; using Newtonsoft.Json; using ReactiveUI; using Serilog; @@ -264,7 +262,7 @@ public class PreChecksViewModel : ViewModelBase var result = await installer.RunPreChecks(); // check for updates - await UpdateInfo.CheckForUpdates(Assembly.GetExecutingAssembly().GetName()?.Version); + //await UpdateInfo.CheckForUpdates(Assembly.GetExecutingAssembly().GetName()?.Version); // get latest spt version InstallButtonText = "Getting latest release ...";