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:
parent
f0a4a9a267
commit
4272d62001
@ -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
|
||||
|
||||
26
src/Artemis.Core/JsonConverters/ForgivingVersionConverter.cs
Normal file
26
src/Artemis.Core/JsonConverters/ForgivingVersionConverter.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user