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
Engine updates keep bottles on their engine; bottles switch engines from their settings
Gauthier Piarrette9c5b07e08387
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 0c27ac8..1b0c615 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -271,8 +271,11 @@ final class AppState {return m}- /// Installs the bundled engine next to the current one, points every bottle at it, refreshes- /// each bottle's Windows environment (wineboot), and removes the old engine directory.+ /// Installs the bundled engine next to the current one. Bottles move to it only when the Wine+ /// build is unchanged (a component-only update, like r1's MoltenVK): nothing to re-run, nothing+ /// that can regress. When the Wine build differs, every bottle stays on its engine and the+ /// old engine stays installed as long as any bottle runs on it; the owner switches a bottle+ /// from its settings, one at a time, and can switch back. New bottles get the new engine./// Licenses already accepted on the old engine carry over; the download cache makes an/// update cost only the components that actually changed.func updateEngine() {@@ -290,31 +293,60 @@ final class AppState {}}await MainActor.run { self.appendLog("engine \(fresh.id) installed") }- let refresh = EngineManifest.needsPrefixRefresh(from: old.manifest, to: fresh.manifest)+ let sameWine = !EngineManifest.needsPrefixRefresh(from: old.manifest, to: fresh.manifest)for var bottle in try bottleStore.list() where bottle.settings.engineID != fresh.id {+ guard sameWine else {+ await MainActor.run { self.appendLog("bottle '\(bottle.name)' stays on \(bottle.settings.engineID): the new engine has a different Wine build; switch it from the bottle's settings when you want") }+ continue+ }let runnerOld = WineRunner(paths: paths, engine: old, bottle: bottle)try? runnerOld.kill()try? await Task.sleep(for: .seconds(2))bottle.settings.engineID = fresh.idtry bottle.save()- guard refresh else {- await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(fresh.id) (same Wine, no prefix refresh needed)") }- continue- }- await MainActor.run { self.stage = String(format: L("Refreshing bottle '%@'"), bottle.name) }- let runner = WineRunner(paths: paths, engine: fresh, bottle: bottle)- let r = try await runner.wineboot()- guard r.exitStatus == 0 else {- throw HighballError.processFailed(command: "wineboot -u", status: r.exitStatus, output: "see \(r.log.path)")- }- try await BottleStore.ensureWoW64(runner: runner, bottle: bottle, log: r.log)- try? await runner.setGpuIdentity()- try? await runner.setServiceTimeout()- try? await runner.setKeyboardMapping(commandIsControl: bottle.settings.commandIsControl)- await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(fresh.id)") }+ await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(fresh.id) (same Wine, no prefix refresh needed)") }+ }+ let referenced = Set(try bottleStore.list().map(\.settings.engineID))+ let installed = try engineStore.installedEngines()+ for stale in EngineStore.unreferencedEngines(installed: installed, referencedIDs: referenced, defaultID: fresh.id) {+ try? FileManager.default.removeItem(at: stale.root)+ await MainActor.run { self.appendLog("old engine \(stale.id) removed (no bottle uses it)") }}- if oldID != fresh.id { try? FileManager.default.removeItem(at: old.root) }- await MainActor.run { self.appendLog("old engine \(oldID) removed") }+ if referenced.contains(oldID) {+ await MainActor.run { self.appendLog("engine \(oldID) kept: bottles still run on it") }+ }+ }+ }++ /// Moves one bottle to another installed engine, on its owner's request. Re-runs the Windows+ /// first boot only when the Wine build differs (the same rule as an engine update), then the+ /// per-bottle setup that boot resets. Switching back is the same call the other way.+ func moveBottle(_ bottle: Bottle, to target: InstalledEngine) {+ guard bottle.settings.engineID != target.id, let current = engine(for: bottle) else { return }+ let title = String(format: L("Moving '%@' to %@"), bottle.name, target.id)+ runBusy(title, expected: L("a minute or two when the Windows setup re-runs"),+ done: DoneState(title: L("Engine switched"), ctaTitle: nil, cta: nil)) { [self] in+ var bottle = bottle+ let runnerOld = WineRunner(paths: paths, engine: current, bottle: bottle)+ try? runnerOld.kill()+ try? await Task.sleep(for: .seconds(2))+ bottle.settings.engineID = target.id+ try bottle.save()+ guard EngineManifest.needsPrefixRefresh(from: current.manifest, to: target.manifest) else {+ await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(target.id) (same Wine, no prefix refresh needed)") }+ return+ }+ await MainActor.run { self.stage = String(format: L("Refreshing bottle '%@'"), bottle.name) }+ let runner = WineRunner(paths: paths, engine: target, bottle: bottle)+ let r = try await runner.wineboot()+ guard r.exitStatus == 0 else {+ throw HighballError.processFailed(command: "wineboot -u", status: r.exitStatus, output: "see \(r.log.path)")+ }+ try await BottleStore.ensureWoW64(runner: runner, bottle: bottle, log: r.log)+ try? await runner.setGpuIdentity()+ try? await runner.setServiceTimeout()+ try? await runner.setKeyboardMapping(commandIsControl: bottle.settings.commandIsControl)+ await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(target.id)") }}}diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swiftindex 0b38a77..0f021fe 100644--- a/Sources/HighballApp/BottleView.swift+++ b/Sources/HighballApp/BottleView.swift@@ -372,6 +372,18 @@ struct BottleSettingsSheet: View {.font(.caption).foregroundStyle(.secondary)}Section(L("Advanced")) {+ if state.engines.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)+ })) {+ ForEach(state.engines, id: \.id) { e in Text(verbatim: e.id).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."))+ .font(.caption).foregroundStyle(.secondary)+ }TextField(L("DLL overrides"), text: binding(\.dllOverrides), prompt: Text(verbatim: "version=n,b;winmm=n,b")).font(.body.monospaced())Text(L("Extra Wine DLL overrides for this bottle, semicolon separated. Mods like Cyber Engine Tweaks need version=n,b."))diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swiftindex 257c172..e8b4f76 100644--- a/Sources/HighballKit/EngineStore.swift+++ b/Sources/HighballKit/EngineStore.swift@@ -57,6 +57,13 @@ public struct EngineStore: Sendable {?? installed.max { $0.id.compare($1.id, options: .numeric) == .orderedAscending }}+ /// Engines nothing references any more: not the default and not the engine of any bottle.+ /// An engine update never removes an engine a bottle still runs on; a bottle keeps its+ /// engine until its owner switches it (per-bottle choice, not migration).+ public static func unreferencedEngines(installed: [InstalledEngine], referencedIDs: Set<String>, defaultID: String?) -> [InstalledEngine] {+ installed.filter { $0.id != defaultID && !referencedIDs.contains($0.id) }+ }+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 77874cd..68d554a 100644--- a/Tests/HighballKitTests/RegressionTests.swift+++ b/Tests/HighballKitTests/RegressionTests.swift@@ -843,6 +843,23 @@ extension RegressionTests {// After an engine update the old and new engines coexist until the old one is removed;// sorted by id the old one comes first, so "first installed" would keep choosing it for// new bottles and the sidebar. The bundled manifest's id must win when it is installed.+ // An engine update must never remove an engine a bottle still runs on, and never the default.+ func testUnreferencedEnginesKeepsWhatBottlesUse() throws {+ func engine(_ id: String) throws -> InstalledEngine {+ let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#+ let m = try JSONDecoder().decode(EngineManifest.self, from: Data(json.utf8))+ return InstalledEngine(manifest: m, root: URL(fileURLWithPath: "/tmp/\(id)"))+ }+ let r0 = try engine("x64-sikarugir10.0_6-r0"), r1 = try engine("x64-sikarugir10.0_6-r1"), r2 = try engine("x64-sikarugir11.0_0-r0")+ let all = [r0, r1, r2]+ XCTAssertEqual(EngineStore.unreferencedEngines(installed: all, referencedIDs: [r1.id], defaultID: r2.id).map(\.id), [r0.id],+ "r1 is in use, r2 is the default: only r0 goes")+ XCTAssertEqual(EngineStore.unreferencedEngines(installed: all, referencedIDs: [r0.id, r1.id], defaultID: r2.id).map(\.id), [],+ "every old engine still has a bottle: nothing is removed")+ XCTAssertEqual(EngineStore.unreferencedEngines(installed: all, referencedIDs: [], defaultID: r2.id).map(\.id), [r0.id, r1.id])+ XCTAssertEqual(EngineStore.unreferencedEngines(installed: all, referencedIDs: [], defaultID: nil).map(\.id), all.map(\.id))+ }+func testDefaultEnginePrefersBundledManifestID() throws {func engine(_ id: String) throws -> InstalledEngine {let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#