Skip to content

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

App: pass --work-dir only when the checkout's script has it (issue #5)

LNPANDY2920c84a44e9
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 242e6260..c678eae9 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -80,6 +80,9 @@ final class BuildModel: ObservableObject {
@Published var doneNote = ""
@Published var ipaPath = "" // captured from the script's "output IPA:" line
@Published var archivePath = "" // the romfs folder the pack wrote
+ /// Where this build's folder actually is: --work-dir when the checkout has it, else the script's
+ /// default under the input folder (issue #5 — an upstream checkout has no --work-dir).
+ var effectiveWorkDir = ""
@Published var deps: [Dep] = []
@Published var depsChecked = false
@@ -119,6 +122,16 @@ final class BuildModel: ObservableObject {
FileManager.default.fileExists(atPath: dir + "/dm/tools/nx_extract/Program.cs")
}
+ /// Whether the checkout's build script has this fork's `--work-dir` (issue #5): an upstream
+ /// nxnative checkout, or a ZIP of an older release, stops with "unrecognized arguments" when the
+ /// app passes it. Read from the script's own argparse rather than assumed — the option is the
+ /// fork's, not upstream's.
+ nonisolated static func repoSupportsWorkDir(_ dir: String) -> Bool {
+ let script = dir + "/scripts/build_ipa_from_nsp.py"
+ guard let text = try? String(contentsOfFile: script, encoding: .utf8) else { return false }
+ return text.contains("'--work-dir'") || text.contains("\"--work-dir\"")
+ }
+
nonisolated static func findRepo() -> String {
if let saved = UserDefaults.standard.string(forKey: "repoPath"), isRepo(saved) { return saved }
var seeds: [String] = []
@@ -534,6 +547,15 @@ final class BuildModel: ObservableObject {
let tidHex = Self.titleID(basePath).map { String(format: "%016llX", $0) } ?? "game"
let workDir = (outDir.isEmpty ? baseDir : outDir) + "/" + tidHex + "_build"
+ // This fork's --work-dir keeps the build folder (extracted files, shader cache, the romfs
+ // archive) outside the NSPs' folder. An upstream checkout or an older ZIP does not have the
+ // option and would stop with "unrecognized arguments" (issue #5), so ask the script; without
+ // it the script's own default (<input>/<title ID>_build) is used and the archive step follows
+ // whatever folder the build reports.
+ let hasWorkDir = Self.repoSupportsWorkDir(repoPath)
+ if !hasWorkDir {
+ say(t("msg.noWorkDir"))
+ }
// A compressed dump (NSZ / XCZ) needs nsz in the interpreter the build runs under; it is not
// part of the dependency probe (most builds never see one), so install it here, once, only
// when such a file is actually selected — otherwise the build stops with "pip install nsz".
@@ -554,8 +576,12 @@ final class BuildModel: ObservableObject {
}
}
var args = [repoPath + "/scripts/build_ipa_from_nsp.py", inputDir, "-k", keysPath,
- "--work-dir", workDir, "--progress", "lines"]
+ "--progress", "lines"]
+ if hasWorkDir { args += ["--work-dir", workDir] }
if !outDir.isEmpty { args += ["-o", outDir + "/" + tidHex + ".ipa"] }
+ // The archive step packs whatever folder the build reported; without --work-dir that is the
+ // script's default, which is the same workDir unless a separate output folder was chosen.
+ effectiveWorkDir = hasWorkDir ? workDir : (inputDir as NSString).appendingPathComponent(tidHex + "_build")
say(String(format: t("msg.running"), py) + " " + args.joined(separator: " "))
let p = Process()
@@ -582,7 +608,7 @@ final class BuildModel: ObservableObject {
self.flushLines()
if status.terminationStatus == 0 {
self.markAllDone()
- self.packArchive(workDir: workDir) // keeps running=true until the archive is done
+ self.packArchive(workDir: self.effectiveWorkDir) // keeps running=true until the archive is done
} else {
if let i = self.stages.lastIndex(where: { $0.state == .running }) {
self.stages[i].state = .failed
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index 06bd4bd2..560a2b4a 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -176,6 +176,8 @@ enum L10n {
"msg.running": ("运行:%@", "Running: %@"),
"msg.installingNsz": ("选中的是 NSZ / XCZ 压缩格式,正在给构建用的 Python 安装 nsz…",
"The selected dump is NSZ / XCZ — installing nsz into the build's Python…"),
+ "msg.noWorkDir": ("这个仓库不是 NX2Apple 的最新版本(构建脚本没有 --work-dir):按脚本默认布局构建。建议换用 NX2Apple 仓库以获得归档复用与断点续传",
+ "This checkout is not the latest NX2Apple (its build script has no --work-dir): using the script's default layout. Switch to the NX2Apple repository for archive reuse and resumable builds"),
"msg.nszFailed": ("nsz 安装失败(构建用的 Python:%@)——网络不通?或手动执行 pip install nsz",
"Could not install nsz (build Python: %@) — network trouble? Or run pip install nsz by hand"),
"msg.stopped": ("已停止", "Stopped"),