migrate to Pilz.AppVersion
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Pilz.Updating;
|
||||
|
||||
[method: JsonConstructor]
|
||||
public class AppVersion(Version version, int build, Channels channel) : IComparable, IComparable<AppVersion>
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public enum Channels
|
||||
{
|
||||
Stable,
|
||||
PreRelease,
|
||||
Beta,
|
||||
Alpha
|
||||
}
|
||||
Reference in New Issue
Block a user