Keep saves safe in Import Saves and Quit, draw no traced game art, and recompile the game for a new processor.

Import Saves: the saves folder picked in the dialog imports what waits in it (it had made the folder's README the
save); the save backed up is the one the game would load, in runtime/fs_host.c save_recover's order, so an interrupted
commit's only copy is kept, and the rest of the commit journal moves into the backup instead of being deleted; the
imported save goes into place before the old one is deleted, which comes back if that fails; another NX2navi install's
finished commit counts as its save. Tests cover each.

Quit waits while the game writes a save, as Restart does: the game runs on under the menu, and closing the window
finishes only a commit that has begun. The VSync row says "in use: Immediate" when VSync On falls back to tearing, and
its default follows the device profile (cfg_default). Without the game's textures the menu's divider is a plain line
and diamond of its own, not a tracing of the game's ornament.

make_game.py: the compile key holds the processor's features (cpu_tag), so a game folder moved to a PC without AVX2
compiles again instead of crashing; the main thread gets 16 MiB of stack with GNU ld too; any error waits for the
RomFS image, so its .part file is not cut short. The launcher tests use a neutral title id; tools/menu_preview.cpp
has cfg_default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-08 03:57:02 -05:00
parent 8daedbd806
commit f57a327a86
11 changed files with 166 additions and 93 deletions

View File

@@ -94,6 +94,9 @@ def find_save(folder):
return None, ()
for base in (p / 'profile' / 'save', p / 'save'): # another game folder, or its profile folder
if base.is_dir():
ready = _ready(base.parent / 'save-tx') # a finished commit there is newer than its account folder
if ready is not None and _has_file(ready):
return ready, ()
accounts = [d for d in base.iterdir() if d.is_dir() and HEX32.match(d.name)]
if accounts:
return max(accounts, key=lambda d: d.stat().st_mtime), ()
@@ -143,18 +146,25 @@ def _files(src, skip):
return out
def _newest(game, account):
"""The folder the game would load now: a finished commit still waiting in save-tx, else the account folder."""
tx = Path(game) / 'profile' / 'save-tx'
def _ready(tx):
"""The newest finished commit (ready-<n>) in a save-tx folder, or None."""
ready = []
if tx.is_dir():
for d in tx.iterdir():
if Path(tx).is_dir():
for d in Path(tx).iterdir():
m = re.fullmatch(r'ready-(\d+)', d.name)
if m and d.is_dir():
ready.append((int(m.group(1)), d))
if ready:
return max(ready)[1]
return account if account.is_dir() else None
return max(ready)[1] if ready else None
def _newest(game, account):
"""The folder the game would load now, in the order of runtime/fs_host.c save_recover: a finished commit still
waiting in save-tx, else the account folder, else an interrupted commit's new save, else the save it replaced."""
tx = Path(game) / 'profile' / 'save-tx'
for d in (_ready(tx), account, tx / 'new', tx / 'old'):
if d is not None and d.is_dir():
return d
return None
def game_running(game):
@@ -175,6 +185,8 @@ def import_save(game, folder=None, log=print):
"""Make the save in folder (None: the one waiting in <game>/saves) the game's save. Returns {'files', 'source',
'backup'}; backup is the folder the replaced save went to, or None when there was none."""
game = Path(game)
if folder is not None and Path(folder).resolve() == saves_dir(game).resolve():
folder = None # the saves folder itself, picked in the dialog: what waits in it, as the button takes it
from_saves = folder is None
src, skip = waiting(game) if from_saves else find_save(folder)
if src is None:
@@ -198,15 +210,34 @@ def import_save(game, folder=None, log=print):
for rel in files:
(stage / rel).parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(Path(src) / rel, stage / rel)
for d in list(tx.iterdir()): # the journal of the replaced save: the game would load a finished commit first
if d != stage:
# The journal of the replaced save goes out of save-tx (the game would load a finished commit first, or complete an
# interrupted one): what holds files moves into the backup, beside the save it was copied from, so a copy the
# backup's own choice missed (an interrupted commit's other half) is kept too.
for d in list(tx.iterdir()):
if d == stage:
continue
if _has_file(d) if d.is_dir() else d.stat().st_size:
if backup is None:
backup = _fresh(saves, f'backup {stamp}')
backup.mkdir()
(backup / 'save-tx').mkdir(exist_ok=True)
shutil.move(str(d), str(backup / 'save-tx' / d.name))
else:
shutil.rmtree(d, ignore_errors=True) if d.is_dir() else d.unlink(missing_ok=True)
account.parent.mkdir(parents=True, exist_ok=True)
# The imported save goes into place before the old one is deleted; a failed rename puts the old one back.
gone = None
if account.exists():
gone = tx / 'replaced'
gone = _fresh(tx, 'replaced')
os.replace(account, gone)
try:
os.replace(stage, account)
except OSError:
if gone is not None:
os.replace(gone, account)
raise
if gone is not None:
shutil.rmtree(gone, ignore_errors=True)
os.replace(stage, account)
if from_saves: # what was put into saves/ moves out whole, so the next import does not take any of it again
done = _fresh(saves, f'imported {stamp}')
done.mkdir()

View File

@@ -141,7 +141,7 @@ def states(app):
def import_saves():
app.release, app.message = None, ''
app.save_message = ('Save imported: 3 files from 0100F2C0115B6000. Your old save is in '
app.save_message = ('Save imported: 3 files from 0100000000010000. Your old save is in '
'saves\\backup 2026-11-08 17.30.12.')
app.show('home', next(i for i, r in enumerate(app.rows_home()) if r.label == 'Import Saves'))