Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Engine: replace the Mac app by moves when the volume has no atomic swap (patch 0074)
v0lumehif8d652093fcd
diff --git a/patches/0074-mac-app-replace-the-old-app-by-moves-when-the-vo.patch b/patches/0074-mac-app-replace-the-old-app-by-moves-when-the-vo.patchnew file mode 100644index 00000000..c28abffb--- /dev/null+++ b/patches/0074-mac-app-replace-the-old-app-by-moves-when-the-vo.patch@@ -0,0 +1,119 @@+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001+From: v0lumehi <[email protected]>+Date: Wed, 4 Nov 2026 11:04:37 +0100+Subject: [PATCH] Mac app: replace the old app by moves when the volume has no+ atomic swap++The second build into the same folder failed on a Mac OS Extended (Journaled) volume with+[Errno 45]: replace_app exchanges the new and the old app with renamex_np(RENAME_SWAP), and that+volume returns ENOTSUP for it. The old app was left in place, but the build stopped.++On ENOTSUP, replace_app now calls swap_by_moves, which leaves the same state RENAME_SWAP does (the+new app at the output, the old one at the partial folder): the old app moves aside, the new one+moves in, and the old one takes the partial folder's place. A step that fails undoes the earlier ones,+so a failure never leaves the player without an app. Every other error is raised as before.++The tests simulate errno 45 through pack and fail each move of swap_by_moves in turn.++Upstream-Status: forwarded seedds/nxnative#1190+Reason: The Mac app step failed with Errno 45 on a Mac OS Extended (Journaled) volume: no atomic swap there, so the old app is now replaced by moves+Issue: LNPANDY/NX2Apple#595++---+ dm/mac/pack_app.py | 24 ++++++++++++++++++++++--+ dm/tools/tests/test_nsp_mac_app.py | 29 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-)++diff --git a/dm/mac/pack_app.py b/dm/mac/pack_app.py+index f974315..b1a7ac4 100755+--- a/dm/mac/pack_app.py++++ b/dm/mac/pack_app.py+@@ -12,7 +12,7 @@+ # file's extended attributes live in such a file beside it, and codesign reads each one as a code object that is not signed, which fails the whole bundle.+ # Usage: pack_app.py <out.app> --host <dmhost> --patched <dir> --romfs <image or dir> --msl <dir> --tables <profile dir> --font <dir> --title-id <id> --name <name> [options]+ # Reuses <out.app> while <out.app>.key matches; otherwise writes <out.app>.partial and swaps it in at the end. Prints "step: ..." and "app: <path>[, reused (inputs unchanged)]".+-import argparse, ctypes, hashlib, json, os, plistlib, re, shutil, stat, subprocess, sys, tempfile++import argparse, ctypes, errno, hashlib, json, os, plistlib, re, shutil, stat, subprocess, sys, tempfile+ from pathlib import Path++ HERE = Path(__file__).resolve().parent+@@ -222,11 +222,31 @@ def replace_app(tmp, out):+ swap.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_uint)+ swap.restype = ctypes.c_int+ if swap(os.fsencode(tmp), os.fsencode(out), 2):+- err = ctypes.get_errno(); raise OSError(err, os.strerror(err), str(out))++ err = ctypes.get_errno()++ if err not in (errno.ENOTSUP, errno.EOPNOTSUPP): raise OSError(err, os.strerror(err), str(out))++ swap_by_moves(tmp, out) # a volume without RENAME_SWAP (Mac OS Extended, Journaled: [Errno 45])+ else:+ tmp.rename(out)++++def swap_by_moves(tmp, out):++ """The state RENAME_SWAP leaves, made with plain renames in out's folder: the new app at out and the old one at tmp. The old app moves aside, the new one moves in, and the old one++ takes tmp's place. A step that fails undoes the ones before it, so out is the old app again (or still) and tmp the new one: a failure never leaves the player without an app."""++ aside = out.with_name(f'{out.name}.old-{os.getpid()}')++ shutil.rmtree(aside, ignore_errors=True)++ out.rename(aside)++ try:++ tmp.rename(out)++ except BaseException:++ aside.rename(out)++ raise++ try:++ aside.rename(tmp)++ except BaseException:++ out.rename(tmp); aside.rename(out)++ raise+++++ def pack(a):+ out = Path(a.out).resolve()+ if out.suffix != '.app': raise SystemExit(f'the output must end in .app: {out}')+diff --git a/dm/tools/tests/test_nsp_mac_app.py b/dm/tools/tests/test_nsp_mac_app.py+index 0fdd6e4..bbc5014 100644+--- a/dm/tools/tests/test_nsp_mac_app.py++++ b/dm/tools/tests/test_nsp_mac_app.py+@@ -3,6 +3,7 @@ runtime; the launcher's environment for the host (the bundle's files, the save,+ code returned and SIGTERM forwarded to it, an alert when the game data is missing; the script's options and its pack_app.py command line.+ No game files, keys or Xcode needed: a stand-in host compiled here records what it was given (temporary files only in a temporary folder)."""+ import contextlib++import errno+ import importlib.util+ import io+ import json+@@ -363,6 +364,34 @@ class PackReuse(unittest.TestCase):+ self.assertEqual((Path(self.args.out) / 'Contents/Info.plist').read_bytes(), before)+ self.assert_repacked()+++ def test_volume_without_atomic_swap_replaces_by_moves(self): # Mac OS Extended (Journaled): renamex_np fails with [Errno 45] on the second build into the same folder++ self.pack(); before = (Path(self.args.out) / 'Contents/Info.plist').read_bytes()++ self.args.name = 'changed'++ library = types.SimpleNamespace(renamex_np=mock.Mock(return_value=-1))++ with mock.patch.object(pack_app.ctypes, 'CDLL', return_value=library), mock.patch.object(pack_app.ctypes, 'get_errno', return_value=errno.ENOTSUP):++ self.pack()++ library.renamex_np.assert_called()++ self.assertNotEqual((Path(self.args.out) / 'Contents/Info.plist').read_bytes(), before)++ self.assertTrue(self.key.exists())++ self.assertEqual([p.name for p in Path(self.args.out).parent.glob('*.old-*')], []) # nothing left of the old app beside the new one++ self.assertIn('reused (inputs unchanged)', self.pack()) # the key matches the app that is in place++++ def test_fallback_restores_the_old_app_when_a_move_fails(self):++ out, tmp = self.tmp / 'Game.app', self.tmp / 'Game.app.partial'++ for n, tree in ((out, 'old'), (tmp, 'new')): (n / 'Contents').mkdir(parents=True); (n / 'Contents/id').write_text(tree)++ real = Path.rename++ for failing in (tmp, Path(f'{out}.old-{os.getpid()}')): # the new app cannot move in, then the old one cannot move to tmp's place++ with self.subTest(failing=failing.name):++ def rename(path, target, failing=failing):++ if path == failing and (failing == tmp or target == tmp): raise OSError(errno.EIO, 'fixture')++ return real(path, target)++ with mock.patch.object(Path, 'rename', rename), self.assertRaises(OSError): pack_app.swap_by_moves(tmp, out)++ self.assertEqual((out / 'Contents/id').read_text(), 'old')++ self.assertEqual((tmp / 'Contents/id').read_text(), 'new')++ pack_app.swap_by_moves(tmp, out)++ self.assertEqual((out / 'Contents/id').read_text(), 'new')++ self.assertEqual((tmp / 'Contents/id').read_text(), 'old')+++ def test_failed_key_write_rolls_back_app_and_drops_key(self):+ self.pack(); before = (Path(self.args.out) / 'Contents/Info.plist').read_bytes()+ self.args.name = 'changed'diff --git a/patches/series b/patches/seriesindex 3157a784..53aec300 100644--- a/patches/series+++ b/patches/series@@ -45,3 +45,4 @@0070-ios-touch-layout.patch0071-ios-shell-restore-native-duo-orientation.patch0072-mac-pack-the-settings-read-the-base-game-s-langu.patch+0074-mac-app-replace-the-old-app-by-moves-when-the-vo.patch