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
GOG Mac: the Windows copy's removal, the Trash and the save sync keep to the game's own files
Gabe0f1f8a101887
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 5bbb831..bb392aa 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -3732,6 +3732,25 @@ final class AppState {/// placement and so Play cannot start a second copy.var macGameProcesses: [String: Process] = [:]+ /// Whether a game runs now, either build: changing or removing a build then would pull its+ /// files from under it.+ func isRunningNow(_ item: LibraryItem) -> Bool {+ macGameProcesses[item.id] != nil || runningSessions.contains { $0.libraryID == item.id }+ }++ /// True when a change to the game's builds may go ahead; otherwise says why.+ private func refuseWhileRunning(_ item: LibraryItem) -> Bool {+ guard isRunningNow(item) else { return true }+ fail(HighballError.failed(String(format: L("Quit %@ first: it is running."), item.title)))+ return false+ }++ /// Play on Mac would do nothing: the game runs already, or a GOG or Epic Mac build would wait+ /// on the progress strip another task holds (its start runs there).+ func macPlayUnavailable(_ item: LibraryItem) -> Bool {+ isRunningNow(item) || ((item.source == .gog || item.source == .epic) && busy)+ }+/// Plays a GOG game's Mac build as the Windows one plays: saves down from GOG's cloud first/// (GOG's Mac locations, GOGSaves.macLocations), comet beside it for achievements and the/// unlock card, and saves back up once it quits. The app runs as itself, no Wine; Highball@@ -3857,7 +3876,7 @@ final class AppState {return (try? saves.macLocations(clientID: client)) ?? nil}.valuereturn (locations ?? []).compactMap { location in- guard let folder = GOGSaves.resolveMac(location.template, installFolder: game.folder) else {+ guard let folder = GOGSaves.resolveMac(location.template, installFolder: game.folder, gameID: game.id) else {appendLog("\(game.title): cloud saves at \(location.template) have no folder on this Mac, skipping that one")return nil}@@ -3869,17 +3888,17 @@ final class AppState {/// A GOG Mac build the player asked to move to the Trash: asked first, with what goes.var pendingGOGMacTrash: LibraryItem?- /// What the Trash takes for a GOG game's Mac build (GOGStore.macTrashTarget). Nil when there- /// is none, or when it would be a folder holding other apps.+ /// What the Trash takes for a GOG game's Mac build, as the scan worked it out+ /// (GOGStore.macTrashTarget). Nil when there is none, or when it would be a folder holding+ /// other apps or another game's.func gogMacTrashTarget(for item: LibraryItem) -> URL? {- guard let id = item.gogID, let game = gogMacInstalled[id] else { return nil }- return GOGStore.macTrashTarget(for: game)+ item.gogID.flatMap { gogMacInstalled[$0]?.trashTarget }}/// Moves a GOG game's Mac build to the Trash, where it can still be put back. Only once the- /// player said yes (pendingGOGMacTrash).+ /// player said yes (pendingGOGMacTrash), and never while it runs.func gogTrashMac(_ item: LibraryItem) {- guard let target = gogMacTrashTarget(for: item) else { return }+ guard refuseWhileRunning(item), let target = gogMacTrashTarget(for: item) else { return }NSWorkspace.shared.recycle([target]) { [weak self] _, error inTask { @MainActor inif let error { self?.appendLog("\(item.title): could not move the Mac version to the Trash: \(error.localizedDescription)") }@@ -4477,7 +4496,8 @@ final class AppState {stage = L("Deleting the game's files")try await Task.detached { try FileManager.default.removeItem(at: game.folder) }.value}- let elsewhere = gogInstalledByBottle.contains { $0.key != bottle.name && $0.value.contains { $0.id == id } }+ let elsewhere = GOGStore.otherInstallsRemain(id, removingFrom: bottle.name, installedByBottle: gogInstalledByBottle,+ macInstalls: Set(gogMacInstalled.keys))store.forget(id, otherInstallsRemain: elsewhere)GOGSaves(store: store).forget(game)try? FileManager.default.removeItem(at: GOGStore.setupMarker(for: game, driveC: bottle.driveC))diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swiftindex 111489d..cb6e910 100644--- a/Sources/HighballApp/GameDetailView.swift+++ b/Sources/HighballApp/GameDetailView.swift@@ -416,7 +416,7 @@ struct GameDetailView: View {}HStack(spacing: 10) {Button(L("Show in Finder")) { NSWorkspace.shared.activateFileViewerSelecting([game.app ?? game.folder]) }- Button(L("Move the Mac version to the Trash…")) { state.pendingGOGMacTrash = item }.disabled(state.busy)+ Button(L("Move the Mac version to the Trash…")) { state.pendingGOGMacTrash = item }.disabled(state.busy || state.isRunningNow(item))}.controlSize(.small).padding(.top, 2)} else if gog {@@ -603,6 +603,7 @@ struct GameDetailView: View {primaryActionLabel(L("Play on Mac"), symbol: "play.fill")}.buttonStyle(.borderedProminent).controlSize(.large).tint(HB.amber)+ .disabled(state.macPlayUnavailable(item))if item.installed {Button(L("Play the Windows version")) { commitTypedArguments(); state.play(item, windowsBuild: true) }.controlSize(.large).disabled(state.busy || blocked)@@ -619,6 +620,7 @@ struct GameDetailView: View {if item.installedOnMac {// The row put the Windows build first (a Mac build missing content); the Mac one stays a click away.Button(L("Play on Mac")) { commitTypedArguments(); state.playOnMac(item) }.controlSize(.large)+ .disabled(state.macPlayUnavailable(item))} else {Text(!blocked ? L("Highball will ask how it went when you finish."): entry?.status == "blocked-publisher" ? L("Its publisher stops it on macOS on purpose.")diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex bcefc94..7fb35f0 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -461,6 +461,7 @@ enum L10n {"%@ goes to the Trash, where you can still put it back.": "%@ va à la corbeille, d’où vous pouvez encore le récupérer.","Highball could not tell which folder is this game's alone, so it leaves the files where they are.":"Highball ne sait pas quel dossier appartient à ce seul jeu, donc il laisse les fichiers où ils sont.",+ "Quit %@ first: it is running.": "Quittez d’abord %@ : le jeu est en cours d’exécution.","Built for Apple silicon: runs natively.": "Conçue pour Apple silicon : tourne en natif.","Built for Intel Macs: runs through Rosetta.": "Conçue pour les Mac Intel : tourne via Rosetta.","A 32-bit build, which current macOS can't run. Play the Windows version instead.":diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swiftindex b392f08..305299f 100644--- a/Sources/HighballApp/LibraryView.swift+++ b/Sources/HighballApp/LibraryView.swift@@ -461,7 +461,7 @@ struct LibraryTile: View {// once the player has seen what goes.if item.source == .gog, item.installedOnMac {Button(L("Move the Mac version to the Trash…"), role: .destructive) { state.pendingGOGMacTrash = item }- .disabled(state.busy)+ .disabled(state.busy || state.isRunningNow(item))}}.accessibilityLabel("\(item.title), \(item.source.rawValue)\(item.installedOnMac ? ", " + (item.source == .steam ? L("Installed in Steam for Mac") : L("Mac version installed")) : item.installed ? "" : ", " + L("Not installed"))")diff --git a/Sources/HighballKit/GOGLibrary.swift b/Sources/HighballKit/GOGLibrary.swiftindex e527915..29c32fd 100644--- a/Sources/HighballKit/GOGLibrary.swift+++ b/Sources/HighballKit/GOGLibrary.swift@@ -416,6 +416,14 @@ extension GOGStore {/// returns "cancelled" on a fatal error), so a finished install is one whose manifest exists.public func downloadCompleted(_ id: String) -> Bool { FileManager.default.fileExists(atPath: manifest(id).path) }+ /// Whether another copy of a game still needs what gogdl kept about it once the copy in+ /// `bottleName` is removed: a copy in another environment, or the Mac build, which gogdl+ /// downloaded with the same support folder.+ public static func otherInstallsRemain(_ id: String, removingFrom bottleName: String,+ installedByBottle: [String: [InstalledGame]], macInstalls: Set<String>) -> Bool {+ macInstalls.contains(id) || installedByBottle.contains { $0.key != bottleName && $0.value.contains { $0.id == id } }+ }+/// Forgets what gogdl kept about a game once no environment holds it any more, so it never/// tries to patch a game that is not there. While another install remains, its state stays.public func forget(_ id: String, otherInstallsRemain: Bool) {diff --git a/Sources/HighballKit/GOGMac.swift b/Sources/HighballKit/GOGMac.swiftindex 6fbf4a4..59b90e3 100644--- a/Sources/HighballKit/GOGMac.swift+++ b/Sources/HighballKit/GOGMac.swift@@ -66,6 +66,9 @@ extension GOGStore {/// The DLC installed with it: the other info files beside the game's own whose root game is/// this one.public var dlcIDs: [String] = []+ /// What Move to the Trash takes (GOGStore.macTrashTarget), worked out when the install is+ /// found, off the main actor, since it reads other apps' info files. Nil: nothing is moved.+ public var trashTarget: URL? = nil/// The same game as the installed-game record the Windows paths take, so the save sync,/// comet's achievement lookup and the rest run unchanged. Its folder keeps the Mac build's@@ -120,7 +123,9 @@ extension GOGStore {guard !searched.contains(folder.standardizedFileURL.path),(try? folder.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true,!fm.fileExists(atPath: folder.appending(path: ".gogdl-resume").path) else { return nil }- return macInstalledGame(in: folder)+ guard var game = macInstalledGame(in: folder) else { return nil }+ game.trashTarget = macTrashTarget(for: game, searched: bases)+ return game}}.filter { seen.insert($0.id).inserted }@@ -160,12 +165,28 @@ extension GOGStore {/// What the Trash takes for a Mac build: the game's own folder (MacInstalledGame.folder), its/// app or the folder holding its info. Never a folder Mac builds are looked for in, nor one- /// holding such a folder, nor the root: those hold other apps. Nil then.+ /// holding such a folder, nor the root, nor a folder holding another game's app (Galaxy's+ /// layout with a second game put beside the first): those hold other games. Nil then.public static func macTrashTarget(for game: MacInstalledGame, searched: [URL] = macSearchFolders) -> URL? {let folder = game.folder.standardizedFileURL.pathguard folder != "/" else { return nil }let held = searched.map { $0.standardizedFileURL.path }- return held.contains { $0 == folder || $0.hasPrefix(folder + "/") } ? nil : game.folder+ guard !held.contains(where: { $0 == folder || $0.hasPrefix(folder + "/") }) else { return nil }+ return holdsOtherGames(game.folder, besides: game.id) ? nil : game.folder+ }++ /// Whether a folder holds another game's app: an app straight inside it whose goggame info+ /// names a different game. The game's own DLC, whose info names it as root, does not count.+ public static func holdsOtherGames(_ folder: URL, besides gameID: String) -> Bool {+ let fm = FileManager.default+ let apps = ((try? fm.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles])) ?? [])+ .filter { $0.pathExtension == "app" }+ return apps.contains { app in+ ((try? fm.contentsOfDirectory(at: app.appending(path: "Contents/Resources"), includingPropertiesForKeys: nil)) ?? [])+ .filter { $0.lastPathComponent.hasPrefix("goggame-") && $0.pathExtension == "info" }+ .compactMap { try? JSONDecoder().decode(InfoFile.self, from: Data(contentsOf: $0)) }+ .contains { ($0.rootGameId ?? $0.gameId) != gameID }+ }}/// The app among `apps` that the primary play task (else the first file task) points at or@@ -193,15 +214,28 @@ public enum MacGameWatch {return executable.hasPrefix(root)}- /// The processes running an executable from inside the folder, never Highball itself.+ /// The processes running an executable from inside the folder, never Highball itself. The+ /// kernel reports where an executable really is, so the folder counts as written, with its+ /// links resolved, and through each link straight inside it (an app linked into the folder+ /// runs from where the link points).public static func processes(runningFrom folder: URL) -> [pid_t] {- let root = ProcessTable.canonical(folder.path)+ let written = folder.standardizedFileURL.path+ let roots = Set([written, ProcessTable.canonical(written)] + linkTargets(in: folder))let own = getpid()return ProcessTable.allPIDs().filter { pid in- pid != own && executablePath(of: pid).map { runs(executable: $0, from: root) } == true+ pid != own && executablePath(of: pid).map { path in roots.contains { runs(executable: path, from: $0) } } == true}}+ /// Where the apps linked straight inside a folder are, resolved. Only apps: a link to a+ /// folder of other things would count everything in it as the game.+ static func linkTargets(in folder: URL) -> [String] {+ ((try? FileManager.default.contentsOfDirectory(at: folder, includingPropertiesForKeys: [.isSymbolicLinkKey])) ?? [])+ .filter { (try? $0.resourceValues(forKeys: [.isSymbolicLinkKey]).isSymbolicLink) == true }+ .map { ProcessTable.canonical($0.path) }+ .filter { $0.hasSuffix(".app") }+ }+/// The executable a process runs, or nil when it cannot be read (not ours, gone).static func executablePath(of pid: pid_t) -> String? {var buffer = [UInt8](repeating: 0, count: Int(MAXPATHLEN) * 4)diff --git a/Sources/HighballKit/GOGSaves.swift b/Sources/HighballKit/GOGSaves.swiftindex 1041778..2961601 100644--- a/Sources/HighballKit/GOGSaves.swift+++ b/Sources/HighballKit/GOGSaves.swift@@ -114,11 +114,10 @@ public struct GOGSaves: Sendable {Self.parseLocations(try Self.remoteConfig(clientID), clientID: clientID, platform: "MacOS")}- /// A Mac location as a folder, from GOG's Mac variables.- /// Never a whole known folder (gogdl deletes local files the cloud lacks): not the variable's- /// own folder, and not one a variable reaches into either (`<?LIBRARY?>/Preferences` is all- /// of ~/Library/Preferences), see `isSharedFolder`.- public static func resolveMac(_ template: String, installFolder: URL,+ /// A Mac location as a folder, from GOG's Mac variables. gogdl deletes local files the cloud+ /// lacks, so only a folder that is clearly the game's own is synced (isOwnFolder), and never+ /// one in an install folder that also holds another game's app (`gameID`, the game asking).+ public static func resolveMac(_ template: String, installFolder: URL, gameID: String? = nil,home: URL = FileManager.default.homeDirectoryForCurrentUser) -> URL? {let values: [String: URL] = ["INSTALL": installFolder,@@ -136,37 +135,42 @@ public struct GOGSaves: Sendable {let parts = path.split(separator: "/").map(String.init)guard !parts.isEmpty, !parts.contains(where: { $0 == "." || $0 == ".." }) else { return nil }let folder = parts.reduce(base) { $0.appending(path: $1) }- return isSharedFolder(folder, home: home) ? nil : folder+ if template.hasPrefix("<?INSTALL?>"), let gameID, GOGStore.holdsOtherGames(installFolder, besides: gameID) { return nil }+ return isOwnFolder(folder, home: home) ? folder : nil}- /// A folder of the home that holds more than one game's files, which a save sync must never- /// be given whole: the home itself, every folder straight inside it (Documents, Library,- /// Desktop and the rest), every folder straight inside its Library (Preferences, Application- /// Support, Caches, Containers, Group Containers, Saved Application State and the rest), and- /// the top of a synced drive or a container there (iCloud Drive's com~apple~CloudDocs, a- /// CloudStorage provider's folder, an app's container). Also the few folders many games share- /// one level deeper: ~/Documents/My Games, and a launcher's or porting house's folder in- /// Application Support (sharedVendorFolders). A game's own folder sits deeper, as in- /// ~/Library/Application Support/<studio>/<game>. Compared without case, as the Mac's disks- /// are.- static func isSharedFolder(_ folder: URL, home: URL) -> Bool {- let homeParts = home.standardizedFileURL.pathComponents.map { $0.lowercased() }- let parts = folder.standardizedFileURL.pathComponents.map { $0.lowercased() }- guard parts.count >= homeParts.count, Array(parts.prefix(homeParts.count)) == homeParts else { return false }- let inside = Array(parts.dropFirst(homeParts.count))- if inside.count <= 1 { return true }- if inside == ["documents", "my games"] { return true }- guard inside[0] == "library" else { return false }- if inside.count == 2 { return true }- guard inside.count == 3 else { return false }- return ["mobile documents", "cloudstorage", "containers", "group containers"].contains(inside[1])- || (inside[1] == "application support" && sharedVendorFolders.contains(inside[2]))+ /// Whether a folder is clearly one game's: at least two levels below every folder that holds+ /// many games' files (isSharedFolder), so ~/Library/Application Support/<studio>/<game> and+ /// ~/Documents/My Games/<game> pass, and a studio's or a launcher's folder, which may hold its+ /// other games, does not. Both the path as written and with its links resolved must pass, so+ /// a link to a shared folder counts as that folder.+ static func isOwnFolder(_ folder: URL, home: URL) -> Bool {+ let written = folder.standardizedFileURL+ return [written, written.resolvingSymlinksInPath()].allSatisfy { path in+ !isSharedFolder(path, home: home) && !isSharedFolder(path.deletingLastPathComponent(), home: home)+ }}- /// Folders in ~/Library/Application Support that hold many games' files, each game in its own- /// folder below: the stores' launchers and the porting houses whose Mac versions keep their- /// saves there. Lowercased.- static let sharedVendorFolders: Set<String> = ["gog.com", "steam", "epic", "epic games", "feral interactive", "aspyr"]+ /// A folder that holds more than one game's files, which a save sync must never be given+ /// whole: the home itself, every folder straight inside it (Documents, Library, Desktop and+ /// the rest), every folder straight inside its Library (Preferences, Application Support,+ /// Caches, Containers, Group Containers, Saved Application State and the rest), the top of a+ /// synced drive or a container there (iCloud Drive's com~apple~CloudDocs, a CloudStorage+ /// provider's folder, an app's container), and the folders Mac builds are looked for in.+ /// Compared without case, as the Mac's disks are, against the home as written and resolved.+ static func isSharedFolder(_ folder: URL, home: URL) -> Bool {+ func parts(_ url: URL) -> [String] { url.standardizedFileURL.pathComponents.map { $0.lowercased() } }+ let path = parts(folder)+ if GOGStore.macSearchFolders.contains(where: { parts($0) == path }) { return true }+ return Set([parts(home), parts(home.resolvingSymlinksInPath())]).contains { homeParts in+ guard path.count >= homeParts.count, Array(path.prefix(homeParts.count)) == homeParts else { return false }+ let inside = Array(path.dropFirst(homeParts.count))+ if inside.count <= 1 { return true }+ guard inside[0] == "library" else { return false }+ if inside.count == 2 { return true }+ return inside.count == 3 && ["mobile documents", "cloudstorage", "containers", "group containers"].contains(inside[1])+ }+ }/// A location as a folder on the Mac, inside the environment. GOG's variables are the Windows/// known folders; Wine keeps them under drive_c/users/<Mac user name>. A Documents folder thediff --git a/Tests/HighballKitTests/StoreMacVersionTests.swift b/Tests/HighballKitTests/StoreMacVersionTests.swiftindex 9362de7..2a6dd7d 100644--- a/Tests/HighballKitTests/StoreMacVersionTests.swift+++ b/Tests/HighballKitTests/StoreMacVersionTests.swift@@ -135,6 +135,36 @@ final class GOGMacBuildTests: XCTestCase {}}+ /// Galaxy's layout with another game's app put beside the first: the scan leaves nothing for+ /// the Trash to take. The game's own DLC app is still the game's.+ func testTheTrashNeverTakesAFolderHoldingAnotherGamesApp() throws {+ let applications = FileManager.default.temporaryDirectory.appending(path: "apps-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: applications) }+ func info(_ json: String, at path: String) throws {+ let file = applications.appending(path: path)+ try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)+ try json.write(to: file, atomically: true, encoding: .utf8)+ }+ try info(#"{"gameId":"1","rootGameId":"1","name":"Shared"}"#, at: "Shared/Contents/Resources/goggame-1.info")+ try info(#"{"gameId":"2","rootGameId":"2"}"#, at: "Shared/Other.app/Contents/Resources/goggame-2.info")+ try info(#"{"gameId":"3","rootGameId":"3","name":"Big"}"#, at: "Big/Contents/Resources/goggame-3.info")+ try info(#"{"gameId":"5","rootGameId":"3"}"#, at: "Big/Extra.app/Contents/Resources/goggame-5.info")+ let games = Dictionary(uniqueKeysWithValues: GOGStore.macInstalledGames(in: [applications]).map { ($0.id, $0) })+ XCTAssertNil(try XCTUnwrap(games["1"]).trashTarget)+ XCTAssertEqual(try XCTUnwrap(games["3"]).trashTarget?.lastPathComponent, "Big")+ XCTAssertTrue(GOGStore.holdsOtherGames(applications.appending(path: "Shared"), besides: "1"))+ XCTAssertFalse(GOGStore.holdsOtherGames(applications.appending(path: "Big"), besides: "3"))+ }++ /// Removing the Windows copy keeps gogdl's files while the Mac build, or another+ /// environment's copy, still uses them.+ func testForgettingAWindowsCopyKeepsWhatTheMacBuildUses() {+ let game = GOGStore.InstalledGame(id: "1", title: "G", folder: URL(fileURLWithPath: "/x"), buildID: nil, clientID: nil, dlcIDs: [], tasks: [])+ XCTAssertTrue(GOGStore.otherInstallsRemain("1", removingFrom: "A", installedByBottle: ["A": [game]], macInstalls: ["1"]))+ XCTAssertTrue(GOGStore.otherInstallsRemain("1", removingFrom: "A", installedByBottle: ["A": [game], "B": [game]], macInstalls: []))+ XCTAssertFalse(GOGStore.otherInstallsRemain("1", removingFrom: "A", installedByBottle: ["A": [game]], macInstalls: ["2"]))+ }+/// An app among others in a folder of /Applications (/Applications/Games/Foo.app): the game,/// and so its Trash, is that app alone, never the folder with the other apps in it.func testAppInAFolderOfOtherAppsIsTheGamesFolderAlone() throws {@@ -280,7 +310,10 @@ final class GOGMacSavesTests: XCTestCase {// Folders many games share one level deeper, each game in its own folder below."<?DOCUMENTS?>/My Games", "<?DOCUMENTS?>/my games/", "<?APPLICATION_SUPPORT?>/GOG.com","<?APPLICATION_SUPPORT?>/Steam", "<?APPLICATION_SUPPORT?>/Epic", "<?APPLICATION_SUPPORT?>/Epic Games",- "<?LIBRARY?>/Application Support/Feral Interactive", "<?APPLICATION_SUPPORT?>/Aspyr"] {+ "<?LIBRARY?>/Application Support/Feral Interactive", "<?APPLICATION_SUPPORT?>/Aspyr",+ // Any folder straight inside a shared one may be a studio's, holding its other games.+ "<?DOCUMENTS?>/Studio", "<?LIBRARY?>/Preferences/Studio Game", "<?LIBRARY?>/Studio",+ "<?LIBRARY?>/Containers/com.studio.game/Data"] {XCTAssertNil(GOGSaves.resolveMac(whole, installFolder: install, home: home), whole)}XCTAssertEqual(GOGSaves.resolveMac("<?DOCUMENTS?>/My Games/Studio Game", installFolder: install, home: home)?.path,@@ -289,15 +322,39 @@ final class GOGMacSavesTests: XCTestCase {"/Users/someone/Library/Application Support/Feral Interactive/Game/Saves")XCTAssertEqual(GOGSaves.resolveMac("<?APPLICATION_SUPPORT?>/GOG.com/Galaxy/Applications/c/Storage/Shared/Files", installFolder: install, home: home)?.path,"/Users/someone/Library/Application Support/GOG.com/Galaxy/Applications/c/Storage/Shared/Files")- XCTAssertEqual(GOGSaves.resolveMac("<?LIBRARY?>/Preferences/Studio Game", installFolder: install, home: home)?.path,- "/Users/someone/Library/Preferences/Studio Game")+ XCTAssertEqual(GOGSaves.resolveMac("<?LIBRARY?>/Preferences/Studio/Game", installFolder: install, home: home)?.path,+ "/Users/someone/Library/Preferences/Studio/Game")+ XCTAssertEqual(GOGSaves.resolveMac("<?APPLICATION_SUPPORT?>/Feral Interactive/Game", installFolder: install, home: home)?.path,+ "/Users/someone/Library/Application Support/Feral Interactive/Game")XCTAssertEqual(GOGSaves.resolveMac("<?LIBRARY?>/Containers/com.studio.game/Data/Saves", installFolder: install, home: home)?.path,"/Users/someone/Library/Containers/com.studio.game/Data/Saves")- XCTAssertEqual(GOGSaves.resolveMac("<?DOCUMENTS?>/Studio", installFolder: install, home: home)?.path, "/Users/someone/Documents/Studio")XCTAssertEqual(GOGSaves.resolveMac("<?INSTALL?>/saves", installFolder: home.appending(path: "Applications/Highball Games/Game.app"), home: home)?.path,"/Users/someone/Applications/Highball Games/Game.app/saves")}+ /// A link to a shared folder counts as that folder.+ func testALinkToASharedFolderIsRefused() throws {+ let home = FileManager.default.temporaryDirectory.appending(path: "home-\(UUID().uuidString)")+ addTeardownBlock { try? FileManager.default.removeItem(at: home) }+ try FileManager.default.createDirectory(at: home.appending(path: "Library/Application Support"), withIntermediateDirectories: true)+ let game = home.appending(path: "Games/Game")+ try FileManager.default.createDirectory(at: game, withIntermediateDirectories: true)+ try FileManager.default.createSymbolicLink(at: game.appending(path: "Support"), withDestinationURL: home.appending(path: "Library/Application Support"))+ XCTAssertNil(GOGSaves.resolveMac("<?INSTALL?>/Support", installFolder: game, home: home))+ XCTAssertNotNil(GOGSaves.resolveMac("<?INSTALL?>/saves", installFolder: game, home: home))+ }++ /// An install folder that also holds another game's app is never synced as this game's.+ func testInstallSavesRefuseAFolderHoldingAnotherGamesApp() throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "shared-\(UUID().uuidString)")+ addTeardownBlock { try? FileManager.default.removeItem(at: folder) }+ let other = folder.appending(path: "Other.app/Contents/Resources")+ try FileManager.default.createDirectory(at: other, withIntermediateDirectories: true)+ try #"{"gameId":"2"}"#.write(to: other.appending(path: "goggame-2.info"), atomically: true, encoding: .utf8)+ XCTAssertNil(GOGSaves.resolveMac("<?INSTALL?>/saves", installFolder: folder, gameID: "1"))+ XCTAssertNotNil(GOGSaves.resolveMac("<?INSTALL?>/saves", installFolder: folder, gameID: "2"))+ }+func testSyncNamesTheSystemOfTheLocation() {let mac = GOGSaves.Location(name: "saves", template: "t", os: "osx")let args = GOGSaves.arguments(folder: URL(fileURLWithPath: "/s"), id: "1", location: mac, timestamp: "0", direction: .download)@@ -340,6 +397,18 @@ final class MacGameWatchTests: XCTestCase {XCTAssertFalse(MacGameWatch.runs(executable: "/Applications/Games/Bar.app/Contents/MacOS/Bar", from: "/Applications/Games/Foo.app"))}+ /// An app linked into the game's folder runs from where the link points: that place counts.+ func testALinkedAppInTheFolderIsFollowed() throws {+ let base = FileManager.default.temporaryDirectory.appending(path: "linked-\(UUID().uuidString)")+ addTeardownBlock { try? FileManager.default.removeItem(at: base) }+ let real = base.appending(path: "Elsewhere/Game.app"), folder = base.appending(path: "Game")+ try FileManager.default.createDirectory(at: real, withIntermediateDirectories: true)+ try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)+ try FileManager.default.createSymbolicLink(at: folder.appending(path: "Game.app"), withDestinationURL: real)+ try FileManager.default.createSymbolicLink(at: folder.appending(path: "Shared"), withDestinationURL: base)+ XCTAssertEqual(MacGameWatch.linkTargets(in: folder), [ProcessTable.canonical(real.path)], "an app, not a folder of other things")+ }+func testALauncherThatHandsOverIsFollowedUntilTheGameQuits() async {var checks = 0let handedOver = await MacGameWatch.waitForHandover(from: URL(fileURLWithPath: "/g"), ranFor: 1, grace: 5, interval: 0.01) { _ in