diff --git a/src/Artemis.Core/Constants.cs b/src/Artemis.Core/Constants.cs index f2abc9aa3..e745c8cc3 100644 --- a/src/Artemis.Core/Constants.cs +++ b/src/Artemis.Core/Constants.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -61,7 +61,7 @@ public static class Constants /// /// The current API version for plugins /// - public static readonly Version PluginApi = new(1, 0); + public static readonly Version PluginApi = CoreAssembly.GetName().Version!; /// /// The plugin info used by core components of Artemis diff --git a/src/Artemis.Core/JsonConverters/ForgivingVersionConverter.cs b/src/Artemis.Core/JsonConverters/ForgivingVersionConverter.cs new file mode 100644 index 000000000..8cfe43151 --- /dev/null +++ b/src/Artemis.Core/JsonConverters/ForgivingVersionConverter.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; + +namespace Artemis.Core.JsonConverters +{ + /// + /// Version converter that is forgiving of missing parts of the version string, + /// setting them to zero instead of -1. + /// + internal class ForgivingVersionConverter : VersionConverter + { + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + object obj = base.ReadJson(reader, objectType, existingValue, serializer); + if (obj is not Version v) + return obj; + + int major = v.Major == -1 ? 0 : v.Major; + int minor = v.Minor == -1 ? 0 : v.Minor; + int build = v.Build == -1 ? 0 : v.Build; + int revision = v.Revision == -1 ? 0 : v.Revision; + return new Version(major, minor, build, revision); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/PluginInfo.cs b/src/Artemis.Core/Plugins/PluginInfo.cs index 7e3957b56..bcc988891 100644 --- a/src/Artemis.Core/Plugins/PluginInfo.cs +++ b/src/Artemis.Core/Plugins/PluginInfo.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using Artemis.Core.JsonConverters; using Newtonsoft.Json; namespace Artemis.Core; @@ -158,6 +159,7 @@ public class PluginInfo : CorePropertyChanged, IPrerequisitesSubject /// Gets the API version the plugin was built for /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + [JsonConverter(typeof(ForgivingVersionConverter))] public Version? Api { get => _api;