From 7d09f18299c3bf7829a2c22e5dd44e1289d6f071 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 22 Aug 2020 02:08:40 -0500 Subject: [PATCH] Added custom deserialization for old features so that they don't totally break the load --- .../JsonConverters/FeaturesFieldConverter.cs | 31 +++++++++++++++++++ IPA.Loader/Loader/PluginManifest.cs | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 IPA.Loader/JsonConverters/FeaturesFieldConverter.cs diff --git a/IPA.Loader/JsonConverters/FeaturesFieldConverter.cs b/IPA.Loader/JsonConverters/FeaturesFieldConverter.cs new file mode 100644 index 00000000..97cccb18 --- /dev/null +++ b/IPA.Loader/JsonConverters/FeaturesFieldConverter.cs @@ -0,0 +1,31 @@ +using IPA.Logging; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IPA.JsonConverters +{ + internal class FeaturesFieldConverter : JsonConverter> + { + public override Dictionary ReadJson(JsonReader reader, Type objectType, Dictionary existingValue, bool hasExistingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.StartArray) + { + _ = serializer.Deserialize(reader); + Logger.features.Warn("Encountered old features used. They no longer do anything, please move to the new format."); + return existingValue; + } + + return serializer.Deserialize>(reader); + } + + public override void WriteJson(JsonWriter writer, Dictionary value, JsonSerializer serializer) + { + serializer.Serialize(writer, value); + } + } +} diff --git a/IPA.Loader/Loader/PluginManifest.cs b/IPA.Loader/Loader/PluginManifest.cs index 405bf488..7361975e 100644 --- a/IPA.Loader/Loader/PluginManifest.cs +++ b/IPA.Loader/Loader/PluginManifest.cs @@ -40,7 +40,7 @@ namespace IPA.Loader [JsonProperty("conflictsWith", Required = Required.DisallowNull, ItemConverterType = typeof(SemverRangeConverter))] public Dictionary Conflicts = new Dictionary(); - [JsonProperty("features", Required = Required.DisallowNull)] + [JsonProperty("features", Required = Required.DisallowNull), JsonConverter(typeof(FeaturesFieldConverter))] public Dictionary Features = new Dictionary(); [JsonProperty("loadBefore", Required = Required.DisallowNull)]