From a89dbce8549abee867d0af65ac62155bb485a911 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 23 Sep 2017 21:48:53 -0400 Subject: unify disabled-mod and compatibility lists (#361) --- .../Core/ModResolverTests.cs | 6 +- .../Framework/ModLoading/ModResolver.cs | 40 ++++++------ .../Framework/Models/DisabledMod.cs | 22 ------- .../Framework/Models/ModStatus.cs | 9 ++- src/StardewModdingAPI/Framework/Models/SConfig.cs | 3 - src/StardewModdingAPI/Program.cs | 2 +- .../StardewModdingAPI.config.json | 76 +++++++++++----------- src/StardewModdingAPI/StardewModdingAPI.csproj | 1 - 8 files changed, 68 insertions(+), 91 deletions(-) delete mode 100644 src/StardewModdingAPI/Framework/Models/DisabledMod.cs diff --git a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs index bc3a0c8c..198ce190 100644 --- a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs +++ b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Tests.Core Directory.CreateDirectory(rootFolder); // act - IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0], new DisabledMod[0]).ToArray(); + IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0]).ToArray(); // assert Assert.AreEqual(0, mods.Length, 0, $"Expected to find zero manifests, found {mods.Length} instead."); @@ -45,7 +45,7 @@ namespace StardewModdingAPI.Tests.Core Directory.CreateDirectory(modFolder); // act - IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0], new DisabledMod[0]).ToArray(); + IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0]).ToArray(); IModMetadata mod = mods.FirstOrDefault(); // assert @@ -84,7 +84,7 @@ namespace StardewModdingAPI.Tests.Core File.WriteAllText(filename, JsonConvert.SerializeObject(original)); // act - IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0], new DisabledMod[0]).ToArray(); + IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0]).ToArray(); IModMetadata mod = mods.FirstOrDefault(); // assert diff --git a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs index 6a971c15..02fd85ea 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs +++ b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs @@ -18,12 +18,10 @@ namespace StardewModdingAPI.Framework.ModLoading /// The root path to search for mods. /// The JSON helper with which to read manifests. /// Metadata about mods that SMAPI should assume is compatible or broken, regardless of whether it detects incompatible code. - /// Metadata about mods that SMAPI should consider obsolete and not load. /// Returns the manifests by relative folder. - public IEnumerable ReadManifests(string rootPath, JsonHelper jsonHelper, IEnumerable compatibilityRecords, IEnumerable disabledMods) + public IEnumerable ReadManifests(string rootPath, JsonHelper jsonHelper, IEnumerable compatibilityRecords) { compatibilityRecords = compatibilityRecords.ToArray(); - disabledMods = disabledMods.ToArray(); foreach (DirectoryInfo modDir in this.GetModFolders(rootPath)) { @@ -62,18 +60,13 @@ namespace StardewModdingAPI.Framework.ModLoading // get unique key for lookups string key = !string.IsNullOrWhiteSpace(manifest.UniqueID) ? manifest.UniqueID : manifest.EntryDll; - // check if mod should be disabled - DisabledMod disabledMod = disabledMods.FirstOrDefault(mod => mod.ID.Contains(key, StringComparer.InvariantCultureIgnoreCase)); - if (disabledMod != null) - error = $"it's obsolete: {disabledMod.ReasonPhrase}"; - // get compatibility record compatibility = ( from mod in compatibilityRecords where mod.ID.Any(p => p.Matches(key, manifest)) && (mod.LowerVersion == null || !manifest.Version.IsOlderThan(mod.LowerVersion)) - && !manifest.Version.IsNewerThan(mod.UpperVersion) + && (mod.UpperVersion == null || !manifest.Version.IsNewerThan(mod.UpperVersion)) select mod ).FirstOrDefault(); } @@ -107,18 +100,25 @@ namespace StardewModdingAPI.Framework.ModLoading // validate compatibility { ModCompatibility compatibility = mod.Compatibility; - if (compatibility?.Status == ModStatus.AssumeBroken) + switch (compatibility?.Status) { - string reasonPhrase = compatibility.ReasonPhrase ?? "it's no longer compatible"; - string error = $"{reasonPhrase}. Please check for a "; - if (mod.Manifest.Version.Equals(compatibility.UpperVersion) && compatibility.UpperVersionLabel == null) - error += "newer version"; - else - error += $"version newer than {compatibility.UpperVersionLabel ?? compatibility.UpperVersion.ToString()}"; - error += " at " + string.Join(" or ", compatibility.UpdateUrls); - - mod.SetStatus(ModMetadataStatus.Failed, error); - continue; + case ModStatus.Obsolete: + mod.SetStatus(ModMetadataStatus.Failed, $"it's obsolete: {compatibility.ReasonPhrase}"); + continue; + + case ModStatus.AssumeBroken: + { + string reasonPhrase = compatibility.ReasonPhrase ?? "it's no longer compatible"; + string error = $"{reasonPhrase}. Please check for a "; + if (mod.Manifest.Version.Equals(compatibility.UpperVersion) && compatibility.UpperVersionLabel == null) + error += "newer version"; + else + error += $"version newer than {compatibility.UpperVersionLabel ?? compatibility.UpperVersion.ToString()}"; + error += " at " + string.Join(" or ", compatibility.UpdateUrls); + + mod.SetStatus(ModMetadataStatus.Failed, error); + continue; + } } } diff --git a/src/StardewModdingAPI/Framework/Models/DisabledMod.cs b/src/StardewModdingAPI/Framework/Models/DisabledMod.cs deleted file mode 100644 index 170fa760..00000000 --- a/src/StardewModdingAPI/Framework/Models/DisabledMod.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace StardewModdingAPI.Framework.Models -{ - /// Metadata about for a mod that should never be loaded. - internal class DisabledMod - { - /********* - ** Accessors - *********/ - /**** - ** From config - ****/ - /// The unique mod IDs. - public string[] ID { get; set; } - - /// The mod name. - public string Name { get; set; } - - /// The reason phrase to show in the warning, or null to use the default value. - /// "this mod is no longer supported or used" - public string ReasonPhrase { get; set; } - } -} diff --git a/src/StardewModdingAPI/Framework/Models/ModStatus.cs b/src/StardewModdingAPI/Framework/Models/ModStatus.cs index 4ab0b790..343ccb7e 100644 --- a/src/StardewModdingAPI/Framework/Models/ModStatus.cs +++ b/src/StardewModdingAPI/Framework/Models/ModStatus.cs @@ -4,12 +4,15 @@ namespace StardewModdingAPI.Framework.Models internal enum ModStatus { /// Don't override the status. - None = 0, + None, + + /// The mod is obsolete and shouldn't be used, regardless of version. + Obsolete, /// Assume the mod is not compatible, even if SMAPI doesn't detect any incompatible code. - AssumeBroken = 0, + AssumeBroken, /// Assume the mod is compatible, even if SMAPI detects incompatible code. - AssumeCompatible = 1 + AssumeCompatible } } diff --git a/src/StardewModdingAPI/Framework/Models/SConfig.cs b/src/StardewModdingAPI/Framework/Models/SConfig.cs index 36799400..720d4a6d 100644 --- a/src/StardewModdingAPI/Framework/Models/SConfig.cs +++ b/src/StardewModdingAPI/Framework/Models/SConfig.cs @@ -23,8 +23,5 @@ namespace StardewModdingAPI.Framework.Models /// A list of mod versions which should be considered compatible or incompatible regardless of whether SMAPI detects incompatible code. public ModCompatibility[] ModCompatibility { get; set; } - - /// A list of mods which should be considered obsolete and not loaded. - public DisabledMod[] DisabledMods { get; set; } } } diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 234572a6..b22fb02a 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -347,7 +347,7 @@ namespace StardewModdingAPI ModResolver resolver = new ModResolver(); // load manifests - IModMetadata[] mods = resolver.ReadManifests(Constants.ModPath, new JsonHelper(), this.Settings.ModCompatibility, this.Settings.DisabledMods).ToArray(); + IModMetadata[] mods = resolver.ReadManifests(Constants.ModPath, new JsonHelper(), this.Settings.ModCompatibility).ToArray(); resolver.ValidateManifests(mods, Constants.ApiVersion); // process dependencies diff --git a/src/StardewModdingAPI/StardewModdingAPI.config.json b/src/StardewModdingAPI/StardewModdingAPI.config.json index e5c42391..7c20a9d9 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.config.json +++ b/src/StardewModdingAPI/StardewModdingAPI.config.json @@ -28,7 +28,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha /** * The base URL for SMAPI's web API, used to perform update checks. - * Note: the protocol will be changed to http:// on Linux/Mac due to OpenSSL issues with the game's bundled Mono. + * Note: the protocol will be changed to http:// on Linux/Mac due to OpenSSL issues with the + * game's bundled Mono. */ "WebApiBaseUrl": "https://api.smapi.io", @@ -37,43 +38,6 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha */ "VerboseLogging": false, - /** - * A list of mods SMAPI should consider obsolete and not load. Changing this field is not - * recommended and may destabilise your game. - */ - "DisabledMods": [ - { - "Name": "Animal Mood Fix", - "ID": [ "GPeters-AnimalMoodFix" ], - "ReasonPhrase": "the animal mood bugs were fixed in Stardew Valley 1.2." - }, - { - "Name": "Colored Chests", - "ID": [ "4befde5c-731c-4853-8e4b-c5cdf946805f" ], - "ReasonPhrase": "colored chests were added in Stardew Valley 1.1." - }, - { - "Name": "Modder Serialization Utility", - "ID": [ "SerializerUtils-0-1" ], - "ReasonPhrase": "it's no longer maintained or used." - }, - { - "Name": "No Debug Mode", - "ID": [ "NoDebugMode" ], - "ReasonPhrase": "debug mode was removed in SMAPI 1.0." - }, - { - "Name": "StarDustCore", - "ID": [ "StarDustCore" ], - "ReasonPhrase": "it was only used by earlier versions of Save Anywhere, and is no longer used or maintained." - }, - { - "Name": "XmlSerializerRetool", - "ID": [ "XmlSerializerRetool.dll" ], - "ReasonPhrase": "it's no longer maintained or used." - } - ], - /** * A list of mod versions SMAPI should consider compatible or broken regardless of whether it * detects incompatible code. The default for each record is to assume broken; to force SMAPI to @@ -117,6 +81,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "UpdateUrls": [ "http://www.nexusmods.com/stardewvalley/mods/439" ], "Notes": "Broke in SDV 1.2." }, + { + "Name": "Animal Mood Fix", + "ID": [ "GPeters-AnimalMoodFix" ], + "Status": "Obsolete", + "ReasonPhrase": "the animal mood bugs were fixed in Stardew Valley 1.2." + }, { "Name": "Animal Sitter", "ID": [ "AnimalSitter.dll" ], @@ -243,6 +213,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "UpdateUrls": [ "http://www.nexusmods.com/stardewvalley/mods/1169", "http://stardewvalleywiki.com/Modding:SMAPI_2.0" ], "Notes": "Broke in SMAPI 2.0." }, + { + "Name": "Colored Chests", + "ID": [ "4befde5c-731c-4853-8e4b-c5cdf946805f" ], + "Status": "Obsolete", + "ReasonPhrase": "colored chests were added in Stardew Valley 1.1." + }, { "Name": "Combat with Farm Implements", "ID": [ "SPDFarmingImplementsInCombat" ], @@ -523,6 +499,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "UpdateUrls": [ "http://community.playstarbound.com/resources/message-box-api.4296", "http://stardewvalleywiki.com/Modding:SMAPI_2.0" ], "Notes": "Broke in SMAPI 2.0." }, + { + "Name": "Modder Serialization Utility", + "ID": [ "SerializerUtils-0-1" ], + "Status": "Obsolete", + "ReasonPhrase": "it's no longer maintained or used." + }, { "Name": "More Artifact Spots", "ID": [ "451" ], @@ -572,6 +554,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "UpdateUrls": [ "http://www.nexusmods.com/stardewvalley/mods/433", "http://stardewvalleywiki.com/Modding:SMAPI_2.0" ], "Notes": "Broke in SMAPI 2.0." }, + { + "Name": "No Debug Mode", + "ID": [ "NoDebugMode" ], + "Status": "Obsolete", + "ReasonPhrase": "debug mode was removed in SMAPI 1.0." + }, { "Name": "NoSoilDecay", "ID": [ "289dee03-5f38-4d8e-8ffc-e440198e8610" ], @@ -853,6 +841,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "UpdateUrls": [ "http://www.nexusmods.com/stardewvalley/mods/425", "http://stardewvalleywiki.com/Modding:SMAPI_2.0" ], "Notes": "Broke in SMAPI 2.0." }, + { + "Name": "StarDustCore", + "ID": [ "StarDustCore" ], + "Status": "Obsolete", + "ReasonPhrase": "it was only used by earlier versions of Save Anywhere, and is no longer used or maintained." + }, { "Name": "StashItemsToChest", "ID": [ "BlueMod_StashItemsToChest" ], @@ -938,6 +932,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "UpdateUrls": [ "http://community.playstarbound.com/threads/115384", "http://stardewvalleywiki.com/Modding:SMAPI_2.0" ], "Notes": "Broke in SDV 1.1 or 1.11." }, + { + "Name": "XmlSerializerRetool", + "ID": [ "XmlSerializerRetool.dll" ], + "Status": "Obsolete", + "ReasonPhrase": "it's no longer maintained or used." + }, { "Name": "Xnb Loader", "ID": [ "Entoarox.XnbLoader" ], diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 46f2ffb1..818e7263 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -142,7 +142,6 @@ - -- cgit