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 steam.exe that is not a Windows program offers the installer, not Open Steam and not a graphics mode (highball#245)
Gauthier Piarrette54627a21915d
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex fca91c3..f9f0e7e 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -1162,8 +1162,12 @@ final class AppState {}))}+ /// Steam counts as installed when its steam.exe is a Windows executable, not merely a file: an+ /// empty or truncated one, the leftover of an interrupted self-update, showed Open Steam and+ /// then a crash alert proposing another graphics mode (highball#245). Now the row offers the+ /// installer again, which writes a fresh client over it and keeps the rest of the folder.func steamInstalled(in bottle: Bottle) -> Bool {- FileManager.default.fileExists(atPath: bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe").path)+ PEExportName.isWindowsExecutable(at: bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe"))}/// A game the row says needs D3DMetal, on an engine where it is not enabled yet: Play asks@@ -1831,6 +1835,13 @@ final class AppState {}return SessionWatch.isAlive(markers: markers, ps: await Self.processList())} crashed: { result in+ // A program whose file is not a Windows executable never ran: Wine's loader hands+ // it to start.exe, which reports "File not found" within seconds. Another graphics+ // mode cannot help, so say what is wrong instead of proposing one (highball#245).+ guard PEExportName.isWindowsExecutable(at: pin.executableURL(driveC: bottle.driveC)) else {+ self.appendLog("\(pin.name) did not start: its file is not a Windows program (empty or cut short), so Wine could not run it. Install it again; for Steam, the Steam row offers the installer.")+ return+ }let current = pin.renderer ?? bottle.settings.rendererself.crashSuggestion = CrashSuggestion(program: pin.name, bottleName: bottle.name,renderer: Renderer.suggestion(after: current, d3dmetalAvailable: engine.rendererDir("d3dmetal") != nil, vkd3dAvailable: engine.rendererDir("vkd3d") != nil),diff --git a/Sources/HighballKit/PEExportName.swift b/Sources/HighballKit/PEExportName.swiftindex 6e50c13..e561496 100644--- a/Sources/HighballKit/PEExportName.swift+++ b/Sources/HighballKit/PEExportName.swift@@ -32,6 +32,16 @@ public enum PEExportName {return out}+ /// Whether the file at `url` is a Windows executable Wine can map: an MZ header whose+ /// e_lfanew points at a PE signature. A steam.exe left empty or truncated by an interrupted+ /// self-update passes a plain existence check, so the Steam row offered Open Steam, Wine's+ /// loader fell back to start.exe, start.exe answered "File not found", and the crash alert+ /// then proposed another graphics mode for a file that was never a program (highball#245).+ public static func isWindowsExecutable(at url: URL) -> Bool {+ guard let h = try? FileHandle(forReadingFrom: url), let head = try? h.read(upToCount: 65536) else { return false }+ return isPE(head)+ }+// MARK: PE walking (PE32 and PE32+)private static func isPE(_ d: Data) -> Bool {diff --git a/Tests/HighballKitTests/PEExecutableTests.swift b/Tests/HighballKitTests/PEExecutableTests.swiftnew file mode 100644index 0000000..5c17b1e--- /dev/null+++ b/Tests/HighballKitTests/PEExecutableTests.swift@@ -0,0 +1,44 @@+import XCTest+@testable import HighballKit++/// A steam.exe left empty or truncated by an interrupted self-update is not an install+/// (highball#245): the Steam row must offer the installer, not Open Steam, and the crash alert+/// must not propose a graphics mode for it.+final class PEExecutableTests: XCTestCase {+ private func temp(_ name: String, _ bytes: [UInt8]) throws -> URL {+ let dir = FileManager.default.temporaryDirectory.appending(path: "pe-exec-\(UUID().uuidString)")+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)+ let url = dir.appending(path: name)+ try Data(bytes).write(to: url)+ return url+ }++ /// The smallest file that walks like a PE: an MZ header whose e_lfanew (0x3c) points at "PE\0\0".+ private func minimalPE() -> [UInt8] {+ var b = [UInt8](repeating: 0, count: 0x100)+ b[0] = 0x4D; b[1] = 0x5A+ b[0x3c] = 0x80+ b[0x80] = 0x50; b[0x81] = 0x45; b[0x82] = 0; b[0x83] = 0+ return b+ }++ func testAnEmptyFileIsNotAnExecutable() throws {+ XCTAssertFalse(PEExportName.isWindowsExecutable(at: try temp("steam.exe", [])))+ }++ func testAFileCutShortAfterTheHeaderIsNotAnExecutable() throws {+ XCTAssertFalse(PEExportName.isWindowsExecutable(at: try temp("steam.exe", Array(minimalPE()[0..<0x40]))))+ }++ func testTextIsNotAnExecutable() throws {+ XCTAssertFalse(PEExportName.isWindowsExecutable(at: try temp("steam.exe", Array("not a program".utf8))))+ }++ func testAMinimalPEIsAnExecutable() throws {+ XCTAssertTrue(PEExportName.isWindowsExecutable(at: try temp("steam.exe", minimalPE())))+ }++ func testAMissingFileIsNotAnExecutable() {+ XCTAssertFalse(PEExportName.isWindowsExecutable(at: URL(fileURLWithPath: "/nonexistent/steam.exe")))+ }+}