mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-16 13:04:09 +01:00
Compare commits
7 Commits
v1.5.228
...
fix/exe-li
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f29ce10f5c | ||
|
|
744720d922 | ||
|
|
b5ba67430f | ||
|
|
c261d4b0ab | ||
|
|
3aa6a256a5 | ||
|
|
95c510b3ac | ||
|
|
da5a1efea1 |
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);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -13,6 +13,6 @@ public static class AppInfo
|
||||
#if DEBUG
|
||||
text += " (DEBUG)";
|
||||
#endif
|
||||
return text + " public beta";
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
InitializeComponent();
|
||||
// The top bar lets the version go first when it runs short of room, which at the usual widths it does;
|
||||
// the title has room for it at any width.
|
||||
Title = $"{Title} {AppInfo.Version}";
|
||||
|
||||
ExtendClientAreaToDecorationsHint = true;
|
||||
ExtendClientAreaTitleBarHeightHint = TitleBarHeight;
|
||||
@@ -105,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