From 61d857c41fc2b90cd495c4923251cb1ed472e5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCssig?= Date: Sat, 2 Apr 2022 03:47:52 +0200 Subject: [PATCH 1/3] Added support for `--developer-mode true|false` Minimal changes required to enable/disable developer mode via command line argument. This commit does not include any error handling for invalid values how ever they will be ignored and not crash the game. --- src/SMAPI/Framework/SCore.cs | 10 +++++++++- src/SMAPI/Program.cs | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index b4aa3595..801a7237 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -168,7 +168,8 @@ namespace StardewModdingAPI.Framework /// Construct an instance. /// The path to search for mods. /// Whether to output log messages to the console. - public SCore(string modsPath, bool writeToConsole) + /// null if not modified else whether to use developer mode + public SCore(string modsPath, bool writeToConsole, bool? developerModeValue) { SCore.Instance = this; @@ -183,6 +184,13 @@ namespace StardewModdingAPI.Framework // init basics this.Settings = JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiConfigPath)); + + // temporary overwrite DeveloperMode Setting + if (developerModeValue.HasValue) + { + this.Settings.DeveloperMode = developerModeValue.Value; + } + if (File.Exists(Constants.ApiUserConfigPath)) JsonConvert.PopulateObject(File.ReadAllText(Constants.ApiUserConfigPath), this.Settings); diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index f2f65287..32bf0bdd 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -179,15 +179,30 @@ namespace StardewModdingAPI bool writeToConsole = !args.Contains("--no-terminal") && Environment.GetEnvironmentVariable("SMAPI_NO_TERMINAL") == null; // get mods path + bool? developerModeValue = null; string modsPath; { string rawModsPath = null; - // get from command line args + // get mods path from command line args int pathIndex = Array.LastIndexOf(args, "--mods-path") + 1; if (pathIndex >= 1 && args.Length >= pathIndex) rawModsPath = args[pathIndex]; + // get developer mode from command line args + int developerModeValueIndex = Array.LastIndexOf(args, "--developer-mode") + 1; + if (developerModeValueIndex >= 1 && args.Length >= developerModeValueIndex) + { + if (args[developerModeValueIndex].ToLower().Equals("true")) + { + developerModeValue = true; + } + else if (args[developerModeValueIndex].ToLower().Equals("false")) + { + developerModeValue = false; + } + } + // get from environment variables if (string.IsNullOrWhiteSpace(rawModsPath)) rawModsPath = Environment.GetEnvironmentVariable("SMAPI_MODS_PATH"); @@ -199,7 +214,7 @@ namespace StardewModdingAPI } // load SMAPI - using SCore core = new SCore(modsPath, writeToConsole); + using SCore core = new SCore(modsPath, writeToConsole, developerModeValue); core.RunInteractively(); } From 092f0aa4eaa23c169c1ca5e8b213915f563f5053 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 9 Apr 2022 11:52:20 -0400 Subject: [PATCH 2/3] simplify format for new CLI arguments --- src/SMAPI/Framework/SCore.cs | 11 +++-------- src/SMAPI/Program.cs | 22 +++++++--------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 801a7237..4746c2ce 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -168,8 +168,8 @@ namespace StardewModdingAPI.Framework /// Construct an instance. /// The path to search for mods. /// Whether to output log messages to the console. - /// null if not modified else whether to use developer mode - public SCore(string modsPath, bool writeToConsole, bool? developerModeValue) + /// Whether to enable development features, or null to use the value from the settings file. + public SCore(string modsPath, bool writeToConsole, bool? developerMode) { SCore.Instance = this; @@ -184,12 +184,7 @@ namespace StardewModdingAPI.Framework // init basics this.Settings = JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiConfigPath)); - - // temporary overwrite DeveloperMode Setting - if (developerModeValue.HasValue) - { - this.Settings.DeveloperMode = developerModeValue.Value; - } + this.Settings.DeveloperMode = developerMode ?? this.Settings.DeveloperMode; if (File.Exists(Constants.ApiUserConfigPath)) JsonConvert.PopulateObject(File.ReadAllText(Constants.ApiUserConfigPath), this.Settings); diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 32bf0bdd..1e3b2000 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -179,7 +179,7 @@ namespace StardewModdingAPI bool writeToConsole = !args.Contains("--no-terminal") && Environment.GetEnvironmentVariable("SMAPI_NO_TERMINAL") == null; // get mods path - bool? developerModeValue = null; + bool? developerMode = null; string modsPath; { string rawModsPath = null; @@ -190,31 +190,23 @@ namespace StardewModdingAPI rawModsPath = args[pathIndex]; // get developer mode from command line args - int developerModeValueIndex = Array.LastIndexOf(args, "--developer-mode") + 1; - if (developerModeValueIndex >= 1 && args.Length >= developerModeValueIndex) - { - if (args[developerModeValueIndex].ToLower().Equals("true")) - { - developerModeValue = true; - } - else if (args[developerModeValueIndex].ToLower().Equals("false")) - { - developerModeValue = false; - } - } + if (args.Contains("--developer-mode")) + developerMode = true; + if (args.Contains("--developer-mode-off")) + developerMode = false; // get from environment variables if (string.IsNullOrWhiteSpace(rawModsPath)) rawModsPath = Environment.GetEnvironmentVariable("SMAPI_MODS_PATH"); - // normalise + // normalize modsPath = !string.IsNullOrWhiteSpace(rawModsPath) ? Path.Combine(Constants.GamePath, rawModsPath) : Constants.DefaultModsPath; } // load SMAPI - using SCore core = new SCore(modsPath, writeToConsole, developerModeValue); + using SCore core = new SCore(modsPath, writeToConsole, developerMode); core.RunInteractively(); } From 6161cc91297dd215a35bfd4d8862d27a0d937898 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 9 Apr 2022 11:54:23 -0400 Subject: [PATCH 3/3] fix config.user.json overriding new CLI arguments --- src/SMAPI/Framework/SCore.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 4746c2ce..44f46179 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -184,10 +184,9 @@ namespace StardewModdingAPI.Framework // init basics this.Settings = JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiConfigPath)); - this.Settings.DeveloperMode = developerMode ?? this.Settings.DeveloperMode; - if (File.Exists(Constants.ApiUserConfigPath)) JsonConvert.PopulateObject(File.ReadAllText(Constants.ApiUserConfigPath), this.Settings); + this.Settings.DeveloperMode = developerMode ?? this.Settings.DeveloperMode; this.LogManager = new LogManager(logPath: logPath, colorConfig: this.Settings.ConsoleColors, writeToConsole: writeToConsole, isVerbose: this.Settings.VerboseLogging, isDeveloperMode: this.Settings.DeveloperMode, getScreenIdForLog: this.GetScreenIdForLog); this.CommandManager = new CommandManager(this.Monitor);