diff options
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 48 |
1 files changed, 28 insertions, 20 deletions
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<string, IModMetadata> modsByKey = new Dictionary<string, IModMetadata>(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<string, IModMetadata[]> 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<IModMetadata, ModInfoModel> updatesByMod = new Dictionary<IModMetadata, ModInfoModel>(); foreach (var result in results) { |