From e70e30ff571296131a846b6fbb026c896a3b7855 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 29 Jul 2023 23:00:13 -0400 Subject: [PATCH 1/2] add installer update info to check for updates WIP --- .../Installer Tasks/ReleaseCheckTask.cs | 2 - SPTInstaller/Models/InstallerUpdateInfo.cs | 92 +++++++++++++++++++ SPTInstaller/SPTInstaller.csproj | 4 +- .../ViewModels/MainWindowViewModel.cs | 16 +++- SPTInstaller/Views/MainWindow.axaml | 4 +- 5 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 SPTInstaller/Models/InstallerUpdateInfo.cs diff --git a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs index e28b14e..926a812 100644 --- a/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs +++ b/SPTInstaller/Installer Tasks/ReleaseCheckTask.cs @@ -20,8 +20,6 @@ public class ReleaseCheckTask : InstallerTaskBase { try { - Configuration.Default.BasePath = "https://dev.sp-tarkov.com/api/v1"; - var repo = new RepositoryApi(Configuration.Default); SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate); diff --git a/SPTInstaller/Models/InstallerUpdateInfo.cs b/SPTInstaller/Models/InstallerUpdateInfo.cs new file mode 100644 index 0000000..b19db7d --- /dev/null +++ b/SPTInstaller/Models/InstallerUpdateInfo.cs @@ -0,0 +1,92 @@ +using Gitea.Api; +using Gitea.Client; +using ReactiveUI; +using Serilog; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace SPTInstaller.Models; +public class InstallerUpdateInfo : ReactiveObject +{ + private bool _updateAvailable; + public bool UpdateAvailable + { + get => _updateAvailable; + set => this.RaiseAndSetIfChanged(ref _updateAvailable, value); + } + + private Version _currentVersion; + public Version CurrentVersion + { + get => _currentVersion; + set => this.RaiseAndSetIfChanged(ref _currentVersion, value); + } + + private Version _newVersion; + public Version NewVersion + { + get => _newVersion; + set => this.RaiseAndSetIfChanged(ref _newVersion, value); + } + + + private bool _checkingForUpdates; + public bool CheckingForUpdates + { + get => _checkingForUpdates; + set => this.RaiseAndSetIfChanged(ref _checkingForUpdates, value); + } + + public async Task CheckForUpdates() + { + CheckingForUpdates = true; + + try + { + var repo = new RepositoryApi(Configuration.Default); + + var releases = await repo.RepoListReleasesAsync("CWX", "SPT-AKI-Installer"); + + if (releases == null || releases.Count == 0) + return false; + + var latest = releases.FindAll(x => !x.Prerelease)[0]; + + if (latest == null) + return false; + + var latestVersion = new Version(latest.TagName); + + if (latestVersion == null || latestVersion <= CurrentVersion) + return false; + + NewVersion = latestVersion; + UpdateAvailable = true; + CheckingForUpdates = false; + + return true; + } + catch (Exception ex) + { + Log.Logger.Error(ex, "Failed to check for updates"); + } + + CheckingForUpdates = false; + return false; + } + + public ICommand UpdateInstaller { get; set; } + + public InstallerUpdateInfo(Version? currentVersion) + { + if (currentVersion == null) + return; + + CurrentVersion = currentVersion; + + UpdateInstaller = ReactiveCommand.Create(() => + { + // TODO: update installer here + }); + } +} diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index 7587cb0..7f49e5a 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -9,8 +9,8 @@ icon.ico Assets\icon.ico Debug;Release;TEST - 2.5 - 2.5 + 2.6 + 2.6 diff --git a/SPTInstaller/ViewModels/MainWindowViewModel.cs b/SPTInstaller/ViewModels/MainWindowViewModel.cs index 8b86439..996ddb7 100644 --- a/SPTInstaller/ViewModels/MainWindowViewModel.cs +++ b/SPTInstaller/ViewModels/MainWindowViewModel.cs @@ -1,7 +1,10 @@ using Avalonia; +using Gitea.Client; using ReactiveUI; using Serilog; +using SPTInstaller.Models; using System.Reflection; +using System.Threading.Tasks; namespace SPTInstaller.ViewModels; @@ -19,13 +22,22 @@ public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScree public MainWindowViewModel() { - string? version = Assembly.GetExecutingAssembly().GetName()?.Version?.ToString(); + Configuration.Default.BasePath = "https://dev.sp-tarkov.com/api/v1"; - Title = $"SPT Installer {"v" + version ?? "--unknown version--"}"; + Version? version = Assembly.GetExecutingAssembly().GetName()?.Version; + + Title = $"SPT Installer {"v" + version?.ToString() ?? "--unknown version--"}"; Log.Information($"========= {Title} Started ========="); Log.Information(Environment.OSVersion.VersionString); + var updateInfo = new InstallerUpdateInfo(version); + + Task.Run(async () => + { + await updateInfo.CheckForUpdates(); + }); + Router.Navigate.Execute(new PreChecksViewModel(this)); } diff --git a/SPTInstaller/Views/MainWindow.axaml b/SPTInstaller/Views/MainWindow.axaml index 659652b..089734d 100644 --- a/SPTInstaller/Views/MainWindow.axaml +++ b/SPTInstaller/Views/MainWindow.axaml @@ -1,4 +1,4 @@ - - + From f135a3e325168c16882a39b6930d7eddb8efe0c8 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sun, 30 Jul 2023 16:15:52 -0400 Subject: [PATCH 2/2] finish auto update feature --- SPTInstaller/Assets/Styles.axaml | 26 +++- .../CustomControls/UpdateInfoCard.axaml | 53 ++++++++ .../CustomControls/UpdateInfoCard.axaml.cs | 60 +++++++++ SPTInstaller/Helpers/DownloadCacheHelper.cs | 8 +- SPTInstaller/Helpers/FileHelper.cs | 30 ++++- SPTInstaller/Models/InstallerUpdateInfo.cs | 116 ++++++++++++------ SPTInstaller/Resources/update.ps1 | 27 ++++ SPTInstaller/SPTInstaller.csproj | 5 + .../ViewModels/DetailedPreChecksViewModel.cs | 2 +- .../ViewModels/MainWindowViewModel.cs | 17 ++- SPTInstaller/ViewModels/MessageViewModel.cs | 10 +- SPTInstaller/ViewModels/PreChecksViewModel.cs | 12 +- SPTInstaller/Views/MainWindow.axaml | 12 +- SPTInstaller/Views/MessageView.axaml | 3 +- 14 files changed, 323 insertions(+), 58 deletions(-) create mode 100644 SPTInstaller/CustomControls/UpdateInfoCard.axaml create mode 100644 SPTInstaller/CustomControls/UpdateInfoCard.axaml.cs create mode 100644 SPTInstaller/Resources/update.ps1 diff --git a/SPTInstaller/Assets/Styles.axaml b/SPTInstaller/Assets/Styles.axaml index 401fbc5..7f446d4 100644 --- a/SPTInstaller/Assets/Styles.axaml +++ b/SPTInstaller/Assets/Styles.axaml @@ -168,7 +168,29 @@ - + + + + + + + + + + + + + + + + +