Skip to content

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

Launcher: a game without a Mac build is not read as the current folder

v0lumehib6a81ae657aa
diff --git a/frontend/Sources/NSPortBuilder/Library.swift b/frontend/Sources/NSPortBuilder/Library.swift
index 5612cef4..35f8cbd1 100644
--- a/frontend/Sources/NSPortBuilder/Library.swift
+++ b/frontend/Sources/NSPortBuilder/Library.swift
@@ -24,8 +24,9 @@ struct LibraryGame: Codable, Identifiable, Equatable {
/// The repository checkout's commit the last finished build used (ToolsAge); empty for a build from before it was recorded.
var toolsCommit = ""
+ /// An empty path means there is no Mac build. It is not read, because URL(fileURLWithPath:) would make it the current folder.
var isReady: Bool {
- guard let app = try? MacGameBundle.read(URL(fileURLWithPath: appPath)) else { return false }
+ guard !appPath.isEmpty, let app = try? MacGameBundle.read(URL(fileURLWithPath: appPath)) else { return false }
return app.titleID == titleID
}
diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
index ade8f35f..ecdf04a3 100644
--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
@@ -47,6 +47,15 @@ final class LibraryTests: XCTestCase {
XCTAssertThrowsError(try MacGameBundle.read(app))
}
+ /// A game without a Mac build has an empty path. That path is not read as the current folder, even when the current folder is a game.
+ func testAGameWithoutAnAppIsNotReady() throws {
+ let app = try makeApp(titleID)
+ let previous = FileManager.default.currentDirectoryPath
+ XCTAssertTrue(FileManager.default.changeCurrentDirectoryPath(app.path))
+ defer { FileManager.default.changeCurrentDirectoryPath(previous) }
+ XCTAssertFalse(LibraryGame(titleID: titleID, name: "Hades").isReady)
+ }
+
func testRejectsUnrelatedApplicationsAndExecutableTraversal() throws {
let app = try makeApp("not-a-title-id")
XCTAssertThrowsError(try MacGameBundle.read(app))