Skip to content

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

Merge remote-tracking branch 'origin/main' into wt-launcher-cards

v0lumehibe6894d9639d
diff --cc frontend/Sources/NXCore/ShellInstall.swift
index 1da8cc06,43eaf8b3..aacc35a0
--- a/frontend/Sources/NXCore/ShellInstall.swift
+++ b/frontend/Sources/NXCore/ShellInstall.swift
@@@ -56,29 -52,60 +56,60 @@@ package struct ShellLibrary: Codable, E
try encoder.encode(self).write(to: URL(fileURLWithPath: Self.stateFile(root: root)), options: .atomic)
}
+ /// The folder a shell root may live in: an absolute path that is not the root of a volume. `""` (no game or output
+ /// folder chosen yet) and `/` both gave `/NX2Apple-shell` on the read-only system volume (#492); `home` stands in.
- static func parentFolder(_ parent: String, home: String = NSHomeDirectory()) -> String {
++ package static func parentFolder(_ parent: String, home: String = NSHomeDirectory()) -> String {
+ let path = (parent as NSString).expandingTildeInPath
+ return path.hasPrefix("/") && path != "/" ? path : home
+ }
+
+ /// Whether a saved root can be used as it is: an absolute path below a volume root. `/NX2Apple-shell` came from an
+ /// empty parent and is repaired instead of used (#492).
- static func rootIsUsable(_ root: String) -> Bool {
++ package static func rootIsUsable(_ root: String) -> Bool {
+ root.hasPrefix("/") && (root as NSString).pathComponents.filter { $0 != "/" }.count >= 2
+ }
+
+ /// The root the next install would use, without saving it. The Settings page shows it before any game is chosen,
+ /// and that look must not decide where builds save (#492).
- static func previewRoot(defaults: UserDefaults = .standard, parent: String, home: String = NSHomeDirectory()) -> String {
++ package static func previewRoot(defaults: UserDefaults = .standard, parent: String, home: String = NSHomeDirectory()) -> String {
+ if let saved = defaults.string(forKey: "shellRoot"), rootIsUsable(saved) { return saved }
+ return parentFolder(parent, home: home) + "/NX2Apple-shell"
+ }
+
/// The shell root: the saved one (`shellRoot` in `defaults`), else `<parent>/NX2Apple-shell`, which is then saved so the shell
- /// stays where it was first made, whatever output folder a later build uses.
- package static func resolveRoot(defaults: UserDefaults = .standard, parent: String) -> String {
- if let saved = defaults.string(forKey: "shellRoot"), !saved.isEmpty { return saved }
- let root = parent + "/NX2Apple-shell"
+ /// stays where it was first made, whatever output folder a later build uses. A saved root at a volume root is repaired.
- static func resolveRoot(defaults: UserDefaults = .standard, parent: String, home: String = NSHomeDirectory()) -> String {
++ package static func resolveRoot(defaults: UserDefaults = .standard, parent: String, home: String = NSHomeDirectory()) -> String {
+ if let saved = defaults.string(forKey: "shellRoot"), rootIsUsable(saved) { return saved }
+ let root = parentFolder(parent, home: home) + "/NX2Apple-shell"
defaults.set(root, forKey: "shellRoot")
return root
}
}
/// The commands and parsers of the shell install, as pure functions.
-enum ShellInstall {
- static let appName = "DmShell.app"
- static let scheme = "DmShell"
- static let projectName = "DmShell.xcodeproj"
+package enum ShellInstall {
+ package static let appName = "DmShell.app"
+ package static let scheme = "DmShell"
+ package static let projectName = "DmShell.xcodeproj"
- static func projectFolder(root: String) -> String { root + "/project" }
+ package static func projectFolder(root: String) -> String { root + "/project" }
+
+ /// Whether the shell root can be written, checked before an hour of building: a folder on a read-only volume (or a
+ /// file where the folder goes) only failed at the last step otherwise (#492).
- static func canWriteRoot(_ root: String, fm: FileManager = .default) -> Bool {
++ package static func canWriteRoot(_ root: String, fm: FileManager = .default) -> Bool {
+ var isDir: ObjCBool = false
+ if fm.fileExists(atPath: root, isDirectory: &isDir) { return isDir.boolValue && fm.isWritableFile(atPath: root) }
+ let parent = (root as NSString).deletingLastPathComponent
+ guard fm.fileExists(atPath: parent, isDirectory: &isDir), isDir.boolValue else { return false }
+ return fm.isWritableFile(atPath: parent)
+ }
+
- static func derivedData(root: String) -> String { root + "/derived-data" }
- static func appPath(root: String) -> String { derivedData(root: root) + "/Build/Products/Release-iphoneos/" + appName }
+ package static func derivedData(root: String) -> String { root + "/derived-data" }
+ package static func appPath(root: String) -> String { derivedData(root: root) + "/Build/Products/Release-iphoneos/" + appName }
/// The folder that mirrors every game's framework inside the shell folder: a game survives its build folder's deletion here.
- static func frameworksMirror(root: String) -> String { root + "/frameworks" }
- static func mirroredFramework(root: String, titleID: String) -> String {
+ package static func frameworksMirror(root: String) -> String { root + "/frameworks" }
+ package static func mirroredFramework(root: String, titleID: String) -> String {
frameworksMirror(root: root) + "/DmGame\(titleID).framework"
}
diff --cc frontend/Tests/NX2AppleTests/ShellInstallTests.swift
index 62ca961d,a2c1ed95..22e5405e
--- a/frontend/Tests/NX2AppleTests/ShellInstallTests.swift
+++ b/frontend/Tests/NX2AppleTests/ShellInstallTests.swift
@@@ -852,7 -891,12 +892,12 @@@ import NXMode
}
finish { model.installShell(framework: f.framework, titleID: titleID, name: "Test Game", archive: f.archive) }
XCTAssertEqual(model.failure?.kind, .shellDataIncomplete)
- XCTAssertTrue(model.doneNote.hasPrefix(String(format: model.t("shell.copyIncomplete"), modelStores.deviceStore.deviceName(modelStores.deviceStore.installDevice), "").components(separatedBy: ": ").first ?? "-"), model.doneNote)
+ // The sentence before the tool's error, in every language: it used to split the English template on ": ", which
+ // never matches a full-width colon (a Chinese macOS ran this test red on main).
+ let marker = "\u{1}"
- let prefix = String(format: model.t("shell.copyIncomplete"), model.deviceName(model.installDevice), marker)
++ let prefix = String(format: model.t("shell.copyIncomplete"), modelStores.deviceStore.deviceName(modelStores.deviceStore.installDevice), marker)
+ .components(separatedBy: marker).first ?? "-"
+ XCTAssertTrue(model.doneNote.hasPrefix(prefix), model.doneNote)
XCTAssertFalse(model.done)
XCTAssertEqual(plans.count, 1)
XCTAssertEqual(plans.first?.connection, .wired)