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
Device install: copy the game's folder (romfs.img, aoc/) now that the game data is one image
v0lumehic438bb61df1f
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex 95dcc001..935979e0 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -33,7 +33,7 @@ TABLE: dict[str, tuple[str, str]] = {'dev.refresh': ('刷新', 'Refresh'),'dev.team': ('签名团队', 'Signing team'),'dev.noTeam': ('没有开发证书。在 Xcode 中登录 Apple ID(设置 → 账户)即可获得。', 'No development certificate. Sign in to Xcode with your Apple ID (Settings → Accounts) to get one.'),- 'dev.note': ('Xcode 会为这台设备签名并直接安装,游戏文件以 RomFS 归档复制到 App 的“文稿”中,与侧载相同;第一次复制大型游戏需要几分钟。第一次需要在设备上开启开发者模式,并信任开发者(设置 → 通用 → VPN 与设备管理)。', 'Xcode signs the game for this device and installs it there, then copies the game files into the app’s Documents as the RomFS archive, as for sideloading; the first copy of a large game takes a few minutes. The first time, turn on Developer Mode on the device and trust the developer (Settings → General → VPN & Device Management).'),+ 'dev.note': ('Xcode 会为这台设备签名并直接安装,游戏数据(romfs.img)复制到 App 的“文稿”中,与侧载相同;第一次复制大型游戏需要几分钟。第一次需要在设备上开启开发者模式,并信任开发者(设置 → 通用 → VPN 与设备管理)。', 'Xcode signs the game for this device and installs it there, then copies the game data (romfs.img) into the app’s Documents, as for sideloading; the first copy of a large game takes a few minutes. The first time, turn on Developer Mode on the device and trust the developer (Settings → General → VPN & Device Management).'),'dev.signStage': ('为 %@ 签名', 'Sign for %@'),'dev.installStage': ('安装到 %@', 'Install on %@'),'dev.copyStage': ('复制游戏文件到 %@', 'Copy the game files to %@'),diff --git a/frontend/README.md b/frontend/README.mdindex 34e91dfb..2c0b59ea 100644--- a/frontend/README.md+++ b/frontend/README.md@@ -42,9 +42,9 @@ next to it. The script then prepares the game's Xcode project`xcodebuild -allowProvisioningUpdates` signs it for that device with the team(Xcode makes the provisioning profile), and `xcrun devicectl device install app`installs it. The game files take the same route as for sideloading. They are packed into-the RomFS archive, and the app is built without them (`DM_COPY_ROMFS=NO`). After the-install, `xcrun devicectl device copy to` puts the archive into the app's-`Documents/games/<title ID>/romfs`, where the app looks first. devicectl skips files+`games/<title ID>/romfs.img`, with any DLC in `aoc/` beside it, and the app is built+without them (`DM_COPY_ROMFS=NO`). After the install, `xcrun devicectl device copy to`+puts that folder into the app's `Documents/games/<title ID>/`, where the app looks first. devicectl skips filesthat did not change, so a reinstall sends the code and shaders, not the whole gameagain. The first copy of a large game takes a few minutes. The game then appearsin the collection, and its button opens it on the device.diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex ddaecbfa..b98dd0b7 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -123,8 +123,8 @@ final class BuildModel: ObservableObject {// ---- Installing on an iPhone or iPad (Xcode with a development certificate) ----// Optional: with a paired device and a signing team chosen, the script prepares the game's Xcode project// (--prepare-xcode, the route its README gives developers), xcodebuild signs it for that device with the- // team (Xcode makes the provisioning profile) without the game files, devicectl installs it and copies the RomFS- // archive into its Documents, as a sideloaded copy has it. Without a device or a team the build stays an unsigned IPA, as before.+ // team (Xcode makes the provisioning profile) without the game files, devicectl installs it and copies the game's+ // folder (romfs.img, aoc/) into its Documents, as a sideloaded copy has it. Without a device or a team the build stays an unsigned IPA, as before.@Published var devices: [AppleDevice] = []@Published var teams: [SigningTeam] = []@Published var devicesChecked = false@@ -1155,10 +1155,10 @@ final class BuildModel: ObservableObject {// MARK: Installing on a device- /// After the script prepared the Xcode project and the archive is packed: sign the app for the device without the- /// game files (DM_COPY_ROMFS=NO), install it, then copy the archive into its Documents/games/<title ID>/romfs, where- /// the app looks first (main.m), as a sideloaded copy has it. devicectl skips files that did not change, so a- /// reinstall sends the code and shaders, not the game again.+ /// After the script prepared the Xcode project and the game data is packed: sign the app for the device without the+ /// game files (DM_COPY_ROMFS=NO), install it, then copy the game's folder (romfs.img, aoc/) into its+ /// Documents/games/<title ID>/, where the app looks first (main.m), as a sideloaded copy has it. devicectl skips files+ /// that did not change, so a reinstall sends the code and shaders, not the game again.private func signAndInstall(archive: String) {let work = effectiveWorkDir, project = work + "/xcode/DmIOS.xcodeproj", derived = work + "/xcode-derived-data"let device = installDevice, team = signingTeam, name = deviceName(device), xcrun = xcrunPath@@ -1201,10 +1201,10 @@ final class BuildModel: ObservableObject {cleanupStaging()}- /// The archive into the installed app's Documents, where main.m looks for this game's files first.+ /// The game's folder (romfs.img, aoc/) into the installed app's Documents, where main.m looks for this game's files first.nonisolated static func archiveCopy(xcrun: String, device: String, bundle: String, archive: String, titleID: String) -> [String] {[xcrun, "devicectl", "device", "copy", "to", "--device", device, "--source", archive,- "--destination", "Documents/games/\(titleID)/romfs", "--domain-type", "appDataContainer", "--domain-identifier", bundle]+ "--destination", "Documents/games/\(titleID)", "--domain-type", "appDataContainer", "--domain-identifier", bundle]}/// The scheme the script made for the game ("<name> (<profile>)"), from `xcodebuild -list`.diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex 2d1f4718..6bd6cf9e 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -67,7 +67,7 @@ enum L10n {"dev.refresh": ("\u{5237}\u{65b0}", "Refresh"),"dev.team": ("\u{7b7e}\u{540d}\u{56e2}\u{961f}", "Signing team"),"dev.noTeam": ("\u{6ca1}\u{6709}\u{5f00}\u{53d1}\u{8bc1}\u{4e66}\u{3002}\u{5728} Xcode \u{4e2d}\u{767b}\u{5f55} Apple ID\u{ff08}\u{8bbe}\u{7f6e} \u{2192} \u{8d26}\u{6237}\u{ff09}\u{5373}\u{53ef}\u{83b7}\u{5f97}\u{3002}", "No development certificate. Sign in to Xcode with your Apple ID (Settings \u{2192} Accounts) to get one."),- "dev.note": ("Xcode 会为这台设备签名并直接安装,游戏文件以 RomFS 归档复制到 App 的“文稿”中,与侧载相同;第一次复制大型游戏需要几分钟。第一次需要在设备上开启开发者模式,并信任开发者(设置 → 通用 → VPN 与设备管理)。", "Xcode signs the game for this device and installs it there, then copies the game files into the app’s Documents as the RomFS archive, as for sideloading; the first copy of a large game takes a few minutes. The first time, turn on Developer Mode on the device and trust the developer (Settings → General → VPN & Device Management)."),+ "dev.note": ("Xcode 会为这台设备签名并直接安装,游戏数据(romfs.img)复制到 App 的“文稿”中,与侧载相同;第一次复制大型游戏需要几分钟。第一次需要在设备上开启开发者模式,并信任开发者(设置 → 通用 → VPN 与设备管理)。", "Xcode signs the game for this device and installs it there, then copies the game data (romfs.img) into the app’s Documents, as for sideloading; the first copy of a large game takes a few minutes. The first time, turn on Developer Mode on the device and trust the developer (Settings → General → VPN & Device Management)."),"dev.signStage": ("\u{4e3a} %@ \u{7b7e}\u{540d}", "Sign for %@"),"dev.installStage": ("\u{5b89}\u{88c5}\u{5230} %@", "Install on %@"),"dev.copyStage": ("复制游戏文件到 %@", "Copy the game files to %@"),diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swiftindex df9516e8..aac039d5 100644--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift@@ -290,9 +290,9 @@ final class LibraryTests: XCTestCase {XCTAssertNil(DeviceTools.team(fromSubject: "subject=CN=Something"))}- /// An iPhone build with a device and a team: the script prepares the Xcode project, the RomFS archive is packed as for+ /// An iPhone build with a device and a team: the script prepares the Xcode project, romfs.img is packed as for/// sideloading, xcodebuild signs the app without the game files for the device, devicectl installs it and copies the- /// archive into its Documents, and the library opens it there. The tools are stand-ins; nothing is signed.+ /// game's folder into its Documents, and the library opens it there. The tools are stand-ins; nothing is signed.@MainActor func testBuildSignsAndInstallsOnTheChosenDevice() throws {guard FileManager.default.isExecutableFile(atPath: "/usr/bin/python3") else { throw XCTSkip("System Python is required for the process fixture") }let saved = ["repoPath", "buildTarget", "buildOutputDirectory", "installDevice", "signingTeam"].map { ($0, UserDefaults.standard.object(forKey: $0)) }@@ -324,12 +324,12 @@ final class LibraryTests: XCTestCase {ev(ev='say', msg='[12:00:00] app name: Test; version: 1.0; bundle ID: org.nxnative.test')ev(ev='stage_end', k=1, name='prepare Xcode', ok=True, summary='', elapsed=1)""".write(to: script, atomically: true, encoding: .utf8)- let packer = temporary.appendingPathComponent("dm/tools/romfs_arc.py") // stand-in: pack <RomFS> <base> writes <base>.idx and one shard+ let packer = temporary.appendingPathComponent("dm/tools/romfs_image.py") // stand-in: --reuse <RomFS> <image> writes the imagetry FileManager.default.createDirectory(at: packer.deletingLastPathComponent(), withIntermediateDirectories: true)try """import sys- open('\(calls.path)', 'a').write('romfs_arc ' + ' '.join(sys.argv[1:]) + '\\n')- open(sys.argv[3] + '.idx', 'wb').write(b'idx'); open(sys.argv[3] + '.00', 'wb').write(b'game')+ open('\(calls.path)', 'a').write('romfs_image ' + ' '.join(sys.argv[1:]) + '\\n')+ open(sys.argv[3], 'wb').write(b'image')""".write(to: packer, atomically: true, encoding: .utf8)let xcrun = temporary.appendingPathComponent("xcrun")try """@@ -367,14 +367,14 @@ final class LibraryTests: XCTestCase {for part in ["-scheme Test (0100535012974000)", "-destination id=00008150-AAAA", "-derivedDataPath \(work)/xcode-derived-data","-allowProvisioningUpdates", "DEVELOPMENT_TEAM=TEAM123456", "DM_COPY_ROMFS=NO"] { XCTAssertTrue(build.contains(part), part) }let app = work + "/xcode-derived-data/Build/Products/Release-iphoneos/DmIOS.app"- let archive = temporary.path + "/games/\(titleID)/romfs"+ let archive = temporary.path + "/games/\(titleID)"// the archive is packed before signing, the app installed before the archive goes into its Documents- let order = ["romfs_arc pack", "xcodebuild -project", "devicectl device install", "devicectl device copy"].map { step in log.firstIndex { $0.hasPrefix(step) } }+ let order = ["romfs_image --reuse", "xcodebuild -project", "devicectl device install", "devicectl device copy"].map { step in log.firstIndex { $0.hasPrefix(step) } }XCTAssertEqual(order.compactMap { $0 }, order.compactMap { $0 }.sorted())XCTAssertEqual(order.compactMap { $0 }.count, 4)XCTAssertTrue(log.contains("devicectl device install app --device 00008150-AAAA \(app)"))- XCTAssertTrue(log.contains("devicectl device copy to --device 00008150-AAAA --source \(archive) --destination Documents/games/\(titleID)/romfs --domain-type appDataContainer --domain-identifier org.nxnative.test"))- XCTAssertTrue(FileManager.default.fileExists(atPath: archive + "/romfs.idx"))+ XCTAssertTrue(log.contains("devicectl device copy to --device 00008150-AAAA --source \(archive) --destination Documents/games/\(titleID) --domain-type appDataContainer --domain-identifier org.nxnative.test"))+ XCTAssertTrue(FileManager.default.fileExists(atPath: archive + "/romfs.img"))XCTAssertEqual(model.archivePath, archive)XCTAssertEqual(model.installedOn, "00008150-AAAA")XCTAssertEqual(model.stages.filter { $0.id >= 1000 }.map(\.state), [.done, .done, .done, .done])