Skip to content

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

What the Trash takes for a GOG Mac build is decided in HighballKit, and tested

Gabe1f869d3b9161
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index f387761..93a9350 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -3846,13 +3846,11 @@ 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: its app, or the folder holding its info
- /// (GOGStore.MacInstalledGame.folder). Nil when there is none, or when it would be a folder
- /// Mac builds are looked for in, which holds other apps.
+ /// 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.
func gogMacTrashTarget(for item: LibraryItem) -> URL? {
- guard let id = item.gogID, let folder = gogMacInstalled[id]?.folder else { return nil }
- let searched = Set(GOGStore.macSearchFolders.map { $0.standardizedFileURL.path })
- return searched.contains(folder.standardizedFileURL.path) ? nil : folder
+ guard let id = item.gogID, let game = gogMacInstalled[id] else { return nil }
+ return GOGStore.macTrashTarget(for: game)
}
/// Moves a GOG game's Mac build to the Trash, where it can still be put back. Only once the
diff --git a/Sources/HighballKit/GOGMac.swift b/Sources/HighballKit/GOGMac.swift
index 6b6d94e..053e680 100644
--- a/Sources/HighballKit/GOGMac.swift
+++ b/Sources/HighballKit/GOGMac.swift
@@ -161,6 +161,16 @@ extension GOGStore {
clientID: base.clientId, tasks: tasks, dlcIDs: dlcs)
}
+ /// 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.
+ public static func macTrashTarget(for game: MacInstalledGame, searched: [URL] = macSearchFolders) -> URL? {
+ let folder = game.folder.standardizedFileURL.path
+ guard folder != "/" else { return nil }
+ let held = searched.map { $0.standardizedFileURL.path }
+ return held.contains { $0 == folder || $0.hasPrefix(folder + "/") } ? nil : game.folder
+ }
+
/// The app among `apps` that the primary play task (else the first file task) points at or
/// into, its path read from `folder` as gogdl and Galaxy read it.
static func taskApp(_ tasks: [PlayTask], in folder: URL, among apps: [URL]) -> URL? {
diff --git a/Tests/HighballKitTests/StoreMacVersionTests.swift b/Tests/HighballKitTests/StoreMacVersionTests.swift
index 1135de6..309d1fe 100644
--- a/Tests/HighballKitTests/StoreMacVersionTests.swift
+++ b/Tests/HighballKitTests/StoreMacVersionTests.swift
@@ -118,6 +118,23 @@ final class GOGMacBuildTests: XCTestCase {
XCTAssertEqual(game.dlcIDs, ["2"])
}
+ /// The Trash takes the game's own app or folder, never a searched folder, one holding it, or
+ /// the root.
+ func testTheTrashNeverTakesAFolderHoldingOtherApps() {
+ let own = URL(fileURLWithPath: "/Users/someone/Applications/Highball Games")
+ let searched = [own, URL(fileURLWithPath: "/Applications")]
+ func game(_ path: String) -> GOGStore.MacInstalledGame {
+ GOGStore.MacInstalledGame(id: "1", title: "Game", folder: URL(fileURLWithPath: path), app: nil, buildID: nil, arch: .unknown)
+ }
+ XCTAssertEqual(GOGStore.macTrashTarget(for: game("/Applications/Games/Foo.app"), searched: searched)?.path, "/Applications/Games/Foo.app")
+ XCTAssertEqual(GOGStore.macTrashTarget(for: game("/Users/someone/Applications/Highball Games/Samorost 1.app"), searched: searched)?.path,
+ "/Users/someone/Applications/Highball Games/Samorost 1.app")
+ for whole in ["/Applications", "/Applications/", "/Users/someone/Applications/Highball Games", "/Users/someone/Applications",
+ "/Users/someone", "/"] {
+ XCTAssertNil(GOGStore.macTrashTarget(for: game(whole), searched: searched), whole)
+ }
+ }
+
/// 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 {