Skip to content

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

Prune old logs at launch and repair a missing 32-bit half before a launch

Gauthier Piarrette0edad1f3ac2c
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index a4f43d5..8003d27 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -225,7 +225,14 @@ final class AppState {
var engineStore: EngineStore { EngineStore(paths: paths) }
var bottleStore: BottleStore { BottleStore(paths: paths) }
+ private var prunedLogsThisRun = false
+
func refresh() {
+ if !prunedLogsThisRun {
+ prunedLogsThisRun = true
+ let n = LogPruner.prune(directory: paths.logs)
+ if n > 0 { appendLog("pruned \(n) old log file(s)") }
+ }
engines = (try? engineStore.installedEngines()) ?? []
bottles = (try? bottleStore.list()) ?? []
damagedBottles = (try? bottleStore.damaged()) ?? []
@@ -526,6 +533,7 @@ final class AppState {
result = r
if resumed { await MainActor.run { self.appendLog("resumed after the known crash") } }
} else {
+ try await BottleStore.preflight(runner: runner, bottle: bottle) { line in Task { @MainActor in self.appendLog(line) } }
result = try await runner.start(pin: pin, extraEnvironment: extra) { line in Task { @MainActor in self.appendLog(line) } }
}
if result.crashedEarly {
diff --git a/Sources/HighballKit/BottleStore.swift b/Sources/HighballKit/BottleStore.swift
index d224a5d..e182e0e 100644
--- a/Sources/HighballKit/BottleStore.swift
+++ b/Sources/HighballKit/BottleStore.swift
@@ -91,6 +91,21 @@ public struct BottleStore: Sendable {
return bottle
}
+ /// True when the prefix's 32-bit half is missing, the state issue #37 users found only when an
+ /// installer died with "could not load kernel32.dll". Checked before every launch.
+ public static func needsPreflightRepair(_ bottle: Bottle) -> Bool {
+ !FileManager.default.fileExists(atPath: woW64Kernel32(in: bottle).path)
+ }
+
+ /// Quiet self-heal before a launch: when the 32-bit half is missing, re-run the first boot
+ /// (with the mscoree set-aside and the 32-bit seeding refreshPrefix carries) instead of
+ /// letting the launch fail and sending the user to find "Repair bottle".
+ public static func preflight(runner: WineRunner, bottle: Bottle, log: ((String) -> Void)? = nil) async throws {
+ guard needsPreflightRepair(bottle) else { return }
+ log?("bottle '\(bottle.name)': 32-bit half missing, repairing before launch")
+ try await refreshPrefix(runner: runner, bottle: bottle)
+ }
+
/// Re-runs the Windows first boot on an existing bottle and the per-bottle setup that boot
/// resets: the 32-bit half check (#37), the GPU identity, the service timeout and the
/// keyboard mapping. Repair, an engine switch and the CLI's repair all go through here;
diff --git a/Sources/HighballKit/LogPruner.swift b/Sources/HighballKit/LogPruner.swift
new file mode 100644
index 0000000..d1a6d22
--- /dev/null
+++ b/Sources/HighballKit/LogPruner.swift
@@ -0,0 +1,54 @@
+import Foundation
+
+/// Keeps Highball's log directory bounded. One file per launch under `fixme-all` is small, but
+/// a week of investigations with debug channels on left 3.8 GB behind (2026-09-04), and nobody
+/// prunes a directory they never open. The policy is pure so it can be tested; `prune` applies it.
+public enum LogPruner {
+ public struct Entry: Equatable, Sendable {
+ public let url: URL
+ public let size: Int64
+ public let modified: Date
+ public init(url: URL, size: Int64, modified: Date) { self.url = url; self.size = size; self.modified = modified }
+ }
+
+ /// Files that never go: the verifier's results are the database's provenance.
+ static let keepAlways: Set<String> = ["verify-results.jsonl"]
+
+ /// Deletes, in order: anything older than `keepDays` beyond the newest `keepNewest` files,
+ /// then the oldest of what remains until the total is at most `maxTotalBytes`. The newest
+ /// `keepNewest` files are never removed by the size rule either, so the log a user is about
+ /// to attach to a report still exists.
+ public static func plan(_ entries: [Entry], now: Date = Date(), keepDays: Int = 14,
+ maxTotalBytes: Int64 = 300 * 1024 * 1024, keepNewest: Int = 50) -> [URL] {
+ let candidates = entries.filter { !keepAlways.contains($0.url.lastPathComponent) }
+ .sorted { $0.modified > $1.modified } // newest first
+ var remove: [URL] = []
+ var kept: [Entry] = []
+ let cutoff = now.addingTimeInterval(-Double(keepDays) * 86_400)
+ for (i, e) in candidates.enumerated() {
+ if i >= keepNewest && e.modified < cutoff { remove.append(e.url) } else { kept.append(e) }
+ }
+ var total = kept.reduce(Int64(0)) { $0 + $1.size }
+ for e in kept.reversed() where total > maxTotalBytes { // oldest first
+ guard let idx = kept.firstIndex(of: e), idx >= keepNewest else { break }
+ remove.append(e.url); total -= e.size
+ }
+ return remove
+ }
+
+ /// Applies `plan` to a directory. Errors on single files are ignored: a log held open by a
+ /// running process is simply pruned next time.
+ @discardableResult
+ public static func prune(directory: URL, now: Date = Date()) -> Int {
+ let fm = FileManager.default
+ guard let urls = try? fm.contentsOfDirectory(at: directory, includingPropertiesForKeys: [.fileSizeKey, .contentModificationDateKey]) else { return 0 }
+ let entries: [Entry] = urls.compactMap { url in
+ guard let v = try? url.resourceValues(forKeys: [.fileSizeKey, .contentModificationDateKey, .isRegularFileKey]),
+ v.isRegularFile == true else { return nil }
+ return Entry(url: url, size: Int64(v.fileSize ?? 0), modified: v.contentModificationDate ?? .distantPast)
+ }
+ let doomed = plan(entries, now: now)
+ for url in doomed { try? fm.removeItem(at: url) }
+ return doomed.count
+ }
+}
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 27f6e2d..d35bf9f 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -316,6 +316,7 @@ struct Run: AsyncParsableCommand {
let b = try BottleStore().get(bottle)
let eng = try EngineStore().engine(b.settings.engineID)
let runner = WineRunner(engine: eng, bottle: b)
+ try await BottleStore.preflight(runner: runner, bottle: b) { print($0) }
let echo: @Sendable (String) -> Void = { print($0) }
let out: (@Sendable (String) -> Void)? = verbose ? echo : nil
let result: LaunchResult
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index 3231246..2e266c1 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -932,6 +932,35 @@ extension RegressionTests {
XCTAssertEqual(Verifier.servedImplementation(fromLog: other), "none")
}
+ // Log pruning: age beyond the newest N, then size, never the verifier's results.
+ func testLogPrunerPolicy() {
+ let now = Date(timeIntervalSince1970: 1_800_000_000)
+ func e(_ name: String, daysOld: Double, mb: Int64) -> LogPruner.Entry {
+ LogPruner.Entry(url: URL(fileURLWithPath: "/logs/\(name)"), size: mb * 1_048_576, modified: now.addingTimeInterval(-daysOld * 86_400))
+ }
+ let entries = [e("old1", daysOld: 30, mb: 1), e("old2", daysOld: 20, mb: 1), e("fresh", daysOld: 1, mb: 1),
+ e("verify-results.jsonl", daysOld: 100, mb: 1), e("big-old", daysOld: 10, mb: 400), e("big-new", daysOld: 0.5, mb: 400)]
+ let byAge = LogPruner.plan(entries, now: now, keepDays: 14, maxTotalBytes: 10_000 * 1_048_576, keepNewest: 2)
+ XCTAssertEqual(Set(byAge.map(\.lastPathComponent)), ["old1", "old2"], "older than 14 days and not among the newest two")
+ let bySize = LogPruner.plan(entries, now: now, keepDays: 14, maxTotalBytes: 500 * 1_048_576, keepNewest: 2)
+ XCTAssertTrue(bySize.map(\.lastPathComponent).contains("big-old"), "size rule removes the oldest big file")
+ XCTAssertFalse(bySize.map(\.lastPathComponent).contains("big-new"), "the newest files are never removed for size")
+ XCTAssertFalse(bySize.map(\.lastPathComponent).contains("verify-results.jsonl"))
+ XCTAssertEqual(LogPruner.plan(entries, now: now, keepDays: 14, maxTotalBytes: 10_000 * 1_048_576, keepNewest: 10).count, 0, "everything within the newest ten stays")
+ }
+
+ // Preflight: the 32-bit half check is a file test, so it is free on the happy path.
+ func testPreflightNeedsRepairOnlyWithoutSyswow64() throws {
+ let dir = FileManager.default.temporaryDirectory.appending(path: "hb-preflight-\(UUID().uuidString)")
+ let bottle = Bottle(url: dir, settings: BottleSettings(name: "p", engineID: "e"))
+ XCTAssertTrue(BottleStore.needsPreflightRepair(bottle))
+ let k32 = dir.appending(path: "drive_c/windows/syswow64/kernel32.dll")
+ try FileManager.default.createDirectory(at: k32.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try Data().write(to: k32)
+ XCTAssertFalse(BottleStore.needsPreflightRepair(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":{}}"#