From 8a1982326799dfe7f3d078beba32348befa1c9e6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 16 Feb 2018 23:12:01 -0500 Subject: add mod page URL to missing-dependency errors (#437) --- src/SMAPI/Framework/ModData/ModDatabase.cs | 58 ++++++++++++++++++++++----- src/SMAPI/Framework/ModLoading/ModResolver.cs | 5 ++- src/SMAPI/Program.cs | 2 +- src/SMAPI/StardewModdingAPI.config.json | 12 ++++-- 4 files changed, 61 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ModData/ModDatabase.cs b/src/SMAPI/Framework/ModData/ModDatabase.cs index af067f8f..332c5c48 100644 --- a/src/SMAPI/Framework/ModData/ModDatabase.cs +++ b/src/SMAPI/Framework/ModData/ModDatabase.cs @@ -15,19 +15,24 @@ namespace StardewModdingAPI.Framework.ModData /// The underlying mod data records indexed by default display name. private readonly IDictionary Records; + /// Get an update URL for an update key (if valid). + private readonly Func GetUpdateUrl; + /********* ** Public methods *********/ /// Construct an empty instance. public ModDatabase() - : this(new Dictionary()) { } + : this(new Dictionary(), key => null) { } /// Construct an instance. /// The underlying mod data records indexed by default display name. - public ModDatabase(IDictionary records) + /// Get an update URL for an update key (if valid). + public ModDatabase(IDictionary records, Func getUpdateUrl) { this.Records = records; + this.GetUpdateUrl = getUpdateUrl; } /// Get a parsed representation of the which match a given manifest. @@ -74,21 +79,54 @@ namespace StardewModdingAPI.Framework.ModData /// The unique mod ID. public string GetDisplayNameFor(string id) { - foreach (var entry in this.Records) - { - if (entry.Value.ID != null && entry.Value.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)) - return entry.Key; - } + return this.TryGetRaw(id, out string displayName, out ModDataRecord _) + ? displayName + : null; + } - return null; + /// Get the mod page URL for a mod (if available). + /// The unique mod ID. + public string GetModPageUrlFor(string id) + { + // get raw record + if (!this.TryGetRaw(id, out string _, out ModDataRecord record)) + return null; + + // get update key + ModDataField updateKeyField = record.GetFields().FirstOrDefault(p => p.Key == ModDataFieldKey.UpdateKey); + if (updateKeyField == null) + return null; + + // get update URL + return this.GetUpdateUrl(updateKeyField.Value); } /********* ** Private models *********/ - /// Get the data record matching a given manifest. - /// The mod manifest. + /// Get a raw data record. + /// The mod ID to match. + /// The mod's default display name. + /// The raw mod record. + 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; + } + /// Get a raw data record. + /// The mod manifest whose fields to match. /// The mod's default display name. /// The raw mod record. private bool TryGetRaw(IManifest manifest, out string displayName, out ModDataRecord record) diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index 99d86bf8..b46ee117 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -272,8 +272,11 @@ namespace StardewModdingAPI.Framework.ModLoading from entry in dependencies where entry.IsRequired && entry.Mod == null let displayName = modDatabase.GetDisplayNameFor(entry.ID) ?? entry.ID + let modUrl = modDatabase.GetModPageUrlFor(entry.ID) orderby displayName - select displayName + select modUrl != null + ? $"{displayName}: {modUrl}" + : displayName ).ToArray(); if (failedModNames.Any()) { diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 85bc83a7..275876dd 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -351,7 +351,7 @@ namespace StardewModdingAPI this.Monitor.Log("SMAPI found problems in your game's content files which are likely to cause errors or crashes. Consider uninstalling XNB mods or reinstalling the game.", LogLevel.Error); // load mod data - ModDatabase modDatabase = new ModDatabase(this.Settings.ModData); + ModDatabase modDatabase = new ModDatabase(this.Settings.ModData, Constants.GetUpdateUrl); // load mods { diff --git a/src/SMAPI/StardewModdingAPI.config.json b/src/SMAPI/StardewModdingAPI.config.json index ff5b1f9d..a9d3673c 100644 --- a/src/SMAPI/StardewModdingAPI.config.json +++ b/src/SMAPI/StardewModdingAPI.config.json @@ -458,7 +458,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "Custom Crops": { - "ID": "spacechase0.CustomCrops" + "ID": "spacechase0.CustomCrops", + "Default | UpdateKey": "Nexus:1592" }, "Custom Element Handler": { @@ -515,7 +516,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "Custom NPC": { - "ID": "Platonymous.CustomNPC" + "ID": "Platonymous.CustomNPC", + "Default | UpdateKey": "Nexus:1607" }, "Custom Shops Redux": { @@ -890,7 +892,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "Json Assets": { - "ID": "spacechase0.JsonAssets" + "ID": "spacechase0.JsonAssets", + "Default | UpdateKey": "Nexus:1720" }, "Junimo Farm": { @@ -1172,7 +1175,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha }, "PyTK - Platonymous Toolkit": { - "ID": "Platonymous.Toolkit" + "ID": "Platonymous.Toolkit", + "Default | UpdateKey": "Nexus:1726" }, "Point-and-Plant": { -- cgit