From b1e6b2cdb2c2e115ce172d482ed364c330ce5dc3 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 10 Apr 2019 00:22:25 -0500 Subject: [PATCH] Actually fixed no-update Now properly parses the dumb deep dependencies of BeatMods --- IPA.Loader/Updating/BeatMods/ApiEndpoint.cs | 23 +++++++++- IPA.Loader/Updating/BeatMods/Updater.cs | 49 ++++++++++++++------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs b/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs index d61c2f77..09dc0d2e 100644 --- a/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs +++ b/IPA.Loader/Updating/BeatMods/ApiEndpoint.cs @@ -4,6 +4,7 @@ using System.Linq; using IPA.JsonConverters; using IPA.Utilities; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using SemVer; using Version = SemVer.Version; @@ -60,6 +61,23 @@ namespace IPA.Updating.BeatMods } } } + class ModMultiformatJsonConverter : JsonConverter + { + public override Mod ReadJson(JsonReader reader, Type objectType, Mod existingValue, bool hasExistingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.String) + return new Mod { Id = reader.Value as string, IsIdReference = true }; + else + { + if (reader.TokenType != JsonToken.StartObject) + return null; + + return serializer.Deserialize(reader); + } + } + + public override void WriteJson(JsonWriter writer, Mod value, JsonSerializer serializer) => serializer.Serialize(writer, value); + } [Serializable] public class Mod @@ -71,6 +89,9 @@ namespace IPA.Updating.BeatMods [JsonProperty("_id")] public string Id; + [JsonIgnore] + public bool IsIdReference = false; + [JsonProperty("required")] public bool Required; @@ -210,7 +231,7 @@ namespace IPA.Updating.BeatMods [JsonProperty("oldVersions", ItemConverterType = typeof(SemverVersionConverter))] public Version[] OldVersions = new Version[0];*/ - [JsonProperty("dependencies")] + [JsonProperty("dependencies", ItemConverterType = typeof(ModMultiformatJsonConverter))] public Mod[] Dependencies; public override string ToString() diff --git a/IPA.Loader/Updating/BeatMods/Updater.cs b/IPA.Loader/Updating/BeatMods/Updater.cs index 5a75bd75..22db2bfb 100644 --- a/IPA.Loader/Updating/BeatMods/Updater.cs +++ b/IPA.Loader/Updating/BeatMods/Updater.cs @@ -170,34 +170,53 @@ namespace IPA.Updating.BeatMods { var depList = new Ref>(new List()); - foreach (var plugin in BSMetas - .Where(m => m.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null)) + foreach (var plugin in BSMetas) + //.Where(m => m.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) == null)) { // initialize with data to resolve (1.1) if (plugin.Metadata.Id != null) { // updatable var msinfo = plugin.Metadata; - depList.Value.Add(new DependencyObject { + var dep = new DependencyObject + { Name = msinfo.Id, Version = msinfo.Version, - Requirement = new Range($">{msinfo.Version}"), + Requirement = new Range($">={msinfo.Version}"), LocalPluginMeta = plugin - }); + }; + + if (msinfo.Features.FirstOrDefault(f => f is NoUpdateFeature) != null) + { // disable updating, by only matching self, so that dependencies can still be resolved + dep.Requirement = new Range(msinfo.Version.ToString()); + } + + depList.Value.Add(dep); } } - foreach (var meta in PluginLoader.ignoredPlugins.Where(m => m.Id != null) - .Where(m => m.Features.FirstOrDefault(f => f is NoUpdateFeature) != null)) + foreach (var meta in PluginLoader.ignoredPlugins.Where(m => m.Id != null)) + //.Where(m => m.Features.FirstOrDefault(f => f is NoUpdateFeature) == null)) { - depList.Value.Add(new DependencyObject - { - Name = meta.Id, - Version = meta.Version, - Requirement = new Range($">{meta.Version}"), - LocalPluginMeta = new PluginLoader.PluginInfo + if (meta.Id != null) + { // updatable + var dep = new DependencyObject { - Metadata = meta, Plugin = null + Name = meta.Id, + Version = meta.Version, + Requirement = new Range($">={meta.Version}"), + LocalPluginMeta = new PluginLoader.PluginInfo + { + Metadata = meta, + Plugin = null + } + }; + + if (meta.Features.FirstOrDefault(f => f is NoUpdateFeature) != null) + { // disable updating, by only matching self + dep.Requirement = new Range(meta.Version.ToString()); } - }); + + depList.Value.Add(dep); + } } foreach (var dep in depList.Value)