diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-05-09 12:12:03 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-05-09 12:12:03 -0400 |
commit | 4b391d631ccde301969ae0c04f407a01ba4055b1 (patch) | |
tree | 2c5d9317dd3b64731739aaeb64235cde00c8a948 /src | |
parent | d9c001a39f4562038fb608468169ea22cf074111 (diff) | |
download | SMAPI-4b391d631ccde301969ae0c04f407a01ba4055b1.tar.gz SMAPI-4b391d631ccde301969ae0c04f407a01ba4055b1.tar.bz2 SMAPI-4b391d631ccde301969ae0c04f407a01ba4055b1.zip |
normalize manifest array fields
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI.Toolkit/Framework/ModData/ModDataField.cs | 2 | ||||
-rw-r--r-- | src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs | 2 | ||||
-rw-r--r-- | src/SMAPI.Toolkit/Serialization/Models/Manifest.cs | 10 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/ModMetadata.cs | 19 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/ModResolver.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 19 |
6 files changed, 32 insertions, 22 deletions
diff --git a/src/SMAPI.Toolkit/Framework/ModData/ModDataField.cs b/src/SMAPI.Toolkit/Framework/ModData/ModDataField.cs index 6658d219..b02be3e4 100644 --- a/src/SMAPI.Toolkit/Framework/ModData/ModDataField.cs +++ b/src/SMAPI.Toolkit/Framework/ModData/ModDataField.cs @@ -66,7 +66,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModData { // update key case ModDataFieldKey.UpdateKey: - return manifest.UpdateKeys != null && manifest.UpdateKeys.Any(p => !string.IsNullOrWhiteSpace(p)); + return manifest.UpdateKeys.Any(p => !string.IsNullOrWhiteSpace(p)); // non-manifest fields case ModDataFieldKey.StatusReasonPhrase: diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs index d0df09a1..825b98e5 100644 --- a/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs +++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs @@ -69,7 +69,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning public IEnumerable<string> GetUpdateKeys(Manifest manifest) { return - (manifest.UpdateKeys ?? new string[0]) + manifest.UpdateKeys .Where(p => !string.IsNullOrWhiteSpace(p)) .ToArray(); } diff --git a/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs b/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs index 99e85cbd..46b654a5 100644 --- a/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs +++ b/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Runtime.Serialization; using Newtonsoft.Json; using StardewModdingAPI.Toolkit.Serialization.Converters; @@ -70,5 +71,14 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models this.UpdateKeys = new string[0]; this.ContentPackFor = new ManifestContentPackFor { UniqueID = contentPackFor }; } + + /// <summary>Normalize the model after it's deserialized.</summary> + /// <param name="context">The deserialization context.</param> + [OnDeserialized] + public void OnDeserialized(StreamingContext context) + { + this.Dependencies ??= new IManifestDependency[0]; + this.UpdateKeys ??= new string[0]; + } } } diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index 17e6d59a..b703f74c 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -195,7 +195,10 @@ namespace StardewModdingAPI.Framework.ModLoading /// <inheritdoc /> public IEnumerable<UpdateKey> GetUpdateKeys(bool validOnly = false) { - foreach (string rawKey in this.Manifest?.UpdateKeys ?? new string[0]) + if (this.Manifest == null) + yield break; + + foreach (string rawKey in this.Manifest.UpdateKeys) { UpdateKey updateKey = UpdateKey.Parse(rawKey); if (updateKey.LooksValid || !validOnly) @@ -251,16 +254,16 @@ namespace StardewModdingAPI.Framework.ModLoading { var ids = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); - // yield dependencies - if (this.Manifest?.Dependencies != null) + if (this.Manifest != null) { - foreach (var entry in this.Manifest?.Dependencies) + // yield dependencies + foreach (IManifestDependency entry in this.Manifest.Dependencies) ids[entry.UniqueID] = entry.IsRequired; - } - // yield content pack parent - if (this.Manifest?.ContentPackFor?.UniqueID != null) - ids[this.Manifest.ContentPackFor.UniqueID] = true; + // yield content pack parent + if (this.Manifest.ContentPackFor?.UniqueID != null) + ids[this.Manifest.ContentPackFor.UniqueID] = true; + } return ids; } diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index 7761a567..3bf2b0a1 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -82,7 +82,7 @@ namespace StardewModdingAPI.Framework.ModLoading // get update URLs List<string> updateUrls = new List<string>(); - foreach (string key in mod.Manifest.UpdateKeys ?? new string[0]) + foreach (string key in mod.Manifest.UpdateKeys) { string url = getUpdateUrl(key); if (url != null) diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 5862b112..8b2c7544 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1593,19 +1593,16 @@ namespace StardewModdingAPI.Framework // validate dependencies // Although dependencies are validated before mods are loaded, a dependency may have failed to load. - if (mod.Manifest.Dependencies?.Any() == true) + foreach (IManifestDependency dependency in mod.Manifest.Dependencies.Where(p => p.IsRequired)) { - foreach (IManifestDependency dependency in mod.Manifest.Dependencies.Where(p => p.IsRequired)) + if (this.ModRegistry.Get(dependency.UniqueID) == null) { - if (this.ModRegistry.Get(dependency.UniqueID) == null) - { - string dependencyName = mods - .FirstOrDefault(otherMod => otherMod.HasID(dependency.UniqueID)) - ?.DisplayName ?? dependency.UniqueID; - errorReasonPhrase = $"it needs the '{dependencyName}' mod, which couldn't be loaded."; - failReason = ModFailReason.MissingDependencies; - return false; - } + string dependencyName = mods + .FirstOrDefault(otherMod => otherMod.HasID(dependency.UniqueID)) + ?.DisplayName ?? dependency.UniqueID; + errorReasonPhrase = $"it needs the '{dependencyName}' mod, which couldn't be loaded."; + failReason = ModFailReason.MissingDependencies; + return false; } } |