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
GOG saves: an install from before the history counts from its earliest date, and a refusal before Play is logged
Gabe94445acfe578
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 0d238b6..57a6afb 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -3987,7 +3987,11 @@ final class AppState {// Before Play: this Mac's saves are newer, and the upload after the game takes them.// After the game: GOG's cloud is newer and this Mac's saves didn't change, so there was// nothing to upload; the download before the next Play brings the cloud's down.- if !beforePlay { appendLog("\(title): GOG's cloud has newer saves, so nothing was uploaded; they come down before the next Play") }+ if beforePlay {+ appendLog("\(title): this Mac has newer saves than GOG's cloud, so nothing was downloaded; they go up after the game")+ } else {+ appendLog("\(title): GOG's cloud has newer saves, so nothing was uploaded; they come down before the next Play")+ }return falsecase let .failed(why):appendLog("\(title): cloud saves did not sync (\(why)); \(beforePlay ? "playing with the saves on this Mac" : "they stay on this Mac until the next sync")")diff --git a/Sources/HighballKit/GOGLibrary.swift b/Sources/HighballKit/GOGLibrary.swiftindex 4481fa3..e811096 100644--- a/Sources/HighballKit/GOGLibrary.swift+++ b/Sources/HighballKit/GOGLibrary.swift@@ -553,8 +553,8 @@ extension GOGStore {driveC.appending(path: "highball/gog-setup/\(game.id).history.json")}- /// An install set up before the history was kept falls back to the marker's date for its- /// first setup. One Highball never set up (an offline installer's: no manifest, so no setup+ /// An install set up before the history was kept falls back to the earliest of its marker's,+ /// info file's and folder's dates for its first setup (storedHistory). One Highball never set up (an offline installer's: no manifest, so no setup/// and no marker) falls back to when its goggame-<id>.info file landed on this disk, which/// the install wrote. nil firstSetup: none of them exists, so nothing tells the game's files/// from the installer's.@@ -564,14 +564,19 @@ extension GOGStore {return history}- /// The history file, or the marker's date. Not the info file's: setup and updates record- /// from this, and setup runs after gogdl wrote the info file, so what it put down would- /// count as the game's.+ /// The history file, or for an install set up before it was kept (a marker, no history) the+ /// earliest of the marker's date, the info file's and the game folder's creation: setup+ /// rewrote the marker on every update before the history was kept, so the marker alone would+ /// leave out saves written before the last update. That can also count files an old update+ /// rewrote, which only copies more. Not the info file's for an install with no marker: setup+ /// and updates record from this, and setup runs after gogdl wrote the info file, so what it+ /// put down would count as the game's.private static func storedHistory(for game: InstalledGame, driveC: URL) -> InstallHistory {var history = (try? Data(contentsOf: historyFile(for: game, driveC: driveC))).flatMap { try? JSONDecoder().decode(InstallHistory.self, from: $0) } ?? InstallHistory()- if history.firstSetup == nil {- history.firstSetup = try? setupMarker(for: game, driveC: driveC).resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate+ if history.firstSetup == nil,+ let marked = try? setupMarker(for: game, driveC: driveC).resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate {+ history.firstSetup = [marked, installedDate(of: game)].compactMap { $0 }.min()}return history}diff --git a/Tests/HighballKitTests/GOGSaveSafetyTests.swift b/Tests/HighballKitTests/GOGSaveSafetyTests.swiftindex b698fd6..a09f788 100644--- a/Tests/HighballKitTests/GOGSaveSafetyTests.swift+++ b/Tests/HighballKitTests/GOGSaveSafetyTests.swift@@ -265,6 +265,30 @@ final class GOGSaveSafetyTests: XCTestCase {XCTAssertEqual(GOGStore.history(for: game, driveC: driveC).firstSetup, marked, "the marker's old date, read before it is rewritten")}+ /// An install updated before the history was kept: the update rewrote the marker, so a save+ /// written beside the exe before it is older than the marker. The install counts from the+ /// earliest of the marker, the info file and the folder, so Keep still copies that save.+ func testAnInstallUpdatedBeforeTheHistoryCountsFromItsEarliestDate() throws {+ let saves = GOGSaves(store: GOGStore(paths: HighballPaths(home: root.appending(path: "home"))))+ let driveC = root.appending(path: "drive_c")+ let game = GOGStore.InstalledGame(id: "7", title: "Game", folder: driveC.appending(path: "GOG Games/Game"), buildID: "b2", clientID: nil, dlcIDs: [], tasks: [])+ let installed = Date().addingTimeInterval(-86400 * 30)+ let updated = Date().addingTimeInterval(-86400)+ let info = game.folder.appending(path: "goggame-7.info")+ try write(#"{"gameId":"7","name":"Game"}"#, to: info, dated: updated)+ try FileManager.default.setAttributes([.creationDate: installed], ofItemAtPath: info.path)+ try FileManager.default.setAttributes([.creationDate: installed], ofItemAtPath: game.folder.path)+ try write("b2", to: GOGStore.setupMarker(for: game, driveC: driveC), dated: updated)+ try write("exe", to: game.folder.appending(path: "game.exe"), dated: installed.addingTimeInterval(-86400))+ try write("save", to: game.folder.appending(path: "slot1.sav"), dated: installed.addingTimeInterval(86400))+ XCTAssertEqual(GOGStore.history(for: game, driveC: driveC).firstSetup, installed)+ let copy = try XCTUnwrap(try saves.backUpGameFolder(game, driveC: driveC))+ XCTAssertEqual(try GOGSaves.files(in: copy).map { GOGSaves.relativePath(of: $0, in: copy) }, ["slot1.sav"])+ // The next setup stores that date, not the marker's.+ GOGStore.markSetupDone(for: game, driveC: driveC)+ XCTAssertEqual(GOGStore.history(for: game, driveC: driveC).firstSetup, installed)+ }+/// An offline installer's game (no manifest, so never set up and no marker) counts from when/// its goggame-<id>.info file was created, or its folder if earlier (a patch rewrites the/// info file). The installer's files, dated when they were built, and its records at the top