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
Using an environment that already has the right engine carries the game there and makes it the game's home, and Open Steam reaches the other environments' Steam (highball#537)
Gauthier Piarrette9916072fbeb0
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex b9d4f8a..d8fcfd0 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -1497,6 +1497,14 @@ final class AppState {return bottle}+ /// The other environments with a Steam of their own, by name. The toolbar's Open Steam only+ /// ever opened the default environment's, so a game living in another one could not reach its+ /// Steam from there (highball#537); these are offered beside it.+ var otherSteamBottles: [Bottle] {+ bottles.filter { $0.name != defaultBottle?.name && !deletingBottles.contains($0.name) && steamInstalled(in: $0) }+ .sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }+ }+func steamLauncherTitle(in bottle: Bottle) -> String {steamClients.contains(bottle.name) ? L("Show Steam") : L("Open Steam")}@@ -1747,9 +1755,21 @@ final class AppState {func useEnvironment(_ env: Bottle, for recipe: HighballKit.Recipe, item: LibraryItem) {pendingEngine = nillet target = item.homed(in: env.name)+ // The chosen environment becomes the game's home. The library put the game wherever it was+ // last played, so the next Play went back to the environment on the wrong engine and the+ // same ask came up every time (highball#537).+ let lastPlayed = libraryPlays[item.id]?.lastPlayedAt ?? Date()+ libraryStore.recordPlay(id: item.id, bottle: env.name, date: lastPlayed)+ libraryPlays[item.id] = LibraryStore.PlayRecord(lastPlayedAt: lastPlayed, bottle: env.name)+ // A Steam game installed where Play started comes along as a clone, as it does into a new+ // environment, instead of being handed to that environment's Steam to download again.+ let source = bottles.first { $0.name == item.bottleName && $0.name != env.name }+ let carries = !target.installed && (source.map { canCarryGame(item, from: $0) } ?? false)let next: () -> Void = { [weak self] inguard let self else { return }- if target.installed { self.play(target) } else { self.installSteamGame(target) }+ if target.installed { self.play(target) }+ else if carries, let source { self.carryAndPlay(item, from: source, into: env) }+ else { self.installSteamGame(target) }}if !env.settings.recipes.contains(recipe.id) || !recipe.artifactsPresent(driveC: env.driveC, steamGames: gamesByBottle[env.name] ?? []) {applyRecipe(recipe.id, to: env, then: DoneState(@@ -1761,6 +1781,32 @@ final class AppState {}}+ /// Clones a Steam game from `source` into `env`'s Steam library and plays it there; hands it to+ /// that Steam to install when the clone is refused. Steam in `env` is stopped first, since a+ /// running client reads the new record only when it starts again.+ private func carryAndPlay(_ item: LibraryItem, from source: Bottle, into env: Bottle) {+ guard let appid = item.steamAppID, let engine = engine(for: env),+ let game = (gamesByBottle[source.name] ?? []).first(where: { $0.appid == appid }),+ let steam = SteamLibrary.steamRoot(of: env) else { installSteamGame(item.homed(in: env.name)); return }+ let paths = paths+ Task { [weak self] in+ try? await WineRunner(paths: paths, engine: engine, bottle: env).stopSteam()+ let outcome = SteamGameCarryOver.carry(game, into: steam.appending(path: "steamapps", directoryHint: .isDirectory))+ await MainActor.run {+ guard let self else { return }+ switch outcome {+ case .carried:+ self.appendLog("\(item.title): carried over from '\(source.name)' to '\(env.name)' as a clone, no download and no extra disk space")+ self.refresh()+ self.play((self.libraryItems.first { $0.id == item.id } ?? item).homed(in: env.name))+ case .skipped(let why):+ self.appendLog("\(item.title): not carried over from '\(source.name)': \(why); the Steam in '\(env.name)' installs it")+ self.installSteamGame(item.homed(in: env.name))+ }+ }+ }+ }+/// The ask's second way out: move the environment itself (the Windows setup re-runs, nothing/// installed is lost), then the done row offers the install.func moveEnvironment(for recipe: HighballKit.Recipe, bottle: Bottle, to manifest: EngineManifest) {diff --git a/Sources/HighballApp/EngineAsk.swift b/Sources/HighballApp/EngineAsk.swiftindex 9d8b274..e823611 100644--- a/Sources/HighballApp/EngineAsk.swift+++ b/Sources/HighballApp/EngineAsk.swift@@ -43,6 +43,8 @@ extension GamePageCopy {}return (existing.holdsGame? String(format: L("'%@' is already on the %@ engine and has the game installed, so it plays there. This environment stays as it is."), existing.name, shortEngineName(manifest))+ : carriesGame+ ? String(format: L("'%@' is already on the %@ engine. Using it brings the game installed here along, without a new download or extra disk space, adds what it needs, and this environment stays as it is."), existing.name, shortEngineName(manifest)): String(format: L("'%@' is already on the %@ engine. Using it installs the game there, with what it needs, and this environment stays as it is."), existing.name, shortEngineName(manifest)))+ memoryNote(recipe: recipe, memoryMB: memoryMB)}diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex a7256a5..ba0535f 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -42,6 +42,14 @@ struct HighballApp: App {.keyboardShortcut("s", modifiers: [.command, .shift]).disabled(state.busy)}+ if !state.otherSteamBottles.isEmpty {+ Menu(L("Steam in another environment")) {+ ForEach(state.otherSteamBottles, id: \.name) { b in+ Button(b.name) { state.showSteam(in: b) }+ }+ }+ .disabled(state.busy)+ }Button(L("A Windows program I have…")) { state.chooseProgramToRun() }.keyboardShortcut("o").disabled(state.busy || state.bottles.isEmpty)@@ -339,9 +347,24 @@ struct ContentView: View {ToolbarItemGroup(placement: .primaryAction) {if !showAddGames {if let bottle = state.defaultSteamBottle {- Button(state.steamLauncherTitle(in: bottle)) { state.showSteam(in: bottle) }+ if state.otherSteamBottles.isEmpty {+ Button(state.steamLauncherTitle(in: bottle)) { state.showSteam(in: bottle) }+ .disabled(state.busy)+ .help(state.steamLauncherTitle(in: bottle))+ } else {+ // A click opens the default environment's Steam as before, the arrow lists the others.+ Menu {+ ForEach(state.otherSteamBottles, id: \.name) { b in+ Button(b.name) { state.showSteam(in: b) }+ }+ } label: {+ Text(state.steamLauncherTitle(in: bottle))+ } primaryAction: {+ state.showSteam(in: bottle)+ }.disabled(state.busy)- .help(state.steamLauncherTitle(in: bottle))+ .help(String(format: L("%@ in '%@'. The arrow opens Steam in another environment."), state.steamLauncherTitle(in: bottle), bottle.name))+ }}Button { showAddGames = true } label: {Label(L("Add games"), systemImage: "plus")diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex 355f4be..41029b8 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -421,6 +421,8 @@ enum L10n {"Install Steam in this bottle to start playing your Windows library.": "Installez Steam dans cette bouteille pour jouer à votre bibliothèque Windows.","Show Steam": "Afficher Steam","Open Steam": "Ouvrir Steam",+ "Steam in another environment": "Steam dans un autre environnement",+ "%@ in '%@'. The arrow opens Steam in another environment.": "%@ dans « %@ ». La flèche ouvre Steam dans un autre environnement.","Install Steam": "Installer Steam","Delete this bottle? Its Windows drive and everything installed in it are removed.": "Supprimer cette bouteille ? Son disque Windows et tout ce qui y est installé seront effacés.",@@ -574,6 +576,7 @@ enum L10n {"Use '%@'": "Utiliser « %@ »","'%@' is already on the %@ engine and has the game installed, so it plays there. This environment stays as it is.": "« %@ » utilise déjà le moteur %@ et le jeu y est installé, il s'y lance donc. Cet environnement reste tel quel.","'%@' is already on the %@ engine. Using it installs the game there, with what it needs, and this environment stays as it is.": "« %@ » utilise déjà le moteur %@. L'utiliser y installe le jeu, avec ce qu'il lui faut, et cet environnement reste tel quel.",+ "'%@' is already on the %@ engine. Using it brings the game installed here along, without a new download or extra disk space, adds what it needs, and this environment stays as it is.": "« %@ » utilise déjà le moteur %@. Le choisir y emmène le jeu installé ici, sans nouveau téléchargement ni espace disque en plus, ajoute ce qu'il lui faut, et cet environnement reste tel quel.","Add": "Ajouter","Automatic": "Automatique","Creating the %@ environment — first boot takes about 90 seconds": "Création de l'environnement %@ — le premier démarrage prend environ 90 secondes",