Keep the Steam shortcut from starting the game while the launcher runs a job in the game folder.

The Steam shortcut's --play runs before the window's single-instance lock and checked only whether the game was running. Started while the window rebuilt the game, installed an update or built the mods' code, it ran mods.prepare into the folder the job was reading and started the old ocarina.exe, and the job then failed at the swap with "ocarina.exe is in use" (an update's install left the new launcher on the old build); during the shaders step, make_game.py's own run of the exe made the shortcut log "already running" and do nothing visible. play_only now tries the launcher folder's lock and lets go of it at once: when another process holds it and data/job-running.json names a job (jobs.running_job, which leaves the marker in place), it logs that the launcher is busy, says which job to wait for in a message box and does not start the game. A marker that a stopped launcher left does not stop it, since its lock went with its process, and neither does the window open without a job.

Not reproduced before the change in a game run: found by reading the code. Checks that passed: tests/launcher_test.py (216 tests, a new one for a held lock with the job's marker, a leftover marker with the lock free, and the window open without a job, 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:
chrg6
2026-11-13 17:18:36 -05:00
parent 0105720217
commit 814c10b355
4 changed files with 62 additions and 6 deletions

View File

@@ -43,6 +43,18 @@ def interrupted(ctx):
return left if isinstance(left, dict) and left.get('task') else None
def running_job(ctx):
"""The job writing into the game folder as MARKER says it ({'task', 'kind', 'game_dir', 'started'}), or None. The
marker stays. Only worth asking while another process holds the launcher folder's lock: one that a launcher
stopped in its job left behind reads the same (interrupted tells it and removes it)."""
try:
with open(ctx.layout.data / MARKER, encoding='utf-8') as f:
job = json.load(f)
except (OSError, ValueError):
return None
return job if isinstance(job, dict) and job.get('task') else None
def failure_line(e):
"""A failure in one line for the log: its kind, its message and what it came from."""
cause = e.__cause__

View File

@@ -2867,6 +2867,18 @@ def play_only(ctx):
exe = Path(gd) / 'ocarina.exe' if gd else None
if not exe or not exe.is_file():
return None
# The window or a command may run a job in the game folder meanwhile (a rebuild, an update's install, the mods'
# build): the game started now would be the build that job is replacing, which then fails to replace it, and
# mods.prepare would unpack into the folder the job reads. Such a job holds the launcher folder's lock and leaves
# jobs.MARKER. The lock is only tried, and let go at once: held, it would keep the window from opening.
try:
locks.FileLock(ctx.layout.instance_lock, 'play from Steam', where=ctx.layout.root).release()
except locks.Busy:
job = jobs.running_job(ctx)
if job:
ctx.log(f'play from Steam: not started: the launcher is busy with {job["task"]}')
tell(f'NX2navi is busy with {job["task"]}. Start the game when it is done.')
return 0
if saves.game_running(gd):
ctx.log('play from Steam: the game is already running')
return 0