Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Frontend: the archive folder is Documents-ready, with an install guide

LNPANDYff8f6874c8f6
diff --git a/frontend/README.md b/frontend/README.md
index 0abe8368..540aad73 100644
--- a/frontend/README.md
+++ b/frontend/README.md
@@ -29,8 +29,10 @@ their own Switch game files — the GUI counterpart of the repository's scripts.
plan (unpack, module rewrite, shader compile, IPA pack, archive) with a live
percentage per stage, not a guessed five-step list.
- **Archive sharding** as the last step: the extracted RomFS goes through
- `dm/tools/romfs_arc.py` into ~200 MiB shards, which is what makes the game
- installable at all (see the [archive docs](../docs/ROMFS_ARCHIVE.md)).
+ `dm/tools/romfs_arc.py` into a `romfs/` folder of ~200 MiB shards — named so it
+ can be copied into the game app's `Documents/` unchanged. When the build
+ finishes the window shows the three installation steps and a Reveal-in-Finder
+ button for the IPA and the folder (see the [archive docs](../docs/ROMFS_ARCHIVE.md)).
## Run
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index cc5eaca8..0019c20c 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -78,6 +78,8 @@ final class BuildModel: ObservableObject {
@Published var logTail = ""
@Published var done = false
@Published var doneNote = ""
+ @Published var ipaPath = "" // captured from the script's "output IPA:" line
+ @Published var archivePath = "" // the romfs folder the pack wrote
@Published var deps: [Dep] = []
@Published var depsChecked = false
@@ -420,15 +422,23 @@ final class BuildModel: ObservableObject {
cleanupStaging(); return
}
let romfs = extract + "/" + v + "/RomFS"
- let dest = (outDir.isEmpty ? (basePath as NSString).deletingLastPathComponent : outDir) + "/archive"
+ // The output folder is named romfs and holds romfs.idx + the shards — exactly the layout
+ // Documents/romfs wants, so it can be copied onto the phone without renaming.
+ let dest = (outDir.isEmpty ? (basePath as NSString).deletingLastPathComponent : outDir) + "/romfs"
try? fm.createDirectory(atPath: dest, withIntermediateDirectories: true)
+ // a previous pack's shards must not survive a smaller new pack (the index names its own
+ // shards, but stale higher-numbered files would sit there confusingly)
+ for old in ((try? fm.contentsOfDirectory(atPath: dest)) ?? [])
+ where old == "romfs.idx" || (old.hasPrefix("romfs.") && old.dropFirst(6).allSatisfy(\.isNumber)) {
+ try? fm.removeItem(atPath: dest + "/" + old)
+ }
let idx = 1000
stages.append(Stage(id: idx, name: t("prog.archive"), state: .running, detail: v))
say(String(format: t("msg.archiveLog"), romfs, dest))
let p = Process()
p.executableURL = URL(fileURLWithPath: pythonPath.isEmpty ? "/usr/bin/python3" : pythonPath)
- p.arguments = [repoPath + "/dm/tools/romfs_arc.py", "pack", romfs, dest + "/romfs", "--shard-mib", "200"]
+ p.arguments = [repoPath + "/dm/tools/romfs_arc.py", "pack", romfs, dest, "--shard-mib", "200"]
p.environment = ["PATH": "/usr/bin:/bin:/usr/local/bin:/opt/homebrew/bin", "PYTHONPATH": repoPath + "/dm/tools"]
let pipe = Pipe(); p.standardOutput = pipe; p.standardError = pipe
pipe.fileHandleForReading.readabilityHandler = { [weak self] h in
@@ -439,18 +449,17 @@ final class BuildModel: ObservableObject {
p.terminationHandler = { [weak self] st in DispatchQueue.main.async {
guard let self else { return }
self.cleanupStaging()
+ if st.terminationStatus == 0 { self.archivePath = dest }
if let i = self.stages.firstIndex(where: { $0.id == idx }) {
self.stages[i].state = st.terminationStatus == 0 ? .done : .failed
self.stages[i].detail = st.terminationStatus == 0
- ? dest + "/romfs.idx"
+ ? String(format: self.t("prog.archiveDone"), dest)
: String(format: self.t("msg.archiveFailed"), st.terminationStatus)
}
let n = ((try? FileManager.default.contentsOfDirectory(atPath: dest)) ?? []).filter { $0.hasPrefix("romfs") }.count
self.running = false
self.done = st.terminationStatus == 0
- self.doneNote = st.terminationStatus == 0
- ? String(format: self.t("msg.done"), n, dest)
- : self.t("msg.archiveIpaOnly")
+ self.doneNote = st.terminationStatus == 0 ? self.t("msg.done") : self.t("msg.archiveIpaOnly")
}}
do { try p.run() } catch {
if let i = stages.firstIndex(where: { $0.id == idx }) {
@@ -818,6 +827,7 @@ struct ContentView: View {
repository
inputs
dependencies
+ if m.done { installGuide }
stagesView
logView
}
@@ -1000,6 +1010,51 @@ struct ContentView: View {
}
}
+ // ---- 安装引导(构建完成后出现) ----
+
+ private func reveal(_ path: String) {
+ NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)])
+ }
+
+ private var installGuide: some View {
+ GroupBox {
+ VStack(alignment: .leading, spacing: 8) {
+ sectionHeader("iphone.gen3", m.t("install.title"))
+ guideRow(m.t("install.step1"))
+ guideRow(m.t("install.step2"))
+ guideRow(m.t("install.step3"))
+ HStack(spacing: 8) {
+ Text(m.ipaPath).font(.system(size: 11.5, design: .monospaced))
+ .lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary)
+ .help(m.ipaPath)
+ Spacer(minLength: 8)
+ Button(m.t("install.reveal")) { reveal(m.ipaPath) }.controlSize(.small)
+ }
+ HStack(spacing: 8) {
+ Text(m.archivePath).font(.system(size: 11.5, design: .monospaced))
+ .lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary)
+ .help(m.archivePath)
+ Spacer(minLength: 8)
+ Button(m.t("install.reveal")) { reveal(m.archivePath) }.controlSize(.small)
+ }
+ }.padding(8)
+ }
+ }
+
+ private func guideRow(_ s: String) -> some View {
+ // "1\t…": the tab splits the step number from the text
+ let parts = s.split(separator: "\t", maxSplits: 1)
+ let num = parts.first.map(String.init) ?? ""
+ let text = parts.count > 1 ? String(parts[1]) : s
+ return HStack(alignment: .top, spacing: 8) {
+ Text(num).font(.system(size: 12, weight: .bold, design: .rounded))
+ .foregroundStyle(.green)
+ .frame(width: 16)
+ Text(text).font(.system(size: 13)).fixedSize(horizontal: false, vertical: true)
+ Spacer(minLength: 0)
+ }
+ }
+
// ---- 构建进度(紧凑) ----
private var stagesView: some View {
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index c396f03b..66042f98 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -120,6 +120,12 @@ enum L10n {
"status.chooseRepo": ("先选择项目仓库", "Choose the project repository first"),
"status.needInputs": ("还需要选择游戏本体和 prod.keys", "Still need the base game and prod.keys"),
"status.output": ("输出:%@", "Output: %@"),
+ "install.title": ("安装到 iPhone", "Install on the iPhone"),
+ "install.step1": ("1\t用 AltStore / Sideloadly 安装上面的 IPA", "1\tInstall the IPA above with AltStore / Sideloadly"),
+ "install.step2": ("2\t把上面的 romfs 文件夹整个拷到游戏 App 的 Documents 里(文件 App → 我的 iPhone → 游戏名)",
+ "2\tCopy the whole romfs folder above into the game app's Documents (Files → On My iPhone → game name)"),
+ "install.step3": ("3\t启动游戏", "3\tLaunch the game"),
+ "install.reveal": ("在访达中显示", "Reveal in Finder"),
// ---- build messages ----
"msg.running": ("运行:%@", "Running: %@"),
@@ -139,8 +145,9 @@ enum L10n {
"msg.archiveFailed": ("归档失败(退出码 %d)", "Archive failed (exit code %d)"),
"msg.archiveNoStart": ("无法启动 romfs_arc.py", "Could not start romfs_arc.py"),
"msg.archiveIpaOnly": ("IPA 已生成,归档失败", "IPA built, but the archive failed"),
- "msg.done": ("完成:IPA + 归档 %d 个文件(%@)", "Done: IPA + %d archive files (%@)"),
- "msg.archiveLog": ("归档:%@ → %@/romfs.idx", "Archive: %@ → %@/romfs.idx"),
+ "msg.done": ("完成:IPA 与 romfs 归档已生成,按下面三步装到手机", "Done: the IPA and the romfs archive are ready — three steps below"),
+ "prog.archiveDone": ("归档就绪:%@", "archive ready: %@"),
+ "msg.archiveLog": ("归档:%@ → %@", "Archive: %@ → %@"),
]
static func string(_ key: String, _ lang: Lang) -> String {