Merge pull request #70 from MaSzyna-EU07/feat/settings-basic-advanced

Feat/settings basic advanced
This commit is contained in:
2026-11-30 19:39:49 +00:00
committed by GitHub
7 changed files with 171 additions and 2 deletions
+48
View File
@@ -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()
{
@@ -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));
}
}
+33
View File
@@ -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()
{
+24 -2
View File
@@ -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))
+28
View File
@@ -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())
@@ -55,6 +55,19 @@ public sealed class ExecutableLocator
public string CanonicalName => _environment.IsWindows ? "eu07.exe" : "eu07";
/// <summary>
/// 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.
/// </summary>
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);
/// <summary>
/// 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);
+10
View File
@@ -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);