From 4e7a67bc6d616950fed03ba8c26f9dec2cc273ff Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 16 Sep 2019 16:28:12 -0400 Subject: log custom SMAPI settings to simplify troubleshooting --- src/SMAPI/Framework/Models/SConfig.cs | 64 +++++++++++++++++++++++++++++++---- src/SMAPI/Framework/SCore.cs | 7 ++++ 2 files changed, 64 insertions(+), 7 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index 2bc71adf..40ed9512 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using System.Linq; using StardewModdingAPI.Internal.ConsoleWriting; namespace StardewModdingAPI.Framework.Models @@ -5,6 +8,35 @@ namespace StardewModdingAPI.Framework.Models /// The SMAPI configuration settings. internal class SConfig { + /******** + ** Fields + ********/ + /// The default config values, for fields that should be logged if different. + private static readonly IDictionary DefaultValues = new Dictionary + { + [nameof(CheckForUpdates)] = true, + [nameof(ParanoidWarnings)] = +#if DEBUG + true, +#else + false, +#endif + [nameof(UseBetaChannel)] = Constants.ApiVersion.IsPrerelease(), + [nameof(GitHubProjectName)] = "Pathoschild/SMAPI", + [nameof(WebApiBaseUrl)] = "https://api.smapi.io", + [nameof(VerboseLogging)] = false, + [nameof(LogNetworkTraffic)] = false, + [nameof(DumpMetadata)] = false + }; + + /// The default values for , to log changes if different. + private static readonly HashSet DefaultSuppressUpdateChecks = new HashSet(StringComparer.InvariantCultureIgnoreCase) + { + "SMAPI.ConsoleCommands", + "SMAPI.SaveBackup" + }; + + /******** ** Accessors ********/ @@ -15,15 +47,10 @@ namespace StardewModdingAPI.Framework.Models public bool CheckForUpdates { get; set; } /// Whether to add a section to the 'mod issues' list for mods which which directly use potentially sensitive .NET APIs like file or shell access. - public bool ParanoidWarnings { get; set; } = -#if DEBUG - true; -#else - false; -#endif + public bool ParanoidWarnings { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.ParanoidWarnings)]; /// Whether to show beta versions as valid updates. - public bool UseBetaChannel { get; set; } = Constants.ApiVersion.IsPrerelease(); + public bool UseBetaChannel { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.UseBetaChannel)]; /// SMAPI's GitHub project name, used to perform update checks. public string GitHubProjectName { get; set; } @@ -45,5 +72,28 @@ namespace StardewModdingAPI.Framework.Models /// The mod IDs SMAPI should ignore when performing update checks or validating update keys. public string[] SuppressUpdateChecks { get; set; } + + + /******** + ** Public methods + ********/ + /// Get the settings which have been customised by the player. + public IDictionary GetCustomSettings() + { + IDictionary custom = new Dictionary(); + + foreach (var pair in SConfig.DefaultValues) + { + object value = typeof(SConfig).GetProperty(pair.Key)?.GetValue(this); + if (!pair.Value.Equals(value)) + custom[pair.Key] = value; + } + + HashSet curSuppressUpdateChecks = new HashSet(this.SuppressUpdateChecks ?? new string[0], StringComparer.InvariantCultureIgnoreCase); + if (SConfig.DefaultSuppressUpdateChecks.Count != curSuppressUpdateChecks.Count || SConfig.DefaultSuppressUpdateChecks.Any(p => !curSuppressUpdateChecks.Contains(p))) + custom[nameof(this.SuppressUpdateChecks)] = "[" + string.Join(", ", this.SuppressUpdateChecks ?? new string[0]) + "]"; + + return custom; + } } } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index fde28852..08d30a29 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -164,6 +164,13 @@ namespace StardewModdingAPI.Framework this.Monitor.Log("(Using custom --mods-path argument.)", LogLevel.Trace); this.Monitor.Log($"Log started at {DateTime.UtcNow:s} UTC", LogLevel.Trace); + // log custom settings + { + IDictionary customSettings = this.Settings.GetCustomSettings(); + if (customSettings.Any()) + this.Monitor.Log($"Loaded with custom settings: {string.Join(", ", customSettings.OrderBy(p => p.Key).Select(p => $"{p.Key}: {p.Value}"))}", LogLevel.Trace); + } + // validate platform #if SMAPI_FOR_WINDOWS if (Constants.Platform != Platform.Windows) -- cgit