From c10d771f00f7802ef975d9d3cb0a5a9d72c38d37 Mon Sep 17 00:00:00 2001 From: maj00r Date: Tue, 3 Nov 2026 21:51:53 +0100 Subject: [PATCH] Save a profile without taking it for a save of eu07.ini A profile went through the save of eu07.ini with another path: what the store holds of the file took the changes the file never got, and the list of changes was empty after it. A profile is now written as an export, from a copy. Like a save, an export is not written from defaults when the settings could not be read. --- StarterNG.Tests/SettingsStoreTests.cs | 17 ++++++++++++++++- StarterNG/Application/SettingsStore.cs | 8 +++++++- StarterNG/Views/Settings.axaml.cs | 6 +++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/StarterNG.Tests/SettingsStoreTests.cs b/StarterNG.Tests/SettingsStoreTests.cs index fd13e4f..c2b0169 100644 --- a/StarterNG.Tests/SettingsStoreTests.cs +++ b/StarterNG.Tests/SettingsStoreTests.cs @@ -1,3 +1,4 @@ +using StarterNG.Application; using StarterNG.Domain.Settings; using StarterNG.Tests.Fakes; @@ -564,11 +565,25 @@ public class SettingsStoreTests var installation = WithHome(files); installation.SettingsStore.Load(); - installation.SettingsStore.SaveTo(profile); + Assert.False(installation.SettingsStore.ExportTo(profile)); Assert.False(files.FileExists(profile)); } + [Fact] + public void A_profile_written_leaves_what_the_users_file_still_lacks_to_be_saved() + { + var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "uart COM3 57600 0.1\n")); + installation.SettingsStore.Load(); + installation.SettingsStore.Settings.UartPort = "COM4"; + + Assert.True(installation.SettingsStore.ExportTo("/home/kolejarz/profile.ini")); + + Assert.Contains(new IniChange("uart", "COM3 57600 0.1", "COM4 57600 0.1"), + installation.SettingsStore.Changes(installation.SettingsStore.Settings)); + Assert.Contains("uart COM3 57600 0.1", installation.Files.ReadAllText(UserIni)); + } + [Fact] public void A_read_that_works_again_lets_the_settings_be_saved() { diff --git a/StarterNG/Application/SettingsStore.cs b/StarterNG/Application/SettingsStore.cs index 16a422a..4755f46 100644 --- a/StarterNG/Application/SettingsStore.cs +++ b/StarterNG/Application/SettingsStore.cs @@ -148,7 +148,7 @@ public sealed class SettingsStore SaveTo(_savePath); } - public void SaveTo(string path) + private void SaveTo(string path) { LastSaveFailed = true; if (LoadFailed) @@ -242,6 +242,12 @@ public sealed class SettingsStore /// public bool ExportTo(string path) { + if (LoadFailed) + { + _log.Log($"{path} not written: the settings could not be read, what is held is defaults"); + return false; + } + var copy = ConfigFile.Parse(_config.ToText()); ApplyChanges(copy, Changes(Settings)); diff --git a/StarterNG/Views/Settings.axaml.cs b/StarterNG/Views/Settings.axaml.cs index e0d15c6..aecbad4 100644 --- a/StarterNG/Views/Settings.axaml.cs +++ b/StarterNG/Views/Settings.axaml.cs @@ -235,13 +235,13 @@ public partial class Settings : UserControl, ISettingsCapture App.Loc["ProfileSaveAs"], MessageBoxButtons.YesNo)) return; - var store = AppServices.Current.SettingsStore; + // Written beside the user's own eu07.ini, which stays as it is. CaptureInto(AppServices.Current.Settings); - store.SaveTo(path); + bool saved = AppServices.Current.SettingsStore.ExportTo(path); PopulateProfileCombo(); int idx = FindComboIndexByContent(ProfileCb, Path.GetFileNameWithoutExtension(path)); if (idx >= 0) ProfileCb.SelectedIndex = idx; - SaveStatus.Text = string.Format(App.Loc[store.LastSaveFailed ? "ProfileNotSaved" : "ProfileSaved"], name); + SaveStatus.Text = string.Format(App.Loc[saved ? "ProfileSaved" : "ProfileNotSaved"], name); } private void PopulateExeCombo()