Skip to content

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

fix: preinstalled games — run and pin exes living anywhere on disk

Gauthier Piarretted1c654e6e23d
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 4010dba..be6edce 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -282,15 +282,21 @@ final class AppState {
guard let engine = engine(for: bottle) else { return }
runBusy("Running \(url.lastPathComponent)") { [self] in
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
- let isMSI = url.pathExtension.lowercased() == "msi"
+ let ext = url.pathExtension.lowercased()
+ let isMSI = ext == "msi"
let args = isMSI ? ["msiexec", "/i", url.path] : [url.path]
- _ = try await runner.run(args, renderer: .wined3d, label: url.lastPathComponent) { line in
+ // Installers get the boring reliable backend; a game exe gets the bottle's
+ // real renderer and runs from its own folder so relative asset paths work.
+ let renderer: Renderer? = (ext == "exe") ? nil : .wined3d
+ _ = try await runner.run(args, renderer: renderer, label: url.lastPathComponent,
+ workingDirectory: url.deletingLastPathComponent()) { line in
Task { @MainActor in self.appendLog(line) }
}
if andPin {
await MainActor.run {
var copy = bottle
- copy.settings.pins.append(Pin(name: url.deletingPathExtension().lastPathComponent, path: url.lastPathComponent))
+ copy.settings.pins.append(Pin(name: url.deletingPathExtension().lastPathComponent,
+ path: Pin.storagePath(for: url, driveC: bottle.driveC)))
self.update(copy)
}
}
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index e8a65c9..ea98c1c 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -48,7 +48,9 @@ public enum SyncMode: String, Codable, CaseIterable, Sendable {
public struct Pin: Codable, Sendable, Identifiable, Hashable {
public var id: UUID = UUID()
public var name: String
- /// Path relative to the bottle's `drive_c`.
+ /// Path relative to the bottle's `drive_c`, or an absolute unix path (leading `/`)
+ /// for programs that live outside the bottle — preinstalled games on the Mac side,
+ /// which Wine reaches through its Z: drive.
public var path: String
public var arguments: [String] = []
public var environment: [String: String] = [:]
@@ -58,6 +60,19 @@ public struct Pin: Codable, Sendable, Identifiable, Hashable {
self.name = name; self.path = path; self.arguments = arguments; self.environment = environment; self.renderer = renderer
}
+ /// Where the pin's executable actually lives for a given bottle.
+ public func executableURL(driveC: URL) -> URL {
+ path.hasPrefix("/") ? URL(fileURLWithPath: path) : driveC.appending(path: path)
+ }
+
+ /// How to store a picked file's location in a pin: drive_c-relative when the file is
+ /// inside the bottle, absolute otherwise. (Storing just a filename was the 0.7.x bug
+ /// that made "Run and add to Programs" produce dead entries for outside-the-bottle exes.)
+ public static func storagePath(for url: URL, driveC: URL) -> String {
+ let prefix = driveC.path.hasSuffix("/") ? driveC.path : driveC.path + "/"
+ return url.path.hasPrefix(prefix) ? String(url.path.dropFirst(prefix.count)) : url.path
+ }
+
enum CodingKeys: String, CodingKey { case id, name, path, arguments, environment, renderer }
/// Lenient decode: hand-written recipe pins may omit id/arguments/environment.
@@ -235,6 +250,11 @@ public struct Bottle: Sendable {
/// Convert a Windows path like `C:\Program Files (x86)\Steam\steam.exe` to a file URL inside the bottle.
public func resolve(windowsPath: String) -> URL {
var p = windowsPath
+ if p.lowercased().hasPrefix("z:") {
+ // Wine maps Z:\ to the unix root — hand back the real absolute path.
+ let rest = String(p.dropFirst(2)).replacingOccurrences(of: "\\", with: "/")
+ return URL(fileURLWithPath: rest.isEmpty ? "/" : rest)
+ }
if p.lowercased().hasPrefix("c:") { p = String(p.dropFirst(2)) }
p = p.replacingOccurrences(of: "\\", with: "/")
if p.hasPrefix("/") { p.removeFirst() }
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 9778cc4..43b43b8 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -91,9 +91,11 @@ public struct WineRunner: Sendable {
/// Runs the pinned program, honouring its own renderer/env/args.
@discardableResult
public func start(pin: Pin, extraEnvironment: [String: String] = [:], onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
- let exe = bottle.driveC.appending(path: pin.path)
+ let exe = pin.executableURL(driveC: bottle.driveC)
let env = pin.environment.merging(extraEnvironment) { $1 }
- return try await start(exe, arguments: pin.arguments, renderer: pin.renderer, extraEnvironment: env, onOutput: onOutput)
+ // cwd = the exe's folder, as a Windows shortcut would — games with relative asset paths need it.
+ return try await start(exe, arguments: pin.arguments, renderer: pin.renderer, extraEnvironment: env,
+ workingDirectory: exe.deletingLastPathComponent(), onOutput: onOutput)
}
/// Steam's first self-update sometimes dies at a known Wine WoW64 spot and resumes cleanly
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 7a306fb..e93b403 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -194,7 +194,35 @@ struct PinCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "pin",
abstract: "Per-program settings: persistent launch arguments, environment, renderer.",
- subcommands: [List.self, Set.self])
+ subcommands: [List.self, Add.self, Set.self])
+
+ struct Add: AsyncParsableCommand {
+ static let configuration = CommandConfiguration(abstract: "Pin a program: a Windows path, a unix path (preinstalled games anywhere on disk), or a drive_c-relative path.")
+ @Argument var bottle: String
+ @Argument var name: String
+ @Argument var path: String
+
+ func run() async throws {
+ let bs = BottleStore()
+ var b = try bs.get(bottle)
+ guard !b.settings.pins.contains(where: { $0.name.lowercased() == name.lowercased() }) else {
+ fail("a pin named '\(name)' already exists in \(b.name)")
+ }
+ let url: URL
+ if path.contains(":") || path.contains("\\") {
+ url = b.resolve(windowsPath: path)
+ } else if path.hasPrefix("/") || path.hasPrefix("~") {
+ url = URL(fileURLWithPath: (path as NSString).expandingTildeInPath)
+ } else {
+ url = b.driveC.appending(path: path)
+ }
+ guard FileManager.default.fileExists(atPath: url.path) else { fail("no file at \(url.path)") }
+ let pin = Pin(name: name, path: Pin.storagePath(for: url, driveC: b.driveC))
+ b.settings.pins.append(pin)
+ try bs.update(b)
+ print("pinned \(name) -> \(pin.path)")
+ }
+ }
struct List: AsyncParsableCommand {
@Argument var bottle: String
@@ -272,9 +300,13 @@ struct Run: AsyncParsableCommand {
result = try await runner.start(pin: p, onOutput: out)
}
} else if program.contains(":") || program.contains("\\") {
- result = try await runner.start(b.resolve(windowsPath: program), arguments: arguments, renderer: renderer, onOutput: out)
+ let exe = b.resolve(windowsPath: program)
+ result = try await runner.start(exe, arguments: arguments, renderer: renderer,
+ workingDirectory: exe.deletingLastPathComponent(), onOutput: out)
} else if FileManager.default.fileExists(atPath: program) {
- result = try await runner.start(URL(fileURLWithPath: program), arguments: arguments, renderer: renderer, onOutput: out)
+ let exe = URL(fileURLWithPath: program)
+ result = try await runner.start(exe, arguments: arguments, renderer: renderer,
+ workingDirectory: exe.deletingLastPathComponent(), onOutput: out)
} else {
// Not a pin, not a Windows path, not a local file: let Wine resolve it (cmd, dxdiag,
// notepad, anything on the Windows PATH) instead of failing on a made-up unix path.
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index 2eace2e..758e948 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -79,6 +79,30 @@ final class RegressionTests: XCTestCase {
"/tmp/b/drive_c/windows/system32/cmd.exe")
}
+ // "Run and add to Programs" on an exe outside the bottle used to store just the
+ // filename, producing a pin that resolved to a nonexistent drive_c file. Pins now
+ // store drive_c-relative paths inside the bottle and absolute paths outside it,
+ // and resolve accordingly. Preinstalled-games flow (Reddit report, 2026-08-26).
+ func testPinPathsInsideAndOutsideBottle() {
+ let driveC = URL(fileURLWithPath: "/tmp/b/drive_c")
+ let inside = URL(fileURLWithPath: "/tmp/b/drive_c/Games/Foo/foo.exe")
+ let outside = URL(fileURLWithPath: "/Users/someone/Games/Bar/bar.exe")
+ XCTAssertEqual(Pin.storagePath(for: inside, driveC: driveC), "Games/Foo/foo.exe")
+ XCTAssertEqual(Pin.storagePath(for: outside, driveC: driveC), "/Users/someone/Games/Bar/bar.exe")
+ XCTAssertEqual(Pin(name: "f", path: "Games/Foo/foo.exe").executableURL(driveC: driveC).path,
+ "/tmp/b/drive_c/Games/Foo/foo.exe")
+ XCTAssertEqual(Pin(name: "b", path: "/Users/someone/Games/Bar/bar.exe").executableURL(driveC: driveC).path,
+ "/Users/someone/Games/Bar/bar.exe")
+ }
+
+ // Z:\ is Wine's window onto the unix root; resolving it must leave the bottle.
+ func testWindowsPathZDrive() {
+ let b = Bottle(url: URL(fileURLWithPath: "/tmp/b"), settings: BottleSettings(name: "b", engineID: "e"))
+ XCTAssertEqual(b.resolve(windowsPath: #"Z:\Users\someone\Games\game.exe"#).path,
+ "/Users/someone/Games/game.exe")
+ XCTAssertEqual(b.resolve(windowsPath: #"C:\Games\g.exe"#).path, "/tmp/b/drive_c/Games/g.exe")
+ }
+
// Pins round trip with everything the program settings sheet can write.
func testPinFullRoundTrip() throws {
var p = Pin(name: "Launcher", path: "Games/l.exe")