fix(settings): a profile is not moved to physicslog.trains, and a closed tape window keeps nothing

- the one-time move runs on the player's own settings only; a profile from before it keeps
  physicslog as it was, and the player's mark of the move stays when it is applied
- a read of the tapes under way when the window closes is let go
This commit is contained in:
maj00r
2026-11-16 00:01:46 +01:00
parent f1d77addae
commit 5ab9bce321
3 changed files with 36 additions and 2 deletions

View File

@@ -1257,6 +1257,23 @@ public class SettingsStoreTests
Assert.False(store.LoadFailed);
}
[Fact]
public void A_profile_from_before_the_move_is_not_moved_and_keeps_the_players_mark()
{
var files = new InMemoryFileSystem()
.WithFile(UserIni, "starter.physicslog.moved yes\nphysicslog yes\n")
.WithFile(Profile, "physicslog yes\n");
var store = WithHome(files).SettingsStore;
store.Load();
Assert.True(store.TryLoadProfile(Profile));
store.Save();
Assert.True(store.Settings.PhysicsLog);
Assert.False(store.Settings.PhysicsLogTrains);
Assert.Contains("starter.physicslog.moved yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
}
[Fact]
public void A_missing_profile_leaves_the_settings_as_they_are()
{

View File

@@ -83,6 +83,9 @@ public sealed class SettingsStore
string source = _files.FileExists(_savePath) ? _savePath : _paths.InstallationConfigPath();
LoadedFrom = source;
LoadFrom(source);
// the player's own settings only, after the snapshot so the next save writes it; a profile is not moved
if (!LoadFailed)
SettingsSerializer.MovePhysicsLog(Settings);
}
/// <summary>A player with no settings of their own yet starts at High, in the file at once so the simulator goes by it too.</summary>
@@ -113,8 +116,6 @@ public sealed class SettingsStore
_serializer.Read(Settings, _config);
_synced = Render(Settings);
if (!LoadFailed)
SettingsSerializer.MovePhysicsLog(Settings);
TouchConfigAge();
}
@@ -126,9 +127,15 @@ public sealed class SettingsStore
{
if (_files.FileExists(path))
{
// a profile saved before the move has no mark of it: the player's mark is kept, so their own
// physicslog is not moved again at the next start
bool moved = Settings.PhysicsLogMoved;
LoadFrom(path);
if (!LoadFailed)
{
Settings.PhysicsLogMoved |= moved;
return true;
}
}
if (LoadFailed)

View File

@@ -73,6 +73,8 @@ public sealed class HaslerTapeWindow : Window
private bool _running;
private bool _loading;
private bool _looking;
// closed: a read already under way when it closed is let go, not kept followed
private bool _closed;
/// <summary>A setting went on from here; the settings page's boxes have to follow it.</summary>
public event Action? LogEnabled;
@@ -226,6 +228,7 @@ public sealed class HaslerTapeWindow : Window
Activated += (_, _) => ShowWhatIsKnown();
Closed += (_, _) =>
{
_closed = true;
_timer.Stop();
_tapes.Forget();
};
@@ -643,6 +646,11 @@ public sealed class HaslerTapeWindow : Window
// the same tape grown, as the simulator writes it: only what was added is read
bool follow = file.Path == _shown?.Path && file.Size >= _shown.Size;
var tape = await Task.Run(() => _tapes.Load(file, follow));
if (_closed)
{
_tapes.Forget();
return;
}
bool another = file.Path != _shown?.Path;
_shown = file;
_tapeless = null;
@@ -697,6 +705,8 @@ public sealed class HaslerTapeWindow : Window
try
{
var sessions = await Task.Run(_tapes.Sessions);
if (_closed)
return;
bool live = _live.IsChecked == true;
bool newDriven = live && DrivenTape(sessions) is { } driven && driven.Path != _followed;
if (newDriven || Fingerprint(sessions) != _listed)