fix(settings): an imported ini moved to the trains' tapes too, a closed tape window forgets only its own tape

- ImportFrom moves an ini of before the trains' tapes as a profile is
- HaslerTapes.Forget takes the file: a window closing lets go of its own tape, not of the one
  another window follows
This commit is contained in:
maj00r
2026-11-16 00:09:36 +01:00
parent 13990a7036
commit 76693c1494
5 changed files with 50 additions and 5 deletions

View File

@@ -182,6 +182,26 @@ public class HaslerTapeTests
Assert.Equal(18, Assert.Single(tapes.Load(file, follow: true)!.Samples).SpeedKmh, 6); Assert.Equal(18, Assert.Single(tapes.Load(file, follow: true)!.Samples).SpeedKmh, 6);
} }
[Fact]
public void Forgetting_another_file_keeps_the_followed_tape_and_its_own_lets_it_go()
{
string Lines(int firstSpeed, int count) =>
Header + Line(0, firstSpeed, 0, 0) + string.Concat(Enumerable.Range(1, count).Select(t => Line(t, 36, 0, 0)));
string path = TestInstallation.At("physicslog", "EU07-424.dat");
var files = new InMemoryFileSystem().WithFile(path, Lines(36, 20));
var tapes = new TestInstallation(files).Tapes;
var file = Assert.Single(tapes.List());
tapes.Load(file, follow: false);
// the first line changed, as long as it was and far from the end: a tape still followed doesn't read it again
files.WithFile(path, Lines(72, 21));
tapes.Forget(TestInstallation.At("physicslog", "EU07-111.dat"));
Assert.Equal(36, tapes.Load(file, follow: true)!.Samples[0].SpeedKmh, 6);
tapes.Forget(file.Path);
Assert.Equal(72, tapes.Load(file, follow: true)!.Samples[0].SpeedKmh, 6);
}
[Fact] [Fact]
public void The_sample_under_a_point_of_the_tape_is_found_by_time_and_by_distance() public void The_sample_under_a_point_of_the_tape_is_found_by_time_and_by_distance()
{ {

View File

@@ -1436,6 +1436,24 @@ public class SettingsStoreTests
Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains); Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains);
} }
[Fact]
public void An_imported_ini_from_before_the_tapes_of_the_trains_is_moved_as_a_profile_is()
{
string backup = Path.Combine("/home/kolejarz", "backup", "eu07.ini");
var files = new InMemoryFileSystem()
.WithFile(UserIni, "physicslog yes\nphysicslog.trains no\n")
.WithFile(backup, "physicslog yes\nblackbox yes\n");
var store = WithHome(files).SettingsStore;
store.Load();
Assert.True(store.ImportFrom(backup));
store.Save();
Assert.False(store.Settings.PhysicsLog);
Assert.True(store.Settings.PhysicsLogTrains);
Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
}
[Fact] [Fact]
public void Once_moved_the_physics_log_of_every_vehicle_turned_on_again_stays_on() public void Once_moved_the_physics_log_of_every_vehicle_turned_on_again_stays_on()
{ {

View File

@@ -458,11 +458,15 @@ public sealed class HaslerTapes
public HaslerTape? Load(TapeFile file) => Load(file, follow: false); public HaslerTape? Load(TapeFile file) => Load(file, follow: false);
/// <summary>No tape followed any more: what was kept of the last one is let go.</summary> /// <summary>
public void Forget() /// The tape of this file no longer followed: what was kept of it is let go. Another file's, followed for another
/// window, stays.
/// </summary>
public void Forget(string path)
{ {
lock (_followedLock) lock (_followedLock)
_followed = null; if (_followed?.Path == path)
_followed = null;
} }
// what the file has between the two: less, up to its end, when it was cut shorter since its length was taken // what the file has between the two: less, up to its end, when it was cut shorter since its length was taken

View File

@@ -236,6 +236,8 @@ public sealed class SettingsStore
s.WindowMaximized = maximized; s.WindowMaximized = maximized;
s.CabLampLight = cabLampLight; s.CabLampLight = cabLampLight;
s.DepthPrepassScene = depthPrepassScene; s.DepthPrepassScene = depthPrepassScene;
// an ini of before the tapes of the trains goes the same way as a profile
SettingsSerializer.MoveToTrainTapes(s);
return true; return true;
} }

View File

@@ -230,7 +230,8 @@ public sealed class HaslerTapeWindow : Window
{ {
_closed = true; _closed = true;
_timer.Stop(); _timer.Stop();
_tapes.Forget(); if (_shown is { } shown)
_tapes.Forget(shown.Path);
}; };
} }
@@ -648,7 +649,7 @@ public sealed class HaslerTapeWindow : Window
var tape = await Task.Run(() => _tapes.Load(file, follow)); var tape = await Task.Run(() => _tapes.Load(file, follow));
if (_closed) if (_closed)
{ {
_tapes.Forget(); _tapes.Forget(file.Path);
return; return;
} }
bool another = file.Path != _shown?.Path; bool another = file.Path != _shown?.Path;