Skip to content

Commit 8ef4e51

Browse files
committed
fix(auto-update): parsing of version with beta
Be sure to use proper semantic versioning lib
1 parent 8a4c670 commit 8ef4e51

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

SoundSwitch/Framework/Updater/Releases/AppRelease.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
/********************************************************************
2-
* Copyright (C) 2015-2017 Antoine Aflalo
3-
*
4-
* This program is free software; you can redistribute it and/or
5-
* modify it under the terms of the GNU General Public License
6-
* as published by the Free Software Foundation; either version 2
7-
* of the License, or (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
********************************************************************/
2+
* Copyright (C) 2015-2017 Antoine Aflalo
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
********************************************************************/
1414

15-
using System;
1615
using System.Collections.Generic;
16+
using NuGet.Versioning;
1717
using SoundSwitch.Framework.Updater.Releases.Models;
1818

1919
namespace SoundSwitch.Framework.Updater.Releases
2020
{
2121
public class AppRelease
2222
{
23-
public AppRelease(Version releaseVersion, Asset asset, string name)
23+
public AppRelease(SemanticVersion releaseVersion, Asset asset, string name)
2424
{
2525
ReleaseVersion = releaseVersion;
2626
Asset = asset;
2727
Name = name;
2828
}
2929

30-
public Version ReleaseVersion { get; private set; }
30+
public SemanticVersion ReleaseVersion { get; private set; }
3131
public Asset Asset { get; }
3232
public List<string> Changelog { get; } = new List<string>();
3333
public string Name { get; private set; }
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
2+
using NuGet.Versioning;
23

34
namespace SoundSwitch.Framework.Updater.Remind
45
{
5-
public record ReleasePostponed(Version Version, DateTime Until, uint Count);
6+
public record ReleasePostponed(SemanticVersion Version, DateTime Until, uint Count);
67
}

SoundSwitch/Framework/Updater/UpdateChecker.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Threading;
2222
using System.Threading.Tasks;
2323
using System.Windows.Forms;
24+
using NuGet.Versioning;
2425
using Sentry;
2526
using Serilog;
2627
using SoundSwitch.Framework.Updater.Releases;
@@ -33,7 +34,7 @@ public class UpdateChecker
3334
private static readonly string UserAgent =
3435
$"Mozilla/5.0 (compatible; {Environment.OSVersion.Platform} {Environment.OSVersion.VersionString}; {Application.ProductName}/{Application.ProductVersion};)";
3536

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

3839
private readonly Uri _releaseUrl;
3940
public EventHandler<NewReleaseEvent> UpdateAvailable;
@@ -58,7 +59,7 @@ private bool ProcessAndNotifyRelease(Release serverRelease)
5859
return false;
5960
}
6061

61-
var version = new Version(serverRelease.TagName.Substring(1).Split("-")[0]);
62+
var version = SemanticVersion.Parse(serverRelease.TagName.Substring(1));
6263
try
6364
{
6465
if (version > AppVersion)
@@ -95,7 +96,7 @@ public async Task CheckForUpdate(CancellationToken token)
9596
httpClient.DefaultRequestHeaders.UserAgent.Add(ApplicationInfo.CommentValue);
9697
httpClient.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
9798
var releases = await httpClient.GetFromJsonAsync(_releaseUrl, GithubReleasesJsonContext.Default.ReleaseArray, token);
98-
foreach (var release in (releases ?? Array.Empty<Release>()).OrderByDescending(release => new Version(release.TagName.Substring(1))))
99+
foreach (var release in (releases ?? Array.Empty<Release>()).OrderByDescending(release => SemanticVersion.Parse(release.TagName.Substring(1))))
99100
{
100101
token.ThrowIfCancellationRequested();
101102
if (ProcessAndNotifyRelease(release))

SoundSwitch/SoundSwitch.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<PackageReference Include="Job.Scheduler" Version="3.1.8" />
5050
<PackageReference Include="Markdig" Version="0.36.2" />
5151
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
52+
<PackageReference Include="NuGet.Versioning" Version="6.9.1" />
5253
<PackageReference Include="RailSharp" Version="1.0.0" />
5354
<PackageReference Include="Sentry.Serilog" Version="4.2.1" />
5455
<PackageReference Include="Serilog" Version="3.1.1" />

0 commit comments

Comments
 (0)