mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-17 14:10:48 +01:00
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
This commit is contained in:
53
StarterNG.Tests/ExecutableListTests.cs
Normal file
53
StarterNG.Tests/ExecutableListTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
31
StarterNG/Views/ExecutableList.cs
Normal file
31
StarterNG/Views/ExecutableList.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user