Skip to content

Commit

Permalink
fix(auto-update): parsing of version with beta
Browse files Browse the repository at this point in the history
Be sure to use proper semantic versioning lib
  • Loading branch information
Belphemur committed Apr 3, 2024
1 parent 8a4c670 commit 8ef4e51
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
30 changes: 15 additions & 15 deletions SoundSwitch/Framework/Updater/Releases/AppRelease.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/********************************************************************
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/
* Copyright (C) 2015-2017 Antoine Aflalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
********************************************************************/

using System;
using System.Collections.Generic;
using NuGet.Versioning;
using SoundSwitch.Framework.Updater.Releases.Models;

namespace SoundSwitch.Framework.Updater.Releases
{
public class AppRelease
{
public AppRelease(Version releaseVersion, Asset asset, string name)
public AppRelease(SemanticVersion releaseVersion, Asset asset, string name)
{
ReleaseVersion = releaseVersion;
Asset = asset;
Name = name;
}

public Version ReleaseVersion { get; private set; }
public SemanticVersion ReleaseVersion { get; private set; }
public Asset Asset { get; }
public List<string> Changelog { get; } = new List<string>();
public string Name { get; private set; }
Expand Down
3 changes: 2 additions & 1 deletion SoundSwitch/Framework/Updater/Remind/ReleasePostponed.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using NuGet.Versioning;

namespace SoundSwitch.Framework.Updater.Remind
{
public record ReleasePostponed(Version Version, DateTime Until, uint Count);
public record ReleasePostponed(SemanticVersion Version, DateTime Until, uint Count);
}
7 changes: 4 additions & 3 deletions SoundSwitch/Framework/Updater/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using NuGet.Versioning;
using Sentry;
using Serilog;
using SoundSwitch.Framework.Updater.Releases;
Expand All @@ -33,7 +34,7 @@ public class UpdateChecker
private static readonly string UserAgent =
$"Mozilla/5.0 (compatible; {Environment.OSVersion.Platform} {Environment.OSVersion.VersionString}; {Application.ProductName}/{Application.ProductVersion};)";

private static readonly Version AppVersion = new Version(Application.ProductVersion.Split("-")[0]);
private static readonly SemanticVersion AppVersion = SemanticVersion.Parse(Application.ProductVersion);

private readonly Uri _releaseUrl;
public EventHandler<NewReleaseEvent> UpdateAvailable;
Expand All @@ -58,7 +59,7 @@ private bool ProcessAndNotifyRelease(Release serverRelease)
return false;
}

var version = new Version(serverRelease.TagName.Substring(1).Split("-")[0]);
var version = SemanticVersion.Parse(serverRelease.TagName.Substring(1));
try
{
if (version > AppVersion)
Expand Down Expand Up @@ -95,7 +96,7 @@ public async Task CheckForUpdate(CancellationToken token)
httpClient.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.CommentValue);
httpClient.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
var releases = await httpClient.GetFromJsonAsync(_releaseUrl, GithubReleasesJsonContext.Default.ReleaseArray, token);
foreach (var release in (releases ?? Array.Empty<Release>()).OrderByDescending(release => new Version(release.TagName.Substring(1))))
foreach (var release in (releases ?? Array.Empty<Release>()).OrderByDescending(release => SemanticVersion.Parse(release.TagName.Substring(1))))
{
token.ThrowIfCancellationRequested();
if (ProcessAndNotifyRelease(release))
Expand Down
1 change: 1 addition & 0 deletions SoundSwitch/SoundSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<PackageReference Include="Job.Scheduler" Version="3.1.8" />
<PackageReference Include="Markdig" Version="0.36.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="NuGet.Versioning" Version="6.9.1" />
<PackageReference Include="RailSharp" Version="1.0.0" />
<PackageReference Include="Sentry.Serilog" Version="4.2.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
Expand Down

0 comments on commit 8ef4e51

Please sign in to comment.