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
The library folder holds only the saves and the log; the pso state stays in ~/Library
LNPANDYc7ea1f567c62
diff --git a/dm/mac/launcher.c b/dm/mac/launcher.cindex 34ef0e0d..3873b7ad 100644--- a/dm/mac/launcher.c+++ b/dm/mac/launcher.c@@ -151,18 +151,21 @@ int main(void) {// never exists — and the migration never ran (the report: saves stayed in ~/Library).*strrchr(appdir, '/') = 0; *strrchr(appdir, '/') = 0;*strrchr(appdir, '/') = 0; *strrchr(appdir, '/') = 0;- char probe[PATH_MAX]; snprintf(probe, sizeof probe, "%s/games", appdir);+ // The marker file the Mac front end writes beside the .app (a dot file, so the Finder hides+ // it): this folder is a game library, and the game's saves and log live in it. DM_ROOT (the+ // learned shader state, env.txt), temp/ and everything else stay under ~/Library — only+ // what is needed and reused comes along, so the library folder stays lean.+ char probe[PATH_MAX]; snprintf(probe, sizeof probe, "%s/.nx2apple-library", appdir);if (!stat(probe, &st)) {snprintf(save, sizeof save, "%s/save/%s", appdir, id);snprintf(logs, sizeof logs, "%s/log", appdir);- snprintf(temp, sizeof temp, "%s/temp/%s", appdir, id);- // First run after this change: bring the old saves and log across rather than starting- // the player on an empty save slot. Copied, not moved — an older build of the same app+ // First run after this change: bring the old saves across rather than starting the+ // player on an empty save slot. Copied, not moved — an older build of the same app// still reads the old place, and a copy is cheap next to a save.char oldsave[PATH_MAX], oldlog[PATH_MAX];- snprintf(oldsave, sizeof oldsave, "%s/Library/Application Support/nxnative/%s/save", home, id);+ snprintf(oldsave, sizeof oldsave, "%s/save", sup);snprintf(oldlog, sizeof oldlog, "%s/Library/Logs/nxnative/%s.log", home, id);- mkdirs(save); mkdirs(logs); mkdirs(temp);+ mkdirs(save); mkdirs(logs);if (dir_has_entries(oldsave) && !dir_has_entries(save)) {copy_tree(oldsave, save);fprintf(stderr, "launcher: saves copied from %s to %s (they now live with the game)\n", oldsave, save);diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex c09833f5..d7c9731e 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -1058,22 +1058,22 @@ final class BuildModel: ObservableObject {if status.terminationStatus == 0 {self.markAllDone()if self.target == "mac-app" {- // The .app keeps its RomFS inside (self-contained, double-clickable), and- // the archive step also writes games/<id>/romfs.img beside it. That folder- // arms the launcher's save relocation (saves beside the game) and is the- // copy for a phone or an external drive; skipping it left every Mac build- // without games/, so the launcher never treated the folder as a library- // and saves stayed in ~/Library (the rebuild test).+ // The .app is self-contained (its RomFS is inside), and the marker file+ // beside it (.nx2apple-library, a dot file the Finder hides) tells the+ // game's launcher that this folder is a library: its saves and log live+ // here, and they follow the folder if it moves. No image copy — the .app+ // already carries one, and a second multi-GB file was pure duplication.let made = !self.macAppPath.isEmpty &&FileManager.default.fileExists(atPath: self.macAppPath)- guard made else {- self.done = false- self.doneNote = self.t("msg.macAppMissing")- self.running = false- self.cleanupStaging()- return+ self.done = made+ self.doneNote = self.t(made ? "msg.macAppDone" : "msg.macAppMissing")+ if made {+ try? Data().write(to: URL(fileURLWithPath:+ (self.macAppPath as NSString).deletingLastPathComponent ++ "/.nx2apple-library"))}- self.packArchive(workDir: self.effectiveWorkDir) // finishes the build when done+ self.running = false+ self.cleanupStaging()} else if self.installsDirectly {// The same archive as for sideloading, then the app without the game files, then the archive into its Documentsself.packArchive(workDir: self.effectiveWorkDir) { self.signAndInstall(archive: $0) }diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swiftindex 8e927423..aa256301 100644--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift@@ -494,11 +494,6 @@ final class LibraryTests: XCTestCase {let completed = expectation(description: "Successful app is added without an import")let token = library.$games.filter { $0.contains(where: \.isReady) }.prefix(1).sink { _ in completed.fulfill() }XCTAssertTrue(model.canBuild)- // The rewriter's extraction output (RomFS.img, one file): the archive step copies it into- // games/<id>/ beside the .app, which is what arms the launcher's save relocation.- let extract = temporary.appendingPathComponent("0100535012974000_build/extract/v0")- try FileManager.default.createDirectory(at: extract, withIntermediateDirectories: true)- try Data("DMROMFS1-fixture".utf8).write(to: extract.appendingPathComponent("RomFS.img"))window.orderOut(nil) // Registration must work even while the launcher is hidden.model.startBuild()wait(for: [completed], timeout: 10)@@ -508,12 +503,12 @@ final class LibraryTests: XCTestCase {wait(for: [settled], timeout: 10)XCTAssertTrue(model.done)XCTAssertFalse(model.running)- XCTAssertEqual(model.stages.map(\.name), ["Mac app", "打包游戏数据为 romfs.img(单文件)"]) // the app, then the archive copy- XCTAssertEqual(model.stages.map(\.state), [.done, .done])+ XCTAssertEqual(model.stages.map(\.name), ["Mac app"]) // from the JSON events, which the log shows as text+ XCTAssertEqual(model.stages.first?.state, .done)XCTAssertEqual(model.stages.first?.detail, "Test build.app")- let games = temporary.appendingPathComponent("games").appendingPathComponent(titleID)- XCTAssertTrue(FileManager.default.fileExists(atPath: games.appendingPathComponent("romfs.img").path),- "the archive must land beside the .app: it arms the launcher's save relocation")+ // The library marker beside the .app: what arms the game launcher's save relocation.+ XCTAssertTrue(FileManager.default.fileExists(atPath:+ temporary.appendingPathComponent(".nx2apple-library").path))XCTAssertTrue(model.logTail.contains("✓ Mac app (4s): Test build.app"))XCTAssertFalse(model.logTail.contains("\"ev\""))XCTAssertEqual(library.games.count, 1)