From 07382277eacdb91a3994bca35fed40a060fbcf0c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 25 Sep 2017 22:15:30 -0400 Subject: add support for multiple mods having the same update key (#336) --- src/StardewModdingAPI/Program.cs | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'src/StardewModdingAPI') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 3575add6..0b58756e 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -517,38 +517,46 @@ namespace StardewModdingAPI // check mod versions try { - // prepare update keys - this.VerboseLog("Collecting mod update keys..."); - IDictionary modsByKey = new Dictionary(StringComparer.InvariantCultureIgnoreCase); - foreach (IModMetadata mod in mods) + // log issues + if (this.Settings.VerboseLogging) { - // validate - if (mod.Manifest == null) - { - this.VerboseLog($" {mod.DisplayName}: no manifest."); - continue; - } - - // add update keys - if (mod.Manifest.UpdateKeys?.Any() == true) + this.VerboseLog("Validating mod update keys..."); + foreach (IModMetadata mod in mods) { - foreach (string updateKey in mod.Manifest.UpdateKeys) - modsByKey[updateKey] = mod; + if (mod.Manifest == null) + this.VerboseLog($" {mod.DisplayName}: no manifest."); + else if (mod.Manifest.UpdateKeys == null || !mod.Manifest.UpdateKeys.Any()) + this.VerboseLog($" {mod.DisplayName}: no update keys."); } - else - this.VerboseLog($" {mod.DisplayName}: no update keys."); } + // prepare update keys + Dictionary modsByKey = + ( + from mod in mods + where mod.Manifest?.UpdateKeys != null + from key in mod.Manifest.UpdateKeys + select new { key, mod } + ) + .GroupBy(p => p.key, StringComparer.InvariantCultureIgnoreCase) + .ToDictionary( + group => group.Key, + group => group.Select(p => p.mod).ToArray(), + StringComparer.InvariantCultureIgnoreCase + ); + // fetch results - this.Monitor.Log($"Checking for updates to {modsByKey.Count} keys...", LogLevel.Trace); + this.Monitor.Log($"Checking for updates to {modsByKey.Keys.Count} keys...", LogLevel.Trace); var results = ( from entry in client.GetModInfoAsync(modsByKey.Keys.ToArray()).Result - let mod = modsByKey[entry.Key] + from mod in modsByKey[entry.Key] orderby mod.DisplayName - select new { entry.Key, Mod = modsByKey[entry.Key], Info = entry.Value } + select new { entry.Key, Mod = mod, Info = entry.Value } ) .ToArray(); + + // extract latest versions IDictionary updatesByMod = new Dictionary(); foreach (var result in results) { -- cgit