From 81d62147294f7bc9a9c44114011cd1782ed14e74 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 1 Feb 2026 18:17:24 -0500 Subject: [PATCH] update Linux/macOS installer color scheme logic for 4.5.0+ changes The selected color scheme should now be set in `config.user.json` instead of `config.json`, and the field was renamed. --- docs/release-notes.md | 1 + src/SMAPI.Installer/InteractiveInstaller.cs | 37 ++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index debc1f8a..61c9652a 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,7 @@ # Release notes ## Upcoming release * For players: + * Fixed the Linux/macOS installer not saving the color scheme correctly in 4.5.0+. * Fixed typo in config UI text (thanks to QuentiumYT!). * Improved translations. Thanks to dewanggatrustha (updated Indonesian), QuentiumYT (updated French), and Timur13240 (updated Russian)! diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 714809fc..306a17ad 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Reflection; +using Newtonsoft.Json.Linq; using StardewModdingApi.Installer.Enums; using StardewModdingAPI.Installer.Framework; using StardewModdingAPI.Internal.ConsoleWriting; @@ -13,6 +14,7 @@ using StardewModdingAPI.Toolkit; using StardewModdingAPI.Toolkit.Framework; using StardewModdingAPI.Toolkit.Framework.GameScanning; using StardewModdingAPI.Toolkit.Framework.ModScanning; +using StardewModdingAPI.Toolkit.Serialization; using StardewModdingAPI.Toolkit.Utilities; namespace StardewModdingApi.Installer; @@ -501,10 +503,10 @@ internal class InteractiveInstaller // set SMAPI's color scheme if defined if (scheme != MonitorColorScheme.AutoDetect) { - string text = File - .ReadAllText(paths.ApiConfigPath) - .Replace(@"""UseScheme"": ""AutoDetect""", $@"""UseScheme"": ""{scheme}"""); - File.WriteAllText(paths.ApiConfigPath, text); + this.SaveUserSettings(paths.ApiUserConfigPath, new Dictionary + { + ["ConsoleColorScheme"] = scheme.ToString() + }); } } } @@ -559,6 +561,33 @@ internal class InteractiveInstaller } } + /// Save the given options to a SMAPI internal config file. + /// The file path to edit. + /// The settings to add or overwrite. + [SuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "This isn't an issue here, since we're only using JToken and object.")] + private void SaveUserSettings(string filePath, Dictionary settings) + { + JsonHelper jsonHelper = new(); + + // merge into existing settings + Dictionary saveSettings = settings.ToDictionary(p => p.Key, p => JToken.FromObject(p.Value)); + try + { + if (jsonHelper.ReadJsonFileIfExists(filePath, out Dictionary? fileSettings)) + { + foreach ((string key, JToken value) in fileSettings) + saveSettings.TryAdd(key, value); + } + } + catch (Exception ex) + { + this.PrintWarning($"Couldn't parse your SMAPI settings file. Replacing it with a default version.\n\nTechnical details:\n{ex}"); + } + + // save file + jsonHelper.WriteJsonFile(filePath, saveSettings); + } + /// Print a message without formatting. /// The text to print. private void PrintPlain(string text)