Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
fix(setup): name the tool already in Steam and offer Repair Steam (#1189) (#1285)
Nathanael3ad60faa4e3d
diff --git a/app/Sources/BridgeplayApp/Model/SteamBundle.swift b/app/Sources/BridgeplayApp/Model/SteamBundle.swiftindex 15c1b3a..9fd0610 100644--- a/app/Sources/BridgeplayApp/Model/SteamBundle.swift+++ b/app/Sources/BridgeplayApp/Model/SteamBundle.swift@@ -74,6 +74,16 @@ enum SteamBundle {return environment[insertKey] as? String}+ // The first library in the insert that isn't ours, by tool name when known.+ static func foreignTool(in insert: String, deployed: String) -> String? {+ guard let other = insert.split(separator: ":").map(String.init).first(where: { $0 != deployed })+ else { return nil }+ let file = URL(filePath: other).lastPathComponent+ return knownTools[file] ?? file+ }++ private static let knownTools = ["cartouche.dylib": "Cartouche"]+static func currentControllerBlock(at url: URL = SupportPaths.Steam.infoPlist) -> String? {guard let dict = readInfoPlist(at: url),let environment = dict[environmentKey] as? [String: Any]diff --git a/app/Sources/BridgeplayApp/Model/SteamInstaller.swift b/app/Sources/BridgeplayApp/Model/SteamInstaller.swiftindex 6f455f5..88fbbc4 100644--- a/app/Sources/BridgeplayApp/Model/SteamInstaller.swift+++ b/app/Sources/BridgeplayApp/Model/SteamInstaller.swift@@ -66,6 +66,17 @@ enum SteamInstaller {}}+ // Typed so Setup can offer Repair Steam for it.+ struct ForeignInsert: LocalizedError {+ let tool: String++ var errorDescription: String? {+ StepFailure(step: SteamInstaller.step,+ detail: String(localized: "\(tool) is already set up in Steam, and Bridgeplay won't install on top of it. Repair Steam to remove it, then try again."))+ .errorDescription+ }+ }+static func run(payload suppliedPayload: InstallPayload.Located? = nil,bridgePayload suppliedBridge: BridgePayload.Located? = nil,@@ -306,13 +317,8 @@ enum SteamInstaller {static func assertInsertIsDeployedOrAbsent(at plist: URL, dylib: URL) throws {guard let insert = SteamBundle.currentInsert(at: plist), !insert.isEmpty else { return }- let deployed = dylib.path(percentEncoded: false)- let foreign = insert.split(separator: ":").map(String.init).filter { $0 != deployed }- guard foreign.isEmpty else {- throw StepFailure(- step: step,- detail: String(localized: "Another dylib is present. Repair your Steam install before installing Bridgeplay.")- )+ if let tool = SteamBundle.foreignTool(in: insert, deployed: dylib.path(percentEncoded: false)) {+ throw ForeignInsert(tool: tool)}}diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstringsindex d8070b5..bbe2ddd 100644--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings@@ -321,6 +321,54 @@}}},+ "%@ is already set up in Steam, and Bridgeplay won't install on top of it. Repair Steam to remove it, then try again." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ è già configurato in Steam e Bridgeplay non si installa sopra. Ripara Steam per rimuoverlo, poi riprova."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ 已在 Steam 中设置,Bridgeplay 不会覆盖安装。请修复 Steam 将其移除,然后重试。"+ }+ }+ }+ },+ "%@ is already set up in Steam." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ è già configurato in Steam."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ 已在 Steam 中设置。"+ }+ }+ }+ },+ "%@ is already set up in Steam. Repair Steam to remove it, and Setup continues by itself." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ è già configurato in Steam. Ripara Steam per rimuoverlo e la configurazione prosegue da sola."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ 已在 Steam 中设置。修复 Steam 即可将其移除,设置会自动继续。"+ }+ }+ }+ },"%@ is left from a rebuild that did not finish and may hold the only copy of the saves. Move it somewhere safe, then try again." : {"localizations" : {"it" : {@@ -545,6 +593,22 @@}}},+ "%@ will stop working in Steam, and Steam may quit for a moment." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ smetterà di funzionare in Steam, e Steam potrebbe chiudersi per un momento."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ 将无法在 Steam 中使用,Steam 可能会短暂退出。"+ }+ }+ }+ },"%@, %@" : {"localizations" : {"en" : {@@ -1436,38 +1500,6 @@}}},- "Another dylib is present." : {- "localizations" : {- "it" : {- "stringUnit" : {- "state" : "translated",- "value" : "È presente un'altra dylib."- }- },- "zh-Hans" : {- "stringUnit" : {- "state" : "translated",- "value" : "检测到其他动态库。"- }- }- }- },- "Another dylib is present. Repair your Steam install before installing Bridgeplay." : {- "localizations" : {- "it" : {- "stringUnit" : {- "state" : "translated",- "value" : "È presente un'altra dylib. Ripara l'installazione di Steam prima di installare Bridgeplay."- }- },- "zh-Hans" : {- "stringUnit" : {- "state" : "translated",- "value" : "检测到其他动态库。请先修复 Steam,再安装 Bridgeplay。"- }- }- }- },"Another installation operation is changing files here. Wait for it to finish." : {"localizations" : {"it" : {@@ -2479,6 +2511,22 @@}}},+ "Bridgeplay is still busy with another task. Try again when it finishes." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bridgeplay sta ancora eseguendo un'altra operazione. Riprova quando ha finito."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bridgeplay 仍在执行另一项任务。完成后再试一次。"+ }+ }+ }+ },"Bridgeplay is still moving its files to the new Bridgeplay folders." : {"localizations" : {"it" : {@@ -7970,18 +8018,18 @@}}},- "Repair your Steam install before installing Bridgeplay." : {+ "Repair Steam to remove it, then install Bridgeplay." : {"localizations" : {"it" : {"stringUnit" : {"state" : "translated",- "value" : "Ripara l'installazione di Steam prima di installare Bridgeplay."+ "value" : "Ripara Steam per rimuoverlo, poi installa Bridgeplay."}},"zh-Hans" : {"stringUnit" : {"state" : "translated",- "value" : "请先修复 Steam,再安装 Bridgeplay。"+ "value" : "请修复 Steam 将其移除,然后安装 Bridgeplay。"}}}@@ -9557,6 +9605,22 @@}}},+ "Steam needs repair" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Steam va riparato"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Steam 需要修复"+ }+ }+ }+ },"Steam not found" : {"localizations" : {"it" : {diff --git a/app/Sources/BridgeplayApp/SetupAssistant.swift b/app/Sources/BridgeplayApp/SetupAssistant.swiftindex ba991e3..784da92 100644--- a/app/Sources/BridgeplayApp/SetupAssistant.swift+++ b/app/Sources/BridgeplayApp/SetupAssistant.swift@@ -61,6 +61,10 @@ final class SetupAssistant {// Finishvar tasks: [SetupTask] = SetupAssistant.plannedTasksvar needsAppManagement = false+ // The tool already set up in Steam, while Setup offers Repair Steam to remove it.+ var needsSteamRepair: String?+ // A repair stopped for App Management, resumed once it's granted.+ @ObservationIgnored private(set) var repairPending = false@ObservationIgnored private var permissionWatch: Task<Void, Never>?// Done: two of the settings for every game (GameDefaults); the rest are on the Game Defaults page.@@ -272,6 +276,8 @@ final class SetupAssistant {isWorking = truedefer { isWorking = false }needsAppManagement = false+ needsSteamRepair = nil+ repairPending = falsemessage = niltasks = Self.plannedTasks@@ -297,10 +303,10 @@ final class SetupAssistant {await status.installIntoSteam()if let failure = status.failure {if status.failureRemedy == .appManagement {- needsAppManagement = true- set("steam", .failed(String(localized: "macOS needs your permission first.")))- openAppManagement()- watchPermission(status)+ askForAppManagement(status)+ } else if let tool = (status.lastRunError as? SteamInstaller.ForeignInsert)?.tool {+ needsSteamRepair = tool+ set("steam", .failed(String(localized: "\(tool) is already set up in Steam.")))} else {set("steam", .failed(failure))}@@ -368,6 +374,54 @@ final class SetupAssistant {tasks[index].state = state}+ // Repair Steam swaps in Valve's bundle, which also needs App Management.+ func repairSteamAndRetry(with status: SystemStatus,+ repair: @MainActor (SystemStatus) async -> Void = { await $0.repairSteam() }) async {+ guard !isWorking else { return }+ // perform() drops a run that overlaps another without a failure, which would read as success.+ guard !status.isBusy else {+ set("steam", .failed(String(localized: "Bridgeplay is still busy with another task. Try again when it finishes.")))+ return+ }+ isWorking = true+ // A card left from an earlier attempt would hide this attempt's error and its Report button.+ permissionWatch?.cancel()+ permissionWatch = nil+ needsAppManagement = false+ needsSteamRepair = nil+ repairPending = false+ set("steam", .running)+ await repair(status)+ isWorking = false+ if let failure = status.failure {+ if repairFailed(failure, remedy: status.failureRemedy) {+ openAppManagement()+ watchPermission(status)+ }+ return+ }+ await finish(with: status)+ }++ // Shows why a repair failed; true when it waits for App Management and resumes after.+ func repairFailed(_ failure: String, remedy: Remedy?) -> Bool {+ guard remedy == .appManagement else {+ set("steam", .failed(failure))+ return false+ }+ needsAppManagement = true+ repairPending = true+ set("steam", .failed(String(localized: "macOS needs your permission first.")))+ return true+ }++ private func askForAppManagement(_ status: SystemStatus) {+ needsAppManagement = true+ set("steam", .failed(String(localized: "macOS needs your permission first.")))+ openAppManagement()+ watchPermission(status)+ }+func openAppManagement() {if let pane = Remedy.appManagement.settingsPane { Remedy.openSettings(pane) }}@@ -379,14 +433,26 @@ final class SetupAssistant {while !Task.isCancelled {try? await Task.sleep(for: .seconds(2))guard let self, self.needsAppManagement else { return }- if Self.canWriteSteam() {- await self.finish(with: status)- return- }+ if await self.resumeAfterPermission(status, canWrite: Self.canWriteSteam()) { return }}}}+ // One poll of the watch; false keeps it polling. A pending repair also waits while another+ // run is in flight, since the repair would refuse it and nothing would retry.+ func resumeAfterPermission(_ status: SystemStatus, canWrite: Bool,+ repair: @MainActor (SystemStatus) async -> Void = { await $0.repairSteam() }) async -> Bool {+ guard canWrite, !(repairPending && status.isBusy) else { return false }+ // Detached first, so the retry's own cancel doesn't stop this task mid-run.+ permissionWatch = nil+ if repairPending {+ await repairSteamAndRetry(with: status, repair: repair)+ } else {+ await finish(with: status)+ }+ return true+ }+nonisolated static func canWriteSteam(app: URL = SupportPaths.Steam.app) -> Bool {let probe = app.appending(path: "Contents/.bridgeplay-write-probe")guard FileManager.default.createFile(atPath: probe.path(percentEncoded: false), contents: Data()) else { return false }diff --git a/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift b/app/Sources/BridgeplayApp/Views/SetupAssistantView.swiftindex 9d0471e..180ed07 100644--- a/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift+++ b/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift@@ -13,6 +13,7 @@ struct SetupAssistantView: View {// How many rows of the current step have resolved; the rest still show "Checking…".@State private var revealed: Int@State private var forward = true+ @State private var confirmingRepair = falseprivate let fixedReveal: Int?private let onClose: (() -> Void)?@@ -296,6 +297,20 @@ struct SetupAssistantView: View {detail: String(localized: "After a Bridgeplay update the switch can look on but no longer work. Turn it off and on again, or remove Bridgeplay from the list with − and add it back with +."),action: StatusAction(label: Remedy.settingsButton, isProminent: true) { model.openAppManagement() }))}+ } else if let tool = model.needsSteamRepair {+ SetupCard {+ WizardRow(row: StatusRow(title: String(localized: "Steam needs repair"),+ value: String(localized: "\(tool) is already set up in Steam. Repair Steam to remove it, and Setup continues by itself."),+ tone: .warning,+ action: StatusAction(label: String(localized: "Repair Steam"), isProminent: true) { confirmingRepair = true }))+ }+ .confirmationDialog(String(localized: "Replace Steam with Valve's bundle?"),+ isPresented: $confirmingRepair, titleVisibility: .visible) {+ Button("Replace Steam", role: .destructive) { Task { await model.repairSteamAndRetry(with: status) } }+ Button("Cancel", role: .cancel) {}+ } message: {+ Text(String(localized: "\(tool) will stop working in Steam, and Steam may quit for a moment."))+ }} else if model.tasks.contains(where: { $0.state != .done }) {approvals}@@ -409,9 +424,10 @@ struct SetupAssistantView: View {}}- // App Management has its own card and button.+ // App Management and Repair Steam have their own card and button.private func report(_ task: SetupAssistant.SetupTask) -> StatusAction? {- guard case .failed(let reason) = task.state, !model.needsAppManagement else { return nil }+ guard case .failed(let reason) = task.state, !model.needsAppManagement, model.needsSteamRepair == nil+ else { return nil }return StatusAction(label: ErrorReport.reportLabel) { ErrorReport.open(reason, in: "Setup: \(task.title)") }}@@ -474,10 +490,17 @@ struct SetupAssistantView: View {.disabled(!model.steamInstalled || !model.signedIn || model.isWorking).keyboardShortcut(.defaultAction)case .finish:- Button(model.failed ? "Try Again" : "Set Up") { Task { await model.finish(with: status) } }- .buttonStyle(.pillLarge)- .disabled(model.isWorking || !(model.failed || model.notStarted))- .keyboardShortcut(.defaultAction)+ // Secondary while the Repair Steam card leads, for a tool removed some other way.+ if model.needsSteamRepair == nil {+ Button(model.failed ? "Try Again" : "Set Up") { Task { await model.finish(with: status) } }+ .buttonStyle(.pillLarge)+ .disabled(model.isWorking || !(model.failed || model.notStarted))+ .keyboardShortcut(.defaultAction)+ } else {+ Button("Try Again") { Task { await model.finish(with: status) } }+ .buttonStyle(.pillSecondaryLarge)+ .disabled(model.isWorking)+ }case .done:Button("Close") { model.dismiss(); close() }.buttonStyle(.pillSecondaryLarge)diff --git a/app/Sources/BridgeplayApp/Views/StatusView.swift b/app/Sources/BridgeplayApp/Views/StatusView.swiftindex 574687f..64956c5 100644--- a/app/Sources/BridgeplayApp/Views/StatusView.swift+++ b/app/Sources/BridgeplayApp/Views/StatusView.swift@@ -611,12 +611,14 @@ struct StatusView: View {tone: .warning,action: installAction(prominent: true))- case .foreign:+ case .foreign(let insert):+ let tool = SteamBundle.foreignTool(in: insert, deployed: SupportPaths.Steam.deployedDylib.path(percentEncoded: false))+ ?? insertStatusRow(title: "Bridgeplay",- value: String(localized: "Another dylib is present."),+ value: String(localized: "\(tool) is already set up in Steam."),tone: .warning,- detail: String(localized: "Repair your Steam install before installing Bridgeplay.")+ detail: String(localized: "Repair Steam to remove it, then install Bridgeplay."))}}diff --git a/app/Tests/BridgeplayAppTests/SetupAssistantSnapshots.swift b/app/Tests/BridgeplayAppTests/SetupAssistantSnapshots.swiftindex a243b36..504bf96 100644--- a/app/Tests/BridgeplayAppTests/SetupAssistantSnapshots.swift+++ b/app/Tests/BridgeplayAppTests/SetupAssistantSnapshots.swift@@ -76,6 +76,11 @@ struct SetupAssistantSnapshots {m.tasks[0].state = .failed("macOS needs your permission first.")m.needsAppManagement = true}+ try wizard("2-wizard-4c-repair") { m in+ m.step = .finish+ m.tasks[0].state = .failed("Cartouche is already set up in Steam.")+ m.needsSteamRepair = "Cartouche"+ }try wizard("2-wizard-5-done") { $0.step = .done }}diff --git a/app/Tests/BridgeplayAppTests/SetupAssistantTests.swift b/app/Tests/BridgeplayAppTests/SetupAssistantTests.swiftindex 0ddf155..9aff72c 100644--- a/app/Tests/BridgeplayAppTests/SetupAssistantTests.swift+++ b/app/Tests/BridgeplayAppTests/SetupAssistantTests.swift@@ -75,6 +75,80 @@ struct SetupAssistantTests {#expect(!SetupAssistant.shouldShow(nil, defaults: defaults))}+ // MARK: Repair Steam++ @MainActor+ private func steamState(_ model: SetupAssistant) -> SetupAssistant.TaskState? {+ model.tasks.first { $0.id == "steam" }?.state+ }++ @Test("A repair that fails for another reason clears the App Management card and shows its error")+ @MainActor+ func repairFailureClearsCards() async {+ let model = SetupAssistant()+ model.needsAppManagement = true+ model.needsSteamRepair = "Cartouche"+ await model.repairSteamAndRetry(with: SystemStatus()) { $0.setFailure("Steam did not quit.") }+ #expect(!model.needsAppManagement)+ #expect(model.needsSteamRepair == nil)+ #expect(!model.repairPending)+ #expect(!model.isWorking)+ #expect(steamState(model) == .failed("Steam did not quit."))+ }++ @Test("A repair stopped by App Management waits to resume; other failures don't")+ @MainActor+ func repairPendingOnlyForAppManagement() {+ let waiting = SetupAssistant()+ #expect(waiting.repairFailed("Could not write files.", remedy: .appManagement))+ #expect(waiting.needsAppManagement)+ #expect(waiting.repairPending)+ #expect(steamState(waiting) == .failed("macOS needs your permission first."))++ let failed = SetupAssistant()+ #expect(!failed.repairFailed("Could not download Steam.", remedy: nil))+ #expect(!failed.needsAppManagement)+ #expect(!failed.repairPending)+ #expect(steamState(failed) == .failed("Could not download Steam."))+ }++ @Test("Repair Steam says so when another run is in flight, and runs nothing")+ @MainActor+ func repairRefusedWhileBusy() async {+ let model = SetupAssistant()+ model.needsSteamRepair = "Cartouche"+ let status = SystemStatus()+ status.activity = "Installing"+ var ran = false+ await model.repairSteamAndRetry(with: status) { _ in ran = true }+ #expect(!ran)+ #expect(model.needsSteamRepair == "Cartouche")+ #expect(steamState(model) == .failed("Bridgeplay is still busy with another task. Try again when it finishes."))+ }++ @Test("A repair waiting for App Management keeps waiting while Bridgeplay is busy, then resumes")+ @MainActor+ func repairResumesAfterBusy() async {+ let model = SetupAssistant()+ #expect(model.repairFailed("Could not write files.", remedy: .appManagement))+ let status = SystemStatus()+ status.activity = "Installing"+ var ran = false+ let repair: @MainActor (SystemStatus) async -> Void = { ran = true; $0.setFailure("Steam did not quit.") }++ #expect(!(await model.resumeAfterPermission(status, canWrite: true, repair: repair)))+ #expect(!ran)+ #expect(model.needsAppManagement)+ #expect(model.repairPending)+ #expect(steamState(model) == .failed("macOS needs your permission first."))++ status.activity = nil+ #expect(await model.resumeAfterPermission(status, canWrite: true, repair: repair))+ #expect(ran)+ #expect(!model.needsAppManagement)+ #expect(steamState(model) == .failed("Steam did not quit."))+ }+// MARK: Making WineCX Steam's default// Steam in this account, another account, or both. quits: whether it obeys steam://exit.diff --git a/app/Tests/BridgeplayAppTests/SteamBundleTests.swift b/app/Tests/BridgeplayAppTests/SteamBundleTests.swiftindex 693db3e..068fae8 100644--- a/app/Tests/BridgeplayAppTests/SteamBundleTests.swift+++ b/app/Tests/BridgeplayAppTests/SteamBundleTests.swift@@ -6,6 +6,19 @@ import Testing@Suite("Steam bundle")struct SteamBundleTests {+ @Test("A foreign insert names the tool when known, else its file, and ignores ours")+ func foreignToolNames() {+ let ours = "/Applications/Steam.app/Contents/MacOS/notproton.dylib"+ let cartouche = "/Applications/Steam.app/Contents/MacOS/cartouche.dylib"+ #expect(SteamBundle.foreignTool(in: cartouche, deployed: ours) == "Cartouche")+ #expect(SteamBundle.foreignTool(in: "\(ours):\(cartouche)", deployed: ours) == "Cartouche")+ #expect(SteamBundle.foreignTool(in: "/opt/other/hook.dylib", deployed: ours) == "hook.dylib")+ #expect(SteamBundle.foreignTool(in: ours, deployed: ours) == nil)+ #expect(SteamBundle.foreignTool(in: "\(ours):/x/other.dylib", deployed: ours) == "other.dylib")+ #expect(SteamBundle.foreignTool(in: ":\(ours)", deployed: ours) == nil)+ #expect(SteamBundle.foreignTool(in: "\(ours):", deployed: ours) == nil)+ }+// The bug this guards was live: the sweep covered only the bundle being replaced, and the// helpers do not run from there, so an ipcserver survived a stop that reported success.@Test("The process sweep covers the helpers as well as the bundle being modified")diff --git a/app/Tests/BridgeplayAppTests/SteamInstallerTests.swift b/app/Tests/BridgeplayAppTests/SteamInstallerTests.swiftindex 9cc7d79..a8c0708 100644--- a/app/Tests/BridgeplayAppTests/SteamInstallerTests.swift+++ b/app/Tests/BridgeplayAppTests/SteamInstallerTests.swift@@ -251,8 +251,9 @@ struct SteamInstallerTests {do {_ = try install(fixture)Issue.record("an install over a foreign insert was allowed")- } catch let failure as StepFailure {- #expect(failure.detail.contains("Repair your Steam install"))+ } catch let failure as SteamInstaller.ForeignInsert {+ #expect(failure.tool == "somethingelse.dylib")+ #expect(failure.localizedDescription.contains("somethingelse.dylib is already set up in Steam"))}#expect(SteamBundle.currentInsert(at: fixture.plist) == foreign, "the foreign insert was modified")