summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-25 21:11:48 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-25 21:11:48 -0400
commit5cb183e16ddc661c38f4bd9e6e740b9457b8c437 (patch)
tree7c4ed899a45d7960b727b76318b9b36f9e52fbe5 /src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs
parent4fd3fdc0d8367fdf0c454a1c728113c282df76b7 (diff)
downloadSMAPI-5cb183e16ddc661c38f4bd9e6e740b9457b8c437.tar.gz
SMAPI-5cb183e16ddc661c38f4bd9e6e740b9457b8c437.tar.bz2
SMAPI-5cb183e16ddc661c38f4bd9e6e740b9457b8c437.zip
consolidate update fields in manifest & SMAPI config (#336, #361)
Diffstat (limited to 'src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs31
1 files changed, 17 insertions, 14 deletions
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
/// <summary>Validate manifest metadata.</summary>
/// <param name="mods">The mod manifests to validate.</param>
/// <param name="apiVersion">The current SMAPI version.</param>
- public void ValidateManifests(IEnumerable<IModMetadata> mods, ISemanticVersion apiVersion)
+ /// <param name="vendorModUrls">Maps vendor keys (like <c>Nexus</c>) to their mod URL template (where <c>{0}</c> is the mod ID).</param>
+ public void ValidateManifests(IEnumerable<IModMetadata> mods, ISemanticVersion apiVersion, IDictionary<string, string> vendorModUrls)
{
mods = mods.ToArray();
@@ -110,12 +107,18 @@ namespace StardewModdingAPI.Framework.ModLoading
// get update URLs
List<string> updateUrls = new List<string>();
- 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);