Skip to content

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

Replace the old library entry when a build finishes for a game already listed

v0lumehif1524f7d0ed5
diff --git a/frontend/Sources/NSPortBuilder/Library.swift b/frontend/Sources/NSPortBuilder/Library.swift
index 1af07879..17427c6b 100644
--- a/frontend/Sources/NSPortBuilder/Library.swift
+++ b/frontend/Sources/NSPortBuilder/Library.swift
@@ -493,11 +493,24 @@ final class GameLibrary: ObservableObject {
guard var game = games.first(where: { $0.id == id }),
let app = try? MacGameBundle.read(URL(fileURLWithPath: path)),
app.titleID == game.titleID || game.titleID.hasPrefix("/") else { return }
+ // An entry keyed by its path (the base package's name carried no title ID) now learns the real one. If the
+ // library already lists that game, this build replaces it: what the user set on the old entry carries over.
+ if game.titleID != app.titleID, let old = games.first(where: { $0.id != id && $0.titleID == app.titleID }) {
+ game.artworkPath = old.artworkPath
+ game.launchOptions = old.launchOptions
+ game.mods = old.mods
+ game.iosAppPath = old.iosAppPath
+ game.installedDevice = old.installedDevice
+ game.ipaPath = old.ipaPath
+ game.archivePath = old.archivePath
+ games.removeAll { $0.id == old.id }
+ }
game.titleID = app.titleID
game.appPath = path
game.name = app.name
game.toolsCommit = commit // empty for a checkout without git: nothing to compare, rather than an older build's commit
upsert(game)
+ selectedID = game.id
}
func recordCompletedIOS(archive: String, app: String, device: String = "", commit: String = "", for id: UUID) {
diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
index 6dbb8076..25ff689e 100644
--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
@@ -137,6 +137,26 @@ final class LibraryTests: XCTestCase {
XCTAssertFalse(library.games[0].isReady)
}
+ func testBuildOfPathKeyedEntryReplacesTheEntryOfTheSameGame() throws {
+ let app = try makeApp(titleID)
+ let file = temporary.appendingPathComponent("library.json")
+ var existing = LibraryGame(titleID: titleID, name: "Hades")
+ existing.appPath = app.path
+ existing.artworkPath = "/some/external/artwork.jpg"
+ // A base package whose name carries no title ID is keyed by its path until the build finishes.
+ var pending = LibraryGame(titleID: "/games/Hades.nsp", name: "Hades")
+ pending.inputs = ["base": ["/games/Hades.nsp"]]
+ try JSONEncoder().encode([existing, pending]).write(to: file)
+ let library = GameLibrary(file: file)
+ library.recordCompletedApp(path: app.path, for: pending.id)
+ XCTAssertEqual(library.games.count, 1)
+ XCTAssertEqual(library.games[0].titleID, titleID)
+ XCTAssertEqual(library.games[0].artworkPath, "/some/external/artwork.jpg")
+ XCTAssertEqual(library.games[0].inputs["base"], ["/games/Hades.nsp"])
+ XCTAssertTrue(library.games[0].isReady)
+ XCTAssertEqual(library.selectedID, library.games[0].id)
+ }
+
func testRebuildingSameGameKeepsOneEntryAndCustomArtwork() throws {
let app = try makeApp(titleID)
let library = GameLibrary(file: temporary.appendingPathComponent("library.json"))