Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(migration): block installs while the 3.0 folder move is pending, and surface its failures

raymondchinsb80483b29f6d
diff --git a/app/Sources/BridgeplayApp/App.swift b/app/Sources/BridgeplayApp/App.swift
index 339af91..943ca36 100644
--- a/app/Sources/BridgeplayApp/App.swift
+++ b/app/Sources/BridgeplayApp/App.swift
@@ -92,7 +92,7 @@ struct BridgeplayApp: App {
CommandMenu("Setup") {
Button("Setup Assistant…") { showsSetup = true }
- .disabled(!status.isIdle)
+ .disabled(!status.isIdle || MigrationLaunch.shared.pending)
Divider()
diff --git a/app/Sources/BridgeplayApp/SetupAssistant.swift b/app/Sources/BridgeplayApp/SetupAssistant.swift
index e5908c9..9c6f3c6 100644
--- a/app/Sources/BridgeplayApp/SetupAssistant.swift
+++ b/app/Sources/BridgeplayApp/SetupAssistant.swift
@@ -145,6 +145,11 @@ final class SetupAssistant {
// MARK: Graphics
func importGPTK(_ image: URL) async {
+ // The toolkit is copied into the support folder, which the 3.0 move has to find untouched.
+ if let refusal = MigrationLaunch.shared.refusal {
+ message = refusal
+ return
+ }
isWorking = true
defer { isWorking = false }
message = nil
@@ -234,6 +239,10 @@ final class SetupAssistant {
step = .done
return
}
+ if let refusal = MigrationLaunch.shared.refusal {
+ message = refusal
+ return
+ }
set("steam", .running)
await status.installIntoSteam()
diff --git a/app/Sources/BridgeplayApp/Support/Launch.swift b/app/Sources/BridgeplayApp/Support/Launch.swift
index 196f87a..6c95840 100644
--- a/app/Sources/BridgeplayApp/Support/Launch.swift
+++ b/app/Sources/BridgeplayApp/Support/Launch.swift
@@ -20,12 +20,23 @@ enum Launch {
}
if CommandLine.arguments.dropFirst().contains(InstallIntoSteamCommand.flag) {
AppLog.note("command line: \(InstallIntoSteamCommand.flag)")
+ refuseWhileMigrating()
InstallIntoSteamCommand.run()
}
if CommandLine.arguments.dropFirst().contains(SetupWinecxCommand.flag) {
AppLog.note("command line: \(SetupWinecxCommand.flag)")
+ refuseWhileMigrating()
SetupWinecxCommand.run()
}
BridgeplayApp.main()
}
+
+ // The installs write the new support folder, which the pending 3.0 move must find as
+ // it left it, so they wait for it like the app's own buttons do.
+ private static func refuseWhileMigrating() {
+ guard let refusal = MainActor.assumeIsolated({ MigrationLaunch.shared.refusal }) else { return }
+ AppLog.note("command line refused: the 3.0 folder move is pending")
+ FileHandle.standardError.write(Data("\(refusal)\n".utf8))
+ exit(AppLog.finished(1))
+ }
}
diff --git a/app/Sources/BridgeplayApp/Support/MigrationLaunch.swift b/app/Sources/BridgeplayApp/Support/MigrationLaunch.swift
index 6cf936f..3fe696e 100644
--- a/app/Sources/BridgeplayApp/Support/MigrationLaunch.swift
+++ b/app/Sources/BridgeplayApp/Support/MigrationLaunch.swift
@@ -2,11 +2,14 @@ import Foundation
import Observation
// Runs the 3.0.0 move from the notproton folders to the bridgeplay ones (BrandMigration).
-// It starts in Launch.main, before AppLog or anything else opens the support folder. If
-// Steam or a game is running it waits: the main window shows a banner, the patch keeper
-// and the post-update install stand still, and the move finishes by itself once both are
-// closed. Bridgeplay then installs itself into Steam again, because the copy Steam holds
-// still points at the old folders.
+// It starts in Launch.main, before AppLog or anything else opens the support folder. While
+// it is pending nothing that writes Bridgeplay's folders runs: installs, the Setup
+// Assistant, the patch keeper, the post-update install and the command line installs all
+// wait. If Steam or a game is running it waits: the main window shows a banner and the move
+// finishes by itself once both are closed. If the move fails, the Status page says why and
+// it keeps waiting until the user tries again or skips it for this launch. Once it is done
+// Bridgeplay installs itself into Steam again, because the copy Steam holds still points at
+// the old folders.
@MainActor
@Observable
final class MigrationLaunch {
@@ -14,8 +17,27 @@ final class MigrationLaunch {
private(set) var pending = false
private(set) var blocker: BrandMigration.Blocker?
+ // Why the last attempt failed; the move stays pending until a retry works or a skip.
+ private(set) var failure: String?
+ // What the move left in the old folders because the new ones already had it.
+ private(set) var keptNotes: [String] = []
+ private(set) var isRunning = false
@ObservationIgnored private var launchNote: String?
+ @ObservationIgnored private let enabled: Bool
+ @ObservationIgnored private let migration: @Sendable () -> BrandMigration
+ @ObservationIgnored private let pollInterval: Duration
+
+ init(
+ enabled: Bool = MigrationLaunch.enabled,
+ migration: @escaping @Sendable () -> BrandMigration = { BrandMigration.live() },
+ pollInterval: Duration = .seconds(4)
+ ) {
+ self.enabled = enabled
+ self.migration = migration
+ self.pollInterval = pollInterval
+ }
+
// Debug builds run from the source tree and never move the real folders.
nonisolated static var enabled: Bool {
#if DEBUG
@@ -26,16 +48,16 @@ final class MigrationLaunch {
}
func runAtLaunch() {
- guard Self.enabled else { return }
- let migration = BrandMigration.live()
+ guard enabled else { return }
+ let migration = migration()
guard migration.isNeeded else { return }
+ pending = true
if let blocker = migration.canRun() {
- pending = true
self.blocker = blocker
launchNote = "migration 3.0.0 waits: \(blocker)"
return
}
- launchNote = Self.run(migration)
+ launchNote = settle(Result { try migration.run() })
}
// AppLog only exists once the app has started, so the launch result is logged then.
@@ -44,26 +66,104 @@ final class MigrationLaunch {
launchNote = nil
}
- func finishWhenPossible(_ status: SystemStatus) async {
- guard pending else { return }
- while !Task.isCancelled {
- try? await Task.sleep(for: .seconds(4))
- let migration = BrandMigration.live()
- guard migration.isNeeded else { pending = false; return }
+ // Waits for Steam and games to close, then moves; finished runs after a move that worked.
+ // Returns without waiting when the last attempt failed: only retry() tries again.
+ func finishWhenPossible(then finished: @MainActor () async -> Void) async {
+ while pending, failure == nil, !Task.isCancelled {
+ try? await Task.sleep(for: pollInterval)
+ guard pending, failure == nil, !isRunning else { continue }
+ let migration = migration()
+ guard migration.isNeeded else {
+ pending = false
+ blocker = nil
+ return
+ }
blocker = migration.canRun()
guard blocker == nil else { continue }
- AppLog.note(Self.run(migration))
+ if await attempt(migration) {
+ await finished()
+ return
+ }
+ }
+ }
+
+ func finishWhenPossible(_ status: SystemStatus) async {
+ await finishWhenPossible { await Self.afterMove(status) }
+ }
+
+ func retry(then finished: @MainActor () async -> Void) async {
+ guard pending, !isRunning else { return }
+ failure = nil
+ AppLog.note("migration 3.0.0: trying again")
+ let migration = migration()
+ guard migration.isNeeded else {
pending = false
- await status.refresh()
- await status.installIntoSteam()
+ blocker = nil
return
}
+ blocker = migration.canRun()
+ if blocker == nil, await attempt(migration) {
+ await finished()
+ } else if pending, failure == nil {
+ // Steam or a game is open: wait for it like the launch does.
+ await finishWhenPossible(then: finished)
+ }
}
- private static func run(_ migration: BrandMigration) -> String {
- do {
- return "migration 3.0.0: \(try migration.run().description)"
- } catch {
+ func retry(_ status: SystemStatus) async {
+ await retry { await Self.afterMove(status) }
+ }
+
+ // Lets installs run again until the next launch, which tries the move once more. Only
+ // offered after a failure: a move waiting on Steam finishes by itself.
+ func skip() {
+ guard pending, failure != nil, !isRunning else { return }
+ AppLog.note("migration 3.0.0 skipped for this launch after: \(failure ?? "")")
+ pending = false
+ failure = nil
+ blocker = nil
+ }
+
+ // Why an install cannot run yet, or nil when it can.
+ var refusal: String? {
+ guard pending else { return nil }
+ if let failure {
+ return String(localized: "Bridgeplay could not move its files to the new Bridgeplay folders: \(failure) Try again or skip it on the Status page first.")
+ }
+ return String(localized: "Bridgeplay is still moving its files to the new Bridgeplay folders.") + " " + bannerMessage
+ }
+
+ private static func afterMove(_ status: SystemStatus) async {
+ await status.refresh()
+ await status.installIntoSteam(unattended: true)
+ }
+
+ private func attempt(_ migration: BrandMigration) async -> Bool {
+ isRunning = true
+ defer { isRunning = false }
+ let result = await Task.detached(priority: .userInitiated) { Result { try migration.run() } }.value
+ AppLog.note(settle(result))
+ return !pending
+ }
+
+ // Records a run's result and returns the line to log.
+ private func settle(_ result: Result<BrandMigration.Summary, Error>) -> String {
+ switch result {
+ case .success(let summary):
+ pending = false
+ blocker = nil
+ failure = nil
+ keptNotes = summary.notes
+ return "migration 3.0.0: \(summary.description)"
+ case .failure(let refusal as BrandMigration.Failure):
+ // Steam or a game started between the check and the run; wait again.
+ switch refusal {
+ case .blocked(let blocker):
+ self.blocker = blocker
+ return "migration 3.0.0 waits: \(blocker)"
+ }
+ case .failure(let error):
+ failure = error.localizedDescription
return "migration 3.0.0 failed: \(error)"
}
}
diff --git a/app/Sources/BridgeplayApp/SystemStatus.swift b/app/Sources/BridgeplayApp/SystemStatus.swift
index 949541e..ab4a927 100644
--- a/app/Sources/BridgeplayApp/SystemStatus.swift
+++ b/app/Sources/BridgeplayApp/SystemStatus.swift
@@ -123,7 +123,11 @@ final class SystemStatus {
var isBusy: Bool { activity != nil || runInFlight || checkingLicense }
var isIdle: Bool { !isBusy && !isRefreshing }
- var canInstall: Bool { isIdle && snapshot?.installContent.blocksInstallation != true }
+ // A pending 3.0 folder move blocks every install: anything written now would land in
+ // the new folders before the old ones are moved in.
+ var canInstall: Bool {
+ isIdle && snapshot?.installContent.blocksInstallation != true && !MigrationLaunch.shared.pending
+ }
enum Confirmation: Identifiable, Hashable {
case replaceSteam
@@ -462,6 +466,10 @@ final class SystemStatus {
}
private func setUpRunner(from install: CrossOverInstall?, replacingExisting: Bool = false) async {
+ if let refusal = MigrationLaunch.shared.refusal {
+ setFailure(refusal)
+ return
+ }
guard let install else {
setFailure(String(localized: "No supported Wine engine found. Download the free WineHQ or WineCX engine first."))
AppLog.note("run refused: no supported CrossOver")
@@ -601,6 +609,11 @@ final class SystemStatus {
// unattended: nobody pressed anything, so a Steam that opened since the decision to
// install is left running and the install stops instead.
func installIntoSteam(unattended: Bool = false) async {
+ if let refusal = MigrationLaunch.shared.refusal {
+ setFailure(refusal)
+ AppLog.note("run refused: install waits for the 3.0 folder move")
+ return
+ }
var failedInputResets: [String]?
await perform(from: InstallPhase.checkingPayload.label) { progress in
let lock = try DeploymentContent.acquireInstallationLock()
diff --git a/app/Sources/BridgeplayApp/Views/RootView.swift b/app/Sources/BridgeplayApp/Views/RootView.swift
index 227c3bb..b06d0e7 100644
--- a/app/Sources/BridgeplayApp/Views/RootView.swift
+++ b/app/Sources/BridgeplayApp/Views/RootView.swift
@@ -76,7 +76,8 @@ struct RootView: View {
}
}
.safeAreaInset(edge: .top, spacing: 0) {
- if MigrationLaunch.shared.pending {
+ // A failed move is reported on the Status page, with its buttons, instead.
+ if MigrationLaunch.shared.pending, MigrationLaunch.shared.failure == nil {
MigrationBanner()
} else if let banner = status.patchBanner {
PatchBanner(banner: banner)
diff --git a/app/Sources/BridgeplayApp/Views/StatusView.swift b/app/Sources/BridgeplayApp/Views/StatusView.swift
index f362d2e..f13b599 100644
--- a/app/Sources/BridgeplayApp/Views/StatusView.swift
+++ b/app/Sources/BridgeplayApp/Views/StatusView.swift
@@ -288,6 +288,8 @@ struct StatusView: View {
private func form(_ snapshot: StatusSnapshot) -> some View {
Form {
+ migrationRows
+
if let failure = status.failure {
StatusRow(
title: String(localized: "Failed"),
@@ -370,6 +372,38 @@ struct StatusView: View {
.safeAreaInset(edge: .top, spacing: 0) { StatusHero(snapshot: snapshot) }
}
+ // The 3.0 folder move: a failure blocks installing until it is tried again or skipped,
+ // and files it could not move are named so they are not lost track of.
+ @ViewBuilder
+ private var migrationRows: some View {
+ let migration = MigrationLaunch.shared
+ if let failure = migration.failure {
+ StatusRow(
+ title: String(localized: "Moving to the Bridgeplay folders failed"),
+ value: failure,
+ tone: .bad,
+ detail: String(localized: "Installing and setting up wait until the move is done. Skipping leaves your files in the old notproton folders and tries again at the next launch."),
+ secondaryAction: StatusAction(
+ label: String(localized: "Skip"),
+ isEnabled: !migration.isRunning
+ ) { migration.skip() },
+ action: StatusAction(
+ label: String(localized: "Try Again"),
+ isProminent: true,
+ isEnabled: !migration.isRunning
+ ) { Task { await migration.retry(status) } }
+ )
+ }
+ if !migration.keptNotes.isEmpty {
+ StatusRow(
+ title: String(localized: "Some files stayed in the old folders"),
+ value: String(localized: "The new Bridgeplay folders already had files with these names, so nothing was overwritten."),
+ tone: .warning,
+ detail: migration.keptNotes.joined(separator: "\n")
+ )
+ }
+ }
+
// A reset macOS refused leaves Steam's old approval in place, and macOS then blocks the
// controller without asking. Only the user can clear it in System Settings.
@ViewBuilder
diff --git a/app/Tests/BridgeplayAppTests/MigrationLaunchTests.swift b/app/Tests/BridgeplayAppTests/MigrationLaunchTests.swift
new file mode 100644
index 0000000..a4fb589
--- /dev/null
+++ b/app/Tests/BridgeplayAppTests/MigrationLaunchTests.swift
@@ -0,0 +1,226 @@
+import Foundation
+import Testing
+
+@testable import BridgeplayApp
+
+// The gate in front of installs while the 3.0 folder move is pending. Every root is a
+// temporary directory and Steam and games are stand-ins, as in the BrandMigration tests.
+@Suite("Migration launch")
+@MainActor
+struct MigrationLaunchTests {
+
+ private final class Switches: @unchecked Sendable {
+ private let lock = NSLock()
+ private var steam = false
+ private var game = false
+ var steamRunning: Bool {
+ get { lock.withLock { steam } }
+ set { lock.withLock { steam = newValue } }
+ }
+ var gameRunning: Bool {
+ get { lock.withLock { game } }
+ set { lock.withLock { game = newValue } }
+ }
+ }
+
+ private final class Count: @unchecked Sendable {
+ private(set) var value = 0
+ func add() { value += 1 }
+ }
+
+ private struct Fixture {
+ let root: URL
+ let migration: BrandMigration
+ let switches: Switches
+ // A file where the new support folder's parent should be, so the move fails.
+ var obstacle: URL { migration.support.deletingLastPathComponent() }
+
+ @MainActor func launcher() -> MigrationLaunch {
+ let migration = migration
+ return MigrationLaunch(enabled: true, migration: { migration }, pollInterval: .milliseconds(10))
+ }
+ }
+
+ private func fixture(obstructed: Bool = false) throws -> Fixture {
+ let root = try scratchDirectory("migration-launch")
+ let switches = Switches()
+ let migration = BrandMigration(
+ legacySupport: root.appending(path: "old/notproton"),
+ support: root.appending(path: "new/bridgeplay"),
+ legacyCaches: root.appending(path: "caches/notproton"),
+ caches: root.appending(path: "caches/bridgeplay"),
+ legacyHome: root.appending(path: "home/.notproton"),
+ home: root.appending(path: "home/.bridgeplay"),
+ steamUserData: root.appending(path: "Steam"),
+ steamRunning: { switches.steamRunning }, gameRunning: { switches.gameRunning })
+ let files = FileManager.default
+ try files.createDirectory(at: migration.legacySupport, withIntermediateDirectories: true)
+ try Data("1.0\n".utf8).write(to: migration.legacySupport.appending(path: "dylib.version"))
+ try files.createDirectory(at: migration.steamUserData, withIntermediateDirectories: true)
+ let fixture = Fixture(root: root, migration: migration, switches: switches)
+ if obstructed { try Data().write(to: fixture.obstacle) }
+ return fixture
+ }
+
+ @Test("Nothing to move leaves installs free")
+ func nothingToMove() throws {
+ let f = try fixture()
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ try FileManager.default.removeItem(at: f.migration.legacySupport)
+
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(!launch.pending)
+ #expect(launch.refusal == nil)
+ }
+
+ @Test("A debug build never moves anything")
+ func disabledDoesNothing() throws {
+ let f = try fixture()
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ let migration = f.migration
+ let launch = MigrationLaunch(enabled: false, migration: { migration })
+
+ launch.runAtLaunch()
+ #expect(!launch.pending)
+ #expect(FileManager.default.fileExists(atPath: f.migration.legacySupport.path))
+ }
+
+ @Test("A move that works at launch leaves installs free")
+ func movesAtLaunch() throws {
+ let f = try fixture()
+ defer { try? FileManager.default.removeItem(at: f.root) }
+
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(!launch.pending)
+ #expect(launch.failure == nil)
+ #expect(FileManager.default.fileExists(atPath: f.migration.support.appending(path: "dylib.version").path))
+ }
+
+ @Test("While Steam runs, installs wait and the move finishes once it quits")
+ func waitsForSteam() async throws {
+ let f = try fixture()
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ f.switches.steamRunning = true
+
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(launch.pending)
+ #expect(launch.blocker == .steamRunning)
+ #expect(launch.refusal != nil)
+
+ f.switches.steamRunning = false
+ let finished = Count()
+ await launch.finishWhenPossible { finished.add() }
+ #expect(!launch.pending)
+ #expect(finished.value == 1)
+ #expect(FileManager.default.fileExists(atPath: f.migration.support.appending(path: "dylib.version").path))
+ }
+
+ // Before, a failure was only logged: the move counted as done and the install ran.
+ @Test("A failed move keeps blocking installs and reports why")
+ func failureKeepsBlocking() async throws {
+ let f = try fixture(obstructed: true)
+ defer { try? FileManager.default.removeItem(at: f.root) }
+
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(launch.pending)
+ #expect(launch.failure != nil)
+ #expect(launch.refusal?.contains(launch.failure ?? "-") == true)
+
+ // The waiting loop does not paper over it, and nothing is installed.
+ let finished = Count()
+ await launch.finishWhenPossible { finished.add() }
+ #expect(launch.pending)
+ #expect(finished.value == 0)
+ #expect(FileManager.default.fileExists(atPath: f.migration.legacySupport.path))
+ }
+
+ @Test("Trying again after the cause is fixed finishes the move and the install")
+ func retryFinishes() async throws {
+ let f = try fixture(obstructed: true)
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(launch.failure != nil)
+
+ // Still in the way: the retry fails the same and keeps blocking.
+ let finished = Count()
+ await launch.retry { finished.add() }
+ #expect(launch.pending)
+ #expect(launch.failure != nil)
+ #expect(finished.value == 0)
+
+ try FileManager.default.removeItem(at: f.obstacle)
+ await launch.retry { finished.add() }
+ #expect(!launch.pending)
+ #expect(launch.failure == nil)
+ #expect(launch.refusal == nil)
+ #expect(finished.value == 1)
+ #expect(FileManager.default.fileExists(atPath: f.migration.support.appending(path: "dylib.version").path))
+ }
+
+ @Test("A retry while a game runs waits for it rather than failing")
+ func retryWaitsForAGame() async throws {
+ let f = try fixture(obstructed: true)
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ try FileManager.default.removeItem(at: f.obstacle)
+
+ f.switches.gameRunning = true
+ let finished = Count()
+ let switches = f.switches
+ Task {
+ try? await Task.sleep(for: .milliseconds(50))
+ switches.gameRunning = false
+ }
+ await launch.retry { finished.add() }
+ #expect(!launch.pending)
+ #expect(finished.value == 1)
+ }
+
+ @Test("Skipping a failed move frees installs for this launch and leaves the old files")
+ func skipFreesInstalls() throws {
+ let f = try fixture(obstructed: true)
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(launch.refusal != nil)
+
+ launch.skip()
+ #expect(!launch.pending)
+ #expect(launch.refusal == nil)
+ #expect(FileManager.default.fileExists(atPath: f.migration.legacySupport.path))
+ // The next launch tries again.
+ #expect(f.migration.isNeeded)
+ }
+
+ @Test("A move waiting on Steam cannot be skipped")
+ func waitingCannotBeSkipped() throws {
+ let f = try fixture()
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ f.switches.steamRunning = true
+ let launch = f.launcher()
+ launch.runAtLaunch()
+
+ launch.skip()
+ #expect(launch.pending)
+ }
+
+ @Test("Files the new folders already had are reported, not overwritten")
+ func keptFilesAreReported() throws {
+ let f = try fixture()
+ defer { try? FileManager.default.removeItem(at: f.root) }
+ try FileManager.default.createDirectory(at: f.migration.support, withIntermediateDirectories: true)
+ try Data("2.0\n".utf8).write(to: f.migration.support.appending(path: "dylib.version"))
+
+ let launch = f.launcher()
+ launch.runAtLaunch()
+ #expect(!launch.pending)
+ #expect(launch.keptNotes.contains { $0.contains("dylib.version") })
+ #expect(try String(contentsOf: f.migration.support.appending(path: "dylib.version"), encoding: .utf8) == "2.0\n")
+ }
+}