Skip to content

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

The shell's framework mirror is the primary copy, and the installer makes it

v0lumehi6c0cc67fa446
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.py
index b86ae7df..01c9ba79 100644
--- a/frontend-qt/nspb_qt/localization.py
+++ b/frontend-qt/nspb_qt/localization.py
@@ -216,7 +216,7 @@ TABLE: dict[str, tuple[str, str, str, str, str]] = {
'settings.note': ('游戏文件夹、构建工具和应用更新,都在这里。', 'Library location, build tools and updates.', 'Biblioteksplats, byggverktyg och uppdateringar.', 'Speicherort der Bibliothek, Build-Werkzeuge und Updates.', 'Emplacement de la bibliothèque, outils de compilation et mises à jour.'),
'shellCache.row': ('缓存文件', 'Cache files', 'Cachefiler', 'Cachedateien', 'Fichiers de cache'),
'shellCache.open': ('打开目录', 'Open folder', 'Öppna mapp', 'Ordner öffnen', 'Ouvrir le dossier'),
- 'shellCache.note': ('壳的 framework 镜像、shell.json 和横幅缓存。删除后:下次安装时每个游戏要从构建文件夹重新提供 framework;构建文件夹也删了的游戏需要重新构建。', "The shell's mirrored frameworks, its library file (shell.json) and the banner cache. Deleting it means every game's framework must come from its build folder again at the next install; a game whose build folder is also gone must be rebuilt.", 'Skalns speglade frameworks, shell.json och banner-cachen. Radering betyder: varje spels framework kommer igen från dess byggmapp vid nästa installation; är den också borta måste spelet byggas om.', 'Gespiegelte Frameworks, shell.json und der Banner-Cache. Löschen bedeutet: das Framework jedes Spiels kommt bei der nächsten Installation wieder aus dessen Build-Ordner. Ist der auch weg, muss das Spiel neu gebaut werden.', 'Les frameworks en miroir de la coque, shell.json et le cache des bannières. Les supprimer signifie que le framework de chaque jeu reviendra de son dossier de compilation à la prochaine installation ; un jeu dont le dossier a aussi disparu doit être recompilé.'),
+ 'shellCache.note': ('壳的 framework 镜像、shell.json 和横幅缓存。删除后:下次安装时每个游戏要从构建文件夹重新提供 framework。构建文件夹也删了的游戏需要重新构建。', "The shell's mirrored frameworks, its library file (shell.json) and the banner cache. Deleting it means every game's framework must come from its build folder again at the next install. A game whose build folder is also gone must be rebuilt.", 'Skalns speglade frameworks, shell.json och banner-cachen. Radering betyder att varje spels framework kommer igen från dess byggmapp vid nästa installation. Är den också borta måste spelet byggas om.', 'Gespiegelte Frameworks, shell.json und der Banner-Cache. Löschen bedeutet: das Framework jedes Spiels kommt bei der nächsten Installation wieder aus dessen Build-Ordner. Ist der auch weg, muss das Spiel neu gebaut werden.', 'Les frameworks en miroir de la coque, shell.json et le cache des bannières. Les supprimer signifie que le framework de chaque jeu reviendra de son dossier de compilation à la prochaine installation. Un jeu dont le dossier a aussi disparu doit être recompilé.'),
'settings.appNote': ('为 Apple 设备构建游戏', 'Build your games for Apple devices', 'Bygg dina spel för Apple-enheter', 'Baue deine Spiele für Apple-Geräte', 'Compilez vos jeux pour les appareils Apple'),
'build.compatibility': ('兼容性选项', 'Older iPhone support', 'Stöd för äldre iPhone-modeller', 'Unterstützung für ältere iPhones', 'Prise en charge des anciens iPhone'),
'build.macNote': ('在这台 Mac 上直接运行。', 'Play directly on this Mac.', 'Spela direkt på den här Mac-datorn.', 'Direkt auf diesem Mac spielen.', 'Jouez directement sur ce Mac.'),
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 6a467ef0..4c701f91 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -118,7 +118,9 @@ final class BuildModel: ObservableObject {
private var chainNoteShown = false // the shader-chain notice shows once per build
@Published var running = false
/// The shell folder the cache row shows: the frameworks' mirror, shell.json and the banner cache live here.
- var shellCachePath: String { ShellLibrary.resolveRoot(parent: outDir.isEmpty ? (basePath as NSString).deletingLastPathComponent : outDir) }
+ var shellCachePath: String { shellRoot }
+ /// The shell folder of the install and of the cache row: the saved one, else next to the output folder (or the game's folder).
+ var shellRoot: String { ShellLibrary.resolveRoot(parent: outDir.isEmpty ? (basePath as NSString).deletingLastPathComponent : outDir) }
@Published var stopping = false
@Published var logTail = ""
@Published var done = false
@@ -1444,8 +1446,6 @@ final class BuildModel: ObservableObject {
let name = ((self.basePath as NSString).lastPathComponent as NSString).deletingPathExtension
let fw = ShellInstall.frameworkPath(workDir: self.effectiveWorkDir, titleID: tid)
self.packArchive(workDir: self.effectiveWorkDir) {
- // The mirror in the shell folder is what survives a deleted build folder (#398).
- try? ShellInstall.mirrorFramework(framework: fw, root: ShellLibrary.resolveRoot(parent: (self.basePath as NSString).deletingLastPathComponent))
self.installShell(framework: fw, titleID: tid, name: name, archive: $0)
}
}
@@ -2023,7 +2023,7 @@ final class BuildModel: ObservableObject {
if dataOnly { failure = nil; done = false; doneNote = "" }
shellRetry = (framework, titleID, name, archive)
let python = pythonPath.isEmpty ? Self.findPython().path : pythonPath
- let root = ShellLibrary.resolveRoot(parent: outDir.isEmpty ? (basePath as NSString).deletingLastPathComponent : outDir)
+ let root = shellRoot
var installer = ShellInstaller(xcrun: xcrunPath, repo: repoPath, python: python, root: root, device: installDevice, team: signingTeam)
installer.deviceName = deviceName(installDevice)
installer.lang = lang
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index 81b36e83..2ffea943 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -257,7 +257,7 @@ enum L10n {
"settings.note": ("\u{6e38}\u{620f}\u{6587}\u{4ef6}\u{5939}\u{3001}\u{6784}\u{5efa}\u{5de5}\u{5177}\u{548c}\u{5e94}\u{7528}\u{66f4}\u{65b0}\u{ff0c}\u{90fd}\u{5728}\u{8fd9}\u{91cc}\u{3002}", "Library location, build tools and updates."),
"shellCache.row": ("缓存文件", "Cache files"),
"shellCache.open": ("打开目录", "Open folder"),
- "shellCache.note": ("壳的 framework 镜像、shell.json 和横幅缓存。删除后:下次安装时每个游戏要从构建文件夹重新提供 framework;构建文件夹也删了的游戏需要重新构建。", "The shell's mirrored frameworks, its library file (shell.json) and the banner cache. Deleting it means every game's framework must come from its build folder again at the next install; a game whose build folder is also gone must be rebuilt."),
+ "shellCache.note": ("壳的 framework 镜像、shell.json 和横幅缓存。删除后:下次安装时每个游戏要从构建文件夹重新提供 framework。构建文件夹也删了的游戏需要重新构建。", "The shell's mirrored frameworks, its library file (shell.json) and the banner cache. Deleting it means every game's framework must come from its build folder again at the next install. A game whose build folder is also gone must be rebuilt."),
"settings.appNote": ("\u{4e3a} Apple \u{8bbe}\u{5907}\u{6784}\u{5efa}\u{6e38}\u{620f}", "Build your games for Apple devices"),
"build.compatibility": ("\u{517c}\u{5bb9}\u{6027}\u{9009}\u{9879}", "Older iPhone support"),
"build.macNote": ("\u{5728}\u{8fd9}\u{53f0} Mac \u{4e0a}\u{76f4}\u{63a5}\u{8fd0}\u{884c}\u{3002}", "Play directly on this Mac."),
@@ -1257,7 +1257,7 @@ enum L10n {
"settings.heading": "Inställningar",
"shellCache.row": "Cachefiler",
"shellCache.open": "Öppna mapp",
- "shellCache.note": "Skalns speglade frameworks, shell.json och banner-cachen. Radering betyder: varje spels framework kommer igen från dess byggmapp vid nästa installation; är den också borta måste spelet byggas om.",
+ "shellCache.note": "Skalns speglade frameworks, shell.json och banner-cachen. Radering betyder att varje spels framework kommer igen från dess byggmapp vid nästa installation. Är den också borta måste spelet byggas om.",
"onboarding.welcome.title": "Välkommen.",
"onboarding.welcome.note": "Spela dina Switch-spel direkt på din Mac på ungefär 15 minuter.",
"onboarding.platform.title": "Var vill du spela?",
@@ -3376,7 +3376,7 @@ enum L10n {
"settings.heading": "Réglages",
"shellCache.row": "Fichiers de cache",
"shellCache.open": "Ouvrir le dossier",
- "shellCache.note": "Les frameworks en miroir de la coque, shell.json et le cache des bannières. Les supprimer signifie que le framework de chaque jeu reviendra de son dossier de compilation à la prochaine installation ; un jeu dont le dossier a aussi disparu doit être recompilé.",
+ "shellCache.note": "Les frameworks en miroir de la coque, shell.json et le cache des bannières. Les supprimer signifie que le framework de chaque jeu reviendra de son dossier de compilation à la prochaine installation. Un jeu dont le dossier a aussi disparu doit être recompilé.",
"settings.note": "Emplacement de la bibliothèque, outils de compilation et mises à jour.",
"settings.appNote": "Compilez vos jeux pour les appareils Apple",
"build.compatibility": "Prise en charge des anciens iPhone",
diff --git a/frontend/Sources/NSPortBuilder/ShellInstall.swift b/frontend/Sources/NSPortBuilder/ShellInstall.swift
index c798e00f..9119276b 100644
--- a/frontend/Sources/NSPortBuilder/ShellInstall.swift
+++ b/frontend/Sources/NSPortBuilder/ShellInstall.swift
@@ -29,16 +29,9 @@ struct ShellLibrary: Codable, Equatable {
if let i = games.firstIndex(where: { $0.titleID == game.titleID }) { games[i] = game } else { games.append(game) }
}
- /// Drops the games whose framework folder is gone (a deleted build folder) and has no mirror in the shell folder,
- /// so the shell is never built against a missing one. A mirrored framework is used in place of the lost one.
- mutating func dropMissing(exists: (String) -> Bool = { FileManager.default.fileExists(atPath: $0) },
- mirror: ((Game) -> String?)? = nil) {
- var out: [Game] = []
- for g in games {
- if exists(g.framework) { out.append(g); continue }
- if let m = mirror?(g) { out.append(Game(titleID: g.titleID, name: g.name, framework: m)) }
- }
- games = out
+ /// Drops the games whose framework folder is gone, so the shell is never built against a missing one.
+ mutating func dropMissing(exists: (String) -> Bool = { FileManager.default.fileExists(atPath: $0) }) {
+ games = games.filter { exists($0.framework) }
}
static func stateFile(root: String) -> String { root + "/shell.json" }
@@ -83,16 +76,19 @@ enum ShellInstall {
frameworksMirror(root: root) + "/DmGame\(titleID).framework"
}
- /// Mirrors a freshly built framework into the shell folder: a hard link when both live on one volume (no extra space),
- /// a copy otherwise. Re-links over the previous mirror, so a rebuilt game's mirror follows.
- static func mirrorFramework(framework: String, root: String) throws {
+ /// Mirrors a framework into the shell folder as a copy. On APFS the copy is a clone: it costs no space, and a later write to
+ /// the build folder does not reach it. On another volume it is a real copy. It replaces the previous mirror, so a rebuilt
+ /// game's mirror follows, and a failed copy leaves no half mirror behind.
+ static func mirrorFramework(framework: String, root: String, titleID: String? = nil) throws {
let fm = FileManager.default
- let mirror = mirroredFramework(root: root, titleID: Self.titleID(ofFramework: framework))
- let parent = (mirror as NSString).deletingLastPathComponent
- try? fm.createDirectory(atPath: parent, withIntermediateDirectories: true)
+ let mirror = mirroredFramework(root: root, titleID: titleID ?? Self.titleID(ofFramework: framework))
+ try fm.createDirectory(atPath: (mirror as NSString).deletingLastPathComponent, withIntermediateDirectories: true)
try? fm.removeItem(atPath: mirror)
- do { try fm.linkItem(atPath: framework, toPath: mirror) }
- catch { try fm.copyItem(atPath: framework, toPath: mirror) } // another volume: a real copy
+ do { try fm.copyItem(atPath: framework, toPath: mirror) }
+ catch {
+ try? fm.removeItem(atPath: mirror)
+ throw error
+ }
}
/// The title ID a framework path carries (`DmGame0100…framework`, the build script's name).
@@ -380,6 +376,29 @@ struct ShellInstaller {
private struct ToolResult { var status: Int32; var output: String; var lastError: String? }
+ /// The mirror in the shell folder is the primary copy of a game's framework: shell.json points there. A game whose
+ /// framework is in its build folder is mirrored now, so a game built before the mirror existed gets one too. A game whose
+ /// build folder is gone plays from the mirror it already has. A failed mirror is logged and the game keeps its build path.
+ private func mirrorFrameworks(_ library: inout ShellLibrary) {
+ let fm = FileManager.default
+ for i in library.games.indices {
+ let game = library.games[i]
+ let mirror = ShellInstall.mirroredFramework(root: root, titleID: game.titleID)
+ if game.framework == mirror { continue }
+ if fm.fileExists(atPath: game.framework) {
+ do {
+ try ShellInstall.mirrorFramework(framework: game.framework, root: root, titleID: game.titleID)
+ library.games[i].framework = mirror
+ } catch {
+ log("library: \(game.titleID)'s framework could not be mirrored at \(mirror), it stays at \(game.framework): \(error.localizedDescription)\n")
+ }
+ } else if fm.fileExists(atPath: mirror) {
+ log("library: \(game.titleID)'s build folder is gone, its framework is the mirror at \(mirror)\n")
+ library.games[i].framework = mirror
+ }
+ }
+ }
+
func install(framework: String, titleID: String, name: String, archive: String) -> Outcome {
guard FileManager.default.fileExists(atPath: framework) else {
return Outcome(ok: false, message: fmt("shell.noFramework", framework))
@@ -390,15 +409,8 @@ struct ShellInstaller {
var library = ShellLibrary.load(root: root)
library.team = team
library.add(.init(titleID: titleID, name: name, framework: framework))
- library.dropMissing(mirror: { g in
- // The build folder is gone, the mirror in the shell folder stands in for the framework.
- let m = ShellInstall.mirroredFramework(root: root, titleID: g.titleID)
- if FileManager.default.fileExists(atPath: m) {
- log("library: \(g.titleID)'s framework is mirrored at \(m)\n")
- return m
- }
- return nil
- })
+ mirrorFrameworks(&library)
+ library.dropMissing()
// The 16:9 banner of the shell's library for every game in it (ShellHost reads <framework>/banner.<ext>, the square
// icon.png is the fallback): a game rebuilt since its last install gets its banner back too
for game in library.games {
@@ -407,11 +419,6 @@ struct ShellInstaller {
log("banner: \(game.titleID) \(banner)\n")
}
}
- // A game whose build folder is gone plays from the mirror: the framework path points there.
- for i in library.games.indices where !FileManager.default.fileExists(atPath: library.games[i].framework) {
- let m = ShellInstall.mirroredFramework(root: root, titleID: library.games[i].titleID)
- if FileManager.default.fileExists(atPath: m) { library.games[i].framework = m }
- }
do { try library.save(root: root) } catch {
return Outcome(ok: false, message: fmt("shell.projectFailed", error.localizedDescription))
}
diff --git a/frontend/Tests/NSPortBuilderTests/ShellInstallTests.swift b/frontend/Tests/NSPortBuilderTests/ShellInstallTests.swift
index f91e743e..b36e5927 100644
--- a/frontend/Tests/NSPortBuilderTests/ShellInstallTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/ShellInstallTests.swift
@@ -368,9 +368,63 @@ final class ShellInstallTests: XCTestCase {
return (status, output)
}
+ private func mirrored(_ root: String, _ id: String? = nil) -> String { ShellInstall.mirroredFramework(root: root, titleID: id ?? titleID) }
+
private var calls: [String] { ((try? String(contentsOfFile: state + "/calls.txt", encoding: .utf8)) ?? "").split(separator: "\n").map(String.init) }
private func copies() -> [String] { calls.filter { $0.hasPrefix("devicectl device copy to") } }
+ // ---- the mirror in the shell folder is the primary copy ----
+
+ func testInstallMirrorsTheBuildAndShellJsonPointsAtTheMirror() throws {
+ let f = try makeFixture()
+ let r = run(f)
+ XCTAssertEqual(r.status, 0, r.output)
+ let mirror = mirrored(f.root)
+ XCTAssertEqual(try String(contentsOfFile: mirror + "/game.manifest.json"), "{}")
+ XCTAssertEqual(ShellLibrary.load(root: f.root).games.map(\.framework), [mirror])
+ // a later write to the build folder does not reach the mirror
+ try write(f.framework + "/game.manifest.json", "changed")
+ XCTAssertEqual(try String(contentsOfFile: mirror + "/game.manifest.json"), "{}")
+ }
+
+ func testInstallMirrorsAGameBuiltBeforeTheMirrorExisted() throws {
+ let f = try makeFixture()
+ let otherID = "0100AAAA00000000"
+ let other = path("work2/shell-framework/DmGame\(otherID).framework")
+ try write(other + "/game.manifest.json", "other")
+ var library = ShellLibrary()
+ library.add(.init(titleID: otherID, name: "Other", framework: other)) // what an install before the mirror wrote
+ try library.save(root: f.root)
+ let r = run(f)
+ XCTAssertEqual(r.status, 0, r.output)
+ let saved = ShellLibrary.load(root: f.root)
+ XCTAssertEqual(Set(saved.games.map(\.framework)), [mirrored(f.root), mirrored(f.root, otherID)])
+ XCTAssertEqual(try String(contentsOfFile: mirrored(f.root, otherID) + "/game.manifest.json"), "other")
+ }
+
+ func testGameWithoutBuildFolderPlaysFromItsMirrorAndOneWithNeitherIsDropped() throws {
+ let f = try makeFixture()
+ let keptID = "0100BBBB00000000", lostID = "0100CCCC00000000"
+ try write(mirrored(f.root, keptID) + "/game.manifest.json", "kept")
+ var library = ShellLibrary()
+ library.add(.init(titleID: keptID, name: "Kept", framework: path("gone/DmGame\(keptID).framework")))
+ library.add(.init(titleID: lostID, name: "Lost", framework: path("gone/DmGame\(lostID).framework")))
+ try library.save(root: f.root)
+ let r = run(f)
+ XCTAssertEqual(r.status, 0, r.output)
+ XCTAssertEqual(Set(ShellLibrary.load(root: f.root).games.map(\.titleID)), [titleID, keptID])
+ XCTAssertEqual(ShellLibrary.load(root: f.root).games.first { $0.titleID == keptID }?.framework, mirrored(f.root, keptID))
+ }
+
+ func testFailedMirrorIsLoggedAndTheGameKeepsItsBuildPath() throws {
+ let f = try makeFixture()
+ try write(f.root + "/frameworks", "a file where the mirror folder should be")
+ let r = run(f)
+ XCTAssertEqual(r.status, 0, r.output)
+ XCTAssertTrue(r.output.contains("\(titleID)'s framework could not be mirrored"), r.output)
+ XCTAssertEqual(ShellLibrary.load(root: f.root).games.map(\.framework), [f.framework])
+ }
+
func testTheFakeDeviceWipesSiblingsWithRemoveExistingContent() throws {
let f = try makeFixture()
try write(container + "/b/Documents/games/X/old.bin", "old")
@@ -402,12 +456,12 @@ final class ShellInstallTests: XCTestCase {
XCTAssertEqual(copies().count, 2)
XCTAssertEqual(try String(contentsOfFile: save), "my save")
let env = try String(contentsOfFile: state + "/shell-env.txt")
- for line in ["DM_BUNDLE_ID=org.nxnative.shell", "DM_SHELL_FRAMEWORKS=\(f.framework)", "DM_TEAM_ID=TEAM123456",
+ for line in ["DM_BUNDLE_ID=org.nxnative.shell", "DM_SHELL_FRAMEWORKS=\(mirrored(f.root))", "DM_TEAM_ID=TEAM123456",
"SHELL_DIR=\(f.root)/project", "DM_XCODE_DERIVED_DATA=\(f.root)/derived-data", "FONT_PY=/usr/bin/python3", "DM_SHELL_PACKAGE=\(f.repo)/frontend-ios"] {
XCTAssertTrue(env.contains(line), line)
}
let library = ShellLibrary.load(root: f.root)
- XCTAssertEqual(library.games, [.init(titleID: titleID, name: "Test Game", framework: f.framework)])
+ XCTAssertEqual(library.games, [.init(titleID: titleID, name: "Test Game", framework: mirrored(f.root))])
XCTAssertEqual(library.team, team)
// second run, same data: nothing is copied
diff --git a/frontend/Tests/NSPortBuilderTests/ShellMirrorTests.swift b/frontend/Tests/NSPortBuilderTests/ShellMirrorTests.swift
index d30b4d79..463d4033 100644
--- a/frontend/Tests/NSPortBuilderTests/ShellMirrorTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/ShellMirrorTests.swift
@@ -2,32 +2,58 @@ import XCTest
@testable import NSPortBuilder
final class ShellMirrorTests: XCTestCase {
- func testMirrorLinksAndStandsIn() throws {
- let tmp = NSHomeDirectory() + "/.nspb-mirror-test-\(UUID().uuidString)"
- try FileManager.default.createDirectory(atPath: tmp + "/fw", withIntermediateDirectories: true)
- defer { try? FileManager.default.removeItem(atPath: tmp) }
- let fw = tmp + "/fw/DmGame0100A00019DE0000.framework"
+ private let id = "0100A00019DE0000"
+ private var tmp = ""
+
+ override func setUpWithError() throws {
+ tmp = NSHomeDirectory() + "/.nspb-mirror-test-\(UUID().uuidString)"
+ try FileManager.default.createDirectory(atPath: tmp, withIntermediateDirectories: true)
+ }
+
+ override func tearDownWithError() throws { try? FileManager.default.removeItem(atPath: tmp) }
+
+ private func makeFramework() throws -> String {
+ let fw = tmp + "/fw/DmGame\(id).framework"
try FileManager.default.createDirectory(atPath: fw + "/inside", withIntermediateDirectories: true)
try "x".write(toFile: fw + "/inside/f", atomically: true, encoding: .utf8)
- XCTAssertEqual(ShellInstall.titleID(ofFramework: fw), "0100A00019DE0000")
+ return fw
+ }
+
+ func testMirrorIsACopyThatLaterWritesDoNotReach() throws {
+ let fw = try makeFramework()
+ XCTAssertEqual(ShellInstall.titleID(ofFramework: fw), id)
try ShellInstall.mirrorFramework(framework: fw, root: tmp)
- let mirror = ShellInstall.mirroredFramework(root: tmp, titleID: "0100A00019DE0000")
- XCTAssertTrue(FileManager.default.fileExists(atPath: mirror))
- // 重镜像:删除原 framework 后重新链接不报错
+ let mirror = ShellInstall.mirroredFramework(root: tmp, titleID: id)
+ XCTAssertEqual(try String(contentsOfFile: mirror + "/inside/f"), "x")
+ // an overwrite in place and a new file in the build folder stay out of the mirror
+ try "changed".write(toFile: fw + "/inside/f", atomically: false, encoding: .utf8)
+ try "new".write(toFile: fw + "/inside/g", atomically: true, encoding: .utf8)
+ XCTAssertEqual(try String(contentsOfFile: mirror + "/inside/f"), "x")
+ XCTAssertFalse(FileManager.default.fileExists(atPath: mirror + "/inside/g"))
+ // not a hard link: the file is another inode
+ let a = try FileManager.default.attributesOfItem(atPath: fw + "/inside/f")[.systemFileNumber] as? Int
+ let b = try FileManager.default.attributesOfItem(atPath: mirror + "/inside/f")[.systemFileNumber] as? Int
+ XCTAssertNotEqual(a, b)
+ }
+
+ func testMirrorAgainReplacesThePreviousMirror() throws {
+ let fw = try makeFramework()
+ try ShellInstall.mirrorFramework(framework: fw, root: tmp)
+ try "changed".write(toFile: fw + "/inside/f", atomically: false, encoding: .utf8)
try ShellInstall.mirrorFramework(framework: fw, root: tmp)
- // dropMissing 的镜像回退:原路径没了,镜像顶上
+ XCTAssertEqual(try String(contentsOfFile: ShellInstall.mirroredFramework(root: tmp, titleID: id) + "/inside/f"), "changed")
+ }
+
+ func testMirrorOfAMissingFrameworkThrowsAndLeavesNothing() throws {
+ XCTAssertThrowsError(try ShellInstall.mirrorFramework(framework: tmp + "/none/DmGame\(id).framework", root: tmp))
+ XCTAssertFalse(FileManager.default.fileExists(atPath: ShellInstall.mirroredFramework(root: tmp, titleID: id)))
+ }
+
+ func testDropMissingChecksTheOnePath() throws {
var lib = ShellLibrary()
- lib.add(.init(titleID: "0100A00019DE0000", name: "Test", framework: fw))
- try FileManager.default.removeItem(atPath: fw)
- lib.dropMissing(mirror: { g in
- let m = ShellInstall.mirroredFramework(root: tmp, titleID: g.titleID)
- return FileManager.default.fileExists(atPath: m) ? m : nil
- })
- XCTAssertEqual(lib.games.count, 1)
- XCTAssertEqual(lib.games[0].framework, mirror)
- // 无镜像时才真正剔除
- try FileManager.default.removeItem(atPath: mirror)
- lib.dropMissing(mirror: { _ in nil })
- XCTAssertEqual(lib.games.count, 0)
+ lib.add(.init(titleID: id, name: "Test", framework: tmp + "/gone.framework"))
+ lib.add(.init(titleID: "B", name: "Kept", framework: tmp))
+ lib.dropMissing()
+ XCTAssertEqual(lib.games.map(\.titleID), ["B"])
}
}