Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
Bottles can move to an engine the app knows but has not installed
Gauthier Piarrette50c6967c94b6
diff --git a/Scripts/make-app.sh b/Scripts/make-app.shindex cbfc9c8..0bdd55a 100755--- a/Scripts/make-app.sh+++ b/Scripts/make-app.sh@@ -21,6 +21,8 @@ cp -R "$SPARKLE_FW" "$APP/Contents/Frameworks/"# Resources: engine manifest, GPTK license, recipes and DB entries (from highball-db).cp spike/engine-manifest.json "$APP/Contents/Resources/engine-manifest.json"+# Other engines the app can offer (previous ones for rollback, candidates for Advanced).+if ls spike/engines/*.json >/dev/null 2>&1; then mkdir -p "$APP/Contents/Resources/engines"; cp spike/engines/*.json "$APP/Contents/Resources/engines/"; ficp spike/d3dmetal-license.txt "$APP/Contents/Resources/d3dmetal-license.txt"RECIPES="../highball-db/recipes"if [ ! -d "$RECIPES" ]; thendiff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 9201d78..905935c 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -818,6 +818,52 @@ final class AppState {?? repoRoot?.appending(path: "spike/engine-manifest.json")}+ /// Every engine manifest the app ships: the default one plus `engines/*.json` (previous+ /// engines kept for rollback, candidates offered in Advanced). A bottle can move to any of+ /// them; one that is not installed downloads first.+ static var knownManifests: [EngineManifest] {+ var urls: [URL] = []+ if let m = bundledManifest { urls.append(m) }+ if let dir = Bundle.main.resourceURL?.appending(path: "engines"),+ let more = try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) {+ urls += more.filter { $0.pathExtension == "json" }+ } else if let dir = repoRoot?.appending(path: "spike/engines"),+ let more = try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) {+ urls += more.filter { $0.pathExtension == "json" }+ }+ var seen = Set<String>()+ return urls.compactMap { try? EngineManifest.load(from: $0) }.filter { seen.insert($0.id).inserted }+ }++ /// What the bottle's Engine picker lists: installed engines, then known ones to download.+ var offeredEngines: [EngineStore.OfferedEngine] {+ EngineStore.offeredEngines(installed: engines, known: Self.knownManifests)+ }++ /// Moves a bottle to an engine by id, installing it first when it is only known from a+ /// bundled manifest. Licenses accepted on any installed engine carry over.+ func moveBottle(_ bottle: Bottle, toEngineID id: String) {+ if let installed = engines.first(where: { $0.id == id }) { moveBottle(bottle, to: installed); return }+ guard let manifest = Self.knownManifests.first(where: { $0.id == id }) else { return }+ let accepted = Set(engines.flatMap { $0.manifest.acceptedLicenses ?? [] })+ let title = String(format: L("Downloading engine %@"), manifest.id)+ runBusy(title, expected: L("usually a few minutes"),+ done: DoneState(title: L("Engine installed"), ctaTitle: nil, cta: nil)) { [self] in+ let fresh = try await engineStore.install(manifest, accepted: accepted) { name, received, total in+ Task { @MainActor in+ let mb = { (b: Int64) in String(format: "%.0f", Double(b) / 1_048_576) }+ if let total, total > 0 { self.stage = "Downloading \(name) — \(mb(received)) / \(mb(total)) MB" }+ else { self.stage = "Downloading \(name) — \(mb(received)) MB" }+ }+ }+ await MainActor.run {+ self.appendLog("engine \(fresh.id) installed")+ self.refresh()+ self.moveBottle(bottle, to: fresh)+ }+ }+ }+/// All bundled dependency ("tweak") recipes, for the Dependencies section in bottle settings.static func tweakRecipes() -> [HighballKit.Recipe] {var dirs: [URL] = []diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swiftindex 0f021fe..8964df1 100644--- a/Sources/HighballApp/BottleView.swift+++ b/Sources/HighballApp/BottleView.swift@@ -372,16 +372,18 @@ struct BottleSettingsSheet: View {.font(.caption).foregroundStyle(.secondary)}Section(L("Advanced")) {- if state.engines.count > 1 {+ let offered = state.offeredEngines+ if offered.count > 1 {Picker(L("Engine"), selection: Binding(get: { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.engineID },set: { newID in- guard let target = state.engines.first(where: { $0.id == newID }) else { return }- state.moveBottle(state.bottles.first { $0.name == bottle.name } ?? bottle, to: target)+ state.moveBottle(state.bottles.first { $0.name == bottle.name } ?? bottle, toEngineID: newID)})) {- ForEach(state.engines, id: \.id) { e in Text(verbatim: e.id).tag(e.id) }+ ForEach(offered, id: \.id) { e in+ Text(verbatim: e.installed ? e.id : "\(e.id) (\(L("download")))").tag(e.id)+ }}- Text(L("Bottles never change engine on their own. Switching re-runs the Windows setup when the Wine build differs; switching back is the same step."))+ Text(L("Bottles never change engine on their own. Switching re-runs the Windows setup when the Wine build differs; switching back is the same step. An engine marked download is fetched first.")).font(.caption).foregroundStyle(.secondary)}TextField(L("DLL overrides"), text: binding(\.dllOverrides), prompt: Text(verbatim: "version=n,b;winmm=n,b"))diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swiftindex aeda183..8719a54 100644--- a/Sources/HighballKit/EngineStore.swift+++ b/Sources/HighballKit/EngineStore.swift@@ -73,6 +73,24 @@ public struct EngineStore: Sendable {.max { $0.id.compare($1.id, options: .numeric) == .orderedAscending }}+ /// One row per engine the app can put a bottle on: every installed engine, then every+ /// bundled manifest that is not installed yet (it downloads when chosen). Newest first+ /// within each group, by numeric-aware id order.+ public struct OfferedEngine: Equatable, Sendable {+ public let id: String+ public let displayName: String+ public let installed: Bool+ public init(id: String, displayName: String, installed: Bool) { self.id = id; self.displayName = displayName; self.installed = installed }+ }+ public static func offeredEngines(installed: [InstalledEngine], known: [EngineManifest]) -> [OfferedEngine] {+ let newestFirst: (String, String) -> Bool = { $0.compare($1, options: .numeric) == .orderedDescending }+ let have = installed.sorted { newestFirst($0.id, $1.id) }.map { OfferedEngine(id: $0.id, displayName: $0.displayName, installed: true) }+ let ids = Set(have.map(\.id))+ let more = known.filter { !ids.contains($0.id) }.sorted { newestFirst($0.id, $1.id) }+ .map { OfferedEngine(id: $0.id, displayName: $0.displayName, installed: false) }+ return have + more+ }+public func engine(_ id: String) throws -> InstalledEngine {let root = paths.engine(id)let m = try EngineManifest.load(from: root.appending(path: "manifest.json"))diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swiftindex 1816511..955ed48 100644--- a/Tests/HighballKitTests/RegressionTests.swift+++ b/Tests/HighballKitTests/RegressionTests.swift@@ -874,6 +874,21 @@ extension RegressionTests {XCTAssertNil(EngineStore.alternateEngine(for: r1.id, installed: [r1], defaultID: r1.id), "single engine: nothing to offer")}+ // The Engine picker lists installed engines first, then known manifests to download, newest first.+ func testOfferedEnginesListsInstalledThenDownloadable() throws {+ func manifest(_ id: String) throws -> EngineManifest {+ let json = #"{"id":"\#(id)","displayName":"e \#(id)","arch":"x86_64","minMacOS":"14.0","components":{}}"#+ return try JSONDecoder().decode(EngineManifest.self, from: Data(json.utf8))+ }+ let r1 = InstalledEngine(manifest: try manifest("x64-a-r1"), root: URL(fileURLWithPath: "/tmp/r1"))+ let r0 = InstalledEngine(manifest: try manifest("x64-a-r0"), root: URL(fileURLWithPath: "/tmp/r0"))+ let known = [try manifest("x64-a-r1"), try manifest("x64-a-r2"), try manifest("x64-a-r10")]+ let offered = EngineStore.offeredEngines(installed: [r0, r1], known: known)+ XCTAssertEqual(offered.map(\.id), ["x64-a-r1", "x64-a-r0", "x64-a-r10", "x64-a-r2"])+ XCTAssertEqual(offered.map(\.installed), [true, true, false, false])+ XCTAssertEqual(EngineStore.offeredEngines(installed: [r1], known: [try manifest("x64-a-r1")]).count, 1, "the installed default is not listed twice")+ }+func testDefaultEnginePrefersBundledManifestID() throws {func engine(_ id: String) throws -> InstalledEngine {let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#