mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-01 17:37:04 +01:00
fix(exit): no box of the starter after eu07_starter.exe or the simulator already said why
Started through eu07_starter.exe, a simulator that failed got two boxes in a row: the one of eu07_starter.exe, then the starter's own with the exit code. The starter's box is now left out where the player already has one: - an error code of the system (0xC...) through eu07_starter.exe: it explained the code, or caught the crash the simulator then reported in its own box; Ctrl+C (0xC000013A), which it leaves without a word, still gets the box; - code 1 through eu07_starter.exe with the simulator's log not written since the start: eu07_starter.exe did not start it (missing, refused by its checks, or the player's No) and said why; - 0xE0450010, the simulator's own notice of a processor it cannot run on, with or without eu07_starter.exe. The log of the starter still records each of these exits.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the simulator ran at all since <paramref name="startedUtc"/>: it opens its log
|
||||
/// first thing, so one not written since is the session before's.
|
||||
/// </summary>
|
||||
public bool SimulatorRanSince(DateTime startedUtc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return LogWrittenSince(SimulatorLogPath, startedUtc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log($"reading {SimulatorLogPath}", ex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> 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<string>();
|
||||
|
||||
var lines = LegacyText.Decode(_files.ReadAllBytes(path))
|
||||
|
||||
@@ -16,6 +16,34 @@ public sealed record SimulatorExit(int ExitCode, TimeSpan RunTime, IReadOnlyList
|
||||
|
||||
public bool Failed => ExitCode != 0 || Quick;
|
||||
|
||||
/// <summary>The code eu07.exe ends with when its check of the processor has told the player (utilities/cpu_features.h).</summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// 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 (<paramref name="throughStarter"/>),
|
||||
/// 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 (<paramref name="simulatorRan"/>: its log was written).
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>The error stream without its colour codes and blank lines.</summary>
|
||||
public IReadOnlyList<string> CleanErrors =>
|
||||
Errors.Select(line => AnsiCode.Replace(line, "").TrimEnd())
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user