From 0863f9b7e5f165f2b1db8750b20ed35bc0c3701a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 24 Sep 2017 00:23:48 -0400 Subject: revamp mod compatibility fields to allow broader use of mod data records (#361) --- .../Framework/ModLoading/ModResolver.cs | 49 +++++++++------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs') diff --git a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs index 3674faec..31ba5bc5 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs +++ b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs @@ -61,14 +61,7 @@ namespace StardewModdingAPI.Framework.ModLoading string key = !string.IsNullOrWhiteSpace(manifest.UniqueID) ? manifest.UniqueID : manifest.EntryDll; // get data record - dataRecord = ( - from mod in dataRecords - where - mod.ID.Matches(key, manifest) - && (mod.LowerVersion == null || !manifest.Version.IsOlderThan(mod.LowerVersion)) - && (mod.UpperVersion == null || !manifest.Version.IsNewerThan(mod.UpperVersion)) - select mod - ).FirstOrDefault(); + dataRecord = dataRecords.FirstOrDefault(record => record.ID.Matches(key, manifest)); } // build metadata @@ -98,28 +91,26 @@ namespace StardewModdingAPI.Framework.ModLoading continue; // validate compatibility + ModCompatibility compatibility = mod.DataRecord?.GetCompatibility(mod.Manifest.Version); + switch (compatibility?.Status) { - ModDataRecord dataRecord = mod.DataRecord; - switch (dataRecord?.Status) - { - case ModStatus.Obsolete: - mod.SetStatus(ModMetadataStatus.Failed, $"it's obsolete: {dataRecord.ReasonPhrase}"); - continue; - - case ModStatus.AssumeBroken: - { - string reasonPhrase = dataRecord.ReasonPhrase ?? "it's no longer compatible"; - string error = $"{reasonPhrase}. Please check for a "; - if (mod.Manifest.Version.Equals(dataRecord.UpperVersion) && dataRecord.UpperVersionLabel == null) - error += "newer version"; - else - error += $"version newer than {dataRecord.UpperVersionLabel ?? dataRecord.UpperVersion.ToString()}"; - error += " at " + string.Join(" or ", dataRecord.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)) + error += "newer version"; + else + error += $"version newer than {compatibility.UpperVersion}"; + error += " at " + string.Join(" or ", mod.DataRecord.UpdateUrls); + + mod.SetStatus(ModMetadataStatus.Failed, error); + } + continue; } // validate SMAPI version -- cgit