fix(settings): a monitor's name outside ASCII is written as the UTF-8 the simulator compares

The simulator compares the word after fullscreenmonitor byte by byte with GLFW's name of the monitor, which is UTF-8 (application.cpp, find_monitor), and has no other way to name one. eu07.ini is written in code page 1250, so a name with a letter outside ASCII never matched and the game opened on the primary monitor. That one word now goes into the file as its UTF-8 bytes, the rest staying in the code page; a name an earlier save left in the code page is read as it is and put right by the next save.
This commit is contained in:
maj00r
2026-11-22 14:52:51 +01:00
parent f7a58e8431
commit d429d041ff
4 changed files with 101 additions and 2 deletions

View File

@@ -58,4 +58,66 @@ public class MonitorsTests
new StarterNG.Infrastructure.Settings.SettingsSerializer().Write(s, c);
Assert.Equal("HDMI-1:1920,0", c.GetRaw("fullscreenmonitor"));
}
// ── A name outside ASCII: the simulator compares the file's bytes with GLFW's UTF-8 name ──
private static readonly string UserIni = Path.Combine("/home/kolejarz", ".config", "MaSzyna", "eu07.ini");
private static StarterNG.Tests.Fakes.TestInstallation WithIni(byte[] ini)
{
var files = new StarterNG.Tests.Fakes.InMemoryFileSystem();
files.WriteAllBytes(UserIni, ini);
var installation = new StarterNG.Tests.Fakes.TestInstallation(files);
installation.Environment.With("HOME", "/home/kolejarz");
installation.SettingsStore.Load();
return installation;
}
private static bool Holds(byte[] file, byte[] part) => file.AsSpan().IndexOf(part) >= 0;
[Theory]
[InlineData("Obecný_monitor_PnP:1920,0")]
[InlineData("Écran_à_Ábc:0,0")]
[InlineData("Монитор_Рабочий:-1920,0")]
[InlineData("显示器:0,0")]
public void A_monitors_name_goes_into_the_file_as_the_utf8_the_simulator_compares(string id)
{
var cp1250 = StarterNG.Infrastructure.Adapters.LegacyText.CodePage1250;
var installation = WithIni(cp1250.GetBytes("lang pl\n// zażółć\nfullscreen yes\n"));
installation.SettingsStore.Settings.FullscreenMonitor = id;
installation.SettingsStore.Save();
byte[] saved = installation.Files.ReadAllBytes(UserIni);
Assert.True(Holds(saved, System.Text.Encoding.UTF8.GetBytes("fullscreenmonitor " + id)));
// The rest of the file stays in the simulator's code page.
Assert.True(Holds(saved, cp1250.GetBytes("// zażółć")));
Assert.Equal(id, WithIni(saved).SettingsStore.Settings.FullscreenMonitor);
}
[Fact]
public void A_monitors_name_written_in_the_code_page_is_read_and_goes_as_utf8_on_a_save()
{
const string id = "Obecný_monitor_PnP:1920,0";
var cp1250 = StarterNG.Infrastructure.Adapters.LegacyText.CodePage1250;
var installation = WithIni(cp1250.GetBytes($"fullscreen yes\nfullscreenmonitor {id}\n"));
Assert.Equal(id, installation.SettingsStore.Settings.FullscreenMonitor);
installation.SettingsStore.Save();
byte[] saved = installation.Files.ReadAllBytes(UserIni);
Assert.True(Holds(saved, System.Text.Encoding.UTF8.GetBytes("fullscreenmonitor " + id)));
Assert.False(Holds(saved, cp1250.GetBytes("fullscreenmonitor " + id)));
}
[Fact]
public void An_ascii_name_of_a_monitor_stays_as_the_file_has_it()
{
var installation = WithIni(System.Text.Encoding.ASCII.GetBytes("fullscreenmonitor HDMI-1:1920,0\n"));
installation.SettingsStore.Save();
Assert.True(Holds(installation.Files.ReadAllBytes(UserIni),
System.Text.Encoding.ASCII.GetBytes("fullscreenmonitor HDMI-1:1920,0")));
}
}