From 5cb183e16ddc661c38f4bd9e6e740b9457b8c437 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 25 Sep 2017 21:11:48 -0400 Subject: consolidate update fields in manifest & SMAPI config (#336, #361) --- .../Framework/ModLoading/ModResolver.cs | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/StardewModdingAPI/Framework/ModLoading') diff --git a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs index 4d20e7c8..d0ef1b08 100644 --- a/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs +++ b/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs @@ -61,13 +61,9 @@ namespace StardewModdingAPI.Framework.ModLoading dataRecord = dataRecords.FirstOrDefault(record => record.ID.Matches(key, manifest)); } - // apply defaults - if (dataRecord?.Defaults != null) - { - manifest.ChucklefishID = manifest.ChucklefishID ?? dataRecord.Defaults.ChucklefishID; - manifest.GitHubProject = manifest.GitHubProject ?? dataRecord.Defaults.GitHubProject; - manifest.NexusID = manifest.NexusID ?? dataRecord.Defaults.NexusID; - } + // add default update keys + if (manifest != null && manifest.UpdateKeys == null && dataRecord?.UpdateKeys != null) + manifest.UpdateKeys = dataRecord.UpdateKeys; // build metadata string displayName = !string.IsNullOrWhiteSpace(manifest?.Name) @@ -84,7 +80,8 @@ namespace StardewModdingAPI.Framework.ModLoading /// Validate manifest metadata. /// The mod manifests to validate. /// The current SMAPI version. - public void ValidateManifests(IEnumerable mods, ISemanticVersion apiVersion) + /// Maps vendor keys (like Nexus) to their mod URL template (where {0} is the mod ID). + public void ValidateManifests(IEnumerable mods, ISemanticVersion apiVersion, IDictionary vendorModUrls) { mods = mods.ToArray(); @@ -110,12 +107,18 @@ namespace StardewModdingAPI.Framework.ModLoading // get update URLs List updateUrls = new List(); - if (!string.IsNullOrWhiteSpace(mod.Manifest.ChucklefishID)) - updateUrls.Add($"https://community.playstarbound.com/resources/{mod.Manifest.ChucklefishID}"); - if (!string.IsNullOrWhiteSpace(mod.Manifest.NexusID)) - updateUrls.Add($"http://nexusmods.com/stardewvalley/mods/{mod.Manifest.NexusID}"); - if (!string.IsNullOrWhiteSpace(mod.Manifest.GitHubProject)) - updateUrls.Add($"https://github.com/{mod.Manifest.GitHubProject}/releases"); + foreach (string key in mod.Manifest.UpdateKeys ?? new string[0]) + { + string[] parts = key.Split(new[] { ':' }, 2); + if (parts.Length != 2) + continue; + + string vendorKey = parts[0].Trim(); + string modID = parts[1].Trim(); + + if (vendorModUrls.TryGetValue(vendorKey, out string urlTemplate)) + updateUrls.Add(string.Format(urlTemplate, modID)); + } if (mod.DataRecord.AlternativeUrl != null) updateUrls.Add(mod.DataRecord.AlternativeUrl); -- cgit