From 34beec588d02594bfac10e23f1e7a82c5810e80c Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 22 Nov 2026 12:40:46 +0100 Subject: [PATCH] fix(settings): an import or a profile keeps the mode, the move keeps the card and GLES Importing an eu07.ini or applying a profile took starter.settings.standard and starter.settings.advanced from the other file. An older one says "standard no", so the next start moved the player again and reset what was just imported, this time with no copy kept; "advanced yes" opened the advanced mode past the warning. Both are now this installation's, like its simulator and its card. The one-time move to the standard mode no longer resets starter.gpu and gfx.usegles: some machines run the simulator only on the integrated card or with OpenGL ES, and the move is done without asking. --- StarterNG.Tests/SettingsStoreTests.cs | 51 ++++++++++++++++++++++++++ StarterNG/Application/SettingsStore.cs | 31 ++++++++++++++++ StarterNG/Views/Settings.axaml.cs | 4 +- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/StarterNG.Tests/SettingsStoreTests.cs b/StarterNG.Tests/SettingsStoreTests.cs index 74fd1de..62e4557 100644 --- a/StarterNG.Tests/SettingsStoreTests.cs +++ b/StarterNG.Tests/SettingsStoreTests.cs @@ -1466,6 +1466,57 @@ public class SettingsStoreTests Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains); } + // An older file says "standard no": taken in, it would move the player again on the next + // start, and its "advanced yes" would open the advanced mode past the warning. + private const string OlderModeLines = "starter.settings.standard no\nstarter.settings.advanced yes\nfieldofview 50\n"; + + [Fact] + public void An_imported_ini_leaves_the_mode_as_this_installation_has_it() + { + string backup = Path.Combine("/home/kolejarz", "backup", "eu07.ini"); + var files = new InMemoryFileSystem() + .WithFile(UserIni, "starter.settings.standard yes\nstarter.settings.advanced no\n") + .WithFile(backup, OlderModeLines); + var store = WithHome(files).SettingsStore; + store.Load(); + + Assert.True(store.ImportFrom(backup)); + store.Save(); + + Assert.Equal(50, store.Settings.FieldOfView); + Assert.True(store.Settings.MovedToStandard); + Assert.False(store.Settings.AdvancedSettings); + string written = files.ReadAllText(UserIni, System.Text.Encoding.UTF8); + Assert.Contains("starter.settings.standard yes", written); + Assert.Contains("starter.settings.advanced no", written); + } + + [Fact] + public void A_profile_leaves_the_mode_as_this_installation_has_it() + { + var files = new InMemoryFileSystem() + .WithFile(UserIni, "starter.settings.standard yes\nstarter.settings.advanced no\n") + .WithFile(Profile, OlderModeLines); + var store = WithHome(files).SettingsStore; + store.Load(); + + Assert.True(store.TryLoadProfile(Profile)); + store.Save(); + + Assert.Equal(50, store.Settings.FieldOfView); + Assert.True(store.Settings.MovedToStandard); + Assert.False(store.Settings.AdvancedSettings); + string written = files.ReadAllText(UserIni, System.Text.Encoding.UTF8); + Assert.Contains("starter.settings.standard yes", written); + Assert.Contains("starter.settings.advanced no", written); + } + + [Theory] + [InlineData("starter.gpu")] + [InlineData("gfx.usegles")] + public void The_move_to_the_standard_mode_keeps_what_lets_a_machine_run_the_simulator(string key) => + Assert.Contains(key, StarterNG.Application.SettingsStore.KeptOnMoveToStandard); + [Fact] public void An_imported_ini_from_before_the_tapes_of_the_trains_is_moved_as_a_profile_is() { diff --git a/StarterNG/Application/SettingsStore.cs b/StarterNG/Application/SettingsStore.cs index 6c7d358..feb7937 100644 --- a/StarterNG/Application/SettingsStore.cs +++ b/StarterNG/Application/SettingsStore.cs @@ -144,6 +144,31 @@ public sealed class SettingsStore TouchConfigAge(); } + /// + /// What lets some machines run the simulator at all: the card it is put on (offloading + /// to the discrete one fails with some drivers) and OpenGL ES where desktop OpenGL does + /// not work. The move to the standard mode, done without asking, leaves them as they are. + /// + public static readonly IReadOnlySet KeptOnMoveToStandard = + new HashSet(StringComparer.OrdinalIgnoreCase) { "starter.gpu", "gfx.usegles" }; + + /// + /// The mode is this installation's, like its simulator and its card: another file, a + /// backup or a profile of an older starter, says nothing of it. Without this, its + /// "starter.settings.standard no" would move the player again on the next start, and its + /// "starter.settings.advanced yes" would open the advanced mode past the warning. + /// The returned action puts the mode back as it was when this was called. + /// + private Action KeepMode() + { + bool advanced = Settings.AdvancedSettings, moved = Settings.MovedToStandard; + return () => + { + Settings.AdvancedSettings = advanced; + Settings.MovedToStandard = moved; + }; + } + /// /// Reads a profile into the settings; true when it read cleanly. A read that failed /// would leave defaults to be saved over the real settings, so those are read again. @@ -152,9 +177,13 @@ public sealed class SettingsStore { if (_files.FileExists(path)) { + var mode = KeepMode(); LoadFrom(path); if (!LoadFailed) + { + mode(); return true; + } } if (LoadFailed) @@ -262,6 +291,7 @@ public sealed class SettingsStore var gpu = s.Gpu; string lastScenery = s.LastScenery; bool maximized = s.WindowMaximized; + var mode = KeepMode(); _serializer.Read(s, imported); @@ -270,6 +300,7 @@ public sealed class SettingsStore s.Gpu = gpu; s.LastScenery = lastScenery; s.WindowMaximized = maximized; + mode(); // an ini of before the tapes of the trains goes the same way as a profile SettingsSerializer.MoveToTrainTapes(s); return true; diff --git a/StarterNG/Views/Settings.axaml.cs b/StarterNG/Views/Settings.axaml.cs index 183fd27..58112d7 100644 --- a/StarterNG/Views/Settings.axaml.cs +++ b/StarterNG/Views/Settings.axaml.cs @@ -1419,10 +1419,12 @@ public partial class Settings : UserControl, ISettingsCapture return; store.KeepCopy(".before-standard"); + var moved = AdvancedKeys(); + moved.ExceptWith(SettingsStore.KeptOnMoveToStandard); _clamping = true; try { - ShowDefaults(AdvancedKeys()); + ShowDefaults(moved); } finally {