Skip to content

Mac app: a dataFolder key keeps a game's save, caches and log in one folder a front end chooses - #460

Open
v0lumehi wants to merge 3 commits into
seedds:mainfrom
v0lumehi:mac-data-folder
Open

v0lumehi wants to merge 3 commits into
seedds:mainfrom
v0lumehi:mac-data-folder

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Refs #388. A front end that keeps each game in its own folder (varyform's <title ID>_build/run) could not have the Mac app keep its data there: the save, the pipeline cache and the log were always in ~/Library. This PR adds that, as agreed in #388.

A dataFolder string in the app's preferences domain (read with CFPreferences, like the launcher.<VAR> saved choices) names the game's own folder:

  • The path. Relative to the folder the .app is in, so a library that's renamed or moved keeps working. An absolute path works too.
  • What moves. save/, save.work/, temp/, the player's env.txt, pso_user.tsv, pso_archive/ and the log (log/<title ID>.log, .prev.log). The folder is DM_ROOT and the working folder.
  • The order. The launcher resolves the key, then reads <data folder>/env.txt, then the bundle's dm/env.txt. A DM_SAVE, DM_TEMP, DM_ROOT or DM_PSO_USER set in the environment or an env.txt still wins, each for its own path. DM_SAVE alone stays the lean option: only the save moves.
  • First start. If the folder has no save/ yet, the old save/ (and save_device/, which the host mounts beside it) and pso_user.tsv are copied, never moved, and the log names both paths. The copy goes to a .copying sibling that is renamed into place, so an interrupted copy leaves no half save and the next start tries again. If the copy fails, that start keeps the old save and prints a [RED] line.
  • A folder that can't be made or written. Checked by creating a real file there, since access() says yes on a read-only volume or where privacy checks refuse the open. It prints [RED] launcher: data folder <path> (dataFolder <key>) cannot be made or written (<reason>), and that start uses ~/Library as before.
  • No layout rule. The key is the opt-in; without it nothing changes.

Save and log only: DM_LOG_DIR and relative paths

A front end that keeps only a game's save and log beside the app (everything else in ~/Library) could say "everything" (dataFolder) or "only the save" (DM_SAVE), not both. Two additions:

  • DM_LOG_DIR is the folder the launcher writes <title ID>.log and <title ID>.prev.log into. It is read like DM_SAVE (the launch environment, the player's env.txt, the bundle's dm/env.txt, the first wins) and beats the data folder's log/ when both are set. One that cannot be made or written is a [RED] line, and the log goes to ~/Library/Logs/nxnative.
  • Relative DM_SAVE and DM_LOG_DIR are resolved against the folder the .app is in, as a relative dataFolder is, so a library that moves keeps working. Absolute values are unchanged, and the host gets the absolute path only.
  • How the log moved. The launcher used to open its log before it read the env.txt files. It now opens it after them. Until then its own lines (the name line, the data folder line, each env line) go to an unnamed temporary file, which is copied into the log first, so nothing is lost. If the log cannot be opened, they go back to stderr.
  • The save folder is made by the launcher, all its levels, whatever set DM_SAVE: the host makes only the last level before it clones the save, and mounts it read-only when that fails. One that cannot be made is a [RED] launcher: cannot make the save folder line (no fallback: the player's choice stays).
  • A front end that already keeps saves somewhere else moves them itself before it writes dataFolder; the launcher copies only from ~/Library (docs/frontends.md, Data folder).

Files:

  • dm/mac/launcher.c;
  • test_data_folder and test_log_dir_and_relative_paths in dm/tools/tests/test_nsp_mac_app.py;
  • the docs: a new "Data folder" section in docs/frontends.md, the paths in docs/development.md (A Mac app) and docs/settings.md, and DM_LOG_DIR in docs/env_switches.tsv.

Checked

  • Tests:
    • test_nsp_mac_app.test_data_folder. It runs the real launcher with a stand-in host, a temporary HOME and a throwaway preferences domain, and covers:
      • the key unset;
      • a relative and an absolute key;
      • the env.txt order;
      • DM_SAVE, DM_TEMP, DM_ROOT and DM_PSO_USER each winning for their own path only;
      • the one-time copy (old data left in place, no .copying left behind, not repeated);
      • .prev.log;
      • a read-only and an uncreatable folder;
      • a non-string value.
    • test_nsp_mac_app.test_log_dir_and_relative_paths, same setup: DM_LOG_DIR from the environment, the player's env.txt, relative and absolute; the early lines in the log; the rotation to .prev.log; relative DM_SAVE; DM_LOG_DIR over a data folder's log/; an unwritable and an uncreatable DM_LOG_DIR falling back to ~/Library/Logs with a [RED] line; a DM_SAVE two levels deep in a fresh library made before the host runs (environment and env.txt) and an unmakeable one's [RED] line; the save-and-log shape without dataFolder leaving DM_ROOT, temp/ and the pipeline list in ~/Library.
    • After the addition: test_nsp_mac_app 44 tests pass (including both new and old data folder tests), test_docs and test_env_switches pass (11). The whole dm/tools/tests (unittest discovery) ran 375 tests; the failures and errors there are all missing Python modules on this machine (capstone, lz4) in test_nso_match, test_nro_pack, test_size_prefixed_frames, test_split_unreadable and three import errors, none touching the launcher.
    • dm/tools/tests: 400 tests pass, apart from test_regress.test_routes, which failed on main too until 3283fee. Rebased onto 3283fee, test_regress, test_docs and test_nsp_mac_app pass.
    • test_docs: OK.
    • The lint ratchet: 0 new findings.
    • make -C dm/host GAME=01007EF00011E000: builds.
  • Games run: none. The launcher's paths are tested with the stand-in host only. That the host derives pso_archive/ from DM_PSO_USER's folder is read from nvn_mtl.m, not seen in a run.
  • Devices and OS: M2 Max, macOS 27.2.
  • Regress: none. The change is only in the Mac app's launcher (dm/mac/launcher.c), and regress.py starts dmhost directly, so its runs don't reach it.
  • Not handled: a .app reached through a symbolic link resolves a relative dataFolder against the app's real location, because the launcher uses the real path of its own executable.

Docs

  • Not applicable: no finding about a game or a subsystem. The behaviour is documented in docs/frontends.md (Data folder) and docs/development.md (A Mac app)
  • Not applicable: no chain tool changed
  • No game files, keys or data extracted from a game in the change or the attachments

@v0lumehi

Copy link
Copy Markdown
Contributor Author

Two additions, after the discussion in #388:

  • DM_LOG_DIR puts the log where a front end wants it, the way DM_SAVE puts the save. It is read from the launch environment and from both env.txt files.
  • DM_SAVE and DM_LOG_DIR may be relative. A relative path is resolved against the folder the .app is in, like a relative dataFolder. A library folder can then move without breaking them.

This makes three shapes:

  • Everything per game in one folder: dataFolder, @varyform's case.
  • Only the save and the log beside the game: DM_SAVE + DM_LOG_DIR, the rest stays in ~/Library. That's the shape NX2Apple uses. Its fork does it today with its own launcher patch, which this change lets it drop.
  • Nothing set: ~/Library, as before.

What else changed in the launcher:

  • It opens its log after the env.txt files now. Its earlier lines are buffered and written first, so none are lost.
  • It makes the DM_SAVE folder at every level before the host starts, wherever DM_SAVE came from. The host makes only the last level. With a missing parent folder it would mount the save read-only, and nothing would be saved.
  • A front end that already keeps saves somewhere else moves them itself before it writes dataFolder. The launcher copies only from ~/Library. The docs now say so.

test_nsp_mac_app.py passes all 44 tests, and test_docs and test_env_switches pass too. The new cases cover the log folder from the environment and from env.txt, relative paths, the "save and log only" shape, an unwritable log folder, and a save folder two levels deep.

Refs seedds#388. A front end that keeps each game in its own folder (varyform's
<title ID>_build/run) could not make the Mac app keep its save, pipeline
cache and log there; they were always in ~/Library.

A dataFolder string in the app's preferences domain (read with
CFPreferences, like the launcher.<VAR> choices) names the game's own folder,
relative to the folder the .app is in (so a moved library keeps working) or
absolute. With it, save/, save.work/, temp/, the player's env.txt,
pso_user.tsv, pso_archive/ and the log (log/<title ID>.log and .prev.log)
live there; it is DM_ROOT and the working folder. DM_SAVE, DM_TEMP, DM_ROOT
and DM_PSO_USER set in the environment or an env.txt still win, each for its
own path (DM_SAVE alone moves only the save). Order: key, then
<data>/env.txt, then the bundle's.

First start with the key and no save/ yet: the old save (and save_device/)
and pso_user.tsv are copied, never moved, via a .copying sibling renamed into
place, and both paths are logged. A folder that cannot be made or written
prints a [RED] line with the path and the start keeps ~/Library. No layout
rule: the key is the opt-in.

Checked: test_nsp_mac_app test_data_folder (key unset, relative, absolute,
env.txt order, DM_SAVE/DM_TEMP/DM_ROOT/DM_PSO_USER precedence, one-time copy,
read-only and uncreatable folders, non-string value); dm/tools/tests (only
test_regress.test_routes fails, as on upstream/main); test_docs; lint
ratchet 0 new; host builds.
…p's folder

The log is opened after the env files are read, so DM_LOG_DIR can come from the launch environment, the player's env.txt or the bundle's; what the launcher prints before is kept in a temporary file and copied into the log first. A relative DM_SAVE or DM_LOG_DIR is resolved against the folder the .app is in, like a relative dataFolder. An unusable DM_LOG_DIR is a [RED] line and ~/Library/Logs/nxnative.
… host starts

The host makes only the last level before it clones the save and mounts the save read-only when that fails, so a relative DM_SAVE in a library without save/ lost every save. An unmakeable DM_SAVE is a [RED] line; the player's choice stays.
@github-actions github-actions Bot added mac The Mac front end and app (dm/mac, front_mac.m) tools Tools and scripts (dm/tools, scripts) docs Documentation labels Nov 3, 2026
lucaszhongsj pushed a commit to lucaszhongsj/nxnative that referenced this pull request Nov 19, 2026
Upstream-Status: pending (seedds#460 is the upstream design)
Reason: Store saves and logs alongside the game library folder while falling back to Library on non-APFS volumes
Issue: LNPANDY/NX2Apple#123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation mac The Mac front end and app (dm/mac, front_mac.m) tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant