diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-24 13:35:26 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-24 13:35:26 -0400 |
commit | 021e1a278b05d1ba177b3759e534cc372fdc8548 (patch) | |
tree | 1936636bc2116b981c4508f43a3e0fd741d366ab /src/StardewModdingAPI/Program.cs | |
parent | 9b247b67f64af903fd610481e74dbe7175580b84 (diff) | |
download | SMAPI-021e1a278b05d1ba177b3759e534cc372fdc8548.tar.gz SMAPI-021e1a278b05d1ba177b3759e534cc372fdc8548.tar.bz2 SMAPI-021e1a278b05d1ba177b3759e534cc372fdc8548.zip |
list SMAPI update separately (#336, #361)
Diffstat (limited to 'src/StardewModdingAPI/Program.cs')
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 5ecc5634..8a337562 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -489,40 +489,36 @@ namespace StardewModdingAPI new Thread(() => { - this.Monitor.Log("Checking for updates...", LogLevel.Trace); - - // update info - List<string> updates = new List<string>(); - bool smapiUpdate = false; - int modUpdates = 0; - // create client WebApiClient client = new WebApiClient(this.Settings.WebApiBaseUrl, Constants.ApiVersion); - // fetch SMAPI version + // check SMAPI version try { + this.Monitor.Log("Checking for SMAPI update...", LogLevel.Trace); + ModInfoModel response = client.GetModInfoAsync($"GitHub:{this.Settings.GitHubProjectName}").Result.Single().Value; if (response.Error != null) - this.Monitor.Log($"Couldn't check for a new version of SMAPI. This won't affect your game, but you may not be notified of new versions if this keeps happening.\n{response.Error}", LogLevel.Warn); - else if (new SemanticVersion(response.Version).IsNewerThan(Constants.ApiVersion)) { - smapiUpdate = true; - updates.Add($"SMAPI {response.Version}: {response.Url}"); - this.VerboseLog($" SMAPI: update to {response.Version} found."); + this.Monitor.Log("Couldn't check for a new version of SMAPI. This won't affect your game, but you may not be notified of new versions if this keeps happening.", LogLevel.Warn); + this.Monitor.Log($"Error: {response.Error}"); } + else if (new SemanticVersion(response.Version).IsNewerThan(Constants.ApiVersion)) + this.Monitor.Log($"You can update SMAPI to {response.Version}: {response.Url}", LogLevel.Alert); else - this.VerboseLog(" SMAPI: OK."); + this.VerboseLog(" OK."); } catch (Exception ex) { - this.Monitor.Log($"Couldn't check for a new version of SMAPI. This won't affect your game, but you may not be notified of new versions if this keeps happening.\n{ex.GetLogSummary()}"); + this.Monitor.Log("Couldn't check for a new version of SMAPI. This won't affect your game, but you may not be notified of new versions if this keeps happening.", LogLevel.Warn); + this.Monitor.Log($"Error: {ex.GetLogSummary()}"); } - // fetch mod versions + // check mod versions try { - // prepare update-check data + // prepare update keys + this.VerboseLog("Collecting mod update keys..."); IDictionary<string, IModMetadata> modsByKey = new Dictionary<string, IModMetadata>(StringComparer.InvariantCultureIgnoreCase); foreach (IModMetadata mod in mods) { @@ -557,6 +553,7 @@ namespace StardewModdingAPI } // fetch results + this.Monitor.Log($"Checking for updates to {modsByKey.Count} keys...", LogLevel.Trace); IDictionary<string, ModInfoModel> response = client.GetModInfoAsync(modsByKey.Keys.ToArray()).Result; IDictionary<IModMetadata, ModInfoModel> updatesByMod = new Dictionary<IModMetadata, ModInfoModel>(); foreach (var entry in response) @@ -577,18 +574,17 @@ namespace StardewModdingAPI if (isUpdate) { if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || version.IsNewerThan(other.Version)) - { updatesByMod[mod] = entry.Value; - modUpdates++; - } } } - // add to output queue + // output if (updatesByMod.Any()) { + this.Monitor.Newline(); + this.Monitor.Log($"You can update {updatesByMod.Count} mod{(updatesByMod.Count != 1 ? "s" : "")}:", LogLevel.Alert); foreach (var entry in updatesByMod.OrderBy(p => p.Key.DisplayName)) - updates.Add($"{entry.Key.DisplayName} {entry.Value.Version}: {entry.Value.Url}"); + this.Monitor.Log($" {entry.Key.DisplayName} {entry.Value.Version}: {entry.Value.Url}", LogLevel.Alert); } } catch (Exception ex) @@ -596,24 +592,7 @@ namespace StardewModdingAPI this.Monitor.Log($"Couldn't check for new mod versions:\n{ex.GetLogSummary()}", LogLevel.Trace); } - // output - if (updates.Any()) - { - this.Monitor.Newline(); - - // print intro - string intro = ""; - if (smapiUpdate) - intro = "You can update SMAPI"; - if (modUpdates > 0) - intro += $"{(smapiUpdate ? " and" : "You can update")} {modUpdates} mod{(modUpdates != 1 ? "s" : "")}"; - intro += ":"; - this.Monitor.Log(intro, LogLevel.Alert); - - // print update list - foreach (string line in updates) - this.Monitor.Log($" {line}", LogLevel.Alert); - } + }).Start(); } |