diff --git a/StarterNG.Tests/ExecutableLocatorTests.cs b/StarterNG.Tests/ExecutableLocatorTests.cs index ccbe4bd..f25584c 100644 --- a/StarterNG.Tests/ExecutableLocatorTests.cs +++ b/StarterNG.Tests/ExecutableLocatorTests.cs @@ -230,6 +230,54 @@ public class ExecutableLocatorTests Assert.Equal(ExeProblem.None, installation.Executables.Validate(build)); } + private static string Automatic(TestInstallation installation) => + Path.GetFileName(installation.Executables.Resolve(new SimulatorSettings(), out _)); + + private static TestInstallation OnWindows(bool lacksAvx2, params string[] names) + { + var files = new InMemoryFileSystem(); + foreach (string name in names) + files.WithFile(TestInstallation.At(name), PortableExecutable); + var installation = new TestInstallation(files, lacksAvx2: lacksAvx2); + installation.Environment.AsWindows(); + return installation; + } + + [Fact] + public void On_windows_the_simulators_own_starter_is_picked_ahead_of_the_simulator() + { + var installation = OnWindows(false, "eu07.exe", "eu07_starter.exe", "eu07_2026-11-15_abc.exe"); + + Assert.Equal("eu07_starter.exe", Automatic(installation)); + } + + [Fact] + public void A_simulator_picked_by_hand_stays_although_the_starter_is_there() + { + var installation = OnWindows(false, "eu07.exe", "eu07_starter.exe"); + var settings = new SimulatorSettings { SelectExeAutomatically = false, ExecutablePath = "eu07.exe" }; + + Assert.Equal("eu07.exe", installation.Executables.Resolve(settings, out _)); + } + + [Fact] + public void Without_avx2_a_build_without_it_still_comes_before_the_starter() + { + var installation = OnWindows(true, "eu07.exe", "eu07_starter.exe", "eu07_noavx2.exe"); + + Assert.Equal("eu07_noavx2.exe", Automatic(installation)); + } + + [Fact] + public void Under_wine_the_simulator_is_started_without_its_windows_starter() + { + var installation = WithWine(new InMemoryFileSystem() + .WithFile(TestInstallation.At("eu07.exe"), PortableExecutable) + .WithFile(TestInstallation.At("eu07_starter.exe"), PortableExecutable)); + + Assert.Equal("eu07.exe", Automatic(installation)); + } + [Fact] public void Wine_is_never_looked_for_on_windows() { diff --git a/StarterNG/Infrastructure/Settings/ExecutableLocator.cs b/StarterNG/Infrastructure/Settings/ExecutableLocator.cs index 332fd5a..dabac45 100644 --- a/StarterNG/Infrastructure/Settings/ExecutableLocator.cs +++ b/StarterNG/Infrastructure/Settings/ExecutableLocator.cs @@ -55,6 +55,19 @@ public sealed class ExecutableLocator public string CanonicalName => _environment.IsWindows ? "eu07.exe" : "eu07"; + /// + /// The simulator's own starter on Windows, built beside eu07.exe: it checks the processor and the + /// libraries first, explains a start the system refuses with a bare code, writes the minidump of a + /// crash from outside, passes the arguments on and returns the simulator's exit code. + /// + public const string WindowsStarterName = "eu07_starter.exe"; + + // Picked ahead of the simulator next to it on Windows alone: under Wine neither its checks nor its + // minidumps are of any use. + private bool IsWindowsStarter(string path) => + _environment.IsWindows && + string.Equals(Path.GetFileName(path), WindowsStarterName, StringComparison.OrdinalIgnoreCase); + /// /// The simulator to start: the one picked in the settings, or the best one in /// the installation. A pick that is not there - the settings live per user and @@ -95,6 +108,7 @@ public sealed class ExecutableLocator .Where(IsCandidate) .OrderBy(Rank) .ThenByDescending(path => _lacksAvx2 && IsNoAvx2(path) ? _files.GetLastWriteTimeUtc(path) : DateTime.MinValue) + .ThenBy(path => IsWindowsStarter(path) ? 0 : 1) .ThenBy(path => string.Equals(Path.GetFileName(path), CanonicalName, StringComparison.OrdinalIgnoreCase) ? 0 : 1) .ThenBy(path => Path.GetFileName(path).Length);