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(uninstall): keep the user's game fixes and clean up what lives outside the support folder
raymondchins089a53a7ea29
diff --git a/app/Sources/BridgeplayApp/Model/Uninstall.swift b/app/Sources/BridgeplayApp/Model/Uninstall.swiftindex d5db333..889dcfc 100644--- a/app/Sources/BridgeplayApp/Model/Uninstall.swift+++ b/app/Sources/BridgeplayApp/Model/Uninstall.swift@@ -25,9 +25,19 @@ struct UninstallOutcome: Sendable {let restoredValveSignature: Boollet removed: [String]var unreachableSteam: [URL] = []+ // Where the user's own game fixes were moved, when there were any.+ var keptGamefixes: URL?+ // Steam's default compatibility tool was ours and was put back or cleared.+ var restoredDefaultTool = falsevar steamNeedsRedownload: Bool { steamInstalled && !restoredValveSignature }+ var keptGamefixesNote: String? {+ keptGamefixes.map {+ String(localized: "Your own game fixes were kept in \($0.path(percentEncoded: false)).")+ }+ }+var partialRemoval: String? {guard !unreachableSteam.isEmpty else { return nil }return unreachableSteam.map {@@ -53,6 +63,27 @@ enum Uninstall {typealias Stop = @Sendable (URL, @Sendable () -> Void) throws -> Bool+ // What Bridgeplay leaves outside the folders `directories` names, and where the user's own+ // game fixes go. No default in run(): the live paths are this Mac's, so tests name theirs.+ struct Leftovers: Sendable {+ var gamefixes: URL+ var keptGamefixes: URL+ var steamConfig: URL+ var defaultToolBackup: URL+ var files: [URL]+ var steamRunning: @Sendable () -> Bool++ static var live: Leftovers {+ Leftovers(+ gamefixes: SupportPaths.gamefixes,+ keptGamefixes: SupportPaths.keptGamefixes,+ steamConfig: SteamDefaultTool.config,+ defaultToolBackup: SteamDefaultTool.backup,+ files: [SupportPaths.homeDir],+ steamRunning: { SteamBundle.isRunningForThisUser })+ }+ }+static func run(app: URL = SupportPaths.Steam.app,innerPlist: URL = SupportPaths.Steam.innerInfoPlist,@@ -66,6 +97,7 @@ enum Uninstall {libraries: [SteamLibrary] = PrefixStore.libraries(),modifications: SteamModifications = .shared,lockFolder: URL = SupportPaths.applicationSupport,+ leftovers: Leftovers,report: @escaping @Sendable (UninstallPhase) -> Void = { _ in },repair: Repair? = nil,stop: Stop = { app, onStopping in try SteamBundle.stopClient(app: app, step: step, onStopping: onStopping) }@@ -138,10 +170,20 @@ enum Uninstall {}_ = try SteamRepair.clearInsert(at: innerPlist)_ = try UpdateBlock.remove(from: updateBlocks)+ // Before the support folder, which holds the backup, goes: a default naming a tool+ // that is about to be deleted would leave Steam pointing at nothing.+ let restoredDefault = try SteamDefaultTool.restore(+ in: leftovers.steamConfig, backup: leftovers.defaultToolBackup, steamRunning: leftovers.steamRunning)report(.removing)+ let kept = try keepGamefixes(leftovers.gamefixes, in: leftovers.keptGamefixes)var removed = try remove(- legacyCompat: legacyCompat, compatTools: compatTools, directories: directories+ legacyCompat: legacyCompat, compatTools: compatTools, directories: directories + leftovers.files)+ // The record of modified bundles is kept while one is out of reach, so a later+ // removal still finds it.+ if missing.isEmpty, try modifications.paths().isEmpty {+ removed += try removeItems([modifications.file] + [modifications.legacyFile].compactMap { $0 })+ }removed += try removeSteamDLLLinks(to: legacyCompat, in: libraries)let templateFailures = RunnerInstaller.removePrefixTemplates(keeping: [], libraries: libraries, removingFolder: true)@@ -155,7 +197,9 @@ enum Uninstall {steamInstalled: steamInstalled,restoredValveSignature: restored,removed: removed,- unreachableSteam: missing+ unreachableSteam: missing,+ keptGamefixes: kept,+ restoredDefaultTool: restoredDefault)}@@ -191,10 +235,14 @@ enum Uninstall {}static func remove(legacyCompat: URL, compatTools: [URL], directories: [URL]) throws -> [String] {+ try removeItems([legacyCompat] + compatTools + directories)+ }++ private static func removeItems(_ targets: [URL]) throws -> [String] {let files = FileManager.defaultvar removed: [String] = []- for target in [legacyCompat] + compatTools + directories {+ for target in targets {let path = target.path(percentEncoded: false)guard files.fileExists(atPath: path) else { continue }try WriteRefused.catching(path) { try files.removeItem(at: target) }@@ -203,6 +251,26 @@ enum Uninstall {return removed}+ // The user's own overrides are theirs: they are moved out of the folder about to be+ // deleted rather than deleted with it. An empty folder is not worth keeping. A previous+ // removal's copy is never overwritten; this one gets a dated name beside it.+ static func keepGamefixes(_ gamefixes: URL, in kept: URL, now: Date = Date()) throws -> URL? {+ let files = FileManager.default+ let entries = (try? files.contentsOfDirectory(atPath: gamefixes.path(percentEncoded: false))) ?? []+ guard entries.contains(where: { $0 != ".DS_Store" }) else { return nil }+ var destination = kept+ if files.fileExists(atPath: destination.path(percentEncoded: false)) {+ let format = DateFormatter()+ format.locale = Locale(identifier: "en_US_POSIX")+ format.dateFormat = "yyyy-MM-dd HH.mm.ss"+ let stamp = format.string(from: now)+ destination = kept.deletingLastPathComponent().appending(path: "\(kept.lastPathComponent) \(stamp)")+ }+ try WriteRefused.catching(destination) { try files.moveItem(at: gamefixes, to: destination) }+ AppLog.note("uninstall: kept the user's game fixes in \(destination.path(percentEncoded: false))")+ return destination+ }+// Links the run script made point at legacycompat. Anything else at that name is left alone.static func removeSteamDLLLinks(to legacyCompat: URL, in libraries: [SteamLibrary]) throws -> [String] {let files = FileManager.defaultdiff --git a/app/Sources/BridgeplayApp/Support/RemoveEverythingCommand.swift b/app/Sources/BridgeplayApp/Support/RemoveEverythingCommand.swiftindex cc9b03d..b6d8ed0 100644--- a/app/Sources/BridgeplayApp/Support/RemoveEverythingCommand.swift+++ b/app/Sources/BridgeplayApp/Support/RemoveEverythingCommand.swift@@ -9,7 +9,7 @@ enum RemoveEverythingCommand {}static func perform(remove: @Sendable (@escaping @Sendable (UninstallPhase) -> Void) async throws -> UninstallOutcome = {- try await Uninstall.run(report: $0)+ try await Uninstall.run(leftovers: .live, report: $0)}) async -> Int32 {do {let output = Output()@@ -23,6 +23,9 @@ enum RemoveEverythingCommand {+ "Reinstall Steam from steampowered.com before using it again.": "Bridgeplay has been removed."))+ if let kept = result.keptGamefixes {+ output.say("Your own game fixes were kept in \(kept.path(percentEncoded: false)).")+ }return result.partialRemoval == nil ? 0 : 1} catch {AppLog.note("command line failed: \(failureMessage(error))")diff --git a/app/Sources/BridgeplayApp/Support/SupportPaths.swift b/app/Sources/BridgeplayApp/Support/SupportPaths.swiftindex 2abf108..bf3c76c 100644--- a/app/Sources/BridgeplayApp/Support/SupportPaths.swift+++ b/app/Sources/BridgeplayApp/Support/SupportPaths.swift@@ -59,6 +59,9 @@ enum SupportPaths {// Per-game defaults Bridgeplay ships. Replaced on every install; the user's own// overrides live in the sibling "gamefixes" directory, which Bridgeplay never writes.static var gamefixesDefault: URL { support.appending(path: "gamefixes-default") }+ static var gamefixes: URL { support.appending(path: "gamefixes") }+ // Where Remove Everything moves the user's own overrides, outside the folder it deletes.+ static var keptGamefixes: URL { applicationSupport.appending(path: "\(supportDirName)-gamefixes") }static var signatures: URL {support.appending(path: "signatures/macos.arm64")diff --git a/app/Sources/BridgeplayApp/SystemStatus.swift b/app/Sources/BridgeplayApp/SystemStatus.swiftindex ab4a927..b5e4fbb 100644--- a/app/Sources/BridgeplayApp/SystemStatus.swift+++ b/app/Sources/BridgeplayApp/SystemStatus.swift@@ -836,12 +836,12 @@ final class SystemStatus {func removeEverything() async {await perform(from: UninstallPhase.stoppingClient.label) { progress in- let result = try await Uninstall.run { progress($0.label) }+ let result = try await Uninstall.run(leftovers: .live) { progress($0.label) }- if let partial = result.partialRemoval { return partial }- return result.steamNeedsRedownload+ let summary = result.partialRemoval ?? (result.steamNeedsRedownload? String(localized: "Bridgeplay has been removed. Steam could not be restored. Reinstall Steam from steampowered.com before using it again.")- : String(localized: "Bridgeplay has been removed.")+ : String(localized: "Bridgeplay has been removed."))+ return [summary, result.keptGamefixesNote].compactMap { $0 }.joined(separator: " ")}}diff --git a/app/Tests/BridgeplayAppTests/SteamRepairTests.swift b/app/Tests/BridgeplayAppTests/SteamRepairTests.swiftindex f749247..09f6604 100644--- a/app/Tests/BridgeplayAppTests/SteamRepairTests.swift+++ b/app/Tests/BridgeplayAppTests/SteamRepairTests.swift@@ -184,6 +184,10 @@ struct SteamRepairTests {app: app, innerPlist: work.appending(path: "inner.plist"), updateBlocks: [],legacyCompat: work.appending(path: "legacycompat"), compatTools: [],directories: [support], libraries: [], modifications: modifications, lockFolder: work,+ leftovers: Uninstall.Leftovers(gamefixes: support.appending(path: "gamefixes"), keptGamefixes: work.appending(path: "kept"),+ steamConfig: work.appending(path: "config.vdf"),+ defaultToolBackup: support.appending(path: "backups/steam-default-tool.json"),+ files: [], steamRunning: { false }),repair: { _, _ in Issue.record("A disconnected repaired copy needs no repair") },stop: { _, _ in false })diff --git a/app/Tests/BridgeplayAppTests/UninstallTests.swift b/app/Tests/BridgeplayAppTests/UninstallTests.swiftindex 7d778a5..ff07da5 100644--- a/app/Tests/BridgeplayAppTests/UninstallTests.swift+++ b/app/Tests/BridgeplayAppTests/UninstallTests.swift@@ -45,6 +45,18 @@ struct UninstallTests {SteamModifications(file: root.appending(path: "steam-bundles.json"),legacyRecord: support.appending(path: "install-build.json"))}+ var steamConfig: URL { root.appending(path: "config.vdf") }+ var keptGamefixes: URL { root.appending(path: "bridgeplay-gamefixes") }+ var homeDir: URL { root.appending(path: ".bridgeplay") }+ var leftovers: Uninstall.Leftovers {+ Uninstall.Leftovers(+ gamefixes: support.appending(path: "gamefixes"),+ keptGamefixes: keptGamefixes,+ steamConfig: steamConfig,+ defaultToolBackup: support.appending(path: "backups/steam-default-tool.json"),+ files: [homeDir],+ steamRunning: { false })+ }}private func layout(signable: Bool = true) throws -> Layout {@@ -221,7 +233,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, layout.caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in throw Offline() },stop: { _, _ in false })@@ -256,7 +268,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, layout.caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in repaired.set() },stop: { _, _ in false })@@ -284,7 +296,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, layout.caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in },stop: { _, _ in false })@@ -307,7 +319,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, layout.caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in },stop: { _, _ in false })@@ -347,7 +359,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, layout.caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in throw Offline() },stop: { _, _ in false })@@ -379,7 +391,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ inlet staged = caches.appending(path: "bundle")try FileManager.default.createDirectory(at: staged, withIntermediateDirectories: true)@@ -408,7 +420,7 @@ struct UninstallTests {compatTools: layout.compatTools,directories: [layout.support, layout.caches],libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,report: { log.add($0) },repair: { _, report inreport(.checking)@@ -451,7 +463,7 @@ struct UninstallTests {app: layout.app, innerPlist: layout.innerPlist, updateBlocks: [layout.updateBlock],legacyCompat: layout.legacyCompat, compatTools: layout.compatTools,directories: [layout.support, layout.caches], libraries: [library],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in }, stop: { _, _ in false })for template in templates { #expect(!FileManager.default.fileExists(atPath: template.path)) }@@ -487,7 +499,7 @@ struct UninstallTests {app: layout.app, innerPlist: layout.innerPlist, updateBlocks: [layout.updateBlock],legacyCompat: layout.legacyCompat, compatTools: layout.compatTools,directories: [layout.support, layout.caches], libraries: [ours, foreign, real, empty],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in }, stop: { _, _ in false })#expect((try? files.destinationOfSymbolicLink(atPath: dll(ours).path(percentEncoded: false))) == nil)@@ -506,7 +518,7 @@ struct UninstallTests {app: app ?? layout.app, innerPlist: layout.innerPlist, updateBlocks: [layout.updateBlock],legacyCompat: layout.legacyCompat, compatTools: layout.compatTools,directories: [layout.support, layout.caches], libraries: [],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: repair, stop: stop)}@@ -703,9 +715,94 @@ struct UninstallTests {app: layout.app, innerPlist: layout.innerPlist, updateBlocks: [layout.updateBlock],legacyCompat: layout.legacyCompat, compatTools: layout.compatTools,directories: [layout.support, layout.caches], libraries: [library],- modifications: layout.modifications, lockFolder: layout.root,+ modifications: layout.modifications, lockFolder: layout.root, leftovers: layout.leftovers,repair: { _, _ in }, stop: { _, _ in false })}#expect(try String(contentsOf: sentinel, encoding: .utf8) == "keep")}++ // MARK: What lives outside the removed folders++ private static let config = """+ "InstallConfigStore"+ {+ \t"Software"+ \t{+ \t\t"Valve"+ \t\t{+ \t\t\t"Steam"+ \t\t\t{+ \t\t\t\t"CompatToolMapping"+ \t\t\t\t{+ \t\t\t\t}+ \t\t\t}+ \t\t}+ \t}+ }+ """++ @Test("The user's own game fixes are moved aside, never deleted")+ func keepsTheUsersGamefixes() async throws {+ let layout = try layout()+ defer { try? FileManager.default.removeItem(at: layout.root) }+ let fix = layout.support.appending(path: "gamefixes/3764200.conf")+ try FileManager.default.createDirectory(at: fix.deletingLastPathComponent(), withIntermediateDirectories: true)+ try Data("BACKEND=wined3d\n".utf8).write(to: fix)+ // A copy kept by an earlier removal stays as it is.+ try FileManager.default.createDirectory(at: layout.keptGamefixes, withIntermediateDirectories: true)++ let outcome = try await remove(layout)++ let kept = try #require(outcome.keptGamefixes)+ #expect(kept != layout.keptGamefixes)+ #expect(try String(contentsOf: kept.appending(path: "3764200.conf"), encoding: .utf8) == "BACKEND=wined3d\n")+ #expect(outcome.keptGamefixesNote?.contains(kept.path(percentEncoded: false)) == true)+ #expect(!FileManager.default.fileExists(atPath: layout.support.path))+ }++ @Test("Without game fixes of the user's own, nothing is kept")+ func keepsNothingWithoutGamefixes() async throws {+ let layout = try layout()+ defer { try? FileManager.default.removeItem(at: layout.root) }+ try FileManager.default.createDirectory(at: layout.support.appending(path: "gamefixes"), withIntermediateDirectories: true)++ let outcome = try await remove(layout)+ #expect(outcome.keptGamefixes == nil)+ #expect(!FileManager.default.fileExists(atPath: layout.keptGamefixes.path))+ }++ // Steam was left defaulting to a tool the removal had just deleted.+ @Test("Steam's default tool is put back to what the user had")+ func restoresSteamsDefaultTool() async throws {+ let layout = try layout()+ defer { try? FileManager.default.removeItem(at: layout.root) }+ let original = Self.config.replacingOccurrences(+ of: "\t\t\t\t{\n\t\t\t\t}",+ with: "\t\t\t\t{\n\t\t\t\t\t\"0\"\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\"\t\t\"GE-Proton9-1\"\n\t\t\t\t\t\t\"config\"\t\t\"\"\n\t\t\t\t\t\t\"priority\"\t\t\"250\"\n\t\t\t\t\t}\n\t\t\t\t}")+ try Data(original.utf8).write(to: layout.steamConfig)+ let leftovers = layout.leftovers+ try SteamDefaultTool.set("bridgeplay-proton-winecx-11.17", in: leftovers.steamConfig,+ backup: leftovers.defaultToolBackup, steamRunning: { false })++ let outcome = try await remove(layout)++ #expect(outcome.restoredDefaultTool)+ #expect(try String(contentsOf: layout.steamConfig, encoding: .utf8) == original)+ }++ @Test("~/.bridgeplay and the record of modified Steam bundles go too")+ func removesTheOtherLeftovers() async throws {+ let layout = try layout()+ defer { try? FileManager.default.removeItem(at: layout.root) }+ try FileManager.default.createDirectory(at: layout.homeDir, withIntermediateDirectories: true)+ try Data("binary".utf8).write(to: layout.homeDir.appending(path: "np-native"))+ try layout.modifications.prepare()+ #expect(FileManager.default.fileExists(atPath: layout.modifications.file.path))++ let outcome = try await remove(layout)++ #expect(!FileManager.default.fileExists(atPath: layout.homeDir.path))+ #expect(!FileManager.default.fileExists(atPath: layout.modifications.file.path))+ #expect(outcome.removed.contains(".bridgeplay"))+ }}