Skip to content

Cloud saves: a game's Mac and iPhone apps share one save through an iCloud Drive folder - #617

Closed
v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:cloud-saves
Closed

v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:cloud-saves

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

What and why

A save moves between a game's Mac app and its iPhone app only by hand. These apps are signed ad hoc or with a free team, so CloudKit and iCloud entitlements are not available. A folder the player picks in iCloud Drive is.

dm/host/save_sync.c packs the committed save (DM_SAVE and DM_SAVE_device) into one file, <folder>/<title ID>/save.dmsync. iCloud replaces a single file as a whole, but syncs a folder file by file. The cloud copy comes in at the game's first save mount. The committed save goes out a few seconds after a Commit, when the iPhone app goes to the background, and from the Mac launcher after the host exits. <DM_SAVE>.sync holds the hash of the last save both sides agreed on, so the host knows which side changed. When both changed, the newer save wins. Every replaced save is first copied to <DM_SAVE>-backups/<date> local|cloud.

The folder is chosen in each app's launcher:

  • Mac: the Cloud saves section of the settings window (dm/mac/Launcher.swift, defaults key cloudSaves.folder, passed on by launcher.c).
  • iPhone: a Cloud saves section in dm/ios/Sources/Launcher.swift. The folder is a security-scoped bookmark in CloudSaves.m. Swift reaches it through DmIOS-Bridging-Header.h. The copies go through NSFileCoordinator in SaveSync.m, which downloads a file iCloud has only listed.

DM_SAVE_SYNC (a folder, icloud, or 0) overrides both. The switch is in docs/env_switches.tsv and docs/settings.md.

The feature was written by @dreamw0rk for the NX2Apple fork (LNPANDY/NX2Apple#185). The commit keeps him as the author. There the iPhone bookmark shared code with a game-data picker that nxnative does not have. I moved the cloud-save part into CloudSaves.h/.m and the Cloud saves section of the iPhone launcher. hle_fs.c uses DM_GAME_ID for the title ID.

Checked

  • Tests (all pass):
    • make -C dm/host GAME=010015100B514000
    • make -C dm/host/tests GAME=010015100B514000 run, including the new t_save_sync with 47 checks
    • make -C dm/host/tests GAME=010015100B514000 tsan-threads, which includes t_save_sync
    • t_save_sync under ASan and UBSan
    • python3 -m unittest dm.tools.tests.test_nsp_mac_app dm.tools.tests.test_launcher_settings dm.tools.tests.test_docs
    • dm/ios/tests (39 tests)
    • Typecheck of the iOS Swift sources with the bridging header, and clang -fsyntax-only of CloudSaves.m, SaveSync.m and front_ios.m against the iOS 26 SDK
  • Games run: TOTK 1.4.3 was synced between an iPhone and a Mac in both directions on the NX2Apple fork. I did not run a game on this branch. The iPhone part as split out here is not tested on a device.
  • Devices and OS: M2 Max, macOS 27.2.
  • regress.py: not run. The change adds a save hook to hle_fs.c that does nothing while DM_SAVE_SYNC is unset and no folder is picked. The other games' paths are unchanged.

Docs

  • The finding is in its game note or its docs/reference/<subsystem>.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index). Not applicable, this is a feature. docs/settings.md and docs/env_switches.tsv describe it.
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change. Not applicable.
  • No game files, keys or data extracted from a game in the change or the attachments

…through an iCloud Drive folder

Until now a save moved between the Mac and an iPhone only by hand (the Mac front end's Saves sheet, over the cable). The apps are signed ad hoc or with a free/personal team, so CloudKit and iCloud entitlements are out; a folder the player picks in iCloud Drive is not.

dm/host/save_sync.c packs the committed save (DM_SAVE and DM_SAVE_device) into one file, <folder>/<title ID>/save.dmsync (a folder named after the title ID is taken as the game's own), because iCloud replaces a file as a whole but syncs a folder file by file. The cloud's copy comes in at the game's first save mount, before the work directory is cloned; the committed save goes out a few seconds after a Commit on a thread of its own, when the iPhone app goes to the background, and from the Mac launcher once the host has exited. <DM_SAVE>.sync keeps the hash of the save last known to be the same on both sides: only the cloud's changed, it comes in; only this one changed, it goes out; both changed, the newer wins. Every save this replaces, here or in the cloud, is kept first in <DM_SAVE>-backups/<date> local|cloud.

The folder is chosen in each app's launcher: Cloud saves in the Mac settings window (dm/mac/Launcher.swift, defaults key cloudSaves.folder, read by launcher.c) and on the iPhone (a security-scoped bookmark, CloudSaves.m). DM_SAVE_SYNC (a folder, icloud, or 0) overrides both. On the iPhone the copies go through NSFileCoordinator (SaveSync.m), which downloads a file iCloud has only listed.

Tested: dm/host/tests/t_save_sync.c (47 checks, also under TSan and ASan/UBSan), and TOTK 1.4.3 between an iPhone and a Mac in both directions on the NX2Apple fork. There the iPhone bookmark shared code with the fork's game-data picker. Here CloudSaves.m holds it on its own, and that iPhone part is not yet tested on a device.
LNPANDY pushed a commit to LNPANDY/NX2Apple that referenced this pull request Oct 29, 2026
The same change is open upstream as seedds/nxnative#617. The patch goes when it merges.
LNPANDY added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 29, 2026
seedds added a commit that referenced this pull request Oct 29, 2026
…Cloud Drive folder (PR #617)

A save moved between the Mac app and the iPhone app only by hand. The apps are signed ad hoc or with a free team, so CloudKit and iCloud entitlements are out; a folder the player picks in iCloud Drive is not.

dm/host/save_sync.c packs the committed save (DM_SAVE and DM_SAVE_device) into one file, <folder>/<title ID>/save.dmsync, because iCloud replaces a file as a whole but syncs a folder file by file. The cloud's copy comes in at the game's first save mount, before the work directory is cloned; the committed save goes out a few seconds after a Commit on a thread of its own, when the iPhone app goes to the background, and from the Mac launcher once the host has exited. <DM_SAVE>.sync keeps the hash of the save last known to be the same on both sides: only the cloud's changed, it comes in; only this one changed, it goes out; both changed, the newer wins. Every save this replaces, here or in the cloud, is kept first in <DM_SAVE>-backups/<date> local|cloud; the newest 10 of each side stay.

The folder is chosen in each app's launcher: Cloud saves in the Mac settings window (dm/mac/Launcher.swift, cloudSaves.folder, read by launcher.c) and on the iPhone (a security-scoped bookmark, CloudSaves.m; copies through NSFileCoordinator, SaveSync.m). DM_SAVE_SYNC (a folder, icloud for iCloud Drive/nxnative Saves, or 0) overrides both.

On top of the PR: the Mac launcher sends the DM_SAVE the host used (an env file may set another folder than the app's own), with trailing slashes stripped as the host strips them; backups are pruned to the newest 10 per side; the fork's names (NX2Apple Saves, the front end's Saves sheet) are gone; docs/frontends.md makes the Mac folder (cloudSaves.folder in the app's preferences, DM_SAVE_SYNC at launch) part of the front-end contract, so a front end can set or change it for every game; impact_map.tsv maps save_sync.* and the Mac Launcher.swift.

Tested: t_save_sync (54 checks, also under TSan), the host tests, test_nsp_mac_app, test_launcher_settings; regress.py not run; TOTK 1.4.3 between an iPhone and a Mac on the NX2Apple fork. The iPhone part of this split is not yet tested on a device.

Co-authored-by: mindw0rk <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
@seedds

seedds commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thanks! This landed on main in 123c7ff, squashed into one commit with you and dreamw0rk as co-authors.

Changes on top of the PR:

  • Names from the fork removed: DM_SAVE_SYNC=icloud is now iCloud Drive › nxnative Saves. The comments and docs no longer point at a Saves sheet or SaveTransfer.swift, which nxnative doesn't have.
  • The Mac launcher sends the right save: after the host exits, it sends the DM_SAVE the host used rather than the app's own save/. An env file can set another folder, and a different folder would have meant sending another save and writing its .sync state in the wrong place. Trailing slashes are stripped as h_fs_MountSave strips them.
  • Backups are capped: the newest 10 of each side (local, cloud) stay. Making a new one removes the oldest of its side. Other folders in -backups are left alone.
  • Front ends can set the folder: docs/frontends.md documents cloudSaves.folder in the app's preferences, plus DM_SAVE_SYNC at launch, as part of the front-end contract. A GUI can set the folder for its whole library.
  • t_save_sync has new checks for the pruning and for a DM_SAVE with a trailing slash (54 checks now). impact_map.tsv maps save_sync.* and the Mac Launcher.swift.

The iPhone part of this split is still untested on a device.

@seedds seedds closed this Oct 29, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…Cloud Drive folder (PR seedds#617)

A save moved between the Mac app and the iPhone app only by hand. The apps are signed ad hoc or with a free team, so CloudKit and iCloud entitlements are out; a folder the player picks in iCloud Drive is not.

dm/host/save_sync.c packs the committed save (DM_SAVE and DM_SAVE_device) into one file, <folder>/<title ID>/save.dmsync, because iCloud replaces a file as a whole but syncs a folder file by file. The cloud's copy comes in at the game's first save mount, before the work directory is cloned; the committed save goes out a few seconds after a Commit on a thread of its own, when the iPhone app goes to the background, and from the Mac launcher once the host has exited. <DM_SAVE>.sync keeps the hash of the save last known to be the same on both sides: only the cloud's changed, it comes in; only this one changed, it goes out; both changed, the newer wins. Every save this replaces, here or in the cloud, is kept first in <DM_SAVE>-backups/<date> local|cloud; the newest 10 of each side stay.

The folder is chosen in each app's launcher: Cloud saves in the Mac settings window (dm/mac/Launcher.swift, cloudSaves.folder, read by launcher.c) and on the iPhone (a security-scoped bookmark, CloudSaves.m; copies through NSFileCoordinator, SaveSync.m). DM_SAVE_SYNC (a folder, icloud for iCloud Drive/nxnative Saves, or 0) overrides both.

On top of the PR: the Mac launcher sends the DM_SAVE the host used (an env file may set another folder than the app's own), with trailing slashes stripped as the host strips them; backups are pruned to the newest 10 per side; the fork's names (NX2Apple Saves, the front end's Saves sheet) are gone; docs/frontends.md makes the Mac folder (cloudSaves.folder in the app's preferences, DM_SAVE_SYNC at launch) part of the front-end contract, so a front end can set or change it for every game; impact_map.tsv maps save_sync.* and the Mac Launcher.swift.

Tested: t_save_sync (54 checks, also under TSan), the host tests, test_nsp_mac_app, test_launcher_settings; regress.py not run; TOTK 1.4.3 between an iPhone and a Mac on the NX2Apple fork. The iPhone part of this split is not yet tested on a device.

Co-authored-by: mindw0rk <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants