Read a comment after a setting's value, and off, false and no for a switch, as players mean them in nx2navi.ini.

A hand-edited "pace_smooth = 0 ; off" kept the comment in the value, which the readers took as on, "fps_limit = 144 #
monitor" gave 60, and "fullscreen = false" or "rtss = off" were on, since every reader took anything but "0" as on;
the log only named these lines (the check added for F-7). Now, for a key whose row has a set of values, cfg_load cuts
an unquoted value at the first blank followed by ';' or '#' after the '=' ("key = ; note" is unset) and logs the line
once; free text keeps its whole value (window_size, monitor, audio_device and keys without a row such as mods_dir,
pipeline_cache and the bindings, where a path or name may hold " #"), as do a value in double quotes and the
environment's values. A switch (a row whose set is 0|1) written as false, off or no reads as 0 and as true, on or yes
as 1 through cfg_get itself, so every reader agrees (cfg_bool, rt_knob, the readers that compare with "0" or parse a
number); cfg_bool and rt_knob also take those words for keys of other rows, and rt_knob no longer logs them. F-7's
check now names a switch value only when it is none of those, and a comment kept in a value only where it stays
(free text, the environment). The launcher's reader (launcher/gameini.py) cuts the same way for keys the caller
says have a set of values; its mods keys stay free text. The menu's save still writes a changed key's line again
without its comment.

This changes what existing files with such lines do, which is what was approved. tests/cfg_parse_check.py,
tests/rt_knob_check.py and launcher_test PlayerIniTest cover the cut, the words, free text, quotes and the
environment, and pass; cfg_rows_check reports 0 problems; the runtime compile check and the -Wall comparison of cfg.c
and perf.c show no new warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:14:43 -05:00
parent 1c26907abe
commit b6709da852
9 changed files with 264 additions and 59 deletions

View File

@@ -380,6 +380,32 @@ class PlayerIniTest(Tmp):
gameini.put(self.tmp, 'discord', 'discord_rpc', '1')
self.assertEqual(ini.read_bytes(), PLAYER_INI + b'\r\n\r\n[discord]\r\ndiscord_rpc = 1\r\n')
def test_a_comment_after_a_value_as_the_game_reads_it(self):
"""runtime/cfg.c cut_comment: for a key whose row has a set of values (choices=True), a blank followed by ';'
or '#' starts a comment, "key = ; note" has no value, and a value in double quotes keeps its text; free text,
the mods folder and lists the launcher writes, keeps the whole value. tests/cfg_parse_check.py has the same
lines for the game."""
ini = self.tmp / 'nx2navi.ini'
body = (b'[frame rate]\r\npace_smooth = 0 ; off\r\nfps_limit = 144 # my monitor\r\nvk_present = fifo\t; x\r\n'
b'aspect = ; later\r\ndlss_preset = "k ; quoted"\r\n[mods]\r\nmods_dir = D:\\My Mods #2\r\n'
b'mods_disabled = a #1|b ; c\r\n')
ini.write_bytes(body)
for key, want in (('pace_smooth', '0'), ('fps_limit', '144'), ('vk_present', 'fifo'), ('aspect', ''),
('dlss_preset', 'k ; quoted')):
self.assertEqual(gameini.get(self.tmp, key, choices=True), want, key)
self.assertEqual(gameini.get(self.tmp, 'fps_limit'), '144 # my monitor')
self.assertEqual(gameini.get(self.tmp, 'mods_dir'), 'D:\\My Mods #2')
self.assertEqual(gameini.get(self.tmp, 'mods_disabled'), 'a #1|b ; c')
from launcher import mods
self.assertEqual(mods._names(self.tmp, 'MODS_DISABLED'), ['a #1', 'b ; c'])
# a key's line that has only a comment has no value as the game reads it: the change goes on the line before
ini.write_bytes(b'vk_present = fifo\r\nvk_present = ; later\r\n')
gameini.put(self.tmp, 'display', 'vk_present', 'mailbox', choices=True)
self.assertEqual(ini.read_bytes(), b'vk_present = mailbox\r\nvk_present = ; later\r\n')
ini.write_bytes(b'pace_smooth = 0 ; off\r\n') # the line is written again whole, as the game's menu writes it
gameini.put(self.tmp, 'performance', 'pace_smooth', '1', choices=True)
self.assertEqual(ini.read_bytes(), b'pace_smooth = 1\r\n')
def test_the_older_installer_changes_the_language_line_only(self):
"""installer/ini.py sets the language, in the older installer's last step at every install and update: the
one line goes under [language] with the file's own line ends, and every other byte stays (it used to write