Browse Source

Added custom deserialization for old features so that they don't totally break the load

pull/53/head
Anairkoen Schno 3 years ago
parent
commit
7d09f18299
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
2 changed files with 32 additions and 1 deletions
  1. +31
    -0
      IPA.Loader/JsonConverters/FeaturesFieldConverter.cs
  2. +1
    -1
      IPA.Loader/Loader/PluginManifest.cs

+ 31
- 0
IPA.Loader/JsonConverters/FeaturesFieldConverter.cs View File

@ -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<Dictionary<string, JObject>>
{
public override Dictionary<string, JObject> ReadJson(JsonReader reader, Type objectType, Dictionary<string, JObject> existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.StartArray)
{
_ = serializer.Deserialize<string[]>(reader);
Logger.features.Warn("Encountered old features used. They no longer do anything, please move to the new format.");
return existingValue;
}
return serializer.Deserialize<Dictionary<string, JObject>>(reader);
}
public override void WriteJson(JsonWriter writer, Dictionary<string, JObject> value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
}

+ 1
- 1
IPA.Loader/Loader/PluginManifest.cs View File

@ -40,7 +40,7 @@ namespace IPA.Loader
[JsonProperty("conflictsWith", Required = Required.DisallowNull, ItemConverterType = typeof(SemverRangeConverter))]
public Dictionary<string, Range> Conflicts = new Dictionary<string, Range>();
[JsonProperty("features", Required = Required.DisallowNull)]
[JsonProperty("features", Required = Required.DisallowNull), JsonConverter(typeof(FeaturesFieldConverter))]
public Dictionary<string, JObject> Features = new Dictionary<string, JObject>();
[JsonProperty("loadBefore", Required = Required.DisallowNull)]


Loading…
Cancel
Save