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
Epic saves: an install's files come from the manifest legendary kept, read offline with list-files --manifest
Gabed9f7d9b3c5c2
diff --git a/Sources/HighballKit/EpicStore.swift b/Sources/HighballKit/EpicStore.swiftindex 58be246..7527f28 100644--- a/Sources/HighballKit/EpicStore.swift+++ b/Sources/HighballKit/EpicStore.swift@@ -187,15 +187,40 @@ public struct EpicStore: Sendable {}/// The files legendary installed for a game, by its installed manifest, as paths relative to- /// the install folder. Read locally, with no sign-in, while the game is installed (cli.py- /// `list_files` loads the installed manifest unless asked to download one). Throws when- /// legendary has no manifest for it.+ /// the install folder. Read offline, with no sign-in, from the manifest file legendary keeps+ /// for the installed version (`list-files --manifest`): `list-files <app>` signs in and+ /// downloads one in 0.21.0, since `main()` always sets a platform. Throws when legendary has+ /// no manifest for it.public func installedFiles(_ appName: String) throws -> [String] {+ guard let manifest = installedManifest(appName) else {+ throw HighballError.failed("legendary has no manifest for \(appName)")+ }struct File: Decodable { let filename: String }- let out = try capture(Self.listFilesArguments(appName: appName))+ let out = try capture(Self.listFilesArguments(manifest: manifest))return try JSONDecoder().decode([File].self, from: Data(out.utf8)).map(\.filename)}- static func listFilesArguments(appName: String) -> [String] { ["list-files", appName, "--json"] }+ static func listFilesArguments(manifest: URL) -> [String] { ["list-files", "--manifest", manifest.path, "--json"] }++ /// The manifest file legendary keeps for a game's installed version, nil when there is none.+ func installedManifest(_ appName: String) -> URL? {+ guard let data = try? Data(contentsOf: configDir.appending(path: "installed.json")),+ let all = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any],+ let entry = all[appName] as? [String: Any] else { return nil }+ return Self.manifestNames(appName, entry: entry)+ .map { configDir.appending(path: "manifests/\($0)") }+ .first { FileManager.default.fileExists(atPath: $0.path) }+ }++ /// The names legendary saves an installed version's manifest under (lgndry.py+ /// `_get_manifest_filename`): with its platform, or without it for an older install.+ static func manifestNames(_ appName: String, entry: [String: Any]) -> [String] {+ guard let version = entry["version"] as? String else { return [] }+ let platform = entry["platform"] as? String ?? "Windows"+ return ["\(appName)_\(platform)_\(version)", "\(appName)_\(version)"].map { cleanFilename($0) + ".manifest" }+ }++ /// legendary's clean_filename: the characters a file name cannot hold, dropped.+ static func cleanFilename(_ name: String) -> String { name.filter { !"<>:\"/\\|?*".contains($0) } }/// Legendary's install records, app name to path, keeping only the ones whose folder still/// exists. Legendary never notices a removed environment or a deleted game folder, and adiff --git a/Tests/HighballKitTests/EpicFakeLegendaryTests.swift b/Tests/HighballKitTests/EpicFakeLegendaryTests.swiftindex f744c7a..17d0d9c 100644--- a/Tests/HighballKitTests/EpicFakeLegendaryTests.swift+++ b/Tests/HighballKitTests/EpicFakeLegendaryTests.swift@@ -42,7 +42,8 @@ final class EpicFakeLegendaryTests: XCTestCase {}private func installed(savePath: String?) throws {- let game: [String: Any] = ["app_name": app, "title": "Game", "install_path": install.path, "save_path": savePath ?? NSNull()]+ let game: [String: Any] = ["app_name": app, "title": "Game", "install_path": install.path, "save_path": savePath ?? NSNull(),+ "version": "1.0", "platform": "Windows"]try JSONSerialization.data(withJSONObject: [app: game]).write(to: config.appending(path: "installed.json"))}private func write(_ text: String, to url: URL, at date: Date) throws {@@ -276,7 +277,10 @@ final class EpicFakeLegendaryTests: XCTestCase {}private func manifest(_ app: String, _ names: [String]) throws {- try JSONSerialization.data(withJSONObject: names).write(to: home.appending(path: "fake-manifest-\(app).json"))+ // Where legendary keeps the installed version's manifest; the stand-in's is a JSON list.+ let file = config.appending(path: "manifests/\(app)_Windows_1.0.manifest")+ try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)+ try JSONSerialization.data(withJSONObject: names).write(to: file)}private func relative(_ backup: URL) -> [String] { SaveBackups.files(in: backup).map { SaveBackups.relativePath($0, in: backup) } }@@ -285,8 +289,8 @@ final class EpicFakeLegendaryTests: XCTestCase {/// manifest names is the game's. With no manifest, or one whose names aren't on disk (an/// encrypted one lists obfuscated names), and no history, nothing tells them apart.func testKeepCopiesWhatNoManifestNames() throws {- let game: [String: Any] = ["app_name": app, "title": "Game", "install_path": install.path]- let dlc: [String: Any] = ["app_name": "GameDLC", "title": "DLC", "install_path": install.path]+ let game: [String: Any] = ["app_name": app, "title": "Game", "install_path": install.path, "version": "1.0", "platform": "Windows"]+ let dlc: [String: Any] = ["app_name": "GameDLC", "title": "DLC", "install_path": install.path, "version": "1.0", "platform": "Windows"]try JSONSerialization.data(withJSONObject: [app: game, "GameDLC": dlc]).write(to: config.appending(path: "installed.json"))let old = dayAgo.addingTimeInterval(-86_400)for name in ["Game.exe", "Data/base.pak", "DLC/extra.pak", "Config/Default.ini"] {@@ -352,15 +356,16 @@ final class EpicFakeLegendaryTests: XCTestCase {config = os.environ['LEGENDARY_CONFIG_PATH']installed_file = os.path.join(config, 'installed.json')installed = json.load(open(installed_file))- app = args[1]- manifest = os.path.join(os.path.dirname(config), f'fake-manifest-{app}.json')- names = json.load(open(manifest)) if os.path.exists(manifest) else Noneif args[0] == 'list-files':- # cli.py list_files: the installed manifest, read locally; with none on disk,- # load_manifest(None) raises and legendary exits non-zero.- if app not in installed or names is None: sys.exit(1)+ # cli.py list_files: --manifest reads that file offline. Without it, main() has set a+ # platform, so legendary signs in and downloads one, which fails here.+ if '--manifest' not in args: sys.exit(1)+ names = json.load(open(args[args.index('--manifest') + 1]))print(json.dumps([dict(filename=n, sha_hash='00', install_tags=[], file_size=0, flags=0) for n in names]))sys.exit(0)+ app = args[1]+ manifest = os.path.join(config, 'manifests', f'{app}_Windows_1.0.manifest')+ names = json.load(open(manifest)) if os.path.exists(manifest) else None# core.py uninstall_game, utils.py delete_filelist: the manifest's files, the folders they# leave empty, the root only if nothing else is in it (os.rmdir), then the record.if app not in installed: sys.exit(0)