diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-22 20:25:26 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-22 20:25:26 -0400 |
commit | a2520024b17e3073d2fffbb0aa84e5f30801f36c (patch) | |
tree | d2f877fbead7bd595ea4927791fc737a385e41c2 /src/SMAPI/Framework/ModData/ModDatabase.cs | |
parent | e149f20583b90c37964c48b8f13777493611aecf (diff) | |
download | SMAPI-a2520024b17e3073d2fffbb0aa84e5f30801f36c.tar.gz SMAPI-a2520024b17e3073d2fffbb0aa84e5f30801f36c.tar.bz2 SMAPI-a2520024b17e3073d2fffbb0aa84e5f30801f36c.zip |
drop support for mods without IDs in metadata file
Diffstat (limited to 'src/SMAPI/Framework/ModData/ModDatabase.cs')
-rw-r--r-- | src/SMAPI/Framework/ModData/ModDatabase.cs | 74 |
1 files changed, 4 insertions, 70 deletions
diff --git a/src/SMAPI/Framework/ModData/ModDatabase.cs b/src/SMAPI/Framework/ModData/ModDatabase.cs index 3fd68440..62f37d9b 100644 --- a/src/SMAPI/Framework/ModData/ModDatabase.cs +++ b/src/SMAPI/Framework/ModData/ModDatabase.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; -using Newtonsoft.Json; namespace StardewModdingAPI.Framework.ModData { @@ -40,7 +38,7 @@ namespace StardewModdingAPI.Framework.ModData public ParsedModDataRecord GetParsed(IManifest manifest) { // get raw record - if (!this.TryGetRaw(manifest, out string displayName, out ModDataRecord record)) + if (!this.TryGetRaw(manifest?.UniqueID, out string displayName, out ModDataRecord record)) return null; // parse fields @@ -111,27 +109,7 @@ namespace StardewModdingAPI.Framework.ModData /// <param name="record">The raw mod record.</param> private bool TryGetRaw(string id, out string displayName, out ModDataRecord record) { - foreach (var entry in this.Records) - { - if (entry.Value.ID != null && entry.Value.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)) - { - displayName = entry.Key; - record = entry.Value; - return true; - } - } - - displayName = null; - record = null; - return false; - } - /// <summary>Get a raw data record.</summary> - /// <param name="manifest">The mod manifest whose fields to match.</param> - /// <param name="displayName">The mod's default display name.</param> - /// <param name="record">The raw mod record.</param> - private bool TryGetRaw(IManifest manifest, out string displayName, out ModDataRecord record) - { - if (manifest != null) + if (!string.IsNullOrWhiteSpace(id)) { foreach (var entry in this.Records) { @@ -139,7 +117,7 @@ namespace StardewModdingAPI.Framework.ModData record = entry.Value; // try main ID - if (record.ID != null && record.ID.Equals(manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase)) + if (record.ID != null && record.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)) return true; // try former IDs @@ -147,26 +125,7 @@ namespace StardewModdingAPI.Framework.ModData { foreach (string part in record.FormerIDs.Split('|')) { - // packed field snapshot - if (part.StartsWith("{")) - { - FieldSnapshot snapshot = JsonConvert.DeserializeObject<FieldSnapshot>(part); - bool isMatch = - (snapshot.ID == null || snapshot.ID.Equals(manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase)) - && (snapshot.EntryDll == null || snapshot.EntryDll.Equals(manifest.EntryDll, StringComparison.InvariantCultureIgnoreCase)) - && ( - snapshot.Author == null - || snapshot.Author.Equals(manifest.Author, StringComparison.InvariantCultureIgnoreCase) - || (manifest.ExtraFields != null && manifest.ExtraFields.ContainsKey("Authour") && snapshot.Author.Equals(manifest.ExtraFields["Authour"].ToString(), StringComparison.InvariantCultureIgnoreCase)) - ) - && (snapshot.Name == null || snapshot.Name.Equals(manifest.Name, StringComparison.InvariantCultureIgnoreCase)); - - if (isMatch) - return true; - } - - // plain ID - else if (part.Equals(manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase)) + if (part.Trim().Equals(id, StringComparison.InvariantCultureIgnoreCase)) return true; } } @@ -177,30 +136,5 @@ namespace StardewModdingAPI.Framework.ModData record = null; return false; } - - - /********* - ** Private models - *********/ - /// <summary>A unique set of fields which identifies the mod.</summary> - [SuppressMessage("ReSharper", "ClassNeverInstantiated.Local", Justification = "Used via JSON deserialisation.")] - [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local", Justification = "Used via JSON deserialisation.")] - private class FieldSnapshot - { - /********* - ** Accessors - *********/ - /// <summary>The unique mod ID (or <c>null</c> to ignore it).</summary> - public string ID { get; set; } - - /// <summary>The entry DLL (or <c>null</c> to ignore it).</summary> - public string EntryDll { get; set; } - - /// <summary>The mod name (or <c>null</c> to ignore it).</summary> - public string Name { get; set; } - - /// <summary>The author name (or <c>null</c> to ignore it).</summary> - public string Author { get; set; } - } } } |