mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 16:49:58 -04:00
Tell the end of a game started from the Steam shortcut as Play tells it, with a message box for a fatal one.
play_only, the --play path of the Steam shortcut, logged only "the game ended (code N)" in launcher.log: it read no FATAL line, added no note to the game's log and showed nothing, so a game that ended with 70, 71, 72 or a Windows status left the player with no word of why (as when Steam starts it while the window replaces a save, and it ends at once with "another copy of the game is running"). The 7b0dbeb1 change that logs every end touched the window's watch only. play_only now follows the run with GameRun, the Restart's copies too, and takes the same game_end as the window: the line in launcher.log, the note in the game's log, and a message box only for an end worth one (a FATAL line, 70, 71 or 72, a Windows status; not 0, nor 1 from Task Manager's End task). The logs are written before the box, which waits for OK while Steam still counts the game as running.
Not reproduced before the change in a game run: the audit's probe showed it with a stand-in process. Checks that passed: tests/launcher_test.py (214 tests, a new one for the Steam shortcut's ends with codes 70, 0xC0000005, 0 and 1, which fails before the change) and tools/check_content.py --staged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -75,7 +75,8 @@ Customize Launcher (on the home screen) makes the look the player's own:
|
|||||||
Steam reads that file only when it starts and writes it back when it closes, so a running Steam is asked to close
|
Steam reads that file only when it starts and writes it back when it closes, so a running Steam is asked to close
|
||||||
first and started again after. The shortcut runs the launcher's `pythonw.exe` on `data/steam_play.pyw`, which
|
first and started again after. The shortcut runs the launcher's `pythonw.exe` on `data/steam_play.pyw`, which
|
||||||
starts the launcher of `app/current.txt` with `--play`: the game starts as Play starts it, and the process waits
|
starts the launcher of `app/current.txt` with `--play`: the game starts as Play starts it, and the process waits
|
||||||
for it, so Steam counts the game as running while it is.
|
for it, so Steam counts the game as running while it is. Its end goes into the logs as Play's does, and a fatal
|
||||||
|
error or a crash gets a message box, as no window shows it.
|
||||||
|
|
||||||
The choices are `theme`, `custom_background`, `custom_panel`, `custom_buttons`, `background`, `background_dim`,
|
The choices are `theme`, `custom_background`, `custom_panel`, `custom_buttons`, `background`, `background_dim`,
|
||||||
`animations` and `sounds` in `data/launcher.json`.
|
`animations` and `sounds` in `data/launcher.json`.
|
||||||
|
|||||||
@@ -241,13 +241,13 @@ def shown_fatal(fatal):
|
|||||||
|
|
||||||
|
|
||||||
def game_end(game_dir, code, started=None, restarted=False):
|
def game_end(game_dir, code, started=None, restarted=False):
|
||||||
"""What the launcher says about an end of the game (App.watch_game): a GameEnd of the line for launcher.log, the
|
"""What the launcher says about an end of the game (App.watch_game, play_only): a GameEnd of the line for
|
||||||
sentence for the player ('' for none), the text note_exit_in_log adds to the game's log ('' for none), and alarm:
|
launcher.log, the sentence for the player ('' for none), the text note_exit_in_log adds to the game's log ('' for
|
||||||
whether the end is worth a message box where no window shows the sentence (a FATAL line, a code of FATAL_CODES or
|
none), and alarm: whether the end is worth a message box where no window shows the sentence (a FATAL line, a code
|
||||||
a Windows status; not 0, nor 1, which Task Manager's End task gives). code is the exit code of the run's last
|
of FATAL_CODES or a Windows status; not 0, nor 1, which Task Manager's End task gives). code is the exit code of
|
||||||
process, or None when it is not known, which happens only for a copy the game's own Restart started that could not
|
the run's last process, or None when it is not known, which happens only for a copy the game's own Restart started
|
||||||
be followed (GameRun). started is time.time() before the game was started, restarted whether it restarted itself
|
that could not be followed (GameRun). started is time.time() before the game was started, restarted whether it
|
||||||
on the way."""
|
restarted itself on the way."""
|
||||||
how = ' after restarting itself' if restarted else ''
|
how = ' after restarting itself' if restarted else ''
|
||||||
if code not in (0, None):
|
if code not in (0, None):
|
||||||
code &= 0xFFFFFFFF
|
code &= 0xFFFFFFFF
|
||||||
@@ -2880,16 +2880,24 @@ def play_only(ctx):
|
|||||||
if waiting: # the window builds the mods' code in, then starts the game (App.start with --play)
|
if waiting: # the window builds the mods' code in, then starts the game (App.start with --play)
|
||||||
ctx.log(f'play from Steam: the game is built again first for the code of {", ".join(waiting)}')
|
ctx.log(f'play from Steam: the game is built again first for the code of {", ".join(waiting)}')
|
||||||
return None
|
return None
|
||||||
|
started = time.time()
|
||||||
try:
|
try:
|
||||||
proc = winsys.start_game(exe)
|
run = GameRun(winsys.start_game(exe), gd, started)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
ctx.log(f'play from Steam: {exe}: {e}')
|
ctx.log(f'play from Steam: {exe}: {e}')
|
||||||
return None
|
return None
|
||||||
ctx.log(f'play from Steam: {exe}')
|
ctx.log(f'play from Steam: {exe}')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
while proc.poll() is None or saves.game_running(gd):
|
while run.running():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ctx.log(f'play from Steam: the game ended (code {proc.returncode})')
|
# The end is told as Play's is (App.watch_game), with no window: a box for an end worth one. The logs come first,
|
||||||
|
# since the box waits for OK and Steam may end this process meanwhile.
|
||||||
|
end = run.end()
|
||||||
|
ctx.log(f'play from Steam: {end.log}')
|
||||||
|
if end.note:
|
||||||
|
note_exit_in_log(gd, end.note)
|
||||||
|
if end.alarm:
|
||||||
|
tell(end.message)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5293,6 +5293,57 @@ class WhilePlayingTest(Tmp):
|
|||||||
a.ctx.log.assert_called_once_with('the game ended with code 0')
|
a.ctx.log.assert_called_once_with('the game ended with code 0')
|
||||||
self.assertNotIn('[launcher]', log.read_text(encoding='utf-8'))
|
self.assertNotIn('[launcher]', log.read_text(encoding='utf-8'))
|
||||||
|
|
||||||
|
def play_from_steam(self, code, log_text):
|
||||||
|
"""play_only (--play, the Steam shortcut) for a game that ends with code, its log then holding log_text; (the
|
||||||
|
context, the stand-in for tell, the log)."""
|
||||||
|
from launcher.ui import app
|
||||||
|
(self.tmp / 'ocarina.exe').write_bytes(b'MZ')
|
||||||
|
log = self.tmp / 'logs' / 'nx2navi.log'
|
||||||
|
log.parent.mkdir(exist_ok=True)
|
||||||
|
log.write_text(log_text, encoding='utf-8')
|
||||||
|
ctx = mock.MagicMock()
|
||||||
|
ctx.settings = {'game_dir': str(self.tmp)}
|
||||||
|
proc = mock.MagicMock(returncode=code, pid=5)
|
||||||
|
proc.poll.return_value = code
|
||||||
|
told = []
|
||||||
|
|
||||||
|
def tell(text): # what the logs hold when the box comes, which waits for OK
|
||||||
|
told.append((text, log.read_text(encoding='utf-8'), list(ctx.log.call_args_list)))
|
||||||
|
with mock.patch('launcher.ui.app.winsys.start_game', return_value=proc), \
|
||||||
|
mock.patch('launcher.ui.app.saves.game_running', return_value=False), \
|
||||||
|
mock.patch('launcher.ui.app.mods.prepare', return_value=[]), \
|
||||||
|
mock.patch('launcher.ui.app.build.can_rebuild', return_value=False), \
|
||||||
|
mock.patch('launcher.ui.app.time.sleep'), \
|
||||||
|
mock.patch('launcher.ui.app.tell', side_effect=tell):
|
||||||
|
self.assertEqual(app.play_only(ctx), 0)
|
||||||
|
return ctx, told, log
|
||||||
|
|
||||||
|
def test_an_end_of_a_game_started_from_steam_is_told(self):
|
||||||
|
"""The Steam shortcut's game ends as Play's does: launcher.log and the game's log say how, and an end worth it
|
||||||
|
(a FATAL line, 70, 71 or 72, a Windows status) gets a message box, as no window shows it."""
|
||||||
|
try:
|
||||||
|
from launcher.ui import app # noqa: F401
|
||||||
|
except ImportError as e:
|
||||||
|
self.skipTest(f'no window toolkit: {e}')
|
||||||
|
ctx, told, log = self.play_from_steam(70, '[host] x\nFATAL: fs: another copy of the game is running\n')
|
||||||
|
self.assertEqual(len(told), 1)
|
||||||
|
text, game_log, calls = told[0]
|
||||||
|
self.assertEqual(text, 'The game ended with a fatal error (code 70): fs: another copy of the game is running. '
|
||||||
|
'Its log is logs\\nx2navi.log in the game folder.')
|
||||||
|
self.assertIn('[launcher] the game ended with code 70', game_log)
|
||||||
|
self.assertIn(mock.call('play from Steam: the game ended with code 70; its log says: FATAL: fs: another copy '
|
||||||
|
'of the game is running'), calls)
|
||||||
|
_, told, _ = self.play_from_steam(0xC0000005, '[host] x\n')
|
||||||
|
self.assertEqual([t[0] for t in told], ['The game ended with code 0xC0000005 (access violation). Its log is '
|
||||||
|
'logs\\nx2navi.log in the game folder.'])
|
||||||
|
ctx, told, log = self.play_from_steam(0, '[host] x\n[host] gfx: window closed; exiting\n')
|
||||||
|
self.assertEqual(told, [])
|
||||||
|
ctx.log.assert_called_with('play from Steam: the game ended with code 0')
|
||||||
|
ctx, told, log = self.play_from_steam(1, '[host] perf: the last line\n') # Task Manager's End task
|
||||||
|
self.assertEqual(told, [])
|
||||||
|
ctx.log.assert_called_with('play from Steam: the game ended with code 1')
|
||||||
|
self.assertIn('[launcher] the game ended with code 1 at', log.read_text(encoding='utf-8'))
|
||||||
|
|
||||||
def test_a_fatal_exit_shows_the_games_fatal_line(self):
|
def test_a_fatal_exit_shows_the_games_fatal_line(self):
|
||||||
"""Exit codes 70 and 71 follow a FATAL line in the game's log: the home screen and launcher.log name it."""
|
"""Exit codes 70 and 71 follow a FATAL line in the game's log: the home screen and launcher.log name it."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user