Download and stage updates in the background, and install them only when the game is not running.

A check that finds a newer release (at start, then hourly while the launcher runs, also hidden during play) stages
it on a background-priority thread: the app into app/<version>, a new Python into app/<version>/python.staged rather
than python.next (which the stub would swap in under the running version), and staged.json written last to mark it
complete. Nothing is switched and nothing restarts. A failed staging is logged and tried again after the next check.

The staged release installs, through the existing switch, restart and ContinueUpdateJob path, when the launcher
starts and right after the game exits, never while a copy of the game runs. Install Updates Automatically (on by
default) can leave it to the Updates row instead. A version the stub rolled back from is not staged or installed by
itself again, prune keeps a staged release, and the Settings rows now fit the window with the new toggle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-09 10:22:37 -05:00
parent 0223d88520
commit cd20bdf09f
8 changed files with 698 additions and 37 deletions

View File

@@ -201,6 +201,22 @@ def keep_awake(on):
pass
def background_thread():
"""Windows: put the calling thread in background mode (SetThreadPriority THREAD_MODE_BACKGROUND_BEGIN), which
lowers its processor, disk and memory priority, so work done beside the game takes only what the game leaves.
False where that is not possible."""
if os.name != 'nt':
return False
try:
from ctypes import wintypes
k = ctypes.WinDLL('kernel32') # a private handle: the argument types set here touch no other caller
k.GetCurrentThread.restype = wintypes.HANDLE
k.SetThreadPriority.argtypes = (wintypes.HANDLE, ctypes.c_int)
return bool(k.SetThreadPriority(k.GetCurrentThread(), 0x00010000))
except (AttributeError, OSError):
return False
# What the launcher puts in its folder (launcher/paths.py, the stub's python.next and python.old-<n>). Uninstall deletes
# only these: the default game folder is <root>\game, and a folder given to the setup with --dest may hold other things.
OWNED = ('NX2navi.exe', 'app', 'python', 'python.next', 'pydeps', 'data', 'toolchain')
@@ -226,7 +242,7 @@ def uninstall_plan(layout, remove_game=''):
def uninstall_script(gone, empty):
"""The cmd.exe line that deletes them once the launcher has exited: a file with del, a folder with rmdir /s, the
folders that must be empty with a plain rmdir (which leaves a folder that still holds something). A path holding
% is left out: cmd.exe expands %NAME% even inside quotes, so a folder named C:\%HOMEPATH% would delete another."""
% is left out: cmd.exe expands %NAME% even inside quotes, so a folder named C:\\%HOMEPATH% would delete another."""
steps = ['ping -n 3 127.0.0.1 >nul']
for p in gone:
if '%' not in str(p):