diff --git a/StarterNG.Tests/HaslerTapeTests.cs b/StarterNG.Tests/HaslerTapeTests.cs index 15e2934..43bc9c3 100644 --- a/StarterNG.Tests/HaslerTapeTests.cs +++ b/StarterNG.Tests/HaslerTapeTests.cs @@ -182,6 +182,26 @@ public class HaslerTapeTests 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] public void The_sample_under_a_point_of_the_tape_is_found_by_time_and_by_distance() { diff --git a/StarterNG.Tests/SettingsStoreTests.cs b/StarterNG.Tests/SettingsStoreTests.cs index 2913880..8b7dd7e 100644 --- a/StarterNG.Tests/SettingsStoreTests.cs +++ b/StarterNG.Tests/SettingsStoreTests.cs @@ -1436,6 +1436,24 @@ public class SettingsStoreTests 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] public void Once_moved_the_physics_log_of_every_vehicle_turned_on_again_stays_on() { diff --git a/StarterNG/Application/HaslerTapes.cs b/StarterNG/Application/HaslerTapes.cs index 46ab209..9ba7fed 100644 --- a/StarterNG/Application/HaslerTapes.cs +++ b/StarterNG/Application/HaslerTapes.cs @@ -458,11 +458,15 @@ public sealed class HaslerTapes public HaslerTape? Load(TapeFile file) => Load(file, follow: false); - /// No tape followed any more: what was kept of the last one is let go. - 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. + /// + public void Forget(string path) { 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 diff --git a/StarterNG/Application/SettingsStore.cs b/StarterNG/Application/SettingsStore.cs index 8ad1dbd..28d340f 100644 --- a/StarterNG/Application/SettingsStore.cs +++ b/StarterNG/Application/SettingsStore.cs @@ -236,6 +236,8 @@ public sealed class SettingsStore s.WindowMaximized = maximized; s.CabLampLight = cabLampLight; s.DepthPrepassScene = depthPrepassScene; + // 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/Tapes/HaslerTapeWindow.cs b/StarterNG/Views/Tapes/HaslerTapeWindow.cs index 7283026..004338d 100644 --- a/StarterNG/Views/Tapes/HaslerTapeWindow.cs +++ b/StarterNG/Views/Tapes/HaslerTapeWindow.cs @@ -230,7 +230,8 @@ public sealed class HaslerTapeWindow : Window { _closed = true; _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)); if (_closed) { - _tapes.Forget(); + _tapes.Forget(file.Path); return; } bool another = file.Path != _shown?.Path;