Skip to content

Commit

Permalink
Merge pull request #618 from NetSparkleUpdater/feature/more-os-compat
Browse files Browse the repository at this point in the history
Make AppCastItem compat with more OS strings
  • Loading branch information
Deadpikle authored Sep 14, 2024
2 parents 988f080 + 4bf71f8 commit d0a54ae
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
* WinForms projects are now in the same project/run the same overall code.
* `NetSparkle.UI.WinForms.NetFramework` now includes `System.Resources.Extensions`
* Fixed WPF and Avalonia download progress windows not turning red on signature validation failure
* `AppCastItem` operating system checks now use `.Contains` rather than `==`, allowing for OS strings like `macOS-arm64` rather than just `macOS`

## Updating from 0.X or 1.X to 2.X

Expand Down
48 changes: 48 additions & 0 deletions src/NetSparkle.Tests/AppCastItemTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using NetSparkleUpdater;
using NetSparkleUpdater.AppCastHandlers;
using NetSparkleUpdater.Enums;
using NetSparkleUpdater.SignatureVerifiers;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Xunit;

namespace NetSparkleUnitTests
{
public class AppCastItemTests
{
[Theory]
[InlineData(null, true, false, false)]
[InlineData("win", true, false, false)]
[InlineData("windows", true, false, false)]
[InlineData("WINDOWS", true, false, false)]
[InlineData("WIndOWS", true, false, false)]
[InlineData("win-x64", true, false, false)]
[InlineData("win-arm", true, false, false)]
[InlineData("windows-arm", true, false, false)]
[InlineData("windows-x86", true, false, false)]
[InlineData("mac", false, true, false)]
[InlineData("macos", false, true, false)]
[InlineData("osx", false, true, false)]
[InlineData("mac-x86", false, true, false)]
[InlineData("macOS-x86", false, true, false)]
[InlineData("macos-arm", false, true, false)]
[InlineData("macos-x64", false, true, false)]
[InlineData("osx-x86", false, true, false)]
[InlineData("osx-arm", false, true, false)]
[InlineData("osx-x64", false, true, false)]
[InlineData("linux", false, false, true)]
[InlineData("linux-x64", false, false, true)]
[InlineData("linux-arm64", false, false, true)]
[InlineData("linux-arm", false, false, true)]
public void CanCheckOSProperly(string osString, bool isWindowsUpdate, bool isMacUpdate, bool isLinuxUpdate)
{
var item = new AppCastItem() { OperatingSystem = osString };
Assert.Equal(item.IsWindowsUpdate, isWindowsUpdate);
Assert.Equal(item.IsMacOSUpdate, isMacUpdate);
Assert.Equal(item.IsLinuxUpdate, isLinuxUpdate);
}
}
}
19 changes: 10 additions & 9 deletions src/NetSparkle/AppCastItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public SemVerLike SemVerLikeVersion

/// <summary>
/// True if this update is a windows update; false otherwise.
/// Acceptable OS strings are: "win" or "windows" (this is
/// Acceptable OS strings contain "win" or "windows" (this is
/// checked with a case-insensitive check). If not specified,
/// assumed to be a Windows update.
/// the OS assumed to be a Windows update.
/// </summary>
[JsonIgnore]
public bool IsWindowsUpdate
Expand All @@ -143,7 +143,7 @@ public bool IsWindowsUpdate
if (OperatingSystem != null)
{
var lowercasedOS = OperatingSystem.ToLower();
if (lowercasedOS == "win" || lowercasedOS == "windows")
if (lowercasedOS.Contains("win") || lowercasedOS.Contains("windows"))
{
return true;
}
Expand All @@ -155,9 +155,9 @@ public bool IsWindowsUpdate

/// <summary>
/// True if this update is a macOS update; false otherwise.
/// Acceptable OS strings are: "mac", "osx", or "macos" (this is
/// Acceptable OS strings contain "mac", "osx", or "macos" (this is
/// checked with a case-insensitive check). If not specified,
/// assumed to be a Windows update.
/// the OS is assumed to be a Windows update.
/// </summary>
[JsonIgnore]
public bool IsMacOSUpdate
Expand All @@ -167,7 +167,8 @@ public bool IsMacOSUpdate
if (OperatingSystem != null)
{
var lowercasedOS = OperatingSystem.ToLower();
if (lowercasedOS == "mac" || lowercasedOS == "macos" || lowercasedOS == "osx")
if (lowercasedOS.Contains("mac") || lowercasedOS.Contains("macos") ||
lowercasedOS.Contains("osx"))
{
return true;
}
Expand All @@ -178,9 +179,9 @@ public bool IsMacOSUpdate

/// <summary>
/// True if this update is a macOS update; false otherwise.
/// Acceptable OS strings are: "linux" (this is
/// Acceptable OS strings contain "linux" (this is
/// checked with a case-insensitive check). If not specified,
/// assumed to be a Linux update.
/// the OS is assumed to be a Windows update.
/// </summary>
[JsonIgnore]
public bool IsLinuxUpdate
Expand All @@ -190,7 +191,7 @@ public bool IsLinuxUpdate
if (OperatingSystem != null)
{
var lowercasedOS = OperatingSystem.ToLower();
if (lowercasedOS == "linux")
if (lowercasedOS.Contains("linux"))
{
return true;
}
Expand Down

0 comments on commit d0a54ae

Please sign in to comment.