Skip to content

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

Dependencies detect by artifacts, not by whether our recipe ran

Gauthier Piarrette2550c2a9bfe3
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index 8d28ad0..35457ec 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -405,7 +405,8 @@ struct BottleSettingsSheet: View {
HStack {
Text(r.title)
Spacer()
- if (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.recipes.contains(r.id) {
+ let live = state.bottles.first { $0.name == bottle.name } ?? bottle
+ if live.settings.recipes.contains(r.id) || r.isInstalled(in: live) {
Label(L("Installed"), systemImage: "checkmark.circle.fill").foregroundStyle(.green).labelStyle(.titleAndIcon)
} else {
Button(L("Install")) {
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swift
index 13c431b..4e062cc 100644
--- a/Sources/HighballKit/Recipe.swift
+++ b/Sources/HighballKit/Recipe.swift
@@ -197,6 +197,40 @@ public struct Recipe: Codable, Sendable, Identifiable {
public var knownIssues: [KnownIssue]?
public var lastVerified: Verification?
public var blocked: Blocked?
+ /// What an installed runtime leaves behind, so the Dependencies panel can tell "installed"
+ /// from "our recipe ran": a file under drive_c, or a registry value in system.reg (exact
+ /// match or a minimum for dword values). Any one marker satisfied means installed. Data, so
+ /// a runtime a game's own prerequisite installed shows as installed too (plan Phase 0.3).
+ public var installedMarkers: [InstalledMarker]?
+
+ public struct InstalledMarker: Codable, Sendable {
+ /// Path under drive_c, e.g. "windows/system32/vcruntime140.dll".
+ public var file: String?
+ /// Registry key under HKLM as written in system.reg, e.g.
+ /// "Software\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64".
+ public var registry: String?
+ public var value: String?
+ /// Exact raw value text, e.g. "dword:00000001".
+ public var equals: String?
+ /// Minimum for a dword value, decimal.
+ public var min: Int?
+ }
+
+ /// True when any marker is present in the bottle. Recipes without markers report false; the
+ /// caller still knows whether the recipe ran.
+ public func isInstalled(in bottle: Bottle) -> Bool {
+ guard let markers = installedMarkers, !markers.isEmpty else { return false }
+ lazy var systemReg: String = (try? String(contentsOf: bottle.url.appending(path: "system.reg"), encoding: .utf8)) ?? ""
+ for m in markers {
+ if let f = m.file, FileManager.default.fileExists(atPath: bottle.driveC.appending(path: f).path) { return true }
+ if let key = m.registry, let name = m.value, let raw = RegistryText.value(in: systemReg, key: key, name: name) {
+ if let eq = m.equals { if raw.lowercased() == eq.lowercased() { return true } else { continue } }
+ if let min = m.min, let n = RegistryText.dword(raw), n >= min { return true }
+ if m.equals == nil, m.min == nil { return true }
+ }
+ }
+ return false
+ }
public var flaky: Flaky?
public static func load(from url: URL) throws -> Recipe {
diff --git a/Sources/HighballKit/RegistryText.swift b/Sources/HighballKit/RegistryText.swift
new file mode 100644
index 0000000..9122c5d
--- /dev/null
+++ b/Sources/HighballKit/RegistryText.swift
@@ -0,0 +1,30 @@
+import Foundation
+
+/// Reads values out of Wine's text registry files (system.reg, user.reg) without running Wine.
+/// Keys appear as `[Software\\Vendor\\Key] <timestamp>` with backslashes doubled, values below
+/// them as `"Name"=dword:00000001` or `"Name"="text"`. Pure, so the Dependencies detection can
+/// be tested with a string.
+public enum RegistryText {
+ /// The raw value text (`dword:00000001`, `"text"`, `hex:...`) for `name` under `key`, or nil.
+ /// `key` is written the way it appears in the file, with doubled backslashes, or with single
+ /// backslashes, which are doubled here.
+ public static func value(in text: String, key: String, name: String) -> String? {
+ let wanted = "[" + key.replacingOccurrences(of: "\\\\", with: "\\").replacingOccurrences(of: "\\", with: "\\\\") + "]"
+ var inKey = false
+ for line in text.split(separator: "\n", omittingEmptySubsequences: false) {
+ if line.hasPrefix("[") {
+ inKey = line.hasPrefix(wanted + " ") || line == Substring(wanted)
+ continue
+ }
+ guard inKey, line.hasPrefix("\"" + name + "\"=") else { continue }
+ return String(line.dropFirst(name.count + 3))
+ }
+ return nil
+ }
+
+ /// `dword:00082348` -> 533320.
+ public static func dword(_ raw: String) -> Int? {
+ guard raw.lowercased().hasPrefix("dword:") else { return nil }
+ return Int(raw.dropFirst(6), radix: 16)
+ }
+}
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index 23b33f2..a210498 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -973,6 +973,43 @@ extension RegressionTests {
XCTAssertEqual(DownloadResume.decide(status: 416, partialBytes: 5), .failed)
}
+ // Dependencies detect by artifacts, not by "our recipe ran" (plan Phase 0.3).
+ func testRegistryTextAndInstalledMarkers() throws {
+ let reg = """
+ WINE REGISTRY Version 2
+
+ [Software\\\\Microsoft\\\\NET Framework Setup\\\\NDP\\\\v4\\\\Full] 1788462370
+ #time=1dd3c551aef527e
+ "Install"=dword:00000001
+ "Release"=dword:00082348
+
+ [Software\\\\Microsoft\\\\VisualStudio\\\\14.0\\\\VC\\\\Runtimes\\\\x64] 1788462371
+ "Installed"=dword:00000001
+ "Version"="v14.44.35211.00"
+ """
+ XCTAssertEqual(RegistryText.value(in: reg, key: "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", name: "Release"), "dword:00082348")
+ XCTAssertEqual(RegistryText.value(in: reg, key: "Software\\\\Microsoft\\\\NET Framework Setup\\\\NDP\\\\v4\\\\Full", name: "Release"), "dword:00082348", "doubled backslashes accepted too")
+ XCTAssertEqual(RegistryText.value(in: reg, key: "Software\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64", name: "Version"), "\"v14.44.35211.00\"")
+ XCTAssertNil(RegistryText.value(in: reg, key: "Software\\Nothing", name: "Release"))
+ XCTAssertEqual(RegistryText.dword("dword:00082348"), 533320)
+
+ let dir = FileManager.default.temporaryDirectory.appending(path: "hb-markers-\(UUID().uuidString)")
+ try FileManager.default.createDirectory(at: dir.appending(path: "drive_c/windows/system32"), withIntermediateDirectories: true)
+ try reg.write(to: dir.appending(path: "system.reg"), atomically: true, encoding: .utf8)
+ let bottle = Bottle(url: dir, settings: BottleSettings(name: "m", engineID: "e"))
+ var recipe = Recipe(id: "dotnet48", kind: .tweak, title: ".NET", requires: nil, renderer: nil, steps: [], knownIssues: nil, lastVerified: nil, blocked: nil, installedMarkers: nil)
+ XCTAssertFalse(recipe.isInstalled(in: bottle), "no markers: unknown, reported as not installed")
+ recipe.installedMarkers = [.init(file: nil, registry: "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", value: "Release", equals: nil, min: 528040)]
+ XCTAssertTrue(recipe.isInstalled(in: bottle), "4.8.1's Release 533320 satisfies the 4.8 minimum")
+ recipe.installedMarkers = [.init(file: nil, registry: "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", value: "Release", equals: nil, min: 600000)]
+ XCTAssertFalse(recipe.isInstalled(in: bottle))
+ recipe.installedMarkers = [.init(file: "windows/system32/marker.dll", registry: nil, value: nil, equals: nil, min: nil)]
+ XCTAssertFalse(recipe.isInstalled(in: bottle))
+ try Data().write(to: dir.appending(path: "drive_c/windows/system32/marker.dll"))
+ XCTAssertTrue(recipe.isInstalled(in: bottle))
+ try? FileManager.default.removeItem(at: dir)
+ }
+
func testDefaultEnginePrefersBundledManifestID() throws {
func engine(_ id: String) throws -> InstalledEngine {
let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#