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
Epic Mac: a switch goes on only once legendary has let go of the old record, and never deletes the folder it still records
Gabeedacf7d15100
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex b690e8b..30674d6 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -3750,6 +3750,12 @@ final class AppState {_ = try? await Task.detached { try store.restoreSavedRecord(app) }.valuethrow HighballError.processFailed(command: "legendary uninstall --keep-files", status: status, output: "see the log above")}+ // legendary exits 0 without touching its records when another legendary holds+ // its lock: the switch goes on only once the record is really gone.+ guard await Task.detached(operation: { store.recordsGame(app) }).value == false else {+ _ = try? await Task.detached { try store.restoreSavedRecord(app) }.value+ throw HighballError.failed(String(format: L("The Epic tools didn't let go of %@'s installed version (another of their tasks may be running), so nothing was changed. Try again in a moment."), item.title))+ }} },install: download,restoreOldRecord: { [self] in@@ -3760,6 +3766,10 @@ final class AppState {: "\(item.title): legendary records the game already, so its record was left as it is")} catch {appendLog("\(item.title): could not put the \(oldPlatform) version's record back yet (\(error.localizedDescription)); its files are still in \(oldPath), and Highball finishes this when it next opens")+ epicRefresh()+ // The alert says this, not only the download's error: the game is missing+ // from Epic's list until the next launch puts it back.+ throw HighballError.failed(String(format: L("The switch didn't finish, and the %@ version couldn't be put back yet, so %@ is missing from Epic's list until Highball next opens. Its files are still in %@."), oldPlatform, item.title, oldPath))}epicRefresh()},@@ -3833,6 +3843,10 @@ final class AppState {return "\(name): left the \(build) in \(path), outside Highball's game folders"case .noFileList(let why):return "\(name): left the \(build) in \(path): legendary could not list them (\(why)), so nothing there was deleted"+ case .stillRecorded:+ return "\(name): left the \(build) in \(path): legendary still records the game there, so it is the installed build"+ case .recordsUnreadable:+ return "\(name): left the \(build) in \(path): legendary's install records could not be read; Highball looks again when it next opens"}}diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex e1a35ef..1ee8a5b 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -537,7 +537,7 @@ private extension View {Button(L("Switch to the Mac version")) { state.pendingEpicMacSwitch = nil; state.epicInstallMac(item, replacingWindows: true) }Button(L("Cancel"), role: .cancel) { state.pendingEpicMacSwitch = nil }} message: { _ in- Text(L("Epic keeps one version of a game installed at a time, so the Mac version downloads and the Windows version is removed once it is in. Stop the download, or should it fail, and the Windows version stays. Your Highball settings for the game stay."))+ Text(L("Epic keeps one version of a game installed at a time, so the Mac version downloads and the Windows version is removed once it is in. Stop the download, or should it fail, and the Windows version stays. Only the files Epic installed for the old version are removed: saves and settings the game keeps in its folder stay, and so do your Highball settings for the game."))}.alert(state.pendingEpicWindowsSwitch.map { String(format: L("Switch %@ to the Windows version?"), $0.title) } ?? "",isPresented: .init(get: { state.pendingEpicWindowsSwitch != nil }, set: { if !$0 { state.pendingEpicWindowsSwitch = nil } }),@@ -545,7 +545,7 @@ private extension View {Button(L("Switch to the Windows version")) { state.pendingEpicWindowsSwitch = nil; state.epicSwitchToWindows(item) }Button(L("Cancel"), role: .cancel) { state.pendingEpicWindowsSwitch = nil }} message: { _ in- Text(L("Epic keeps one version of a game installed at a time, so the Windows version downloads into your environment and the Mac version is removed once it is in. Stop the download, or should it fail, and the Mac version stays."))+ Text(L("Epic keeps one version of a game installed at a time, so the Windows version downloads into your environment and the Mac version is removed once it is in. Stop the download, or should it fail, and the Mac version stays. Only the files Epic installed for the old version are removed: saves and settings the game keeps in its folder stay."))}.alert(state.pendingEpicMacUninstall.map { String(format: L("Remove the Mac version of %@?"), $0.title) } ?? "",isPresented: .init(get: { state.pendingEpicMacUninstall != nil }, set: { if !$0 { state.pendingEpicMacUninstall = nil } }),diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex 9339de0..58c3a81 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -442,8 +442,12 @@ enum L10n {"Switch to the Windows version…": "Passer à la version Windows…","Switch to the Windows version": "Passer à la version Windows","Switch %@ to the Windows version?": "Passer %@ à la version Windows ?",- "Epic keeps one version of a game installed at a time, so the Windows version downloads into your environment and the Mac version is removed once it is in. Stop the download, or should it fail, and the Mac version stays.":- "Epic n’installe qu’une version d’un jeu à la fois : la version Windows est téléchargée dans votre environnement, puis la version Mac est supprimée une fois la nouvelle en place. Si vous arrêtez le téléchargement, ou s’il échoue, la version Mac reste.",+ "The Epic tools didn't let go of %@'s installed version (another of their tasks may be running), so nothing was changed. Try again in a moment.":+ "Les outils d’Epic n’ont pas libéré la version installée de %@ (une autre de leurs tâches est peut-être en cours), donc rien n’a été modifié. Réessayez dans un instant.",+ "The switch didn't finish, and the %@ version couldn't be put back yet, so %@ is missing from Epic's list until Highball next opens. Its files are still in %@.":+ "Le changement n’a pas abouti et la version %@ n’a pas encore pu être remise en place : %@ n’apparaît plus dans la liste d’Epic jusqu’à la prochaine ouverture de Highball. Ses fichiers sont toujours dans %@.",+ "Epic keeps one version of a game installed at a time, so the Windows version downloads into your environment and the Mac version is removed once it is in. Stop the download, or should it fail, and the Mac version stays. Only the files Epic installed for the old version are removed: saves and settings the game keeps in its folder stay.":+ "Epic n’installe qu’une version d’un jeu à la fois : la version Windows est téléchargée dans votre environnement, puis la version Mac est supprimée une fois la nouvelle en place. Si vous arrêtez le téléchargement, ou s’il échoue, la version Mac reste. Seuls les fichiers installés par Epic pour l’ancienne version sont supprimés : les sauvegardes et réglages que le jeu garde dans son dossier restent.","Highball could not find the Mac version of %@ to open.": "Highball ne trouve pas la version Mac de %@ à ouvrir.","The Mac version of %@ did not start: %@": "La version Mac de %@ n’a pas démarré : %@","Removing the Windows version of %@": "Suppression de la version Windows de %@",@@ -451,8 +455,8 @@ enum L10n {"Switch %@ to the Mac version?": "Passer %@ à la version Mac ?","Switch to the Mac version": "Passer à la version Mac","Switch to the Mac version…": "Passer à la version Mac…",- "Epic keeps one version of a game installed at a time, so the Mac version downloads and the Windows version is removed once it is in. Stop the download, or should it fail, and the Windows version stays. Your Highball settings for the game stay.":- "Epic n’installe qu’une version d’un jeu à la fois : la version Mac est téléchargée, puis la version Windows est supprimée une fois la nouvelle en place. Si vous arrêtez le téléchargement, ou s’il échoue, la version Windows reste. Vos réglages Highball pour ce jeu sont conservés.",+ "Epic keeps one version of a game installed at a time, so the Mac version downloads and the Windows version is removed once it is in. Stop the download, or should it fail, and the Windows version stays. Only the files Epic installed for the old version are removed: saves and settings the game keeps in its folder stay, and so do your Highball settings for the game.":+ "Epic n’installe qu’une version d’un jeu à la fois : la version Mac est téléchargée, puis la version Windows est supprimée une fois la nouvelle en place. Si vous arrêtez le téléchargement, ou s’il échoue, la version Windows reste. Seuls les fichiers installés par Epic pour l’ancienne version sont supprimés : les sauvegardes et réglages que le jeu garde dans son dossier restent, tout comme vos réglages Highball pour ce jeu.","Asking Epic about the Mac version": "Demande des informations sur la version Mac à Epic","Highball could not ask Epic whether a Mac build of this game is there to download, so nothing was changed. Check your connection, then try again.":"Highball n’a pas pu demander à Epic si une version Mac de ce jeu est disponible au téléchargement, donc rien n’a été modifié. Vérifiez votre connexion, puis réessayez.",diff --git a/Sources/HighballKit/EpicBuildSwitch.swift b/Sources/HighballKit/EpicBuildSwitch.swiftindex 1c7a584..55f6d38 100644--- a/Sources/HighballKit/EpicBuildSwitch.swift+++ b/Sources/HighballKit/EpicBuildSwitch.swift@@ -238,6 +238,18 @@ extension EpicStore {case outsideGameFolders/// legendary could not list the old build's files: nothing was deleted.case noFileList(String)+ /// legendary still records the game in that folder (its uninstall didn't drop the record,+ /// another legendary holding its lock): it is the installed build, and nothing was deleted.+ case stillRecorded+ /// legendary's installed.json could not be read, so nothing says the folder is free:+ /// nothing was deleted, and the kept record stays for the next launch.+ case recordsUnreadable+ }++ /// Whether legendary records the game; nil when its installed.json can't be read. Read+ /// locally, no legendary run.+ public func recordsGame(_ appName: String) -> Bool? {+ do { return try Self.readInstalledIfThere(configDir)?[appName] != nil } catch { return nil }}/// Deletes an old build's files once a switch is done, the way legendary's own uninstall does@@ -248,6 +260,12 @@ extension EpicStore {/// (EpicBuildSwitch.isSafeToDelete) or when the list cannot be had. The kept record goes/// afterwards either way.public func deleteOldBuild(_ appName: String, at oldPath: String, roots: [URL]) -> OldBuildDeletion {+ // The folder legendary records as the game is the installed build, never an old one.+ let installed: [String: Any]+ do { installed = try Self.readInstalledIfThere(configDir) ?? [:] } catch { return .recordsUnreadable }+ if let now = (installed[appName] as? [String: Any])?["install_path"] as? String, Self.samePath(now, oldPath) {+ return .stillRecorded+ }defer { discardSavedRecord(appName) }let folder = URL(fileURLWithPath: oldPath, isDirectory: true)guard EpicBuildSwitch.isSafeToDelete(folder, roots: roots) else { return .outsideGameFolders }diff --git a/Tests/HighballKitTests/EpicBuildSwitchTests.swift b/Tests/HighballKitTests/EpicBuildSwitchTests.swiftindex 222ae29..1c4dc5f 100644--- a/Tests/HighballKitTests/EpicBuildSwitchTests.swift+++ b/Tests/HighballKitTests/EpicBuildSwitchTests.swift@@ -250,11 +250,43 @@ final class EpicBuildSwitchTests: XCTestCase {/// highball#609: an old build's folder went whole, saves and mods with it. Now only what its/// manifests list goes, then the folders that leaves empty, as legendary's uninstall does.- func testOnlyTheOldBuildsListedFilesAreDeleted() throws {+ /// A finished switch as deleteOldBuild meets it: the old build's record kept aside, and+ /// legendary recording the new build in another folder.+ private func switched(_ store: EpicStore, _ config: URL) throws {+ let file = config.appending(path: "installed.json")+ var games = try installed(config)+ if games["Garlic"]?["platform"] as? String == "Mac" { games = oldGames ?? games } // back to the old record first+ oldGames = games+ try JSONSerialization.data(withJSONObject: games).write(to: file)+ try store.saveRecord("Garlic")+ games["Garlic"] = ["app_name": "Garlic", "install_path": "/U/Applications/Highball Games/Garlic", "platform": "Mac", "version": "1.0-m"]+ games["GarlicDLC"] = nil+ try JSONSerialization.data(withJSONObject: games).write(to: file)+ }+ private var oldGames: [String: [String: Any]]?++ /// legendary still recording the game in the old folder (its uninstall didn't drop the record,+ /// another legendary holding its lock), or records that can't be read: nothing is deleted.+ func testTheFolderLegendaryStillRecordsIsNeverDeleted() throws {let (store, config) = try legendaryHome()try fakeLegendary(store)let (root, folder) = try oldBuild(store, config)try store.saveRecord("Garlic")+ XCTAssertEqual(store.recordsGame("Garlic"), true)+ XCTAssertEqual(store.deleteOldBuild("Garlic", at: folder.path, roots: [root]), .stillRecorded)+ XCTAssertTrue(FileManager.default.fileExists(atPath: folder.appending(path: "GAME.EXE").path))+ try Data("{not json".utf8).write(to: config.appending(path: "installed.json"))+ XCTAssertNil(store.recordsGame("Garlic"))+ XCTAssertEqual(store.deleteOldBuild("Garlic", at: folder.path, roots: [root]), .recordsUnreadable)+ XCTAssertTrue(FileManager.default.fileExists(atPath: folder.appending(path: "GAME.EXE").path))+ XCTAssertEqual(store.switchesInFlight(), ["Garlic"], "the kept record stays for the next launch")+ }++ func testOnlyTheOldBuildsListedFilesAreDeleted() throws {+ let (store, config) = try legendaryHome()+ try fakeLegendary(store)+ let (root, folder) = try oldBuild(store, config)+ try switched(store, config)XCTAssertEqual(store.deleteOldBuild("Garlic", at: folder.path, roots: [root]), .deleted(files: 4, failed: 0))let fm = FileManager.defaultfor gone in ["GAME.EXE", "Data/Pak0.pak", "Data/Movies", "DLC"] {@@ -274,7 +306,7 @@ final class EpicBuildSwitchTests: XCTestCase {let fm = FileManager.defaulttry fm.removeItem(at: folder.appending(path: "Saved"))try fm.removeItem(at: folder.appending(path: "Data/mods"))- try store.saveRecord("Garlic")+ try switched(store, config)XCTAssertEqual(store.deleteOldBuild("Garlic", at: folder.path, roots: [root]), .deleted(files: 4, failed: 0))XCTAssertFalse(fm.fileExists(atPath: folder.path))XCTAssertTrue(fm.fileExists(atPath: root.path))@@ -286,18 +318,18 @@ final class EpicBuildSwitchTests: XCTestCase {let (store, config) = try legendaryHome()try fakeLegendary(store, fails: true)let (root, folder) = try oldBuild(store, config)- try store.saveRecord("Garlic")+ try switched(store, config)guard case .noFileList = store.deleteOldBuild("Garlic", at: folder.path, roots: [root]) else { return XCTFail("listed") }XCTAssertTrue(FileManager.default.fileExists(atPath: folder.appending(path: "GAME.EXE").path))XCTAssertEqual(store.switchesInFlight(), [])try fakeLegendary(store)- try store.saveRecord("Garlic")+ try switched(store, config)try FileManager.default.removeItem(at: store.paths.home.appending(path: "epic-switch/Garlic/manifests/Garlic_Windows_1.0-w.manifest"))guard case .noFileList = store.deleteOldBuild("Garlic", at: folder.path, roots: [root]) else { return XCTFail("listed") }XCTAssertTrue(FileManager.default.fileExists(atPath: folder.appending(path: "GAME.EXE").path))- try store.saveRecord("Garlic")+ try switched(store, config)XCTAssertEqual(store.deleteOldBuild("Garlic", at: folder.path, roots: [folder]), .outsideGameFolders)XCTAssertTrue(FileManager.default.fileExists(atPath: folder.appending(path: "GAME.EXE").path))}