From daacd980f94750cda4226a0827d4c35a7b3b0ce2 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Mon, 26 Nov 2018 17:57:29 -0600 Subject: [PATCH] Added Semver version verification to ModsaberModInfo --- IPA.Loader/Loader/PluginManager.cs | 4 +++- .../PluginInterfaces/BeatSaber/ModsaberModInfo.cs | 6 ++++++ IPA.Loader/Updating/ModSaber/Updater.cs | 13 ++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/IPA.Loader/Loader/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs index 0322d705..860ad191 100644 --- a/IPA.Loader/Loader/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -188,7 +188,9 @@ namespace IPA.Loader _bsPlugins.Add(selfPlugin); - configProviders.Add(new KeyValuePair>(SelfConfigProvider = new JsonConfigProvider { Filename = Path.Combine("UserData", SelfPlugin.IPA_Name) }, new Ref(SelfConfigProvider.LastModified))); + configProviders.Add(new KeyValuePair>( + SelfConfigProvider = new JsonConfigProvider {Filename = Path.Combine("UserData", SelfPlugin.IPA_Name)}, + new Ref(SelfConfigProvider.LastModified))); SelfConfigProvider.Load(); //Load copied plugins diff --git a/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs b/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs index dc4f8989..5dc073c0 100644 --- a/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs +++ b/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs @@ -1,4 +1,6 @@ using System; +using Version = SemVer.Version; + // ReSharper disable CheckNamespace namespace IPA @@ -39,7 +41,9 @@ namespace IPA { if (_currentVersion == null) { + var version = new Version(value); // check for valid version _currentVersion = value; + _semverVersion = version; } else { @@ -48,5 +52,7 @@ namespace IPA } } private string _currentVersion; + + internal Version _semverVersion = null; } } diff --git a/IPA.Loader/Updating/ModSaber/Updater.cs b/IPA.Loader/Updating/ModSaber/Updater.cs index 5f4bc0db..e55e0f84 100644 --- a/IPA.Loader/Updating/ModSaber/Updater.cs +++ b/IPA.Loader/Updating/ModSaber/Updater.cs @@ -70,7 +70,7 @@ namespace IPA.Updating.ModSaber } } - private Dictionary requestCache = new Dictionary(); + private readonly Dictionary requestCache = new Dictionary(); private IEnumerator GetModsaberEndpoint(string url, Ref result) { if (requestCache.TryGetValue(url, out string value)) @@ -174,7 +174,7 @@ namespace IPA.Updating.ModSaber var msinfo = plugin.ModSaberInfo; depList.Value.Add(new DependencyObject { Name = msinfo.InternalName, - Version = new Version(msinfo.CurrentVersion), + Version = msinfo._semverVersion, Requirement = new Range($">={msinfo.CurrentVersion}"), LocalPluginMeta = plugin }); @@ -234,7 +234,7 @@ namespace IPA.Updating.ModSaber } else { - var toMod = final.Where(d => d.Name == dep.Name).First(); + var toMod = final.First(d => d.Name == dep.Name); if (dep.Requirement != null) { @@ -244,10 +244,9 @@ namespace IPA.Updating.ModSaber } else if (dep.Conflicts != null) { - if (toMod.Conflicts == null) - toMod.Conflicts = dep.Conflicts; - else - toMod.Conflicts = new Range($"{toMod.Conflicts} || {dep.Conflicts}"); // there should be a better way to do this + toMod.Conflicts = toMod.Conflicts == null + ? dep.Conflicts + : new Range($"{toMod.Conflicts} || {dep.Conflicts}"); } } }