Compare commits

..

3 Commits

Author SHA1 Message Date
maj00r
f29ce10f5c fix: a simulator copied in while the starter runs is on the list
The list of simulators in the settings was filled when they opened, so a new
eu07*.exe from CI or one's own build stayed missing until the starter was
reopened, and the older file was easy to start by mistake. The folder is now
looked at again when the settings page is shown, when the list takes focus
and when the window comes back to the front.

Looking again never changes the choice: a file picked from elsewhere, or one
since removed, stays chosen rather than falling back to automatic, and
nothing waits for Save after it. A list that did not change is left alone.

Closes #48
2026-11-15 21:13:53 +01:00
maj00r
744720d922 Merge pull request #44 from MaSzyna-EU07/fix/dotted-model-names
fix: a dot in a model name is part of the name, not an extension
2026-11-12 21:33:51 +01:00
maj00r
b5ba67430f fix: a dot in a model name is part of the name, not an extension
The 9-107 and 9-110 coal wagons (9-107.13.fiz and the like) found no physics, so no load could be set on them.
2026-11-12 20:57:36 +01:00
6 changed files with 140 additions and 10 deletions

View File

@@ -0,0 +1,53 @@
using StarterNG.Views;
namespace StarterNG.Tests;
public class ExecutableListTests
{
[Fact]
public void A_build_copied_in_joins_the_list_and_the_choice_stays()
{
var (entries, chosen) = ExecutableList.Refreshed(["eu07_new.exe", "eu07.exe"], "eu07.exe");
Assert.Equal(new[] { "eu07_new.exe", "eu07.exe" }, entries);
Assert.Equal(1, chosen);
}
[Fact]
public void Automatic_stays_automatic()
{
var (entries, chosen) = ExecutableList.Refreshed(["eu07_new.exe", "eu07.exe"], null);
Assert.Equal(new[] { "eu07_new.exe", "eu07.exe" }, entries);
Assert.Equal(-1, chosen);
}
[Fact]
public void A_simulator_picked_from_elsewhere_stays_on_the_list_and_chosen()
{
const string picked = @"D:\build\eu07.exe";
var (entries, chosen) = ExecutableList.Refreshed(["eu07.exe"], picked);
Assert.Equal(new[] { "eu07.exe", picked }, entries);
Assert.Equal(1, chosen);
}
[Fact]
public void A_chosen_file_since_removed_stays_chosen_rather_than_switch_silently()
{
var (entries, chosen) = ExecutableList.Refreshed(["eu07.exe"], "eu07_old.exe");
Assert.Equal(new[] { "eu07.exe", "eu07_old.exe" }, entries);
Assert.Equal(1, chosen);
}
[Fact]
public void The_choice_is_found_whatever_the_case_of_its_name()
{
var (entries, chosen) = ExecutableList.Refreshed(["EU07.exe"], "eu07.exe");
Assert.Equal(new[] { "EU07.exe" }, entries);
Assert.Equal(0, chosen);
}
}

View File

@@ -65,6 +65,19 @@ public class PhysicsAndAssetsTests
Assert.Equal(125, physics.VMax);
}
[Fact]
public void A_dot_in_the_model_name_is_part_of_the_name()
{
// As in the game: cd/9-107_v1 holds 9-107.13.fiz, 9-107.6.fiz and more.
var installation = new TestInstallation(new InMemoryFileSystem()
.WithFile(Fiz("cd", "9-107_v1", "9-107.13"), "Load: LoadAccepted=coal MaxLoad=58")
.WithFile(Fiz("cd", "9-107_v1", "9-107.6"), "Load: LoadAccepted=coal MaxLoad=55"));
Assert.Equal(58, installation.Physics.For("cd/9-107_v1/", "9-107.13")!.MaxLoad);
Assert.Equal(55, installation.Physics.For("cd/9-107_v1/", "9-107.6")!.MaxLoad);
Assert.Equal(58, installation.Physics.For("cd/9-107_v1/", "9-107.13.e3d")!.MaxLoad);
}
[Fact]
public void A_dumb_variant_stands_in_when_the_model_has_no_fiz_of_its_own()
{

View File

@@ -51,7 +51,7 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
if (string.IsNullOrEmpty(model))
return null;
string name = Path.GetFileNameWithoutExtension(model);
string name = Path.GetFileName(model);
if (name.Length == 0)
return null;
@@ -60,7 +60,10 @@ public sealed class FizPhysicsRepository : IPhysicsRepository
if (_cache.TryGetValue(key, out var cached))
return cached;
var physics = Read(folder, name);
// The name as written first: in 9-107.13 the dot is part of the name, not an extension.
string bare = Path.GetFileNameWithoutExtension(name);
var physics = Read(folder, name)
?? (bare.Length > 0 && bare != name ? Read(folder, bare) : null);
_cache[key] = physics;
return physics;
}

View File

@@ -108,7 +108,13 @@ public partial class MainWindow : Window
_sceneryFilesTimer.Start();
FollowLastRun();
};
Activated += (_, _) => CheckExternalSettings();
Activated += (_, _) =>
{
CheckExternalSettings();
// Back from a build or a download: a new simulator is on the list already.
if (SettingsView.IsVisible)
SettingsView.RefreshExecutables();
};
_sceneryFilesTimer.Tick += async (_, _) => await LookAtSceneryFilesAsync();
Closed += (_, _) => _sceneryFilesTimer.Stop();
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace StarterNG.Views;
/// <summary>
/// The simulators offered in the settings after the folder was looked at again: a build
/// copied in while the starter runs joins the list, and what was chosen stays chosen, even
/// a file picked from elsewhere or one since removed - looking again never changes the choice.
/// </summary>
public static class ExecutableList
{
/// <summary>The entries that follow "automatic", and the place of <paramref name="chosen"/> among them.</summary>
/// <param name="found">The simulators in the folder now, newest first.</param>
/// <param name="chosen">The entry chosen, or null for "automatic" or nothing chosen yet.</param>
/// <returns>Entries, and the index of the chosen one in them, -1 when <paramref name="chosen"/> is null.</returns>
public static (IReadOnlyList<string> Entries, int Chosen) Refreshed(IReadOnlyList<string> found, string? chosen)
{
var entries = found.ToList();
if (chosen is null)
return (entries, -1);
int at = entries.FindIndex(entry => string.Equals(entry, chosen, StringComparison.OrdinalIgnoreCase));
if (at >= 0)
return (entries, at);
entries.Add(chosen);
return (entries, entries.Count - 1);
}
}

View File

@@ -105,6 +105,13 @@ public partial class Settings : UserControl, ISettingsCapture
FeedbackCb.SelectionChanged += FeedbackCb_OnSelectionChanged;
SelectExeCb.SelectionChanged += (_, _) => UpdateIdleNotes();
// Coming to the page or to the list is when a new build is looked for.
SelectExeCb.GotFocus += (_, _) => RefreshExecutables();
PropertyChanged += (_, e) =>
{
if (e.Property == IsVisibleProperty && IsVisible)
RefreshExecutables();
};
FullscreenWindowedCb.IsCheckedChanged += (_, _) => UpdateIdleNotes();
App.Loc.LanguageChanged += UpdateIdleNotes;
App.Loc.LanguageChanged += UpdateGpuNote;
@@ -246,16 +253,33 @@ public partial class Settings : UserControl, ISettingsCapture
private void PopulateExeCombo()
{
string? current = (SelectExeCb.SelectedItem as ComboBoxItem)?.Content?.ToString();
int index = SelectExeCb.SelectedIndex;
string? chosen = index > 0 ? (SelectExeCb.SelectedItem as ComboBoxItem)?.Content?.ToString() : null;
var (entries, at) = ExecutableList.Refreshed(AppServices.Current.Executables.ListCandidates(), chosen);
// The same files as shown: left alone, so a reader on the list hears nothing change.
var shown = SelectExeCb.Items.Skip(1).Select(item => (item as ComboBoxItem)?.Content?.ToString() ?? "");
if (SelectExeCb.Items.Count > 0 && shown.SequenceEqual(entries, StringComparer.Ordinal))
return;
SelectExeCb.Items.Clear();
SelectExeCb.Items.Add(new ComboBoxItem { Content = App.Loc["SelectEXEAuto"] });
foreach (string exe in AppServices.Current.Executables.ListCandidates())
foreach (string exe in entries)
SelectExeCb.Items.Add(new ComboBoxItem { Content = exe });
if (current is not null)
{
int idx = FindComboIndexByContent(SelectExeCb, current);
SelectExeCb.SelectedIndex = idx >= 0 ? idx : 0;
}
if (index >= 0)
SelectExeCb.SelectedIndex = at >= 0 ? at + 1 : 0;
}
/// <summary>
/// Looks at the simulator folder again, so a build copied in while the starter runs is
/// on the list without reopening anything. The choice stays as it was and is no edit:
/// nothing waits for Save after it. Not while the list is open under the user's hand.
/// </summary>
public void RefreshExecutables()
{
if (SelectExeCb.IsDropDownOpen)
return;
WhileLoading(PopulateExeCombo);
}
private async void BrowseExeButton_OnClick(object? sender, RoutedEventArgs e) =>