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/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);