diff options
-rw-r--r-- | src/StardewModdingAPI/Constants.cs | 3 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 33 | ||||
-rw-r--r-- | src/StardewModdingAPI/StardewModdingAPI.config.json | 1 |
3 files changed, 21 insertions, 16 deletions
diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 57a89e76..6df9b76c 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -68,6 +68,9 @@ namespace StardewModdingAPI /// <summary>The file path to the error log where the latest output should be saved.</summary> public static string LogPath => Path.Combine(Constants.LogDir, "MODDED_ProgramLog.Log_LATEST.txt"); + /// <summary>The file path for the SMAPI configuration file.</summary> + internal static string ApiConfigPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.config.json"); + /********* ** Protected methods diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index f2d7faa8..e316dbd8 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -49,8 +49,8 @@ namespace StardewModdingAPI /// <summary>The core logger for SMAPI.</summary> private static readonly Monitor Monitor = new Monitor("SMAPI", Program.LogFile); - /// <summary>Whether SMAPI is running in developer mode.</summary> - private static bool DeveloperMode; + /// <summary>The user settings for SMAPI.</summary> + private static UserSettings Settings; /// <summary>Tracks whether the game should exit immediately and any pending initialisation should be cancelled.</summary> private static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource(); @@ -100,26 +100,29 @@ namespace StardewModdingAPI // add info header Program.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Game1.version} on {Environment.OSVersion}", LogLevel.Info); - // load user settings + // initialise user settings { - string settingsFileName = $"{typeof(Program).Assembly.GetName().Name}.config.json"; - string settingsPath = Path.Combine(Constants.ExecutionPath, settingsFileName); + string settingsPath = Constants.ApiConfigPath; if (File.Exists(settingsPath)) { string json = File.ReadAllText(settingsPath); - UserSettings settings = JsonConvert.DeserializeObject<UserSettings>(json); - Program.DeveloperMode = settings?.DeveloperMode == true; - - if (Program.DeveloperMode) - { - Program.Monitor.ShowTraceInConsole = true; - Program.Monitor.Log($"SMAPI is running in developer mode. The console may be much more verbose. You can disable developer mode by deleting the {settingsFileName} file in the game directory.", LogLevel.Alert); - } + Program.Settings = JsonConvert.DeserializeObject<UserSettings>(json); } + else + Program.Settings = new UserSettings(); + + File.WriteAllText(settingsPath, JsonConvert.SerializeObject(Program.Settings, Formatting.Indented)); + } + + // add warning headers + if (Program.Settings.DeveloperMode) + { + Program.Monitor.ShowTraceInConsole = true; + Program.Monitor.Log($"SMAPI is running in developer mode. The console may be much more verbose. You can disable developer mode by editing or deleting {Constants.ApiConfigPath}.", LogLevel.Alert); } // initialise legacy log - Log.Monitor = new Monitor("legacy mod", Program.LogFile) { ShowTraceInConsole = Program.DeveloperMode }; + Log.Monitor = new Monitor("legacy mod", Program.LogFile) { ShowTraceInConsole = Program.Settings.DeveloperMode }; Log.ModRegistry = Program.ModRegistry; // hook into & launch the game @@ -478,7 +481,7 @@ namespace StardewModdingAPI // inject data mod.ModManifest = manifest; mod.Helper = helper; - mod.Monitor = new Monitor(manifest.Name, Program.LogFile) { ShowTraceInConsole = Program.DeveloperMode }; + mod.Monitor = new Monitor(manifest.Name, Program.LogFile) { ShowTraceInConsole = Program.Settings.DeveloperMode }; mod.PathOnDisk = directory; // track mod diff --git a/src/StardewModdingAPI/StardewModdingAPI.config.json b/src/StardewModdingAPI/StardewModdingAPI.config.json index d27d0141..771c28e2 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.config.json +++ b/src/StardewModdingAPI/StardewModdingAPI.config.json @@ -1,4 +1,3 @@ { - /* show all deprecation notices in the console? */ "DeveloperMode": true } |