Skip to content

Commit

Permalink
Merge pull request #449 from Vivelin/new-repo-release-check
Browse files Browse the repository at this point in the history
Check release against new repo location
  • Loading branch information
MattEqualsCoder authored Dec 22, 2023
2 parents 3fe8d0b + c6ffdbc commit 001bae3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Randomizer.App/Randomizer.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net7.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>chozo20.ico</ApplicationIcon>
<Version>9.6.1.1</Version>
<Version>9.6.1</Version>
<Title>SMZ3 Cas' Randomizer</Title>
<AssemblyTitle>SMZ3 Cas' Randomizer</AssemblyTitle>
<Authors>Vivelin</Authors>
Expand Down Expand Up @@ -60,7 +60,7 @@
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="FluentIcons.WPF" Version="1.1.221" />
<PackageReference Include="Material.Icons.WPF" Version="2.0.0" />
<PackageReference Include="MattEqualsCoder.GitHubReleaseChecker" Version="1.0.0" />
<PackageReference Include="MattEqualsCoder.GitHubReleaseChecker" Version="1.1.2" />
<PackageReference Include="MattEqualsCoder.MSURandomizer.UI" Version="1.2.2" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
Expand Down
57 changes: 41 additions & 16 deletions src/Randomizer.App/Windows/RomListWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,31 +70,55 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
}
}

if (Options.GeneralOptions.CheckForUpdatesOnStartup)
var soloPanel = _serviceProvider.GetService<SoloRomListPanel>();
if (soloPanel != null) SoloTab.Children.Add(soloPanel);
var multiPanel = _serviceProvider.GetService<MultiRomListPanel>();
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<SoloRomListPanel>();
if (soloPanel != null) SoloTab.Children.Add(soloPanel);
var multiPanel = _serviceProvider.GetService<MultiRomListPanel>();
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)
Expand Down
8 changes: 5 additions & 3 deletions tests/Randomizer.SMZ3.Tests/MetaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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("<Version>", StringComparison.OrdinalIgnoreCase))
.Select(x => x.Replace("<Version>", "", StringComparison.OrdinalIgnoreCase).Replace("</Version>", "").Trim())
.First();
Expand All @@ -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<IGitHubReleaseService>().GetReleases("Vivelin", "SMZ3Randomizer")?.FirstOrDefault();
var releases = await serviceProvider.GetRequiredService<IGitHubReleaseService>()
.GetReleasesAsync("Vivelin", "SMZ3Randomizer");
var latestRelease = releases?.FirstOrDefault();
latestRelease.Should().NotBeNull();
latestRelease!.Tag.Should().NotBeEquivalentTo($"v{version}");
serviceProvider.GetRequiredService<IGitHubReleaseCheckerService>()
Expand Down
2 changes: 1 addition & 1 deletion tests/Randomizer.SMZ3.Tests/Randomizer.SMZ3.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="MattEqualsCoder.GitHubReleaseChecker" Version="1.0.0" />
<PackageReference Include="MattEqualsCoder.GitHubReleaseChecker" Version="1.1.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
Expand Down

0 comments on commit 001bae3

Please sign in to comment.