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: the put-back question never answers the next game's, and reads kept saves once
Gabe031bd0b756ea
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 7317ac7..c5203b3 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -4056,9 +4056,11 @@ final class AppState {private func offerKeptGOGSaves() {guard gogSavesToPutBack == nil else { return }let saves = GOGSaves(store: gogStore)+ let all = saves.keptSaves() // one read, not one per installed game+ guard !all.isEmpty else { return }for bottle in bottles {for game in gogInstalledByBottle[bottle.name] ?? [] {- guard let kept = saves.keptSavesToOffer(game),+ guard let kept = GOGSaves.toOffer(all[game.id], to: game),!gogStore.hasManifest(game) || GOGStore.setupDone(for: game, driveC: bottle.driveC),!runningSessions.contains(where: { $0.libraryID == "gog:\(game.id)" && $0.bottleName == bottle.name }) else { continue }gogSavesToPutBack = GOGSavesToPutBack(game: game, title: game.title, kept: kept)diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex 9e13da8..65acd08 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -563,7 +563,9 @@ private extension View {@MainActor func gogPutBackSavesAsk(_ state: AppState) -> some View {self.alert(state.gogSavesToPutBack.map { String(format: L("Put back your saves from %@?"),$0.kept.date.formatted(date: .abbreviated, time: .omitted)) } ?? "",- isPresented: .init(get: { state.gogSavesToPutBack != nil }, set: { if !$0 { state.gogPutBackSaves(false) } }),+ // The buttons answer (Escape is Not now); the dismissal that follows must not answer+ // the next game's question, which an answer may already have raised.+ isPresented: .init(get: { state.gogSavesToPutBack != nil }, set: { _ in }),presenting: state.gogSavesToPutBack) { _ inButton(L("Put them back")) { state.gogPutBackSaves(true) }.keyboardShortcut(.defaultAction)Button(L("Not now"), role: .cancel) { state.gogPutBackSaves(false) }diff --git a/Sources/HighballKit/GOGSaves.swift b/Sources/HighballKit/GOGSaves.swiftindex 11c148b..ca9758b 100644--- a/Sources/HighballKit/GOGSaves.swift+++ b/Sources/HighballKit/GOGSaves.swift@@ -749,9 +749,9 @@ public struct GOGSaves: Sendable {updateKeptSaves { $0[game.id]?.asked.append(game.folder.standardizedFileURL.path) }}- /// Whether this install has kept saves it hasn't been asked about.- public func keptSavesToOffer(_ game: GOGStore.InstalledGame) -> KeptSaves? {- guard let kept = keptSaves()[game.id], !kept.asked.contains(game.folder.standardizedFileURL.path) else { return nil }+ /// The kept saves to offer this install: nil when there are none or it was asked already.+ public static func toOffer(_ kept: KeptSaves?, to game: GOGStore.InstalledGame) -> KeptSaves? {+ guard let kept, !kept.asked.contains(game.folder.standardizedFileURL.path) else { return nil }return kept}diff --git a/Tests/HighballKitTests/GOGSaveSafetyTests.swift b/Tests/HighballKitTests/GOGSaveSafetyTests.swiftindex 46afcff..134bd69 100644--- a/Tests/HighballKitTests/GOGSaveSafetyTests.swift+++ b/Tests/HighballKitTests/GOGSaveSafetyTests.swift@@ -313,16 +313,16 @@ final class GOGSaveSafetyTests: XCTestCase {only: [old.folder.appending(path: "Profiles/p1.sav")]))saves.keep([(location.name, old.folder.appending(path: "saves"), named), (GOGSaves.gameFolder.name, old.folder, written)],of: old, otherInstalls: [elsewhere.folder])- XCTAssertNil(saves.keptSavesToOffer(elsewhere))+ XCTAssertNil(GOGSaves.toOffer(saves.keptSaves()[elsewhere.id], to: elsewhere))try write("fresh", to: new.folder.appending(path: "saves/slot.sav"))- let kept = try XCTUnwrap(saves.keptSavesToOffer(new))+ let kept = try XCTUnwrap(GOGSaves.toOffer(saves.keptSaves()[new.id], to: new))XCTAssertEqual(try saves.putBack(kept, into: new), 2)XCTAssertEqual(try String(contentsOf: new.folder.appending(path: "saves/slot.sav"), encoding: .utf8), "cloud slot")XCTAssertEqual(try String(contentsOf: new.folder.appending(path: "Profiles/p1.sav"), encoding: .utf8), "local slot")let before = try XCTUnwrap(saves.backups(in: saves.backupsFolder(new, location)).first)XCTAssertEqual(try String(contentsOf: before.appending(path: "slot.sav"), encoding: .utf8), "fresh", "what was there is copied first")saves.markAsked(new)- XCTAssertNil(saves.keptSavesToOffer(new), "asked once")+ XCTAssertNil(GOGSaves.toOffer(saves.keptSaves()[new.id], to: new), "asked once")}/// The latest uninstall's backups replace an earlier one's: a location it had nothing for@@ -333,9 +333,9 @@ final class GOGSaveSafetyTests: XCTestCase {let old = root.appending(path: "backups/old"), new = root.appending(path: "backups/new")saves.keep([("saves", game.folder.appending(path: "saves"), old), (GOGSaves.gameFolder.name, game.folder, old)], of: game, otherInstalls: [])saves.keep([(GOGSaves.gameFolder.name, game.folder, new)], of: game, otherInstalls: [])- XCTAssertEqual(saves.keptSavesToOffer(game)?.entries.map(\.name), [GOGSaves.gameFolder.name])- XCTAssertEqual(saves.keptSavesToOffer(game)?.entries.map(\.backup), [new])+ XCTAssertEqual(GOGSaves.toOffer(saves.keptSaves()[game.id], to: game)?.entries.map(\.name), [GOGSaves.gameFolder.name])+ XCTAssertEqual(GOGSaves.toOffer(saves.keptSaves()[game.id], to: game)?.entries.map(\.backup), [new])saves.keep([], of: game, otherInstalls: [])- XCTAssertNil(saves.keptSavesToOffer(game))+ XCTAssertNil(GOGSaves.toOffer(saves.keptSaves()[game.id], to: game))}}