From c5aee5160100a4c14fe37032b0dc04723b365324 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Thu, 12 Nov 2026 22:15:21 -0500 Subject: [PATCH] Leave the game's settings file alone while the game runs. The game and the launcher each read nx2navi.ini, change their own lines and put a new file in place, so of two changes in the same moment the second dropped the first. The mods' switches already refused while the game runs; the Discord Status switch of the Settings screen now does too, and says to use the game's menu. Co-Authored-By: Claude Fable 5.2 --- launcher/ui/app.py | 9 +++++++++ tests/launcher_test.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/launcher/ui/app.py b/launcher/ui/app.py index 293bc9ec..7d8439e1 100644 --- a/launcher/ui/app.py +++ b/launcher/ui/app.py @@ -908,8 +908,17 @@ class App: menu keeps it; the game reads it when it starts. On unless the file says 0, as the game reads it (cfg_bool, default on).""" def on(v): + # Not while the game runs, as the mods' switches (switch_mod): the game writes the same file when a menu + # setting changes. Each side reads the file, changes its own lines and puts a new file in place, so of + # two changes in the same moment the second drops the first. The game reads this setting only when it + # starts, and its own menu switches it meanwhile. + if self.game_busy(game_dir): + self.message = ('Quit the game first, or switch Discord Status in the game\'s menu (Game tab): the ' + 'game writes its settings file while it runs.') + return try: gameini.put(game_dir, 'discord', 'discord_rpc', '1' if v else '0') + self.message = '' except OSError as e: self.message = f'The game\'s settings could not be written: {e}' diff --git a/tests/launcher_test.py b/tests/launcher_test.py index cda6263e..d6b74cdd 100644 --- a/tests/launcher_test.py +++ b/tests/launcher_test.py @@ -4799,6 +4799,37 @@ class WhilePlayingTest(Tmp): App.watch_game(a) a.root.deiconify.assert_called_once() + def test_the_games_settings_file_is_left_alone_while_it_runs(self): + """The game writes nx2navi.ini when a menu setting changes, so the launcher's Discord Status switch (the one + setting of that file the Settings screen has) changes nothing while the game runs and says why; the mods' + switches refuse the same way (switch_mod).""" + try: + from launcher.ui.app import App + except ImportError as e: + self.skipTest(f'no window toolkit: {e}') + game = self.tmp / 'game' + game.mkdir() + (game / 'nx2navi.ini').write_text('[discord]\ndiscord_rpc = 1\n', encoding='utf-8') + a = mock.MagicMock() + a.message = '' + a.game_busy.return_value = True + row = App.discord_row(a, str(game)) + before = (game / 'nx2navi.ini').read_bytes() + row.on(False) + self.assertEqual((game / 'nx2navi.ini').read_bytes(), before) + self.assertTrue(row.get()) # the switch still shows what the file says + self.assertIn('Quit the game first', a.message) + a.game_busy.return_value = False + row.on(False) + self.assertEqual(gameini.get(game, 'discord_rpc'), '0') + self.assertFalse(row.get()) + self.assertEqual(a.message, '') + a.game_busy.return_value = True # a mod's switch while the game runs + a.settings = {'game_dir': str(game)} + App.switch_mod(a, mock.Mock(), False) + self.assertEqual(gameini.get(game, 'MODS_DISABLED'), '') + self.assertIn('Quit the game first', a.mods_message) + def ended(self, code, log_text): """watch_game after the game ended with code, its log holding log_text; (the stand-in window, the log).""" from launcher.ui.app import App