bug fixes, improve update-check logging (#361)

This commit is contained in:
Jesse Plamondon-Willard 2017-09-24 12:13:34 -04:00
parent ce9be43db3
commit 96acccad7c
1 changed files with 43 additions and 6 deletions

View File

@ -334,8 +334,7 @@ namespace StardewModdingAPI
this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn); this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn);
if (!this.Monitor.WriteToConsole) if (!this.Monitor.WriteToConsole)
this.Monitor.Log("Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn); this.Monitor.Log("Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn);
if (this.Settings.VerboseLogging) this.VerboseLog("Verbose logging enabled.");
this.Monitor.Log("Verbose logging enabled.", LogLevel.Trace);
// validate XNB integrity // validate XNB integrity
if (!this.ValidateContentIntegrity()) if (!this.ValidateContentIntegrity())
@ -490,6 +489,8 @@ namespace StardewModdingAPI
new Thread(() => new Thread(() =>
{ {
this.Monitor.Log("Checking for updates...", LogLevel.Trace);
// update info // update info
List<string> updates = new List<string>(); List<string> updates = new List<string>();
bool smapiUpdate = false; bool smapiUpdate = false;
@ -508,7 +509,10 @@ namespace StardewModdingAPI
{ {
smapiUpdate = true; smapiUpdate = true;
updates.Add($"SMAPI {response.Version}: {response.Url}"); updates.Add($"SMAPI {response.Version}: {response.Url}");
this.VerboseLog($" SMAPI: update to {response.Version} found.");
} }
else
this.VerboseLog(" SMAPI: OK.");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -522,12 +526,34 @@ namespace StardewModdingAPI
IDictionary<string, IModMetadata> modsByKey = new Dictionary<string, IModMetadata>(StringComparer.InvariantCultureIgnoreCase); IDictionary<string, IModMetadata> modsByKey = new Dictionary<string, IModMetadata>(StringComparer.InvariantCultureIgnoreCase);
foreach (IModMetadata mod in mods) foreach (IModMetadata mod in mods)
{ {
// validate
if (mod.Manifest == null)
{
this.VerboseLog($" {mod.DisplayName}: no manifest.");
continue;
}
// add update keys
bool hasUpdateKeys = false;
if (!string.IsNullOrWhiteSpace(mod.Manifest.ChucklefishID)) if (!string.IsNullOrWhiteSpace(mod.Manifest.ChucklefishID))
{
hasUpdateKeys = true;
modsByKey[$"Chucklefish:{mod.Manifest.ChucklefishID}"] = mod; modsByKey[$"Chucklefish:{mod.Manifest.ChucklefishID}"] = mod;
}
if (!string.IsNullOrWhiteSpace(mod.Manifest.NexusID)) if (!string.IsNullOrWhiteSpace(mod.Manifest.NexusID))
{
hasUpdateKeys = true;
modsByKey[$"Nexus:{mod.Manifest.NexusID}"] = mod; modsByKey[$"Nexus:{mod.Manifest.NexusID}"] = mod;
}
if (!string.IsNullOrWhiteSpace(mod.Manifest.GitHubProject)) if (!string.IsNullOrWhiteSpace(mod.Manifest.GitHubProject))
{
hasUpdateKeys = true;
modsByKey[$"GitHub:{mod.Manifest.GitHubProject}"] = mod; modsByKey[$"GitHub:{mod.Manifest.GitHubProject}"] = mod;
}
// log
if (!hasUpdateKeys)
this.VerboseLog($" {mod.DisplayName}: no update keys.");
} }
// fetch results // fetch results
@ -535,17 +561,20 @@ namespace StardewModdingAPI
IDictionary<IModMetadata, ModInfoModel> updatesByMod = new Dictionary<IModMetadata, ModInfoModel>(); IDictionary<IModMetadata, ModInfoModel> updatesByMod = new Dictionary<IModMetadata, ModInfoModel>();
foreach (var entry in response) foreach (var entry in response)
{ {
IModMetadata mod = modsByKey[entry.Key];
// handle error // handle error
if (entry.Value.Error != null) if (entry.Value.Error != null)
{ {
this.Monitor.Log($"Couldn't fetch version of {modsByKey[entry.Key].DisplayName} with key {entry.Key}:\n{entry.Value.Error}", LogLevel.Trace); this.Monitor.Log($" {mod.DisplayName} ({entry.Key}): update error: {entry.Value.Error}", LogLevel.Trace);
continue; continue;
} }
// collect latest mod version // track update
IModMetadata mod = modsByKey[entry.Key];
ISemanticVersion version = new SemanticVersion(entry.Value.Version); ISemanticVersion version = new SemanticVersion(entry.Value.Version);
if (version.IsNewerThan(mod.Manifest.Version)) bool isUpdate = version.IsNewerThan(mod.Manifest.Version);
this.VerboseLog($" {mod.DisplayName} ({entry.Key}): {(isUpdate ? $"update to {entry.Value.Version} found" : "OK")}.");
if (isUpdate)
{ {
if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || version.IsNewerThan(other.Version)) if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || version.IsNewerThan(other.Version))
{ {
@ -942,5 +971,13 @@ namespace StardewModdingAPI
#endif #endif
return Environment.OSVersion.ToString(); return Environment.OSVersion.ToString();
} }
/// <summary>Log a message if verbose mode is enabled.</summary>
/// <param name="message">The message to log.</param>
private void VerboseLog(string message)
{
if (this.Settings.VerboseLogging)
this.Monitor.Log(message, LogLevel.Trace);
}
} }
} }