The bot now checks for update
This commit is contained in:
87
PluginManager/Interfaces/Updater/AppVersion.cs
Normal file
87
PluginManager/Interfaces/Updater/AppVersion.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginManager.Interfaces.Updater
|
||||
{
|
||||
public class AppVersion : IVersion
|
||||
{
|
||||
public int Major { get; set; }
|
||||
|
||||
public int Minor { get; set; }
|
||||
|
||||
public int Patch { get; set; }
|
||||
|
||||
public int PatchVersion { get; set; }
|
||||
|
||||
public static readonly AppVersion CurrentAppVersion = new AppVersion(Config.AppSettings["Version"]);
|
||||
|
||||
private readonly char _Separator = '.';
|
||||
|
||||
public AppVersion(string versionAsString)
|
||||
{
|
||||
string[] versionParts = versionAsString.Split(_Separator);
|
||||
|
||||
if (versionParts.Length != 4)
|
||||
{
|
||||
throw new ArgumentException("Invalid version string");
|
||||
}
|
||||
|
||||
Major = int.Parse(versionParts[0]);
|
||||
Minor = int.Parse(versionParts[1]);
|
||||
Patch = int.Parse(versionParts[2]);
|
||||
PatchVersion = int.Parse(versionParts[3]);
|
||||
}
|
||||
|
||||
public bool IsNewerThan(IVersion version)
|
||||
{
|
||||
if (Major > version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor > version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch > version.Patch)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion > version.PatchVersion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOlderThan(IVersion version)
|
||||
{
|
||||
if (Major < version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor < version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch < version.Patch)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion < version.PatchVersion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsEqualTo(IVersion version)
|
||||
{
|
||||
return Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion == version.PatchVersion;
|
||||
}
|
||||
|
||||
public string ToShortString()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Patch}.{PatchVersion}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToShortString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ public interface IVersion
|
||||
public int Major { get; }
|
||||
public int Minor { get; }
|
||||
public int Patch { get; }
|
||||
public int PatchVersion => 0;
|
||||
|
||||
public bool IsNewerThan(IVersion version);
|
||||
|
||||
|
||||
@@ -68,4 +68,9 @@ public abstract class Version: IVersion
|
||||
{
|
||||
return $"{Major}.{Minor}.{Patch}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToShortString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user