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
Read the title ID from the file name only, not the full path
v0lumehi0dd7b95e1893
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex b1500d5c..a467e80e 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -1195,8 +1195,10 @@ final class BuildModel: ObservableObject {func clear(_ id: String) { updateSlot(id) { $0.paths = []; $0.problem = "" } }/// The title ID in a file name: `[0100F2C0115B6000]` first, else a bare 16-digit ID that starts with 01 as a token- /// (start of the name or after `_`, space, `-`, `.`, `(`, `[`), like `01007EF00011E000_v0_420d1c5034ab.nsp`.- nonisolated static func titleID(_ name: String) -> UInt64? {+ /// (start of the name or after `_`, space, `-`, `.`, `(`, `[`). Only the file name counts, so a full path works and a folder named with an ID never+ /// stands in for the file (#382). Like `01007EF00011E000_v0_420d1c5034ab.nsp`.+ nonisolated static func titleID(_ path: String) -> UInt64? {+ let name = (path as NSString).lastPathComponentlet found = firstGroup(#"\[([0-9A-Fa-f]{16})\]"#, in: name)?? firstGroup(#"(?:^|[_ \-.(\[])(01[0-9A-Fa-f]{14})(?![0-9A-Fa-f])"#, in: name)return found.flatMap { UInt64($0, radix: 16) }@@ -1207,7 +1209,7 @@ final class BuildModel: ObservableObject {/// digits, `-` and `_`, plus a short hash of the full name: two games never share a folder (and so a shader cache),/// the same file name always gets the same one (a rebuild reuses its cache). Never a constant.nonisolated static func buildKey(_ path: String) -> String {- let name = (path as NSString).lastPathComponent // a bare ID is a token, so a "/" before it would hide it+ let name = (path as NSString).lastPathComponentif let id = titleID(name) { return String(format: "%016llX", id) }let stem = (name as NSString).deletingPathExtensionvar hash: UInt32 = 2166136261 // FNV-1a, stable across runs (Hashable is seeded per launch)diff --git a/frontend/Tests/NSPortBuilderTests/BuildKeyTests.swift b/frontend/Tests/NSPortBuilderTests/BuildKeyTests.swiftindex 67a311ca..e70d2f65 100644--- a/frontend/Tests/NSPortBuilderTests/BuildKeyTests.swift+++ b/frontend/Tests/NSPortBuilderTests/BuildKeyTests.swift@@ -33,4 +33,18 @@ final class BuildKeyTests: XCTestCase {XCTAssertTrue((BuildModel.buildKey("/x/Zelda.nsp") + "_build").hasSuffix("_build"))XCTAssertEqual(BuildModel.buildKey("/x/[0100F2C0115B6000].nsp") + "_build", "0100F2C0115B6000_build")}++ /// The reporter's layout: <ID>/<ID>_v0_<hash>.nsp, the ID bare (no brackets), the full path passed in.+ func testBareIDInAFullPathIsFound() {+ let dir = "/Users/me/Games/01007EF00011E000/"+ XCTAssertEqual(BuildModel.titleID(dir + "01007EF00011E000_v0_420d1c5034ab.nsp"), 0x01007EF00011E000)+ XCTAssertEqual(BuildModel.buildKey(dir + "01007EF00011E000_v0_420d1c5034ab.nsp"), "01007EF00011E000")+ // the update and the DLC beside it keep their own IDs and never stand in for the base+ XCTAssertEqual(BuildModel.titleID(dir + "01007EF00011E800_v1048576_aaaa.nsp"), 0x01007EF00011E800)+ XCTAssertEqual(BuildModel.titleID(dir + "01007EF00011F001_bbbb.nsp"), 0x01007EF00011F001)+ XCTAssertEqual(BuildModel.buildKey(dir + "01007EF00011E000_v0_420d1c5034ab.nsp"),+ BuildModel.buildKey("01007EF00011E000_v0_420d1c5034ab.nsp"))+ // the folder's ID does not leak into a file name that has none+ XCTAssertNotEqual(BuildModel.buildKey(dir + "Zelda.nsp"), "01007EF00011E000")+ }}