Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

Epic Mac: a switch that finished as Highball quit has its old files deleted at launch

Gabe051c11a30dcf
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 900696d..5bb26ac 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -3729,7 +3729,7 @@ final class AppState {
-> @MainActor (_ download: @escaping @MainActor () async throws -> Void) async throws -> Void {
let store = epicStore
let log: @Sendable (String) -> Void = { line in Task { @MainActor in self.appendLog(line) } }
- let roots = bottles.map { $0.driveC.appending(path: "Games", directoryHint: .isDirectory) } + [GOGStore.macGamesDir]
+ let roots = epicInstallRoots
let removing = oldPlatform == "Mac" ? String(format: L("Removing the Mac version of %@"), item.title)
: String(format: L("Removing the Windows version of %@"), item.title)
return { [self] download in
@@ -3778,6 +3778,12 @@ final class AppState {
@ObservationIgnored private var epicSwitchesFinished = false
+ /// The folders Highball installs Epic builds into: an old build's files are deleted only from
+ /// inside one of them (EpicBuildSwitch.isSafeToDelete).
+ private var epicInstallRoots: [URL] {
+ bottles.map { $0.driveC.appending(path: "Games", directoryHint: .isDirectory) } + [GOGStore.macGamesDir]
+ }
+
/// Completes the undo of a build switch Highball quit in the middle of (EpicStore.switchesInFlight):
/// the old build's record goes back from where the switch kept it. Once, at launch.
private func finishEpicSwitches() {
@@ -3785,8 +3791,18 @@ final class AppState {
epicSwitchesFinished = true
let store = epicStore
for app in store.switchesInFlight() {
+ let oldPath = store.savedInstallPath(app)
do {
- if try store.restoreSavedRecord(app) { appendLog("\(app): a switch between Epic builds did not finish, so the old build is back as it was") }
+ if try store.restoreSavedRecord(app) {
+ appendLog("\(app): a switch between Epic builds did not finish, so the old build is back as it was")
+ } else if let oldPath, !((try? store.installedGames()) ?? []).contains(where: { $0.install_path == oldPath }),
+ EpicBuildSwitch.isSafeToDelete(URL(fileURLWithPath: oldPath, isDirectory: true), roots: epicInstallRoots),
+ FileManager.default.fileExists(atPath: oldPath) {
+ // The new build was in when Highball quit, before the old files went: they go now,
+ // off the main thread (a game is tens of thousands of files).
+ appendLog("\(app): a switch between Epic builds finished as Highball quit; deleting the old build's files in \(oldPath)")
+ Task.detached { try? FileManager.default.removeItem(atPath: oldPath) }
+ }
} catch {
appendLog("\(app): a switch between Epic builds did not finish, and its old record could not go back yet (\(error.localizedDescription)); Highball tries again when it next opens")
}
diff --git a/Sources/HighballKit/EpicBuildSwitch.swift b/Sources/HighballKit/EpicBuildSwitch.swift
index bc990da..3c3f451 100644
--- a/Sources/HighballKit/EpicBuildSwitch.swift
+++ b/Sources/HighballKit/EpicBuildSwitch.swift
@@ -125,6 +125,13 @@ extension EpicStore {
return restored
}
+ /// Where the old build of a switch still in flight was installed, from its kept record.
+ public func savedInstallPath(_ appName: String) -> String? {
+ guard let data = try? Data(contentsOf: savedRecordFolder(appName).appending(path: "record.json")),
+ let entries = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return nil }
+ return (entries[appName] as? [String: Any])?["install_path"] as? String
+ }
+
/// Forgets a kept record once the new build is in.
public func discardSavedRecord(_ appName: String) {
try? FileManager.default.removeItem(at: savedRecordFolder(appName))
diff --git a/Tests/HighballKitTests/EpicBuildSwitchTests.swift b/Tests/HighballKitTests/EpicBuildSwitchTests.swift
index fd2f60b..9a02226 100644
--- a/Tests/HighballKitTests/EpicBuildSwitchTests.swift
+++ b/Tests/HighballKitTests/EpicBuildSwitchTests.swift
@@ -135,6 +135,9 @@ final class EpicBuildSwitchTests: XCTestCase {
func testARecordLegendaryHasIsLeftAsItIs() throws {
let (store, config) = try legendaryHome()
try store.saveRecord("Garlic")
+ let oldPath = try installed(config)["Garlic"]?["install_path"] as? String
+ XCTAssertNotNil(oldPath)
+ XCTAssertEqual(store.savedInstallPath("Garlic"), oldPath, "the old build's folder, for deleting it at launch")
var games = try installed(config)
games["Garlic"] = ["app_name": "Garlic", "install_path": "/U/Applications/Highball Games/Garlic", "platform": "Mac", "version": "1.0-m"]
games["GarlicDLC"] = nil