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
iOS shell host: unknown game name and state labels that match the cause
v0lumehi2bf3ba6f2157
diff --git a/frontend-ios/Sources/ShellHost/GameCatalogue.swift b/frontend-ios/Sources/ShellHost/GameCatalogue.swiftindex 500cb559..0b79a316 100644--- a/frontend-ios/Sources/ShellHost/GameCatalogue.swift+++ b/frontend-ios/Sources/ShellHost/GameCatalogue.swift@@ -30,7 +30,11 @@ public struct CatalogueEntry: Equatable, Sendable, Identifiable {/// Set when the bundle cannot run at all, whatever the app or the data: the broken state.public var problem: GameProblem?- public var title: String { manifest?.name ?? id }+ /// The name from a manifest that could not be fully read, when it still has one.+ public var readableName: String?++ /// Never the bare title ID: an unreadable bundle is "Unknown game" and its ID is the subtitle.+ public var title: String { manifest?.name ?? readableName ?? hostText("Unknown game") }public var frameworkURL: URL? { manifest.map { directory.appendingPathComponent($0.framework, isDirectory: true) } }}@@ -54,6 +58,7 @@ public enum GameCatalogue {public static func read(directory dir: URL, fileManager fm: FileManager = .default) -> CatalogueEntry {let id = dir.lastPathComponentvar entry = CatalogueEntry(id: id, directory: dir, bannerURL: image(named: "banner", in: dir, fm), iconURL: image(named: "icon", in: dir, fm))+ entry.readableName = lenientName(in: dir.appendingPathComponent("game.manifest.json"), fm)do {guard let data = fm.contents(atPath: dir.appendingPathComponent("game.manifest.json").path) else {throw GameProblem(cause: .manifestMissing, reason: hostText("Game manifest missing"), detail: hostText("This game's folder has no game.manifest.json."))@@ -89,6 +94,14 @@ public enum GameCatalogue {return entry}+ /// The `name` of a manifest that fails validation, when the file is still JSON with a name in it.+ private static func lenientName(in url: URL, _ fm: FileManager) -> String? {+ guard let data = fm.contents(atPath: url.path),+ let name = (try? JSONSerialization.jsonObject(with: data) as? [String: Any])?["name"] as? String else { return nil }+ let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines)+ return trimmed.isEmpty ? nil : trimmed+ }+private static func image(named base: String, in dir: URL, _ fm: FileManager) -> URL? {imageExtensions.map { dir.appendingPathComponent("\(base).\($0)") }.first { fm.fileExists(atPath: $0.path) }}diff --git a/frontend-ios/Sources/ShellHost/GameManifest.swift b/frontend-ios/Sources/ShellHost/GameManifest.swiftindex 7a1e21a1..1a97f945 100644--- a/frontend-ios/Sources/ShellHost/GameManifest.swift+++ b/frontend-ios/Sources/ShellHost/GameManifest.swift@@ -49,19 +49,19 @@ public struct GameManifest: Decodable, Equatable, Sendable {detail: hostText("game.manifest.json has schema \(manifest.schema), this app reads schema \(supportedSchema)."))}guard isTitleID(manifest.titleID) else {- throw GameProblem(cause: .manifestDamaged, reason: hostText("Manifest damaged"), detail: hostText("title_id \"\(manifest.titleID)\" is not 16 hex digits."))+ throw GameProblem(cause: .manifestDamaged, reason: ProblemCause.manifestDamaged.label, detail: hostText("title_id \"\(manifest.titleID)\" is not 16 hex digits."))}guard !manifest.modules.isEmpty else {- throw GameProblem(cause: .manifestDamaged, reason: hostText("Manifest damaged"), detail: hostText("The manifest lists no modules."))+ throw GameProblem(cause: .manifestDamaged, reason: ProblemCause.manifestDamaged.label, detail: hostText("The manifest lists no modules."))}guard manifest.chain.hasPrefix("b-"), manifest.chain.count > 2, manifest.chain.dropFirst(2).allSatisfy(\.isHexDigit) else {- throw GameProblem(cause: .manifestDamaged, reason: hostText("Manifest damaged"), detail: hostText("chain \"\(manifest.chain)\" is not of the form b-<hex>."))+ throw GameProblem(cause: .manifestDamaged, reason: ProblemCause.manifestDamaged.label, detail: hostText("chain \"\(manifest.chain)\" is not of the form b-<hex>."))}guard ["FR", "FH"].contains(manifest.loader) else {- throw GameProblem(cause: .manifestDamaged, reason: hostText("Manifest damaged"), detail: hostText("loader \"\(manifest.loader)\" is neither FR nor FH."))+ throw GameProblem(cause: .manifestDamaged, reason: ProblemCause.manifestDamaged.label, detail: hostText("loader \"\(manifest.loader)\" is neither FR nor FH."))}guard manifest.framework.hasSuffix(".framework"), !manifest.framework.contains("/") else {- throw GameProblem(cause: .manifestDamaged, reason: hostText("Manifest damaged"), detail: hostText("framework \"\(manifest.framework)\" is not a .framework name."))+ throw GameProblem(cause: .manifestDamaged, reason: ProblemCause.manifestDamaged.label, detail: hostText("framework \"\(manifest.framework)\" is not a .framework name."))}return manifest}@@ -87,7 +87,7 @@ func isVersion(_ a: OperatingSystemVersion, atLeast b: OperatingSystemVersion) -/// A decoding error as one readable sentence.func describe(_ error: Error, file: String, cause: ProblemCause) -> GameProblem {- let short = hostText("Game files damaged")+ let short = cause.labelguard let e = error as? DecodingError else { return GameProblem(cause: cause, reason: short, detail: "\(file): \(error.localizedDescription)") }func path(_ c: [CodingKey]) -> String { c.map { $0.stringValue }.joined(separator: ".") }switch e {diff --git a/frontend-ios/Sources/ShellHost/HostText.swift b/frontend-ios/Sources/ShellHost/HostText.swiftindex fd93c191..59bf6f91 100644--- a/frontend-ios/Sources/ShellHost/HostText.swift+++ b/frontend-ios/Sources/ShellHost/HostText.swift@@ -13,6 +13,20 @@ public enum ProblemCause: Equatable, Sendable {case codeMissingcase filesDamaged+ /// The short state label, which says the same thing as `message`.+ public var label: String {+ switch self {+ case .manifestMissing: hostText("Game manifest missing")+ case .manifestDamaged: hostText("Can't read this game")+ case .manifestUnsupported: hostText("Manifest not supported")+ case .settingsMissing: hostText("Settings list missing")+ case .settingsDamaged: hostText("Settings list damaged")+ case .settingsUnsupported: hostText("Settings list not supported")+ case .codeMissing: hostText("Game code missing")+ case .filesDamaged: hostText("Game files damaged")+ }+ }+/// What happened and what to do, for the player. The technical message stays in `GameProblem.detail`.public var message: String {switch self {diff --git a/frontend-ios/Sources/ShellHost/LauncherProfile.swift b/frontend-ios/Sources/ShellHost/LauncherProfile.swiftindex 3af6322d..70b864cf 100644--- a/frontend-ios/Sources/ShellHost/LauncherProfile.swift+++ b/frontend-ios/Sources/ShellHost/LauncherProfile.swift@@ -55,7 +55,7 @@ public struct LauncherProfile: Decodable, Equatable, Sendable {let profile: LauncherProfiledo { profile = try JSONDecoder().decode(LauncherProfile.self, from: data) }catch { throw describe(error, file: "launcher.json", cause: .settingsDamaged) }- let reason = hostText("Settings list damaged")+ let reason = ProblemCause.settingsDamaged.labelif let schema = profile.schema, schema != 1 {throw GameProblem(cause: .settingsUnsupported, reason: hostText("Settings list not supported"), detail: hostText("launcher.json has schema \(schema), this app reads schema 1."))}diff --git a/frontend-ios/Sources/ShellHost/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellHost/Resources/Localizable.xcstringsindex 9d02129d..35178d56 100644--- a/frontend-ios/Sources/ShellHost/Resources/Localizable.xcstrings+++ b/frontend-ios/Sources/ShellHost/Resources/Localizable.xcstrings@@ -111,6 +111,16 @@}}},+ "Can't read this game": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Can't read this game"+ }+ }+ }+ },"Choose a RomFS folder or romfs.img on this device, an external drive, or iCloud Drive.": {"localizations": {"en": {@@ -171,16 +181,6 @@}}},- "Manifest damaged": {- "localizations": {- "en": {- "stringUnit": {- "state": "translated",- "value": "Manifest damaged"- }- }- }- },"Manifest not supported": {"localizations": {"en": {@@ -491,6 +491,16 @@}}},+ "Unknown game": {+ "localizations": {+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Unknown game"+ }+ }+ }+ },"chain \"%@\" is not of the form b-<hex>.": {"localizations": {"en": {diff --git a/frontend-ios/Sources/ShellHost/ShellHostModel.swift b/frontend-ios/Sources/ShellHost/ShellHostModel.swiftindex 61d17c98..16100b66 100644--- a/frontend-ios/Sources/ShellHost/ShellHostModel.swift+++ b/frontend-ios/Sources/ShellHost/ShellHostModel.swift@@ -129,7 +129,7 @@ public struct ShellHostConfig: Sendable {let data = data(for: entry)let state = GameStateResolver.state(for: entry, data: data, environment: config.environment)let played = lastPlayed(entry.id)- let tile = GameTile(id: entry.id, title: entry.title, subtitle: ShellFormat.version(entry.manifest?.displayVersion ?? ""),+ let tile = GameTile(id: entry.id, title: entry.title, subtitle: entry.manifest.map { ShellFormat.version($0.displayVersion) } ?? entry.id,banner: image(entry.bannerURL), icon: image(entry.iconURL), state: state,recentlyPlayed: played.map { ShellFormat.played($0, now: config.now()) })guard let profile = entry.profile, entry.problem == nil else {diff --git a/frontend-ios/Tests/ShellHostTests/CatalogueStateTests.swift b/frontend-ios/Tests/ShellHostTests/CatalogueStateTests.swiftindex a01e3636..eb76f436 100644--- a/frontend-ios/Tests/ShellHostTests/CatalogueStateTests.swift+++ b/frontend-ios/Tests/ShellHostTests/CatalogueStateTests.swift@@ -14,7 +14,7 @@ import ShellUI#expect(byID[Fixtures.badManifest]?.problem?.detail.contains("not valid JSON") == true)#expect(byID[Fixtures.missingKey]?.problem != nil)#expect(byID[Fixtures.badSettings]?.problem?.detail.contains("DM_X") == true)- #expect(byID[Fixtures.badManifest]?.title == Fixtures.badManifest, "a broken manifest leaves the folder name as the title")+ #expect(byID[Fixtures.badManifest]?.title == "Unknown game", "a manifest with no readable name is an unknown game, never its folder name")#expect(entries.suffix(2).allSatisfy { $0.manifest == nil }, "games whose manifest cannot be read sort last")}diff --git a/frontend-ios/Tests/ShellHostTests/ParsingTests.swift b/frontend-ios/Tests/ShellHostTests/ParsingTests.swiftindex 95266f3e..5b40b71b 100644--- a/frontend-ios/Tests/ShellHostTests/ParsingTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ParsingTests.swift@@ -26,7 +26,7 @@ import Testing#expect(truncated.detail.contains("not valid JSON"))let missing = try #require(problem(String(decoding: fixture(Fixtures.missingKey, "game.manifest.json"), as: UTF8.self)))#expect(missing.detail.contains("display_version") || missing.detail.contains("\"") )- #expect(missing.reason == "Game files damaged")+ #expect(missing.reason == "Can't read this game")#expect(problem("[]") != nil)#expect(problem("")?.detail.contains("game.manifest.json") == true)}diff --git a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swiftindex b8bdc589..04db476e 100644--- a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift@@ -332,4 +332,36 @@ final class Clock: @unchecked Sendable { var date: Date; init(_ d: Date) { datemodel.reload()#expect(model.details.first?.id == Fixtures.orbit)}++ @Test func anUnreadableManifestNeverShowsTheBareTitleID() throws {+ let box = try Sandbox()+ let model = ShellHostModel(config: box.config())+ // Truncated JSON: no name anywhere, so "Unknown game" with the ID as the small line.+ let unknown = try detail(model, Fixtures.badManifest).game+ #expect(unknown.title == "Unknown game" && unknown.subtitle == Fixtures.badManifest)+ #expect(unknown.state == .broken(reason: "Can't read this game", detail: ProblemCause.manifestDamaged.message,+ technical: try #require({ () -> String? in if case .broken(_, _, let t) = unknown.state { t } else { nil } }())))+ // Valid JSON that fails validation keeps its own name.+ let partial = try detail(model, Fixtures.missingKey).game+ #expect(partial.title == "Missing Key Fixture" && partial.subtitle == Fixtures.missingKey)+ // Nothing the player reads as a title is a 16 digit ID.+ for d in model.details { #expect(d.game.title.count != 16 || !d.game.title.allSatisfy(\.isNumber)) }+ }++ @Test func theStateLabelMatchesTheCause() throws {+ let box = try Sandbox()+ let model = ShellHostModel(config: box.config())+ func reason(_ id: String) throws -> String {+ guard case .broken(let r, _, _) = try detail(model, id).game.state else { throw Failure() }+ return r+ }+ #expect(try reason(Fixtures.badManifest) == "Can't read this game")+ #expect(try reason(Fixtures.missingKey) == "Can't read this game")+ #expect(try reason(Fixtures.badSettings) == "Settings list damaged")+ #expect(try reason(Fixtures.noFramework) == "Game code missing")+ for cause in [ProblemCause.manifestMissing, .manifestDamaged, .manifestUnsupported, .settingsMissing, .settingsDamaged,+ .settingsUnsupported, .codeMissing, .filesDamaged] {+ #expect(!cause.label.isEmpty && !cause.label.contains(";"))+ }+ }}diff --git a/frontend-ios/UITests/ShellHostUITests.swift b/frontend-ios/UITests/ShellHostUITests.swiftindex 042613b1..a4a124b9 100644--- a/frontend-ios/UITests/ShellHostUITests.swift+++ b/frontend-ios/UITests/ShellHostUITests.swift@@ -43,6 +43,14 @@ import XCTestXCTAssertTrue(app.staticTexts["Details"].exists)}+ func testUnreadableManifestIsUnknownGameWithItsIDAsSmallText() {+ launch(select: "0100000000050000")+ XCTAssertEqual(app.staticTexts["hero.title"].label, "Unknown game")+ XCTAssertTrue(app.staticTexts["0100000000050000"].exists)+ XCTAssertTrue(app.staticTexts.matching(NSPredicate(format: "label CONTAINS[c] \"Can't read this game\"")).firstMatch.exists)+ XCTAssertTrue(app.staticTexts["This game's manifest is damaged. Rebuild the game in the launcher on your Mac."].exists)+ }+func testLibraryStartsOnAPlayableGameWithTheVersionLine() {XCUIDevice.shared.orientation = .portraitapp.launchArguments = ["--host"]