Skip to content

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

iOS shell: the shell data folder holds one folder per game

v0lumehi979b154dbf67
diff --git a/frontend-ios/Sources/ShellHost/GameCatalogue.swift b/frontend-ios/Sources/ShellHost/GameCatalogue.swift
index 8c195486..794e0c96 100644
--- a/frontend-ios/Sources/ShellHost/GameCatalogue.swift
+++ b/frontend-ios/Sources/ShellHost/GameCatalogue.swift
@@ -190,7 +190,10 @@ public struct DataResolution: Equatable, Sendable {
}
/// The same order as the per-game app's `romfs_locate` (dm/ios/Sources/main.m): the picked location first, then the
-/// app's `Documents/games/<title ID>/`, each accepted only when it holds the game's image or marker.
+/// app's `Documents/games/<title ID>/`, each accepted only when it holds the game's image or marker. It differs in the
+/// shell-level folder, which the per-game app has no counterpart for: one folder serves every game, so it is searched as
+/// `<folder>/<title ID>/` first (one `romfs.img` per game, DLC in `aoc/` beside it), then as the folder itself, the
+/// layout for a single game. The order is the game's own pick, the shell folder, then the app folder.
public enum DataLocator {
public static func locate(manifest: GameManifest, picked: BookmarkResolution, appFolder: URL, fileManager fm: FileManager = .default,
global: BookmarkResolution = .none) -> DataResolution {
@@ -203,7 +206,10 @@ public enum DataLocator {
}
switch global { // the shell-level data folder: the game's own bookmark wins, this backs it up
case .url(let url):
- if let dir = holder(of: url, manifest: manifest, fm) { result.url = dir; result.source = .shell; return result }
+ let titleFolder = url.appendingPathComponent(manifest.titleID, isDirectory: true)
+ if let dir = holder(of: titleFolder, manifest: manifest, fm) ?? holder(of: url, manifest: manifest, fm) {
+ result.url = dir; result.source = .shell; return result
+ }
case .stale, .none: break
}
if let dir = holder(of: appFolder, manifest: manifest, fm) { result.url = dir; result.source = .app }
diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
index f07a92e8..3b9dda52 100644
--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
@@ -401,18 +401,18 @@
}
}
},
- "Games look for their data here. Each game can have a folder of its own.": {
+ "Games look for their data here. Put one folder per game inside, named by its title ID, with its romfs.img in it. Each game can also have a folder of its own.": {
"localizations": {
"en": {
"stringUnit": {
"state": "translated",
- "value": "Games look for their data here. Each game can have a folder of its own."
+ "value": "Games look for their data here. Put one folder per game inside, named by its title ID, with its romfs.img in it. Each game can also have a folder of its own."
}
},
"zh-Hans": {
"stringUnit": {
"state": "translated",
- "value": "游戏会在这里查找游戏数据。每个游戏也可以单独指定文件夹。"
+ "value": "游戏会在这里查找游戏数据。请为每个游戏放一个以 Title ID 命名的文件夹,其中放入它的 romfs.img。每个游戏也可以单独指定文件夹。"
}
}
}
diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift b/frontend-ios/Sources/ShellUI/ShellSettingsView.swift
index ba4d80d3..ede7cb0f 100644
--- a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift
+++ b/frontend-ios/Sources/ShellUI/ShellSettingsView.swift
@@ -50,7 +50,7 @@ struct ShellSettingsView: View {
}.id("shs.top")
SettingsGroup(title: ShellStrings.text("Game data")) {
SourceRow(symbol: "folder", title: store.dataFolderName ?? ShellStrings.text("No folder chosen"),
- note: ShellStrings.text("Games look for their data here. Each game can have a folder of its own.")) {
+ note: ShellStrings.text("Games look for their data here. Put one folder per game inside, named by its title ID, with its romfs.img in it. Each game can also have a folder of its own.")) {
Button(ShellStrings.text("Choose folder…")) { actions.onPickShellData() }
.buttonStyle(ShellButtonStyle(fills: true)).accessibilityIdentifier("shellSettings.data")
.shellTarget("shs.data") { actions.onPickShellData() }
diff --git a/frontend-ios/Tests/ShellHostTests/ShellDataFolderTests.swift b/frontend-ios/Tests/ShellHostTests/ShellDataFolderTests.swift
new file mode 100644
index 00000000..4bf056dc
--- /dev/null
+++ b/frontend-ios/Tests/ShellHostTests/ShellDataFolderTests.swift
@@ -0,0 +1,71 @@
+import Foundation
+import Testing
+@testable import ShellHost
+
+/// The shell-level data folder serves every game: `<folder>/<title ID>/romfs.img` per game, the folder itself for one game.
+@Suite struct ShellDataFolderTests {
+ func manifest(title: String, size: Int) throws -> GameManifest {
+ let url = Fixtures.gamesURL.appendingPathComponent(Fixtures.orbit).appendingPathComponent("game.manifest.json")
+ let text = try String(contentsOf: url, encoding: .utf8)
+ .replacingOccurrences(of: "\"DMROMFSID1 fixture\"", with: "\"DMROMFSID1 title=\(title) version=1.0 build=v0 size=\(size) index=ab\"")
+ .replacingOccurrences(of: Fixtures.orbit, with: title)
+ return try GameManifest.parse(Data(text.utf8))
+ }
+
+ func image(_ size: Int, at url: URL) throws {
+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data(count: size).write(to: url)
+ }
+
+ @Test func oneFolderHoldsSeveralGames() throws {
+ let box = try Sandbox()
+ let shared = box.root.appendingPathComponent("Drive/All", isDirectory: true)
+ let a = try manifest(title: Fixtures.orbit, size: 12), b = try manifest(title: Fixtures.chain, size: 20)
+ try image(12, at: shared.appendingPathComponent(Fixtures.orbit).appendingPathComponent("romfs.img"))
+ try image(20, at: shared.appendingPathComponent(Fixtures.chain).appendingPathComponent("romfs.img"))
+ let ra = DataLocator.locate(manifest: a, picked: .none, appFolder: box.appData.appendingPathComponent(a.titleID), global: .url(shared))
+ let rb = DataLocator.locate(manifest: b, picked: .none, appFolder: box.appData.appendingPathComponent(b.titleID), global: .url(shared))
+ #expect(ra.source == .shell && ra.url == shared.appendingPathComponent(Fixtures.orbit))
+ #expect(rb.source == .shell && rb.url == shared.appendingPathComponent(Fixtures.chain))
+ }
+
+ @Test func aCutOffImageInTheTitleFolderFallsBackToTheAppFolder() throws {
+ let box = try Sandbox()
+ let shared = box.root.appendingPathComponent("Drive/All", isDirectory: true)
+ let m = try manifest(title: Fixtures.orbit, size: 12)
+ try image(5, at: shared.appendingPathComponent(Fixtures.orbit).appendingPathComponent("romfs.img"))
+ let app = box.appData.appendingPathComponent(Fixtures.orbit)
+ #expect(!DataLocator.locate(manifest: m, picked: .none, appFolder: app, global: .url(shared)).found)
+ try image(12, at: app.appendingPathComponent("romfs.img"))
+ #expect(DataLocator.locate(manifest: m, picked: .none, appFolder: app, global: .url(shared)).source == .app)
+ }
+
+ @Test func theSingleGameLayoutAndTheGamesOwnFolderStillWork() throws {
+ let box = try Sandbox()
+ let shared = box.root.appendingPathComponent("Drive/One", isDirectory: true)
+ let m = try manifest(title: Fixtures.orbit, size: 12)
+ let app = box.appData.appendingPathComponent(Fixtures.orbit)
+ try image(12, at: shared.appendingPathComponent("romfs.img"))
+ let single = DataLocator.locate(manifest: m, picked: .none, appFolder: app, global: .url(shared))
+ #expect(single.source == .shell && single.url == shared)
+ // The title folder is tried before the folder itself, and the game's own pick before both.
+ try image(12, at: shared.appendingPathComponent(Fixtures.orbit).appendingPathComponent("romfs.img"))
+ #expect(DataLocator.locate(manifest: m, picked: .none, appFolder: app, global: .url(shared)).url == shared.appendingPathComponent(Fixtures.orbit))
+ let own = box.root.appendingPathComponent("Drive/Own", isDirectory: true)
+ try image(12, at: own.appendingPathComponent("romfs.img"))
+ let r = DataLocator.locate(manifest: m, picked: .url(own), appFolder: app, global: .url(shared))
+ #expect(r.source == .picked && r.url == own)
+ }
+
+ @Test func dlcSitsBesideTheTitleFolderImage() throws {
+ let box = try Sandbox()
+ let shared = box.root.appendingPathComponent("Drive/All", isDirectory: true)
+ let m = try manifest(title: Fixtures.orbit, size: 12)
+ let folder = shared.appendingPathComponent(Fixtures.orbit, isDirectory: true)
+ try image(12, at: folder.appendingPathComponent("romfs.img"))
+ try image(3, at: folder.appendingPathComponent("aoc/0.img"))
+ let r = DataLocator.locate(manifest: m, picked: .none, appFolder: box.appData.appendingPathComponent(m.titleID), global: .url(shared))
+ // The launch plan takes `aoc/` from the folder the locator returns.
+ #expect(FileManager.default.fileExists(atPath: try #require(r.url).appendingPathComponent("aoc/0.img").path))
+ }
+}
diff --git a/frontend-ios/UITests/ShellCaptureTests.swift b/frontend-ios/UITests/ShellCaptureTests.swift
index 9b3d99e1..5258b8c3 100644
--- a/frontend-ios/UITests/ShellCaptureTests.swift
+++ b/frontend-ios/UITests/ShellCaptureTests.swift
@@ -20,7 +20,8 @@ import XCTest
private func launch(_ arguments: [String]) {
app.terminate()
// TEST_RUNNER_SHOT_REAL_ART=1: the demo reads real game art from the host (see RealArt.swift).
- app.launchArguments = arguments + ((ProcessInfo.processInfo.environment["SHOT_REAL_ART"] ?? "").isEmpty ? [] : ["--real-art"])
+ let language = ProcessInfo.processInfo.environment["SHOT_LANG"] ?? "" // TEST_RUNNER_SHOT_LANG=zh-Hans
+ app.launchArguments = arguments + (language.isEmpty ? [] : ["-AppleLanguages", "(\(language))"]) + ((ProcessInfo.processInfo.environment["SHOT_REAL_ART"] ?? "").isEmpty ? [] : ["--real-art"])
app.launch()
_ = app.buttons["controllers.open"].firstMatch.waitForExistence(timeout: 10)
|| app.buttons["controllers.close"].waitForExistence(timeout: 2)
@@ -45,6 +46,17 @@ import XCTest
appShot("settings-scrolled-top-bar")
}
+ /// The shell's own settings page (the game-data and cloud-saves folders), opened from the library.
+ func testShellSettings() {
+ launch(["--screen", "library"])
+ let open = app.buttons["shellSettings.open"].firstMatch
+ XCTAssertTrue(open.waitForExistence(timeout: 5))
+ open.tap()
+ XCTAssertTrue(app.buttons["shellSettings.data"].waitForExistence(timeout: 5))
+ sleep(1)
+ shot("shell-settings")
+ }
+
func testCaptureMatrix() {
for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {
XCUIDevice.shared.orientation = orientation