From bba9e3ef4841078feba1d3ca388bd1628542b58d Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 15 Nov 2026 21:28:47 +0100 Subject: [PATCH] fix: without AVX2 the starter starts the simulator built without it The simulator now also comes built without AVX2, its file name ending in _noavx2 (eu07-x64___noavx2.exe, eu07_noavx2 on Linux), and both builds can lie side by side in the game folder. The automatic choice took eu07.exe or the shortest name and never that one, so a processor without AVX2 got a simulator that stops at its first instruction and a notice telling it to build its own. Without AVX2 the automatic choice now takes the newest _noavx2 build, even one through Wine before a native build that would not run. With AVX2 the build made for it stays first and a _noavx2 one is used only when it is all there is. The notice comes only when what would start still needs AVX2. With a _noavx2 build in the folder but another chosen by hand it names both and offers to go back to the automatic choice; with none it says what such a build is called and that the starter picks it up from the game folder. --- StarterNG.Tests/ExecutableNoAvx2Tests.cs | 82 +++++++++++++++++++ StarterNG.Tests/Fakes/TestInstallation.cs | 5 +- StarterNG/App.axaml.cs | 8 +- .../Settings/ExecutableLocator.cs | 39 ++++++++- StarterNG/MainWindow.axaml.cs | 29 ++++++- StarterNG/startercfg/lang/cz.xml | 4 +- StarterNG/startercfg/lang/en.xml | 4 +- StarterNG/startercfg/lang/hu.xml | 4 +- StarterNG/startercfg/lang/pl.xml | 4 +- StarterNG/startercfg/lang/ru.xml | 4 +- 10 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 StarterNG.Tests/ExecutableNoAvx2Tests.cs diff --git a/StarterNG.Tests/ExecutableNoAvx2Tests.cs b/StarterNG.Tests/ExecutableNoAvx2Tests.cs new file mode 100644 index 0000000..35902a5 --- /dev/null +++ b/StarterNG.Tests/ExecutableNoAvx2Tests.cs @@ -0,0 +1,82 @@ +using StarterNG.Domain.Settings; +using StarterNG.Infrastructure.Settings; +using StarterNG.Tests.Fakes; + +namespace StarterNG.Tests; + +public class ExecutableNoAvx2Tests +{ + private const string Elf = "\u007fELF binary"; + private static readonly DateTime Older = new(2026, 11, 1, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime Newer = new(2026, 11, 15, 0, 0, 0, DateTimeKind.Utc); + + private static InMemoryFileSystem With(params string[] names) + { + var files = new InMemoryFileSystem(); + foreach (string name in names) + files.WithExecutable(TestInstallation.At(name), Elf); + return files; + } + + private static string Automatic(InMemoryFileSystem files, bool lacksAvx2) => + Path.GetFileName(new TestInstallation(files, lacksAvx2: lacksAvx2).Executables + .Resolve(new SimulatorSettings(), out _)); + + [Theory] + [InlineData("eu07_noavx2", true)] + [InlineData("eu07-x64_20261115_abc1234_noavx2.exe", true)] + [InlineData("EU07_NOAVX2.EXE", true)] + [InlineData("eu07", false)] + [InlineData("eu07-x64_20261115_abc1234.exe", false)] + [InlineData("eu07_noavx2_old.exe", false)] + public void A_build_without_avx2_is_known_by_the_end_of_its_name(string name, bool noAvx2) => + Assert.Equal(noAvx2, ExecutableLocator.IsNoAvx2(name)); + + [Fact] + public void Without_avx2_the_build_without_it_is_chosen_over_the_canonical_one() => + Assert.Equal("eu07_noavx2", Automatic(With("eu07", "eu07_noavx2"), lacksAvx2: true)); + + [Fact] + public void With_avx2_the_build_made_for_it_stays_first() => + Assert.Equal("eu07", Automatic(With("eu07", "eu07_noavx2"), lacksAvx2: false)); + + [Fact] + public void With_avx2_a_build_without_it_is_used_when_it_is_the_only_one() => + Assert.Equal("eu07_noavx2", Automatic(With("eu07_noavx2"), lacksAvx2: false)); + + [Fact] + public void Without_avx2_the_newest_build_without_it_is_chosen() + { + var files = With("eu07_20261101_aaa_noavx2", "eu07_20261115_bbb_noavx2") + .WrittenAt(TestInstallation.At("eu07_20261101_aaa_noavx2"), Older) + .WrittenAt(TestInstallation.At("eu07_20261115_bbb_noavx2"), Newer); + + Assert.Equal("eu07_20261115_bbb_noavx2", Automatic(files, lacksAvx2: true)); + } + + [Fact] + public void Without_avx2_and_no_build_without_it_the_usual_choice_stands() => + Assert.Equal("eu07", Automatic(With("eu07-dev", "eu07"), lacksAvx2: true)); + + [Fact] + public void Only_a_build_with_avx2_on_a_processor_without_it_will_not_run() + { + var lacking = new TestInstallation(lacksAvx2: true).Executables; + var able = new TestInstallation(lacksAvx2: false).Executables; + + Assert.True(lacking.WillNotRunHere("eu07.exe")); + Assert.False(lacking.WillNotRunHere("eu07-x64_noavx2.exe")); + Assert.False(able.WillNotRunHere("eu07.exe")); + } + + [Fact] + public void The_newest_build_without_avx2_is_offered_by_name() + { + var files = With("eu07", "eu07_20261101_aaa_noavx2", "eu07_20261115_bbb_noavx2") + .WrittenAt(TestInstallation.At("eu07_20261101_aaa_noavx2"), Older) + .WrittenAt(TestInstallation.At("eu07_20261115_bbb_noavx2"), Newer); + + Assert.Equal("eu07_20261115_bbb_noavx2", new TestInstallation(files).Executables.NewestNoAvx2()); + Assert.Null(new TestInstallation(With("eu07")).Executables.NewestNoAvx2()); + } +} diff --git a/StarterNG.Tests/Fakes/TestInstallation.cs b/StarterNG.Tests/Fakes/TestInstallation.cs index 3f4a791..d05c435 100644 --- a/StarterNG.Tests/Fakes/TestInstallation.cs +++ b/StarterNG.Tests/Fakes/TestInstallation.cs @@ -14,7 +14,7 @@ public sealed class TestInstallation { public const string Root = "game"; - public TestInstallation(InMemoryFileSystem? files = null, DateTime? now = null) + public TestInstallation(InMemoryFileSystem? files = null, DateTime? now = null, bool lacksAvx2 = false) { Files = files ?? new InMemoryFileSystem(); Paths = new GamePaths(Root); @@ -35,7 +35,8 @@ public sealed class TestInstallation SettingsPaths.VehicleCacheDirectory()); Library = new GameLibrary(VehicleCache, Sceneries, MiniTextures, Physics, Log); - Executables = new ExecutableLocator(Files, Paths, Environment, Log); + // The processor of the machine running the tests is not the one tested. + Executables = new ExecutableLocator(Files, Paths, Environment, Log, lacksAvx2); SettingsStore = new SettingsStore(Files, Clock, Log, SettingsPaths, new SettingsSerializer(), Executables); Tapes = new HaslerTapes(Files, Paths, Log, Clock, new TimetableLocator(Files), () => SimulatorRunning); } diff --git a/StarterNG/App.axaml.cs b/StarterNG/App.axaml.cs index 76778b8..bfa9c13 100644 --- a/StarterNG/App.axaml.cs +++ b/StarterNG/App.axaml.cs @@ -202,8 +202,12 @@ public partial class App : Avalonia.Application if (check.ExecutableMissing()) await main.OfferExecutablePickAsync(); - if (CpuFeatures.LacksAvx2 && AppServices.Current.Settings.CpuNotice) - await main.ShowCpuNoticeAsync(); + // A build without AVX2 in the folder is started instead, and needs no notice. + var services = AppServices.Current; + if (services.Settings.CpuNotice + && services.Executables.Resolve(services.Settings, out _) is var executable + && services.Executables.WillNotRunHere(executable)) + await main.ShowCpuNoticeAsync(executable); }); }); } diff --git a/StarterNG/Infrastructure/Settings/ExecutableLocator.cs b/StarterNG/Infrastructure/Settings/ExecutableLocator.cs index c2e321c..b9d2669 100644 --- a/StarterNG/Infrastructure/Settings/ExecutableLocator.cs +++ b/StarterNG/Infrastructure/Settings/ExecutableLocator.cs @@ -22,15 +22,37 @@ public sealed class ExecutableLocator private string? _wine; private bool _wineLookedUp; private string? _missingPickLogged; + private readonly bool _lacksAvx2; - public ExecutableLocator(IFileSystem files, IGamePaths paths, IEnvironment environment, IDiagnosticsLog log) + /// Whether this processor runs no AVX2; asked of it when left out. + public ExecutableLocator(IFileSystem files, IGamePaths paths, IEnvironment environment, IDiagnosticsLog log, + bool? lacksAvx2 = null) { _files = files; _paths = paths; _environment = environment; _log = log; + _lacksAvx2 = lacksAvx2 ?? CpuFeatures.LacksAvx2; } + /// + /// The end of the name of a simulator built without AVX2, last before any extension: + /// eu07-x64_20261115_abc1234_noavx2.exe, eu07_noavx2. It runs on any x86-64 processor. + /// + public const string NoAvx2Suffix = "_noavx2"; + + public static bool IsNoAvx2(string path) => + Path.GetFileNameWithoutExtension(path).EndsWith(NoAvx2Suffix, StringComparison.OrdinalIgnoreCase); + + /// + /// Whether stops at its first instruction here: a build + /// with AVX2 on a processor without it. Such a processor is told so before a start. + /// + public bool WillNotRunHere(string executable) => _lacksAvx2 && !IsNoAvx2(executable); + + /// The newest build without AVX2 in the installation, or null where there is none. + public string? NewestNoAvx2() => ListCandidates().FirstOrDefault(IsNoAvx2); + public string CanonicalName => _environment.IsWindows ? "eu07.exe" : "eu07"; /// @@ -71,7 +93,8 @@ public sealed class ExecutableLocator { var candidates = _files.GetFiles(_paths.Root, "eu07*") .Where(IsCandidate) - .OrderBy(path => IsExeOnLinux(path) ? 1 : 0) + .OrderBy(Rank) + .ThenByDescending(path => _lacksAvx2 && IsNoAvx2(path) ? _files.GetLastWriteTimeUtc(path) : DateTime.MinValue) .ThenBy(path => string.Equals(Path.GetFileName(path), CanonicalName, StringComparison.OrdinalIgnoreCase) ? 0 : 1) .ThenBy(path => Path.GetFileName(path).Length); @@ -101,6 +124,18 @@ public sealed class ExecutableLocator return CanonicalName; } + /// + /// The order of the search. Without AVX2 a build without it comes first, the newest of + /// them, even through Wine: the others stop at once. With AVX2 one is the last resort, + /// as the build made for the processor runs faster; native before Wine either way. + /// + private int Rank(string path) + { + int wine = IsExeOnLinux(path) ? 1 : 0; + int noAvx2 = IsNoAvx2(path) ? 1 : 0; + return _lacksAvx2 ? (1 - noAvx2) * 2 + wine : wine * 2 + noAvx2; + } + public List ListCandidates(string? directory = null) { try diff --git a/StarterNG/MainWindow.axaml.cs b/StarterNG/MainWindow.axaml.cs index 2a203ad..a00c853 100644 --- a/StarterNG/MainWindow.axaml.cs +++ b/StarterNG/MainWindow.axaml.cs @@ -508,11 +508,34 @@ public partial class MainWindow : Window private const string SimulatorBuildGuide = "https://github.com/MaSzyna-EU07/maszyna#getting-started"; /// - /// Tells a user whose processor lacks AVX2 that the published simulator will - /// not run, and where the instructions for a build of their own are. + /// Tells a user whose processor lacks AVX2 that the simulator that would start will + /// not run. With a build without AVX2 in the folder, chosen away from by hand, the + /// notice offers to go back to the automatic choice, which takes it; with none, it + /// says what such a build is called and where the instructions for one's own are. /// - public async Task ShowCpuNoticeAsync() + public async Task ShowCpuNoticeAsync(string executable) { + var services = AppServices.Current; + if (services.Executables.NewestNoAvx2() is { } noAvx2) + { + var (useIt, quiet) = await MessageBox.ShowNotice( + this, string.Format(App.Loc["CpuNoAvx2Chosen"], Path.GetFileName(executable), noAvx2), + App.Loc["CpuNoAvx2Title"], App.Loc["CpuNoAvx2UseIt"], App.Loc["DontShowAgain"]); + if (useIt) + { + services.Settings.SelectExeAutomatically = true; + services.SettingsStore.Save(); + SettingsView.ReloadFromSettings(); + UpdateStartButton(); + } + if (quiet) + { + services.Settings.CpuNotice = false; + services.SettingsStore.Save(); + } + return; + } + var (open, silence) = await MessageBox.ShowNotice( this, string.Format(App.Loc["CpuNoAvx2"], SimulatorBuildGuide), App.Loc["CpuNoAvx2Title"], App.Loc["CpuNoAvx2Open"], App.Loc["DontShowAgain"]); diff --git a/StarterNG/startercfg/lang/cz.xml b/StarterNG/startercfg/lang/cz.xml index 0bb1d32..10821c4 100644 --- a/StarterNG/startercfg/lang/cz.xml +++ b/StarterNG/startercfg/lang/cz.xml @@ -592,8 +592,10 @@ O programu Zavřít Procesor bez AVX2 - Tento procesor nemá AVX2 a oficiální simulátor ho vyžaduje: nespustí se. Simulátor lze sestavit bez AVX2 (CMake -DENABLE_AVX2=OFF). Návod: {0} + Tento procesor nemá AVX2 a oficiální simulátor ho vyžaduje: nespustí se. Existuje verze simulátoru bez AVX2 - název jejího souboru končí na _noavx2. Vložte ji do složky hry a starter ji sám použije. Simulátor lze také sestavit sám (CMake -DENABLE_AVX2=OFF). Návod: {0} Otevřít návod + Tento procesor nemá AVX2 a zvolený simulátor {0} ho vyžaduje: nespustí se. Ve složce hry je verze bez AVX2: {1}. Automatická volba vezme právě ji. + Volit automaticky Znovu nezobrazovat Nastavení načteno z: diff --git a/StarterNG/startercfg/lang/en.xml b/StarterNG/startercfg/lang/en.xml index e0a4ba1..ce6e488 100644 --- a/StarterNG/startercfg/lang/en.xml +++ b/StarterNG/startercfg/lang/en.xml @@ -618,8 +618,10 @@ About Close Processor without AVX2 - This processor has no AVX2 and the official simulator needs it: it will not start. You can build the simulator without AVX2 (CMake -DENABLE_AVX2=OFF). Instructions: {0} + This processor has no AVX2 and the official simulator needs it: it will not start. There is a simulator build without AVX2 - its file name ends in _noavx2. Put it in the game folder and the starter will use it. You can also build the simulator yourself (CMake -DENABLE_AVX2=OFF). Instructions: {0} Open the instructions + This processor has no AVX2 and the chosen simulator {0} needs it: it will not start. The game folder has a build without AVX2: {1}. The automatic choice takes that one. + Choose automatically Don't show again Settings loaded from: diff --git a/StarterNG/startercfg/lang/hu.xml b/StarterNG/startercfg/lang/hu.xml index 4c1a4dc..c71fe5b 100644 --- a/StarterNG/startercfg/lang/hu.xml +++ b/StarterNG/startercfg/lang/hu.xml @@ -592,8 +592,10 @@ Névjegy Bezárás AVX2 nélküli processzor - Ez a processzor nem tudja az AVX2-t, a hivatalos szimulátornak pedig kell: nem indul el. A szimulátor lefordítható AVX2 nélkül (CMake -DENABLE_AVX2=OFF). Útmutató: {0} + Ez a processzor nem tudja az AVX2-t, a hivatalos szimulátornak pedig kell: nem indul el. Van AVX2 nélküli szimulátor-változat - a fájl neve _noavx2-re végződik. Tegye a játék mappájába, és az indító magától azt használja. A szimulátor saját maga is lefordítható (CMake -DENABLE_AVX2=OFF). Útmutató: {0} Útmutató megnyitása + Ez a processzor nem tudja az AVX2-t, a kiválasztott {0} szimulátornak pedig kell: nem indul el. A játék mappájában van AVX2 nélküli változat: {1}. Az automatikus választás ezt veszi. + Automatikus választás Ne mutasd többé Beállítások betöltve innen: diff --git a/StarterNG/startercfg/lang/pl.xml b/StarterNG/startercfg/lang/pl.xml index 3713dd5..6767057 100644 --- a/StarterNG/startercfg/lang/pl.xml +++ b/StarterNG/startercfg/lang/pl.xml @@ -618,8 +618,10 @@ O programie Zamknij Procesor bez AVX2 - Ten procesor nie ma AVX2, a oficjalny symulator go wymaga: nie uruchomi się. Można zbudować symulator bez AVX2 (CMake -DENABLE_AVX2=OFF). Instrukcja: {0} + Ten procesor nie ma AVX2, a oficjalny symulator go wymaga: nie uruchomi się. Istnieje wersja symulatora bez AVX2 - nazwa jej pliku kończy się na _noavx2. Umieść ją w folderze gry, a starter sam jej użyje. Można też zbudować symulator samemu (CMake -DENABLE_AVX2=OFF). Instrukcja: {0} Otwórz instrukcję + Ten procesor nie ma AVX2, a wybrany symulator {0} go wymaga: nie uruchomi się. W folderze gry jest wersja bez AVX2: {1}. Wybór automatyczny weźmie właśnie ją. + Wybieraj automatycznie Nie pokazuj więcej Lokalizacja wczytanych ustawień: diff --git a/StarterNG/startercfg/lang/ru.xml b/StarterNG/startercfg/lang/ru.xml index c73f842..3fdbfa3 100644 --- a/StarterNG/startercfg/lang/ru.xml +++ b/StarterNG/startercfg/lang/ru.xml @@ -592,8 +592,10 @@ О программе Закрыть Процессор без AVX2 - Этот процессор не поддерживает AVX2, а официальному симулятору он нужен: симулятор не запустится. Можно собрать симулятор без AVX2 (CMake -DENABLE_AVX2=OFF). Инструкция: {0} + Этот процессор не поддерживает AVX2, а официальному симулятору он нужен: симулятор не запустится. Есть версия симулятора без AVX2 - имя её файла оканчивается на _noavx2. Положите её в папку игры, и стартер сам её использует. Симулятор можно также собрать самому (CMake -DENABLE_AVX2=OFF). Инструкция: {0} Открыть инструкцию + Этот процессор не поддерживает AVX2, а выбранному симулятору {0} он нужен: он не запустится. В папке игры есть версия без AVX2: {1}. Автоматический выбор возьмёт именно её. + Выбирать автоматически Больше не показывать Настройки загружены из: