small code refactoring
This commit is contained in:
@@ -1,73 +1,72 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Pilz.Updating
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public class ApplicationVersion
|
||||
{
|
||||
public class ApplicationVersion
|
||||
|
||||
// P r o p e r t i e s
|
||||
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
||||
public Version Version { get; set; }
|
||||
public int Build { get; set; }
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public Channels Channel { get; set; }
|
||||
|
||||
// C o n s t r u c t o r s
|
||||
|
||||
public ApplicationVersion() : this(new Version("1.0.0.0"))
|
||||
{
|
||||
}
|
||||
|
||||
// P r o p e r t i e s
|
||||
public ApplicationVersion(Version version) : this(version, 1, Channels.Stable)
|
||||
{
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
||||
public Version Version { get; set; }
|
||||
public int Build { get; set; }
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public Channels Channel { get; set; }
|
||||
public ApplicationVersion(Version version, int build, Channels channel)
|
||||
{
|
||||
Version = version;
|
||||
Build = build;
|
||||
Channel = channel;
|
||||
}
|
||||
|
||||
// C o n s t r u c t o r s
|
||||
// F e a t u r e s
|
||||
|
||||
public ApplicationVersion() : this(new Version("1.0.0.0"))
|
||||
{
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Version.ToString()} {Channel.ToString()} {Build}";
|
||||
}
|
||||
|
||||
public ApplicationVersion(Version version) : this(version, 1, Channels.Stable)
|
||||
{
|
||||
}
|
||||
// O p e r a t o r s
|
||||
|
||||
public ApplicationVersion(Version version, int build, Channels channel)
|
||||
{
|
||||
Version = version;
|
||||
Build = build;
|
||||
Channel = channel;
|
||||
}
|
||||
public static bool operator >(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a.Version > b.Version || a.Version == b.Version && (a.Channel < b.Channel || (a.Channel == b.Channel && a.Build > b.Build));
|
||||
}
|
||||
|
||||
// F e a t u r e s
|
||||
public static bool operator <(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a.Version < b.Version || a.Version == b.Version && (a.Channel > b.Channel || (a.Channel == b.Channel && a.Build < b.Build));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Version.ToString()} {Channel.ToString()} {Build}";
|
||||
}
|
||||
public static bool operator ==(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a.Version == b.Version && a.Channel == b.Channel && a.Build == b.Build;
|
||||
}
|
||||
|
||||
// O p e r a t o r s
|
||||
public static bool operator !=(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a.Version != b.Version || a.Channel != b.Channel || a.Build != b.Build;
|
||||
}
|
||||
|
||||
public static bool operator >(ApplicationVersion a, ApplicationVersion 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 >=(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a == b || a > b;
|
||||
}
|
||||
|
||||
public static bool operator <(ApplicationVersion a, ApplicationVersion 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 ==(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a.Version == b.Version && a.Channel == b.Channel && a.Build == b.Build;
|
||||
}
|
||||
|
||||
public static bool operator !=(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a.Version != b.Version || a.Channel != b.Channel || a.Build != b.Build;
|
||||
}
|
||||
|
||||
public static bool operator >=(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a == b || a > b;
|
||||
}
|
||||
|
||||
public static bool operator <=(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a == b || a < b;
|
||||
}
|
||||
public static bool operator <=(ApplicationVersion a, ApplicationVersion b)
|
||||
{
|
||||
return a == b || a < b;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
namespace Pilz.Updating
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public enum Channels
|
||||
{
|
||||
public enum Channels
|
||||
{
|
||||
Stable,
|
||||
PreRelease,
|
||||
Beta,
|
||||
Alpha
|
||||
}
|
||||
Stable,
|
||||
PreRelease,
|
||||
Beta,
|
||||
Alpha
|
||||
}
|
||||
@@ -1,24 +1,23 @@
|
||||
using System;
|
||||
using global::System.IO;
|
||||
using global::System.IO;
|
||||
using System;
|
||||
|
||||
namespace Pilz.Updating
|
||||
namespace Pilz.Updating;
|
||||
|
||||
internal static class MyPaths
|
||||
{
|
||||
internal static class MyPaths
|
||||
private static string p = string.Empty;
|
||||
|
||||
public static string GetMyAppDataPath()
|
||||
{
|
||||
private static string p = string.Empty;
|
||||
|
||||
public static string GetMyAppDataPath()
|
||||
if (string.IsNullOrEmpty(p))
|
||||
{
|
||||
if (string.IsNullOrEmpty(p))
|
||||
p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PilzUpdater");
|
||||
if (!Directory.Exists(p))
|
||||
{
|
||||
p = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PilzUpdater");
|
||||
if (!Directory.Exists(p))
|
||||
{
|
||||
Directory.CreateDirectory(p);
|
||||
}
|
||||
Directory.CreateDirectory(p);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Pilz.Updating</RootNamespace>
|
||||
<TargetFrameworks>net6.0-windows;net8.0-windows</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0-windows</TargetFrameworks>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<AssemblyTitle>Pilz.Updating</AssemblyTitle>
|
||||
@@ -11,7 +11,6 @@
|
||||
<DocumentationFile>Pilz.Updating.xml</DocumentationFile>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,CS1591,CS0660,CS0661</NoWarn>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DefineDebug>true</DefineDebug>
|
||||
@@ -37,7 +36,6 @@
|
||||
<DefineConstants>TRACE;RelMono</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>2.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using global::System;
|
||||
using global::System.Reflection;
|
||||
using global::System.Runtime.CompilerServices;
|
||||
using global::System.Runtime.InteropServices;
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Pilz.Updating
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public class UpdateInfo
|
||||
{
|
||||
public class UpdateInfo
|
||||
public string UpdateInstallerLink { get; set; }
|
||||
public List<UpdatePackageInfo> Packages { get; set; } = [];
|
||||
|
||||
public static UpdateInfo Parse(string str)
|
||||
{
|
||||
public string UpdateInstallerLink { get; set; }
|
||||
public List<UpdatePackageInfo> Packages { get; set; } = new List<UpdatePackageInfo>();
|
||||
return JObject.Parse(str).ToObject<UpdateInfo>();
|
||||
}
|
||||
|
||||
public static UpdateInfo Parse(string str)
|
||||
{
|
||||
return JObject.Parse(str).ToObject<UpdateInfo>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JObject.FromObject(this).ToString();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return JObject.FromObject(this).ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,29 @@
|
||||
using System;
|
||||
using global::System.Drawing;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace Pilz.Updating.UpdateInstaller
|
||||
namespace Pilz.Updating.UpdateInstaller;
|
||||
|
||||
public class UpdateInstallerConfig
|
||||
{
|
||||
public class UpdateInstallerConfig
|
||||
public string PackagePath { get; set; }
|
||||
public bool RestartHostApplication { get; set; }
|
||||
public string RestartHostApplicationArguments { get; set; }
|
||||
public string ApplicationName { get; set; }
|
||||
public string HostApplicationPath { get; set; }
|
||||
public string HostApplicationProcessPath { get; set; }
|
||||
public bool ForceClosingHostApplication { get; set; }
|
||||
public uint MillisecondsToWaitForHostApplicationToClose { get; set; }
|
||||
public bool UIDarkMode { get; set; }
|
||||
public ApplicationVersion CurrentApplicationVersion { get; set; }
|
||||
public ApplicationVersion NewApplicationVersion { get; set; }
|
||||
|
||||
public static UpdateInstallerConfig Parse(string str)
|
||||
{
|
||||
public string PackagePath { get; set; }
|
||||
public bool RestartHostApplication { get; set; }
|
||||
public string RestartHostApplicationArguments { get; set; }
|
||||
public string ApplicationName { get; set; }
|
||||
public string HostApplicationPath { get; set; }
|
||||
public string HostApplicationProcessPath { get; set; }
|
||||
public bool ForceClosingHostApplication { get; set; }
|
||||
public uint MillisecondsToWaitForHostApplicationToClose { get; set; }
|
||||
public bool UIDarkMode { get; set; }
|
||||
public ApplicationVersion CurrentApplicationVersion { get; set; }
|
||||
public ApplicationVersion NewApplicationVersion { get; set; }
|
||||
return JObject.Parse(System.Text.Encoding.Default.GetString(Convert.FromBase64String(str))).ToObject<UpdateInstallerConfig>();
|
||||
}
|
||||
|
||||
public static UpdateInstallerConfig Parse(string str)
|
||||
{
|
||||
return JObject.Parse(System.Text.Encoding.Default.GetString(Convert.FromBase64String(str))).ToObject<UpdateInstallerConfig>();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(JObject.FromObject(this).ToString()));
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(JObject.FromObject(this).ToString()));
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,10 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Updating
|
||||
namespace Pilz.Updating;
|
||||
|
||||
public class UpdateNotes
|
||||
{
|
||||
public class UpdateNotes
|
||||
{
|
||||
public string Content { get; set; }
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public UpdateNotesContentType ContentType { get; set; } = UpdateNotesContentType.PlainText;
|
||||
}
|
||||
public string Content { get; set; }
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public UpdateNotesContentType ContentType { get; set; } = UpdateNotesContentType.PlainText;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Updating;
|
||||
|
||||
namespace Pilz.Updating
|
||||
public enum UpdateNotesContentType
|
||||
{
|
||||
public enum UpdateNotesContentType
|
||||
{
|
||||
PlainText,
|
||||
Markdown,
|
||||
HTML
|
||||
}
|
||||
PlainText,
|
||||
Markdown,
|
||||
HTML
|
||||
}
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Pilz.Updating
|
||||
{
|
||||
public class UpdatePackageInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public ApplicationVersion Version { get; set; }
|
||||
public UpdateNotes Notes { get; } = new UpdateNotes();
|
||||
public string Packagelink { get; set; }
|
||||
namespace Pilz.Updating;
|
||||
|
||||
[JsonProperty]
|
||||
private string Changelog
|
||||
public class UpdatePackageInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public ApplicationVersion Version { get; set; }
|
||||
public UpdateNotes Notes { get; } = new UpdateNotes();
|
||||
public string Packagelink { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
private string Changelog
|
||||
{
|
||||
set
|
||||
{
|
||||
set
|
||||
{
|
||||
Notes.Content = value;
|
||||
Notes.ContentType = UpdateNotesContentType.PlainText;
|
||||
}
|
||||
Notes.Content = value;
|
||||
Notes.ContentType = UpdateNotesContentType.PlainText;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user