From c6ffdbccbf0d0227d7a2e8a631c787b1e2194896 Mon Sep 17 00:00:00 2001 From: MattEqualsCoder Date: Fri, 22 Dec 2023 14:44:02 -0500 Subject: [PATCH] Check release against new repo location --- src/Randomizer.App/Randomizer.App.csproj | 4 +- .../Windows/RomListWindow.xaml.cs | 57 +++++++++++++------ tests/Randomizer.SMZ3.Tests/MetaTests.cs | 8 ++- .../Randomizer.SMZ3.Tests.csproj | 2 +- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/Randomizer.App/Randomizer.App.csproj b/src/Randomizer.App/Randomizer.App.csproj index 3b4cc357b..8a9c509b1 100644 --- a/src/Randomizer.App/Randomizer.App.csproj +++ b/src/Randomizer.App/Randomizer.App.csproj @@ -5,7 +5,7 @@ net7.0-windows true chozo20.ico - 9.6.1.1 + 9.6.1 SMZ3 Cas' Randomizer SMZ3 Cas' Randomizer Vivelin @@ -60,7 +60,7 @@ - + diff --git a/src/Randomizer.App/Windows/RomListWindow.xaml.cs b/src/Randomizer.App/Windows/RomListWindow.xaml.cs index 1af7fe313..d9381c92e 100644 --- a/src/Randomizer.App/Windows/RomListWindow.xaml.cs +++ b/src/Randomizer.App/Windows/RomListWindow.xaml.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; +using System.Threading.Tasks; using System.Windows; using System.Windows.Navigation; using GitHubReleaseChecker; @@ -69,31 +70,55 @@ private async void Window_Loaded(object sender, RoutedEventArgs e) } } - if (Options.GeneralOptions.CheckForUpdatesOnStartup) + var soloPanel = _serviceProvider.GetService(); + if (soloPanel != null) SoloTab.Children.Add(soloPanel); + var multiPanel = _serviceProvider.GetService(); + if (multiPanel != null) MultiTab.Children.Add(multiPanel); + + _ = CheckForUpdates(); + } + + private async Task CheckForUpdates() + { + if (!Options.GeneralOptions.CheckForUpdatesOnStartup) return; + + var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; + + try { - var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; + var gitHubRelease = await _gitHubReleaseCheckerService + .GetGitHubReleaseToUpdateToAsync("TheTrackerCouncil", "SMZ3Randomizer", version ?? "", false); - try + if (gitHubRelease != null) { - var newerGitHubRelease = _gitHubReleaseCheckerService - .GetGitHubReleaseToUpdateTo("Vivelin", "SMZ3Randomizer", version ?? "", false); - - if (newerGitHubRelease != null && newerGitHubRelease.Url != Options.GeneralOptions.IgnoredUpdateUrl) + if (gitHubRelease.Url != Options.GeneralOptions.IgnoredUpdateUrl) { - UpdateNotificationBorder.Visibility = Visibility.Visible; - _gitHubReleaseUrl = newerGitHubRelease.Url; + Dispatcher.Invoke(() => + { + UpdateNotificationBorder.Visibility = Visibility.Visible; + _gitHubReleaseUrl = gitHubRelease.Url; + }); } } - catch (Exception ex) + else { - _logger.LogError(ex, "Error getting GitHub release"); + gitHubRelease = await _gitHubReleaseCheckerService + .GetGitHubReleaseToUpdateToAsync("Vivelin", "SMZ3Randomizer", version ?? "", false); + + if (gitHubRelease != null && gitHubRelease.Url != Options.GeneralOptions.IgnoredUpdateUrl) + { + Dispatcher.Invoke(() => + { + UpdateNotificationBorder.Visibility = Visibility.Visible; + _gitHubReleaseUrl = gitHubRelease.Url; + }); + } } } - - var soloPanel = _serviceProvider.GetService(); - if (soloPanel != null) SoloTab.Children.Add(soloPanel); - var multiPanel = _serviceProvider.GetService(); - if (multiPanel != null) MultiTab.Children.Add(multiPanel); + catch (Exception ex) + { + _logger.LogError(ex, "Error getting GitHub release"); + } } private void Window_Closing(object sender, CancelEventArgs e) diff --git a/tests/Randomizer.SMZ3.Tests/MetaTests.cs b/tests/Randomizer.SMZ3.Tests/MetaTests.cs index 259d9f074..25b79addb 100644 --- a/tests/Randomizer.SMZ3.Tests/MetaTests.cs +++ b/tests/Randomizer.SMZ3.Tests/MetaTests.cs @@ -18,7 +18,7 @@ namespace Randomizer.SMZ3.Tests; public class MetaTests { [Fact] - public void ValidateVersionNumber() + public async void ValidateVersionNumber() { // Get csproj file for Randomizer.App var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); @@ -29,7 +29,7 @@ public void ValidateVersionNumber() var projectPath = Path.Combine(directory!.FullName, "src", "Randomizer.App", "Randomizer.App.csproj"); // Get version from csproj file - var version = File.ReadAllLines(projectPath) + var version = (await File.ReadAllLinesAsync(projectPath)) .Where(x => x.Trim().StartsWith("", StringComparison.OrdinalIgnoreCase)) .Select(x => x.Replace("", "", StringComparison.OrdinalIgnoreCase).Replace("", "").Trim()) .First(); @@ -44,7 +44,9 @@ public void ValidateVersionNumber() .BuildServiceProvider(); // Get latest version from GitHub and make sure the current version is newer - var latestRelease = serviceProvider.GetRequiredService().GetReleases("Vivelin", "SMZ3Randomizer")?.FirstOrDefault(); + var releases = await serviceProvider.GetRequiredService() + .GetReleasesAsync("Vivelin", "SMZ3Randomizer"); + var latestRelease = releases?.FirstOrDefault(); latestRelease.Should().NotBeNull(); latestRelease!.Tag.Should().NotBeEquivalentTo($"v{version}"); serviceProvider.GetRequiredService() diff --git a/tests/Randomizer.SMZ3.Tests/Randomizer.SMZ3.Tests.csproj b/tests/Randomizer.SMZ3.Tests/Randomizer.SMZ3.Tests.csproj index 2eac5b960..d6f6b0157 100644 --- a/tests/Randomizer.SMZ3.Tests/Randomizer.SMZ3.Tests.csproj +++ b/tests/Randomizer.SMZ3.Tests/Randomizer.SMZ3.Tests.csproj @@ -7,7 +7,7 @@ - +