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
A game whose program sits four levels down keeps its per-program settings (highball#156)
Gauthier Piarrettee37585761866
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 86b9d1d..fca91c3 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -734,6 +734,7 @@ final class AppState {func refresh() {executableCache.removeAll()+ executableMisses.removeAll()if !prunedLogsThisRun {prunedLogsThisRun = truelet n = LogPruner.prune(directory: paths.logs)@@ -1360,10 +1361,15 @@ final class AppState {/// Finding it walks the game's folder, so the answer is kept per item until the next/// library refresh: views ask on every evaluation.private var executableCache: [String: URL] = [:]+ /// Installed games whose folder holds no program the search recognises, kept for the same+ /// span: without it a page would walk such a folder five levels deep on every evaluation.+ private var executableMisses: Set<String> = []func programExecutable(for item: LibraryItem) -> URL? {if let hit = executableCache[item.id] { return hit }+ if executableMisses.contains(item.id) { return nil }let found = findProgramExecutable(for: item)if let found { executableCache[item.id] = found }+ else if programFolder(for: item) != nil { executableMisses.insert(item.id) }return found}private func findProgramExecutable(for item: LibraryItem) -> URL? {diff --git a/Sources/HighballKit/PEIcon.swift b/Sources/HighballKit/PEIcon.swiftindex a573f8c..df0c8c3 100644--- a/Sources/HighballKit/PEIcon.swift+++ b/Sources/HighballKit/PEIcon.swift@@ -17,14 +17,22 @@ public enum PEIcon {}/// The program most likely to be the game in a folder: the largest .exe up to three levels- /// down whose name does not say installer, crash handler or redistributable.+ /// down whose name does not say installer, crash handler or redistributable. A folder with+ /// none that shallow is searched two levels deeper: Source 2 games keep theirs at+ /// game/bin/win64 (Counter-Strike 2's cs2.exe is four levels down), and finding nothing hid+ /// every per-program setting on the game's page, Display mode among them (highball#156). A+ /// folder with a program within three levels keeps the answer it always had.public static func bestExecutable(in dir: URL) -> URL? {+ bestExecutable(in: dir, maxLevel: 3) ?? bestExecutable(in: dir, maxLevel: 5)+ }++ static func bestExecutable(in dir: URL, maxLevel: Int) -> URL? {let fm = FileManager.defaultlet excluded = ["unins", "setup", "redist", "crash", "report", "vc_redist", "vcredist", "dxsetup", "dotnet", "directx", "easyanticheat", "installscript", "launcher_", "helper"]guard let e = fm.enumerator(at: dir, includingPropertiesForKeys: [.fileSizeKey, .isRegularFileKey], options: [.skipsHiddenFiles]) else { return nil }var best: (URL, Int)?for case let url as URL in e {- if e.level > 3 { e.skipDescendants(); continue }+ if e.level > maxLevel { e.skipDescendants(); continue }guard url.pathExtension.lowercased() == "exe" else { continue }let name = url.lastPathComponent.lowercased()if excluded.contains(where: { name.contains($0) }) { continue }diff --git a/Tests/HighballKitTests/PEIconTests.swift b/Tests/HighballKitTests/PEIconTests.swiftindex ce693fc..ad4b89c 100644--- a/Tests/HighballKitTests/PEIconTests.swift+++ b/Tests/HighballKitTests/PEIconTests.swift@@ -39,6 +39,21 @@ final class PEIconTests: XCTestCase {XCTAssertEqual(PEIcon.bestExecutable(in: dir)?.lastPathComponent, "Game-Win64-Shipping.exe")}+ /// highball#156: Counter-Strike 2 keeps its program at game/bin/win64/cs2.exe, four levels+ /// down. Nothing was found, so the game's page hid its per-program settings (Display mode).+ func testAProgramFourLevelsDownIsFoundWhenNothingShallowerIs() throws {+ let dir = FileManager.default.temporaryDirectory.appending(path: "hb-exe-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: dir) }+ try FileManager.default.createDirectory(at: dir.appending(path: "game/bin/win64"), withIntermediateDirectories: true)+ try Data(count: 100).write(to: dir.appending(path: "game/bin/win64/cs2.exe"))+ try Data(count: 900).write(to: dir.appending(path: "game/bin/win64/steamerrorreporter64.exe"))+ XCTAssertEqual(PEIcon.bestExecutable(in: dir)?.lastPathComponent, "cs2.exe")+ // A program within three levels still wins, as before: the deeper search only runs when+ // the usual one finds nothing, so no game that had a program changes it.+ try Data(count: 10).write(to: dir.appending(path: "start.exe"))+ XCTAssertEqual(PEIcon.bestExecutable(in: dir)?.lastPathComponent, "start.exe")+ }+func testARealProgramOnThisMacWhenThereIsOne() throws {let candidates = ["Library/Application Support/Highball/bottles/Gaming/drive_c/highball/ahk/AutoHotkeyU64.exe",