Skip to content

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

Reparse points: compare a path with drive_c as built before standardizing. standardizedFileURL drops a leading /private only from paths that exist, so drive_c (/tmp/...) and a path through a Windows link below it (/private/tmp/..., no Mac side) disagreed, and a pinned EA app in a scratch home under /private/tmp was handed to Wine as Z:\private\... and exited 53. Players' homes under ~/Library never had the prefix, the test home did. New test with drive_c under /private/var. End to end on the M1 with the EA app 13.805.2.6319 installed silently (EAappInstaller.exe /passive /norestart) on Wine 11 r21 in scratch environments: Wine makes its own 'EA Desktop?' link, the app starts through it with no Mac symlink (its service from C:\...\EA Desktop\EA Desktop\EABackgroundService.exe, the client and five CEF processes, the sign-in page loads), the pin launch removes an old-style symlink first, and repairs (/repair /passive) keep all 169 files. With an old-style Mac symlink in place, one repair deleted the first 60 files of the version folder in name order, chrome_elf.dll among them, the exact damage reported in highball-db#318; repairs without it never did.

Gauthier Piarrette16433f056a8a
diff --git a/Sources/HighballKit/WineReparsePoint.swift b/Sources/HighballKit/WineReparsePoint.swift
index ffafd88..ee6b5c3 100644
--- a/Sources/HighballKit/WineReparsePoint.swift
+++ b/Sources/HighballKit/WineReparsePoint.swift
@@ -87,6 +87,19 @@ public enum WineReparsePoint {
}
}
+ /// The components of `url` below drive_c, or nil when it is not inside. Compared as built
+ /// first: `standardizedFileURL` drops a leading /private only from paths that exist, so drive_c
+ /// and a path through a link below it (which has no Mac side) can come out with different
+ /// prefixes (/tmp against /private/tmp).
+ static func componentsBelow(_ url: URL, driveC: URL) -> [String]? {
+ for (path, base) in [(url.path, driveC.path), (url.standardizedFileURL.path, driveC.standardizedFileURL.path)] {
+ let root = base.hasSuffix("/") ? String(base.dropLast()) : base
+ if path == root { return [] }
+ if path.hasPrefix(root + "/") { return String(path.dropFirst(root.count)).split(separator: "/").map(String.init) }
+ }
+ return nil
+ }
+
// MARK: Following
/// The Mac path `url` lands on when Wine resolves it, going through the stubs on the way
@@ -96,13 +109,11 @@ public enum WineReparsePoint {
public static func follow(_ url: URL, driveC: URL) -> URL? {
let fm = FileManager.default
if fm.fileExists(atPath: url.path) { return url }
- let path = url.standardizedFileURL.path
- let base = driveC.standardizedFileURL.path
var current: URL
var remaining: ArraySlice<String>
- if path == base || path.hasPrefix(base.hasSuffix("/") ? base : base + "/") {
+ if let below = componentsBelow(url, driveC: driveC) {
current = driveC
- remaining = String(path.dropFirst(base.count)).split(separator: "/").map(String.init)[...]
+ remaining = below[...]
} else {
current = URL(fileURLWithPath: "/")
remaining = url.standardizedFileURL.pathComponents.dropFirst()[...]
@@ -127,12 +138,8 @@ public enum WineReparsePoint {
/// The Windows path Wine knows a Mac path inside the bottle by: drive_c is C:, anything else
/// goes through Z:, the Mac's root.
public static func windowsPath(for url: URL, driveC: URL) -> String {
- let path = url.standardizedFileURL.path
- let base = driveC.standardizedFileURL.path
- if path == base || path.hasPrefix(base.hasSuffix("/") ? base : base + "/") {
- return "C:\\" + String(path.dropFirst(base.count)).split(separator: "/").joined(separator: "\\")
- }
- return "Z:" + path.replacingOccurrences(of: "/", with: "\\")
+ if let below = componentsBelow(url, driveC: driveC) { return "C:\\" + below.joined(separator: "\\") }
+ return "Z:" + url.standardizedFileURL.path.replacingOccurrences(of: "/", with: "\\")
}
// MARK: Undoing the old symlinks
@@ -195,12 +202,10 @@ public enum WineReparsePoint {
/// `dematerialize` in each folder along `url` inside drive_c, which is all a launch needs.
@discardableResult
public static func dematerializeAlong(_ url: URL, driveC: URL) -> [URL] {
- let path = url.standardizedFileURL.path
- let base = driveC.standardizedFileURL.path
- guard path.hasPrefix(base.hasSuffix("/") ? base : base + "/") else { return [] }
+ guard let below = componentsBelow(url, driveC: driveC), !below.isEmpty else { return [] }
var current = driveC
var removed: [URL] = []
- for component in String(path.dropFirst(base.count)).split(separator: "/").map(String.init).dropLast() {
+ for component in below.dropLast() {
removed += dematerialize(in: current, driveC: driveC)
current = current.appending(path: component)
}
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 90585d3..1e8c2f9 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -375,7 +375,7 @@ public struct WineRunner: Sendable {
}
// cwd = the exe's folder, as a Windows shortcut would — games with relative asset paths need it.
// Wine gets the path through the link by its Windows name, since that path has no Mac side.
- let throughLink = exe.standardizedFileURL.path != named.standardizedFileURL.path
+ let throughLink = exe.path != named.path
return try await start(exe, arguments: pin.arguments, renderer: renderer, extraEnvironment: env,
workingDirectory: exe.deletingLastPathComponent(),
program: throughLink ? WineReparsePoint.windowsPath(for: named, driveC: bottle.driveC) : nil, onOutput: onOutput)
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index e0390b1..55333eb 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -447,7 +447,7 @@ struct Run: AsyncParsableCommand {
let exe = WineReparsePoint.follow(named, driveC: b.driveC) ?? named
result = try await runner.start(exe, arguments: arguments, renderer: renderer, extraEnvironment: scoped,
workingDirectory: exe.deletingLastPathComponent(),
- program: exe.standardizedFileURL.path == named.standardizedFileURL.path ? nil : program, onOutput: out)
+ program: exe.path == named.path ? nil : program, onOutput: out)
} else if FileManager.default.fileExists(atPath: program) {
let exe = URL(fileURLWithPath: program)
result = try await runner.start(exe, arguments: arguments, renderer: renderer,
diff --git a/Tests/HighballKitTests/WineReparsePointTests.swift b/Tests/HighballKitTests/WineReparsePointTests.swift
index 76a0d0d..69e3c9f 100644
--- a/Tests/HighballKitTests/WineReparsePointTests.swift
+++ b/Tests/HighballKitTests/WineReparsePointTests.swift
@@ -185,4 +185,18 @@ final class WineReparsePointTests: XCTestCase {
"depth 3 is found, depth 8 is beyond the cap")
XCTAssertEqual(WineReparsePoint.dematerializeTree(under: driveC, driveC: driveC, maxDepth: 10).map(\.lastPathComponent), ["X"])
}
+
+ func testABottleUnderPrivateKeepsItsDriveLetter() throws {
+ // /var is a link to /private/var. Standardizing drops /private only from paths that exist,
+ // so drive_c and a path through a link below it used to disagree, and a pin behind a link
+ // was handed to Wine as Z:\\private\\... (exit 53, seen with a scratch home in /private/tmp).
+ let real = URL(fileURLWithPath: "/private" + root.resolvingSymlinksInPath().path.replacingOccurrences(of: "/private", with: ""))
+ let driveC = real.appending(path: "drive_c")
+ let (dir, exe) = try makeEAInstall(under: driveC)
+ let named = dir.appending(path: "EA Desktop/EADesktop.exe")
+ XCTAssertEqual(WineReparsePoint.windowsPath(for: named, driveC: driveC), "C:\\Program Files\\Electronic Arts\\EA Desktop\\EA Desktop\\EADesktop.exe")
+ XCTAssertEqual(WineReparsePoint.follow(named, driveC: driveC)?.resolvingSymlinksInPath().path, exe.resolvingSymlinksInPath().path)
+ try makeOldLink(in: dir)
+ XCTAssertEqual(WineReparsePoint.dematerializeAlong(named, driveC: driveC).map(\.lastPathComponent), ["EA Desktop"])
+ }
}