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 Mac build's size is never the Windows build's

Gabe0e343926cf6d
diff --git a/Sources/HighballKit/GameSizes.swift b/Sources/HighballKit/GameSizes.swift
index 2bd749b..ff390f5 100644
--- a/Sources/HighballKit/GameSizes.swift
+++ b/Sources/HighballKit/GameSizes.swift
@@ -41,17 +41,27 @@ extension EpicStore {
/// takes, from its manifest: the bytes fetched and the installed size. Throws when legendary's
/// answer has no manifest to read, so an answer that says nothing is never kept as the size.
public func downloadEstimate(_ appName: String, platform: String = "Windows") throws -> DownloadEstimate {
- let out = try capture(["info", appName, "--json", "--platform", platform])
- guard let estimate = Self.parseEstimate(Data(out.utf8)) else {
+ let (out, log) = try captureWithLog(["info", appName, "--json", "--platform", platform])
+ guard let estimate = Self.parseEstimate(Data(out.utf8), log: log, platform: platform) else {
throw HighballError.invalid("legendary info gave no manifest for \(appName) (\(platform))")
}
return estimate
}
- static func parseEstimate(_ data: Data) -> DownloadEstimate? {
- guard let start = data.firstIndex(of: UInt8(ascii: "{")),
- let obj = try? JSONSerialization.jsonObject(with: data[start...]) as? [String: Any],
- let manifest = obj["manifest"] as? [String: Any] else { return nil }
+ /// The sizes in legendary's manifest. The Mac build's count only from its own manifest
+ /// (EpicStore.manifest): with the Mac asset missing, legendary prints the installed Windows
+ /// build's instead, which would show as the Mac build's size.
+ static func parseEstimate(_ data: Data, log: String = "", platform: String = "Windows") -> DownloadEstimate? {
+ let found: [String: Any]?
+ if platform == "Mac" {
+ found = manifest(data, log: log, platform: platform)
+ } else if let start = data.firstIndex(of: UInt8(ascii: "{")),
+ let obj = try? JSONSerialization.jsonObject(with: data[start...]) as? [String: Any] {
+ found = obj["manifest"] as? [String: Any]
+ } else {
+ found = nil
+ }
+ guard let manifest = found else { return nil }
return DownloadEstimate(download: (manifest["download_size"] as? NSNumber)?.int64Value,
disk: (manifest["disk_size"] as? NSNumber)?.int64Value)
}
diff --git a/Tests/HighballKitTests/GameSizesTests.swift b/Tests/HighballKitTests/GameSizesTests.swift
index d5efa05..e485080 100644
--- a/Tests/HighballKitTests/GameSizesTests.swift
+++ b/Tests/HighballKitTests/GameSizesTests.swift
@@ -28,6 +28,19 @@ final class GameSizesTests: XCTestCase {
XCTAssertNil(EpicStore.parseEstimate(Data("no json".utf8)))
}
+ /// With the Mac asset gone, legendary warns, answers offline and prints the installed Windows
+ /// build's manifest: that is never shown as the Mac build's size.
+ func testEpicMacEstimateIgnoresTheWindowsManifestLegendaryFallsBackTo() {
+ let windowsOnly = #"{"game": {"platform_versions": {"Windows": "2.1.9a"}}, "install": {}, "manifest": {"build_version": "2.1.9a", "disk_size": 1, "download_size": 2}}"#
+ XCTAssertNil(EpicStore.parseEstimate(Data(windowsOnly.utf8), platform: "Mac"))
+ XCTAssertEqual(EpicStore.parseEstimate(Data(windowsOnly.utf8), platform: "Windows"), DownloadEstimate(download: 2, disk: 1))
+ let listedButOffline = #"{"game": {"platform_versions": {"Mac": "3 OSX", "Windows": "2.1.9a"}}, "manifest": {"build_version": "2.1.9a", "disk_size": 1, "download_size": 2}}"#
+ XCTAssertNil(EpicStore.parseEstimate(Data(listedButOffline.utf8), platform: "Mac"))
+ let mac = #"{"game": {"platform_versions": {"Mac": "3 OSX"}}, "manifest": {"build_version": "3 OSX", "disk_size": 1, "download_size": 2}}"#
+ XCTAssertNil(EpicStore.parseEstimate(Data(mac.utf8), log: #"[Core] WARNING: Asset information for "A" is missing"#, platform: "Mac"))
+ XCTAssertEqual(EpicStore.parseEstimate(Data(mac.utf8), platform: "Mac"), DownloadEstimate(download: 2, disk: 1))
+ }
+
func testEpicInstallRecordKeepsSizeAndSaveFolder() throws {
let json = #"[{"app_name":"Garlic","install_path":"/x","install_size":356045656,"save_path":"/s"},{"app_name":"Old","install_path":"/y"}]"#
let games = try JSONDecoder().decode([EpicStore.InstalledGame].self, from: Data(json.utf8))