Skip to content

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

A symlinked steamapps folder lists its games (highball-db#316)

Gauthier Piarrettee944c4330c5c
diff --git a/Sources/HighballKit/MacSteam.swift b/Sources/HighballKit/MacSteam.swift
index 0875f33..86f7744 100644
--- a/Sources/HighballKit/MacSteam.swift
+++ b/Sources/HighballKit/MacSteam.swift
@@ -42,7 +42,8 @@ public enum MacSteam {
var seen = Set<Int>()
return steamappsDirectories(root: root)
.flatMap { dir in
- ((try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil)) ?? [])
+ // Resolved first, as SteamLibrary.games does: a symlinked steamapps lists as nothing.
+ ((try? FileManager.default.contentsOfDirectory(at: dir.resolvingSymlinksInPath(), includingPropertiesForKeys: nil)) ?? [])
.filter { $0.lastPathComponent.hasPrefix("appmanifest_") && $0.pathExtension == "acf" }
}
.compactMap { SteamLibrary.parseManifest($0) }
diff --git a/Sources/HighballKit/SteamLibrary.swift b/Sources/HighballKit/SteamLibrary.swift
index 11b6f8a..460e921 100644
--- a/Sources/HighballKit/SteamLibrary.swift
+++ b/Sources/HighballKit/SteamLibrary.swift
@@ -58,7 +58,10 @@ public enum SteamLibrary {
static func games(steamRoot root: URL, bottleURL: URL) -> [SteamGame] {
var seen = Set<Int>(), games: [SteamGame] = []
for library in libraryFolders(steamRoot: root, bottleURL: bottleURL) {
- let steamapps = library.appending(path: "steamapps")
+ // Resolved first: players move steamapps to an external disk and leave a symlink in its
+ // place, and FileManager's URL listing refuses a symlink ("Not a directory"), so the
+ // whole library read as empty (highball-db#316, steamapps on /Volumes/MEDIA_DEV).
+ let steamapps = library.appending(path: "steamapps").resolvingSymlinksInPath()
guard let entries = try? FileManager.default.contentsOfDirectory(at: steamapps, includingPropertiesForKeys: nil) else { continue }
for url in entries where url.lastPathComponent.hasPrefix("appmanifest_") && url.pathExtension == "acf" {
guard let game = parseManifest(url, libraryRoot: library),
diff --git a/Tests/HighballKitTests/SteamLibraryFoldersTests.swift b/Tests/HighballKitTests/SteamLibraryFoldersTests.swift
index 03b2425..beb4307 100644
--- a/Tests/HighballKitTests/SteamLibraryFoldersTests.swift
+++ b/Tests/HighballKitTests/SteamLibraryFoldersTests.swift
@@ -65,6 +65,22 @@ final class SteamLibraryFoldersTests: XCTestCase {
external.appending(path: "steamapps/common/BloodySpell").standardizedFileURL.path)
}
+ func testASymlinkedSteamappsFolderIsRead() throws {
+ // highball-db#316: steamapps moved to an external disk with a symlink left in its place.
+ let bottle = tmp.appending(path: "bottle", directoryHint: .isDirectory)
+ let steam = bottle.appending(path: "drive_c/Program Files (x86)/Steam", directoryHint: .isDirectory)
+ let external = tmp.appending(path: "MEDIA_DEV/roms/steam/steamapps", directoryHint: .isDirectory)
+ try write("", to: steam.appending(path: "steam.exe"))
+ try write(manifest(992300, "Bloody Spell", dir: "BloodySpell"), to: external.appending(path: "appmanifest_992300.acf"))
+ try write("", to: external.appending(path: "common/BloodySpell/BloodySpell.exe"))
+ try FileManager.default.createSymbolicLink(atPath: steam.appending(path: "steamapps").path, withDestinationPath: external.path)
+
+ let games = SteamLibrary.games(steamRoot: steam, bottleURL: bottle)
+ XCTAssertEqual(games.map(\.appid), [992300], "a symlinked steamapps must list its manifests")
+ XCTAssertEqual(games.first?.installFolder?.resolvingSymlinksInPath().path,
+ external.appending(path: "common/BloodySpell").resolvingSymlinksInPath().path)
+ }
+
func testWindowsPathsGoThroughTheBottlesDriveLetters() throws {
let bottle = tmp.appending(path: "b", directoryHint: .isDirectory)
XCTAssertEqual(SteamLibrary.unixURL(windowsPath: "C:\\Games\\X", bottleURL: bottle)?.standardizedFileURL.path,