1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Core - Moved PluginApi version to the csproj

This commit is contained in:
Diogo Trindade 2022-09-29 21:16:52 +01:00 committed by RobertBeekman
parent f0a4a9a267
commit 4272d62001
3 changed files with 30 additions and 2 deletions

View File

@ -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
/// <summary>
/// The current API version for plugins
/// </summary>
public static readonly Version PluginApi = new(1, 0);
public static readonly Version PluginApi = CoreAssembly.GetName().Version!;
/// <summary>
/// The plugin info used by core components of Artemis

View File

@ -0,0 +1,26 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
namespace Artemis.Core.JsonConverters
{
/// <summary>
/// Version converter that is forgiving of missing parts of the version string,
/// setting them to zero instead of -1.
/// </summary>
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);
}
}
}

View File

@ -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
/// </summary>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
[JsonConverter(typeof(ForgivingVersionConverter))]
public Version? Api
{
get => _api;