summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-25 22:15:30 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-25 22:15:30 -0400
commit07382277eacdb91a3994bca35fed40a060fbcf0c (patch)
tree00b313ecc922e425dc106d18bebdce233f8e327f /src/StardewModdingAPI
parent4aa028dc74d3d92ce141e0f4a98f54690ecf97a5 (diff)
downloadSMAPI-07382277eacdb91a3994bca35fed40a060fbcf0c.tar.gz
SMAPI-07382277eacdb91a3994bca35fed40a060fbcf0c.tar.bz2
SMAPI-07382277eacdb91a3994bca35fed40a060fbcf0c.zip
add support for multiple mods having the same update key (#336)
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Program.cs48
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)
{