From faa06fb9d8320251ee03be48fdb64fb44c184e6c Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 16 Nov 2026 01:24:17 +0100 Subject: [PATCH] fix(settings): a profile or an ini exported takes the page's edits in a copy, so discarding them still works Saving a profile or exporting eu07.ini captured the page's edits into the settings held, so discarding them before a start showed them again and the start's save wrote them. The export writes a copy with the edits in; the settings held stay as saved. --- StarterNG.Tests/SettingsStoreTests.cs | 16 ++++++++++++++++ StarterNG/Application/SettingsStore.cs | 5 +++-- StarterNG/Views/Settings.Graphics.cs | 5 ++--- StarterNG/Views/Settings.axaml.cs | 5 ++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/StarterNG.Tests/SettingsStoreTests.cs b/StarterNG.Tests/SettingsStoreTests.cs index 8b7dd7e..68c1730 100644 --- a/StarterNG.Tests/SettingsStoreTests.cs +++ b/StarterNG.Tests/SettingsStoreTests.cs @@ -1274,6 +1274,22 @@ public class SettingsStoreTests Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8)); } + [Fact] + public void A_profile_exported_from_a_pages_edits_leaves_the_settings_held_and_the_ini_alone() + { + var files = new InMemoryFileSystem().WithFile(UserIni, "fieldofview 45\n"); + var store = WithHome(files).SettingsStore; + store.Load(); + var edited = store.Settings.Copy(); + edited.FieldOfView = 60; + + Assert.True(store.ExportTo(Profile, edited)); + + Assert.Contains("fieldofview 60", files.ReadAllText(Profile, System.Text.Encoding.UTF8)); + Assert.Equal(45, store.Settings.FieldOfView); + Assert.Contains("fieldofview 45", files.ReadAllText(UserIni, System.Text.Encoding.UTF8)); + } + [Fact] public void A_missing_profile_leaves_the_settings_as_they_are() { diff --git a/StarterNG/Application/SettingsStore.cs b/StarterNG/Application/SettingsStore.cs index 28d340f..036bf80 100644 --- a/StarterNG/Application/SettingsStore.cs +++ b/StarterNG/Application/SettingsStore.cs @@ -245,7 +245,8 @@ public sealed class SettingsStore /// Writes the settings as a complete eu07.ini somewhere else - this user's file /// with the settings applied - leaving the file itself and its state alone. /// - public bool ExportTo(string path) + /// What to write, when not the settings held: a page's edits, still not taken in. + public bool ExportTo(string path, SimulatorSettings? settings = null) { if (LoadFailed) { @@ -254,7 +255,7 @@ public sealed class SettingsStore } var copy = ConfigFile.Parse(_config.ToText()); - ApplyChanges(copy, Changes(Settings)); + ApplyChanges(copy, Changes(settings ?? Settings)); try { diff --git a/StarterNG/Views/Settings.Graphics.cs b/StarterNG/Views/Settings.Graphics.cs index 52e8146..a9114ee 100644 --- a/StarterNG/Views/Settings.Graphics.cs +++ b/StarterNG/Views/Settings.Graphics.cs @@ -328,9 +328,8 @@ public partial class Settings return; // The edits on screen go into the export as they would into a save, but the - // user's own eu07.ini is not written. - CaptureInto(AppServices.Current.Settings); - if (!AppServices.Current.SettingsStore.ExportTo(path)) + // user's own eu07.ini is not written, nor the settings held: the edits stay the page's, not saved. + if (!AppServices.Current.SettingsStore.ExportTo(path, Trial())) { await MessageBox.Show(owner, string.Format(App.Loc["ExportIniFailed"], path), App.Loc["ExportIni"], MessageBoxButtons.Ok); diff --git a/StarterNG/Views/Settings.axaml.cs b/StarterNG/Views/Settings.axaml.cs index 0b9e00d..648b1d1 100644 --- a/StarterNG/Views/Settings.axaml.cs +++ b/StarterNG/Views/Settings.axaml.cs @@ -235,9 +235,8 @@ public partial class Settings : UserControl, ISettingsCapture App.Loc["ProfileSaveAs"], MessageBoxButtons.YesNo)) return; - // Written beside the user's own eu07.ini, which stays as it is. - CaptureInto(AppServices.Current.Settings); - bool saved = AppServices.Current.SettingsStore.ExportTo(path); + // Written beside the user's own eu07.ini, which stays as it is; the edits stay the page's, not saved + bool saved = AppServices.Current.SettingsStore.ExportTo(path, Trial()); PopulateProfileCombo(); int idx = FindComboIndexByContent(ProfileCb, Path.GetFileNameWithoutExtension(path)); if (idx >= 0) ProfileCb.SelectedIndex = idx;