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.Tests/SimulatorAftermathTests.cs b/StarterNG.Tests/SimulatorAftermathTests.cs
index 1c3f31b..2144274 100644
--- a/StarterNG.Tests/SimulatorAftermathTests.cs
+++ b/StarterNG.Tests/SimulatorAftermathTests.cs
@@ -67,4 +67,18 @@ public class SimulatorAftermathTests
Assert.Equal(new[] { "opening" }, tail);
}
+
+ [Fact]
+ public void The_simulator_ran_when_it_wrote_its_log_since_the_start()
+ {
+ var installation = new TestInstallation(new InMemoryFileSystem()
+ .WithFile(TestInstallation.At("log.txt"), "opening\r\n"));
+ var aftermath = new SimulatorAftermath(installation.Files, installation.Paths, installation.Log);
+ var written = installation.Files.LastWriteTimeUtc;
+
+ Assert.True(aftermath.SimulatorRanSince(written.AddMinutes(-1)));
+ Assert.False(aftermath.SimulatorRanSince(written.AddMinutes(10)));
+ Assert.False(new SimulatorAftermath(new InMemoryFileSystem(), installation.Paths, installation.Log)
+ .SimulatorRanSince(written));
+ }
}
diff --git a/StarterNG.Tests/SimulatorExitTests.cs b/StarterNG.Tests/SimulatorExitTests.cs
index 7cb0f68..a854c37 100644
--- a/StarterNG.Tests/SimulatorExitTests.cs
+++ b/StarterNG.Tests/SimulatorExitTests.cs
@@ -47,6 +47,39 @@ public class SimulatorExitTests
Assert.Equal(["Bad file: texture"], exit.CleanErrors);
}
+ private static SimulatorExit Ended(uint code) => new(unchecked((int)code), Session, []);
+
+ [Theory]
+ [InlineData(0xC0000135u)] // a library missing, explained by eu07_starter.exe
+ [InlineData(0xC000001Du)] // an instruction the processor lacks
+ [InlineData(0xC0000005u)] // a crash: its minidump by eu07_starter.exe, its box by the simulator
+ public void An_error_code_of_the_system_was_explained_by_the_simulators_starter(uint code)
+ {
+ Assert.True(Ended(code).AlreadyExplained(throughStarter: true, simulatorRan: true));
+ Assert.False(Ended(code).AlreadyExplained(throughStarter: false, simulatorRan: true));
+ }
+
+ [Fact]
+ public void A_close_by_ctrl_c_is_left_without_a_word_by_the_simulators_starter()
+ {
+ Assert.False(Ended(0xC000013A).AlreadyExplained(throughStarter: true, simulatorRan: true));
+ }
+
+ [Fact]
+ public void A_refusal_of_the_simulators_starter_is_one_where_the_simulator_never_ran()
+ {
+ Assert.True(Ended(1).AlreadyExplained(throughStarter: true, simulatorRan: false));
+ Assert.False(Ended(1).AlreadyExplained(throughStarter: true, simulatorRan: true));
+ Assert.False(Ended(1).AlreadyExplained(throughStarter: false, simulatorRan: false));
+ Assert.False(Ended(3).AlreadyExplained(throughStarter: true, simulatorRan: false));
+ }
+
+ [Fact]
+ public void A_processor_the_simulator_cannot_run_on_it_tells_of_itself()
+ {
+ Assert.True(Ended(SimulatorExit.UnsupportedProcessor).AlreadyExplained(throughStarter: false, simulatorRan: true));
+ }
+
[Fact]
public async Task A_real_process_leaves_its_exit_code_and_error_stream()
{
diff --git a/StarterNG/Application/SimulatorAftermath.cs b/StarterNG/Application/SimulatorAftermath.cs
index ad39a80..bfef834 100644
--- a/StarterNG/Application/SimulatorAftermath.cs
+++ b/StarterNG/Application/SimulatorAftermath.cs
@@ -58,6 +58,28 @@ public sealed class SimulatorAftermath
}
}
+ private string SimulatorLogPath => _paths.FromRoot("log.txt");
+
+ private bool LogWrittenSince(string path, DateTime startedUtc) =>
+ _files.FileExists(path) && _files.GetLastWriteTimeUtc(path) >= startedUtc - StartSlack;
+
+ ///
+ /// Whether the simulator ran at all since : it opens its log
+ /// first thing, so one not written since is the session before's.
+ ///
+ public bool SimulatorRanSince(DateTime startedUtc)
+ {
+ try
+ {
+ return LogWrittenSince(SimulatorLogPath, startedUtc);
+ }
+ catch (Exception ex)
+ {
+ _log.Log($"reading {SimulatorLogPath}", ex);
+ return true;
+ }
+ }
+
///
/// The end of the simulator's own log, for when it died without a word on its
/// error stream. A log not written since the start is the session before's, the
@@ -65,10 +87,10 @@ public sealed class SimulatorAftermath
///
public IReadOnlyList SimulatorLogTail(int count, DateTime startedUtc)
{
- string path = _paths.FromRoot("log.txt");
+ string path = SimulatorLogPath;
try
{
- if (!_files.FileExists(path) || _files.GetLastWriteTimeUtc(path) < startedUtc - StartSlack)
+ if (!LogWrittenSince(path, startedUtc))
return Array.Empty();
var lines = LegacyText.Decode(_files.ReadAllBytes(path))
diff --git a/StarterNG/Application/SimulatorExit.cs b/StarterNG/Application/SimulatorExit.cs
index 1ac75a5..855d9ee 100644
--- a/StarterNG/Application/SimulatorExit.cs
+++ b/StarterNG/Application/SimulatorExit.cs
@@ -16,6 +16,34 @@ public sealed record SimulatorExit(int ExitCode, TimeSpan RunTime, IReadOnlyList
public bool Failed => ExitCode != 0 || Quick;
+ /// The code eu07.exe ends with when its check of the processor has told the player (utilities/cpu_features.h).
+ public const uint UnsupportedProcessor = 0xE0450010;
+
+ // What eu07_starter.exe returns when it does not start the simulator: missing, refused by its checks of the
+ // system after a box that said why, or the player's No to a start anyway.
+ private const int StarterRefused = 1;
+
+ // A close by Ctrl+C: the one error code eu07_starter.exe leaves without a word.
+ private const uint ControlCExit = 0xC000013A;
+
+ ///
+ /// Whether the player already has a box saying why, so the starter's own would only repeat it. The simulator
+ /// tells of a processor it cannot run on itself. Started through eu07_starter.exe (),
+ /// an error code of the system was explained by it, or the crash it caught reported by the simulator, and a
+ /// refusal of its own is one where the simulator never ran (: its log was written).
+ ///
+ public bool AlreadyExplained(bool throughStarter, bool simulatorRan)
+ {
+ uint code = unchecked((uint)ExitCode);
+ if (code == UnsupportedProcessor)
+ return true;
+ if (!throughStarter)
+ return false;
+ if ((code & 0xF0000000) == 0xC0000000)
+ return code != ControlCExit;
+ return ExitCode == StarterRefused && !simulatorRan;
+ }
+
/// The error stream without its colour codes and blank lines.
public IReadOnlyList CleanErrors =>
Errors.Select(line => AnsiCode.Replace(line, "").TrimEnd())
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);
diff --git a/StarterNG/MainWindow.axaml.cs b/StarterNG/MainWindow.axaml.cs
index e084912..9e29ea2 100644
--- a/StarterNG/MainWindow.axaml.cs
+++ b/StarterNG/MainWindow.axaml.cs
@@ -813,6 +813,16 @@ public partial class MainWindow : Window
if (!exit.Failed)
return;
+ bool throughStarter = string.Equals(Path.GetFileName(executable),
+ Infrastructure.Settings.ExecutableLocator.WindowsStarterName,
+ StringComparison.OrdinalIgnoreCase);
+ if (exit.AlreadyExplained(throughStarter, AppServices.Current.Aftermath.SimulatorRanSince(startedUtc)))
+ {
+ Diagnostics.Log($"The simulator ended with {exit.DescribeCode()}, already explained to the player" +
+ (throughStarter ? $" (started through {Path.GetFileName(executable)})" : ""));
+ return;
+ }
+
var words = exit.CleanErrors.Count > 0
? exit.CleanErrors
: AppServices.Current.Aftermath.SimulatorLogTail(12, startedUtc);