Skip to content

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

An Epic game's install shows its size, progress bar and download speed in the activity strip (highball#287). legendary prints the download's size before it starts ("Download size: 95232.19 MiB") and how much has arrived about once a second (" - Downloaded: 9075.51 MiB, Written: ..."). The strip only showed the elapsed time beside "a large download", so a player watched the log scroll to learn where a 100 GB download stood. Those two lines now feed the same bar, bytes and measured rate an engine download uses, and sizes from a gigabyte up read in gigabytes ("8.9 of 93.0 GB · 27.9 MB/s"). legendary's own time estimate stays in Details: the strip predicts nothing, as before. Tested with the lines from the reporter's screenshot, and other legendary lines (progress, cache, rates, install size) parse as nothing.

Gauthier Piarrettec9f59d1a304b
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 2c05357..e56f10d 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -1168,15 +1168,35 @@ final class AppState {
/// Feeds the strip from a component download: a plain stage, moving bytes, a measured rate.
private func reportDownload(_ name: String, received: Int64, total: Int64?) {
let total = (total ?? 0) > 0 ? total : nil
+ recordTransfer(received: received, total: total)
+ stage = String(format: L("Downloading %@"), name)
+ if let total, received >= total {
+ appendLog("downloaded \(name), verifying and unpacking…")
+ busyProgress = nil; transferRate = nil; transferSamples = []
+ }
+ }
+
+ /// Moving bytes and the rate measured from them, for the strip's bar and numbers.
+ private func recordTransfer(received: Int64, total: Int64?) {
if let last = transferSamples.last, received < last.bytes { transferSamples = [] } // next component
transferSamples.append(.init(bytes: received, at: Date()))
if transferSamples.count > 40 { transferSamples.removeFirst(transferSamples.count - 40) }
transferRate = ActivityText.rate(transferSamples)
busyProgress = Transfer(received: received, total: total)
- stage = String(format: L("Downloading %@"), name)
- if let total, received >= total {
- appendLog("downloaded \(name), verifying and unpacking…")
- busyProgress = nil; transferRate = nil; transferSamples = []
+ }
+
+ /// The size legendary announced for the Epic download in progress, nil until it does.
+ private var epicDownloadTotal: Int64?
+
+ /// legendary prints the download's size, then how much has arrived about once a second. The
+ /// strip shows them as it does an engine download's: bar, bytes and measured rate, never
+ /// legendary's own time estimate, which stays in Details (ActivityText predicts nothing,
+ /// highball#287).
+ private func reportEpicDownload(_ line: String) {
+ if let total = EpicStore.downloadSize(inLegendaryLine: line) {
+ epicDownloadTotal = total > 0 ? total : nil
+ } else if busy, let received = EpicStore.downloaded(inLegendaryLine: line) {
+ recordTransfer(received: received, total: epicDownloadTotal)
}
}
@@ -2565,9 +2585,10 @@ final class AppState {
runBusy("Installing \(game.app_title)", expected: L("a large download; you can leave it running"),
stop: .cancelTask(label: L("Stop"))) { [self] in
let store = epicStore
+ epicDownloadTotal = nil
let status = try await Task.detached {
try store.install(game.app_name, into: bottle) { line in
- Task { @MainActor in self.appendLog(line) }
+ Task { @MainActor in self.appendLog(line); self.reportEpicDownload(line) }
}
}.value
guard status == 0 else {
diff --git a/Sources/HighballKit/ActivityText.swift b/Sources/HighballKit/ActivityText.swift
index 6895b5d..d1fb264 100644
--- a/Sources/HighballKit/ActivityText.swift
+++ b/Sources/HighballKit/ActivityText.swift
@@ -28,17 +28,21 @@ public enum ActivityText {
}
/// "164 of 270 MB · 2.4 MB/s"; "240 KB" before the first megabyte so a live copy is not
- /// stuck on "0 MB".
+ /// stuck on "0 MB", and "9.1 of 93.0 GB" from a gigabyte up, for a game download.
public static func transfer(received: Int64, total: Int64?, rate: Double?) -> String {
var parts: [String] = []
if let total, total > 0 {
- if total < 1_048_576 {
+ if total >= 1 << 30 {
+ parts.append("\(gigabytes(received)) of \(gigabytes(total)) GB")
+ } else if total < 1_048_576 {
parts.append("\(received / 1024) of \(total / 1024) KB")
} else {
parts.append("\(megabytes(received)) of \(megabytes(total)) MB")
}
} else if received < 1_048_576 {
parts.append("\(received / 1024) KB")
+ } else if received >= 1 << 30 {
+ parts.append("\(gigabytes(received)) GB")
} else {
parts.append("\(megabytes(received)) MB")
}
@@ -71,6 +75,10 @@ public enum ActivityText {
return s < 60 ? (s, true) : (s / 60, false)
}
+ static func gigabytes(_ bytes: Int64) -> String {
+ String(format: "%.1f", Double(bytes) / 1_073_741_824)
+ }
+
static func megabytes(_ bytes: Int64) -> String {
String(format: "%.0f", Double(bytes) / 1_048_576)
}
diff --git a/Sources/HighballKit/EpicStore.swift b/Sources/HighballKit/EpicStore.swift
index f3d445d..93d0f18 100644
--- a/Sources/HighballKit/EpicStore.swift
+++ b/Sources/HighballKit/EpicStore.swift
@@ -194,6 +194,21 @@ public struct EpicStore: Sendable {
return try runStreaming(Self.installArguments(appName: appName, basePath: base.path), onLine: onLine)
}
+ /// legendary's install log names the download's size before it starts ("Download size:
+ /// 95232.19 MiB (Compression savings: 2.1%)") and then, about once a second, how much has
+ /// arrived (" - Downloaded: 9075.51 MiB, Written: 9415.55 MiB"). The activity strip shows
+ /// them like an engine download's bytes (highball#287). Bytes, or nil for any other line.
+ public static func downloadSize(inLegendaryLine line: String) -> Int64? { mebibytes(after: "Download size:", in: line) }
+ public static func downloaded(inLegendaryLine line: String) -> Int64? { mebibytes(after: "- Downloaded:", in: line) }
+
+ private static func mebibytes(after label: String, in line: String) -> Int64? {
+ guard let r = line.range(of: label) else { return nil }
+ let rest = line[r.upperBound...].drop { $0 == " " }
+ let number = rest.prefix { $0.isNumber || $0 == "." }
+ guard !number.isEmpty, rest.dropFirst(number.count).hasPrefix(" MiB"), let value = Double(number) else { return nil }
+ return Int64(value * 1_048_576)
+ }
+
static func uninstallArguments(appName: String) -> [String] { ["uninstall", appName, "-y"] }
/// Removes a game legendary installed. Legendary owns the Epic install state, so it does the
diff --git a/Tests/HighballKitTests/ActivityTextTests.swift b/Tests/HighballKitTests/ActivityTextTests.swift
index 398d57e..8b62d7c 100644
--- a/Tests/HighballKitTests/ActivityTextTests.swift
+++ b/Tests/HighballKitTests/ActivityTextTests.swift
@@ -33,6 +33,12 @@ final class ActivityTextTests: XCTestCase {
XCTAssertEqual(ActivityText.transfer(received: 5 << 20, total: 0, rate: 640 * 1024), "5 MB · 640 KB/s")
XCTAssertEqual(ActivityText.transfer(received: 240 * 1024, total: nil, rate: nil), "240 KB")
XCTAssertEqual(ActivityText.transfer(received: 0, total: nil, rate: nil), "0 KB")
+ // A game download reads in gigabytes (highball#287): GTA V Enhanced's 93 GB from Epic.
+ XCTAssertEqual(ActivityText.transfer(received: Int64(9075.51 * 1_048_576), total: Int64(95232.19 * 1_048_576), rate: 27.94 * 1_048_576),
+ "8.9 of 93.0 GB · 27.9 MB/s")
+ XCTAssertEqual(ActivityText.transfer(received: 512 << 20, total: 2 << 30, rate: nil), "0.5 of 2.0 GB")
+ XCTAssertEqual(ActivityText.transfer(received: 3 << 30, total: nil, rate: nil), "3.0 GB")
+ XCTAssertEqual(ActivityText.transfer(received: 900 << 20, total: 1000 << 20, rate: nil), "900 of 1000 MB", "under a gigabyte stays in megabytes")
}
func testFractionAndSteps() {
diff --git a/Tests/HighballKitTests/EpicStoreTests.swift b/Tests/HighballKitTests/EpicStoreTests.swift
index ab9111d..cd4047b 100644
--- a/Tests/HighballKitTests/EpicStoreTests.swift
+++ b/Tests/HighballKitTests/EpicStoreTests.swift
@@ -4,6 +4,23 @@ import XCTest
final class EpicStoreTests: XCTestCase {
/// Legendary has no terminal under Highball: the selective-download prompt (optional
/// language packs) raised EOFError and killed the install (#110). `-y` alone does not skip it.
+ /// legendary's lines as a GTA V Enhanced install printed them (highball#287): the size once,
+ /// then the amount downloaded, which the activity strip turns into a bar and bytes.
+ func testLegendarySizeAndProgressLines() {
+ XCTAssertEqual(EpicStore.downloadSize(inLegendaryLine: "[cli] INFO: Download size: 95232.19 MiB (Compression savings: 2.1%)"),
+ Int64(95232.19 * 1_048_576))
+ XCTAssertEqual(EpicStore.downloaded(inLegendaryLine: "[DLManager] INFO: - Downloaded: 9075.51 MiB, Written: 9415.55 MiB"),
+ Int64(9075.51 * 1_048_576))
+ for other in ["[DLManager] INFO: = Progress: 10.07% (10035/99671), Running for 00:06:22, ETA: 00:56:57",
+ "[DLManager] INFO: - Cache usage: 463.00 MiB, active tasks: 32",
+ "[DLManager] INFO: + Download\t- 27.94 MiB/s (raw) / 27.94 MiB/s (decompressed)",
+ "[cli] INFO: Install size: 97000.00 MiB",
+ "[DLManager] INFO: - Downloaded: n/a"] {
+ XCTAssertNil(EpicStore.downloadSize(inLegendaryLine: other), other)
+ XCTAssertNil(EpicStore.downloaded(inLegendaryLine: other), other)
+ }
+ }
+
func testInstallAnswersEveryPromptOnTheCommandLine() {
let args = EpicStore.installArguments(appName: "Phoenix", basePath: "/c/Games")
XCTAssertTrue(args.contains("-y"))