using System;
using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI.Internal.ConsoleWriting;
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)] = Constants.IsDebugBuild,
[nameof(UseBetaChannel)] = Constants.ApiVersion.IsPrerelease(),
[nameof(GitHubProjectName)] = "Pathoschild/SMAPI",
[nameof(WebApiBaseUrl)] = "https://smapi.io/api/",
[nameof(VerboseLogging)] = false,
[nameof(LogNetworkTraffic)] = false
};
/// The default values for , to log changes if different.
private static readonly HashSet DefaultSuppressUpdateChecks = new HashSet(StringComparer.OrdinalIgnoreCase)
{
"SMAPI.ConsoleCommands",
"SMAPI.SaveBackup"
};
/********
** Accessors
********/
/// Whether to enable development features.
public bool DeveloperMode { get; set; }
/// Whether to check for newer versions of SMAPI and mods on startup.
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; } = (bool)SConfig.DefaultValues[nameof(SConfig.ParanoidWarnings)];
/// Whether to show beta versions as valid updates.
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; }
/// The base URL for SMAPI's web API, used to perform update checks.
public string WebApiBaseUrl { get; set; }
/// Whether SMAPI should log more information about the game context.
public bool VerboseLogging { get; set; }
/// Whether SMAPI should log network traffic. Best combined with , which includes network metadata.
public bool LogNetworkTraffic { get; set; }
/// The colors to use for text written to the SMAPI console.
public ColorSchemeConfig ConsoleColors { get; set; }
/// 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.OrdinalIgnoreCase);
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;
}
}
}