From a21c25b91da01cec0a83afe9772ea6a2ee72b1da Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Fri, 30 Aug 2024 11:48:03 +0200 Subject: [PATCH] migrate to Pilz.AppVersion --- Pilz.Updating.Client/UpdateClient.cs | 4 +- Pilz.Updating/AppVersion.cs | 152 --------------------------- Pilz.Updating/Channels.cs | 9 -- 3 files changed, 2 insertions(+), 163 deletions(-) delete mode 100644 Pilz.Updating/AppVersion.cs delete mode 100644 Pilz.Updating/Channels.cs diff --git a/Pilz.Updating.Client/UpdateClient.cs b/Pilz.Updating.Client/UpdateClient.cs index 097b78e..9caff53 100644 --- a/Pilz.Updating.Client/UpdateClient.cs +++ b/Pilz.Updating.Client/UpdateClient.cs @@ -2,7 +2,7 @@ namespace Pilz.Updating.Client; -public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels minimumChannel) +public class UpdateClient(string updateUrl, AppVersion currentVersion, AppChannel minimumChannel) { // E v e n t s @@ -17,7 +17,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels public HttpClient WebClient { get; private set; } = new(); public string UpdateUrl { get; private set; } = updateUrl; public AppVersion CurrentVersion { get; private set; } = currentVersion; - public Channels MinimumChannel { get; private set; } = (Channels)Math.Max((int)minimumChannel, (int)currentVersion.Channel); + public AppChannel MinimumChannel { get; private set; } = (AppChannel)Math.Max((int)minimumChannel, (int)currentVersion.Channel); public UpdateInfo? UpdateInfo { get; private set; } public UpdatePackageInfo? UpdatePackageInfo { get; private set; } public string? HostApplicationPath { get; set; } diff --git a/Pilz.Updating/AppVersion.cs b/Pilz.Updating/AppVersion.cs deleted file mode 100644 index 6e7abd3..0000000 --- a/Pilz.Updating/AppVersion.cs +++ /dev/null @@ -1,152 +0,0 @@ -using Newtonsoft.Json; - -namespace Pilz.Updating; - -[method: JsonConstructor] -public class AppVersion(Version version, int build, Channels channel) : IComparable, IComparable -{ - // P r o p e r t i e s - - [JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))] - public Version Version { get; set; } = version; - [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] - public Channels Channel { get; set; } = channel; - public int Build { get; set; } = build; - - // C o n s t r u c t o r s - - public AppVersion() : this(new Version("1.0.0.0")) - { - } - - public AppVersion(Version version) : this(version, 1, Channels.Stable) - { - } - - // F e a t u r e s - - public override string ToString() - { - if (Channel == Channels.Stable && Build == 1) - return Version.ToString(); - - return $"{Version} {Channel} {Build}"; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(this, obj)) - return true; - if (obj is not AppVersion applicationVersion) - return false; - return applicationVersion == this; - } - - public override int GetHashCode() - { - return ToString().GetHashCode(); - } - - public static bool TryParse(string input, out AppVersion version) - { - try - { - version = Parse(input); - } - catch (Exception) - { - version = null; - } - return version != null; - } - - public static AppVersion Parse(string input) - { - if (string.IsNullOrWhiteSpace(input)) - throw new FormatException(); - - if (input.StartsWith("version", StringComparison.InvariantCultureIgnoreCase)) - input = input[7..]; - - var splitted = input.Trim().Split(' '); - - if (splitted.Length < 1 || !Version.TryParse(splitted[0], out Version? version) || version == null) - throw new FormatException(); - - if (splitted.Length < 2 || !Enum.TryParse(splitted[1], out Channels channel)) - channel = Channels.Stable; - - if (splitted.Length < 3 || !int.TryParse(splitted[2], out int build)) - build = 1; - - return new AppVersion(version, build, channel); - } - - // C o m p a r e - - public int CompareTo(object appVersion) - { - return CompareTo(appVersion as AppVersion); - } - - public int CompareTo(AppVersion appVersion) - { - if (appVersion is null) - return 1; - - if (Version != appVersion.Version) - { - if (Version > appVersion.Version) - return 1; - return -1; - } - - if (Channel != appVersion.Channel) - { - if (Channel < appVersion.Channel) - return 1; - return -1; - } - - if (Build != appVersion.Build) - { - if (Build > appVersion.Build) - return 1; - return -1; - } - - return 0; - } - - // O p e r a t o r s - - public static bool operator >(AppVersion a, AppVersion b) - { - return a.Version > b.Version || a.Version == b.Version && (a.Channel < b.Channel || (a.Channel == b.Channel && a.Build > b.Build)); - } - - public static bool operator <(AppVersion a, AppVersion b) - { - return a.Version < b.Version || a.Version == b.Version && (a.Channel > b.Channel || (a.Channel == b.Channel && a.Build < b.Build)); - } - - public static bool operator ==(AppVersion a, AppVersion b) - { - return a.Version == b.Version && a.Channel == b.Channel && a.Build == b.Build; - } - - public static bool operator !=(AppVersion a, AppVersion b) - { - return a.Version != b.Version || a.Channel != b.Channel || a.Build != b.Build; - } - - public static bool operator >=(AppVersion a, AppVersion b) - { - return a == b || a > b; - } - - public static bool operator <=(AppVersion a, AppVersion b) - { - return a == b || a < b; - } -} \ No newline at end of file diff --git a/Pilz.Updating/Channels.cs b/Pilz.Updating/Channels.cs deleted file mode 100644 index ba9cc17..0000000 --- a/Pilz.Updating/Channels.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Pilz.Updating; - -public enum Channels -{ - Stable, - PreRelease, - Beta, - Alpha -} \ No newline at end of file