summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Models/SConfig.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-13 21:07:43 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-13 21:07:43 -0400
commit4adf8611131a5d86b15f017a42a0366837d14528 (patch)
tree879ba8dfc546382c3795e3d13a623b0e17f96469 /src/SMAPI/Framework/Models/SConfig.cs
parent5b24fff4771dd11c627ae20c827599fe37fa89ad (diff)
downloadSMAPI-4adf8611131a5d86b15f017a42a0366837d14528.tar.gz
SMAPI-4adf8611131a5d86b15f017a42a0366837d14528.tar.bz2
SMAPI-4adf8611131a5d86b15f017a42a0366837d14528.zip
enable nullable annotations in the rest of SMAPI core (#837)
Diffstat (limited to 'src/SMAPI/Framework/Models/SConfig.cs')
-rw-r--r--src/SMAPI/Framework/Models/SConfig.cs78
1 files changed, 56 insertions, 22 deletions
diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs
index e74d73b5..d626ab4d 100644
--- a/src/SMAPI/Framework/Models/SConfig.cs
+++ b/src/SMAPI/Framework/Models/SConfig.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Collections.Generic;
using System.Linq;
@@ -40,60 +38,96 @@ namespace StardewModdingAPI.Framework.Models
** Accessors
********/
/// <summary>Whether to enable development features.</summary>
- public bool DeveloperMode { get; set; }
+ public bool DeveloperMode { get; private set; }
/// <summary>Whether to check for newer versions of SMAPI and mods on startup.</summary>
- public bool CheckForUpdates { get; set; }
+ public bool CheckForUpdates { get; }
/// <summary>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.</summary>
- public bool ParanoidWarnings { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.ParanoidWarnings)];
+ public bool ParanoidWarnings { get; }
/// <summary>Whether to show beta versions as valid updates.</summary>
- public bool UseBetaChannel { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.UseBetaChannel)];
+ public bool UseBetaChannel { get; }
/// <summary>SMAPI's GitHub project name, used to perform update checks.</summary>
- public string GitHubProjectName { get; set; }
+ public string GitHubProjectName { get; }
/// <summary>The base URL for SMAPI's web API, used to perform update checks.</summary>
- public string WebApiBaseUrl { get; set; }
+ public string WebApiBaseUrl { get; }
/// <summary>Whether SMAPI should log more information about the game context.</summary>
- public bool VerboseLogging { get; set; }
+ public bool VerboseLogging { get; }
/// <summary>Whether SMAPI should rewrite mods for compatibility.</summary>
- public bool RewriteMods { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.RewriteMods)];
+ public bool RewriteMods { get; }
/// <summary>Whether to enable more aggressive memory optimizations.</summary>
- public bool AggressiveMemoryOptimizations { get; set; } = (bool)SConfig.DefaultValues[nameof(SConfig.AggressiveMemoryOptimizations)];
+ public bool AggressiveMemoryOptimizations { get; }
/// <summary>Whether SMAPI should log network traffic. Best combined with <see cref="VerboseLogging"/>, which includes network metadata.</summary>
- public bool LogNetworkTraffic { get; set; }
+ public bool LogNetworkTraffic { get; }
/// <summary>The colors to use for text written to the SMAPI console.</summary>
- public ColorSchemeConfig ConsoleColors { get; set; }
+ public ColorSchemeConfig ConsoleColors { get; }
/// <summary>The mod IDs SMAPI should ignore when performing update checks or validating update keys.</summary>
- public string[] SuppressUpdateChecks { get; set; }
+ public string[] SuppressUpdateChecks { get; }
/********
** Public methods
********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="developerMode">Whether to enable development features.</param>
+ /// <param name="checkForUpdates">Whether to check for newer versions of SMAPI and mods on startup.</param>
+ /// <param name="paranoidWarnings">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.</param>
+ /// <param name="useBetaChannel">Whether to show beta versions as valid updates.</param>
+ /// <param name="gitHubProjectName">SMAPI's GitHub project name, used to perform update checks.</param>
+ /// <param name="webApiBaseUrl">The base URL for SMAPI's web API, used to perform update checks.</param>
+ /// <param name="verboseLogging">Whether SMAPI should log more information about the game context.</param>
+ /// <param name="rewriteMods">Whether SMAPI should rewrite mods for compatibility.</param>
+ /// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
+ /// <param name="logNetworkTraffic">Whether SMAPI should log network traffic.</param>
+ /// <param name="consoleColors">The colors to use for text written to the SMAPI console.</param>
+ /// <param name="suppressUpdateChecks">The mod IDs SMAPI should ignore when performing update checks or validating update keys.</param>
+ public SConfig(bool developerMode, bool checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, bool verboseLogging, bool? rewriteMods, bool? aggressiveMemoryOptimizations, bool logNetworkTraffic, ColorSchemeConfig consoleColors, string[]? suppressUpdateChecks)
+ {
+ this.DeveloperMode = developerMode;
+ this.CheckForUpdates = checkForUpdates;
+ this.ParanoidWarnings = paranoidWarnings ?? (bool)SConfig.DefaultValues[nameof(SConfig.ParanoidWarnings)];
+ this.UseBetaChannel = useBetaChannel ?? (bool)SConfig.DefaultValues[nameof(SConfig.UseBetaChannel)];
+ this.GitHubProjectName = gitHubProjectName;
+ this.WebApiBaseUrl = webApiBaseUrl;
+ this.VerboseLogging = verboseLogging;
+ this.RewriteMods = rewriteMods ?? (bool)SConfig.DefaultValues[nameof(SConfig.RewriteMods)];
+ this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations ?? (bool)SConfig.DefaultValues[nameof(SConfig.AggressiveMemoryOptimizations)];
+ this.LogNetworkTraffic = logNetworkTraffic;
+ this.ConsoleColors = consoleColors;
+ this.SuppressUpdateChecks = suppressUpdateChecks ?? Array.Empty<string>();
+ }
+
+ /// <summary>Override the value of <see cref="DeveloperMode"/>.</summary>
+ /// <param name="value">The value to set.</param>
+ public void OverrideDeveloperMode(bool value)
+ {
+ this.DeveloperMode = value;
+ }
+
/// <summary>Get the settings which have been customized by the player.</summary>
- public IDictionary<string, object> GetCustomSettings()
+ public IDictionary<string, object?> GetCustomSettings()
{
- IDictionary<string, object> custom = new Dictionary<string, object>();
+ Dictionary<string, object?> custom = new();
- foreach (var pair in SConfig.DefaultValues)
+ foreach ((string? name, object defaultValue) in SConfig.DefaultValues)
{
- object value = typeof(SConfig).GetProperty(pair.Key)?.GetValue(this);
- if (!pair.Value.Equals(value))
- custom[pair.Key] = value;
+ object? value = typeof(SConfig).GetProperty(name)?.GetValue(this);
+ if (!defaultValue.Equals(value))
+ custom[name] = value;
}
- HashSet<string> curSuppressUpdateChecks = new HashSet<string>(this.SuppressUpdateChecks ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
+ HashSet<string> curSuppressUpdateChecks = new(this.SuppressUpdateChecks, StringComparer.OrdinalIgnoreCase);
if (SConfig.DefaultSuppressUpdateChecks.Count != curSuppressUpdateChecks.Count || SConfig.DefaultSuppressUpdateChecks.Any(p => !curSuppressUpdateChecks.Contains(p)))
- custom[nameof(this.SuppressUpdateChecks)] = "[" + string.Join(", ", this.SuppressUpdateChecks ?? Array.Empty<string>()) + "]";
+ custom[nameof(this.SuppressUpdateChecks)] = "[" + string.Join(", ", this.SuppressUpdateChecks) + "]";
return custom;
}