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 and Epic saves: the Cloud saves setting says when they last synced
Gabec8cec77d3093
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex fbecfd6..13c373c 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -3694,6 +3694,10 @@ final class AppState {if on { epicCloudSavesOff.remove(app) } else { epicCloudSavesOff.insert(app) }}+ /// Counts the GOG and Epic syncs that worked, so a game page shows a new last-synced time+ /// as soon as one ends, also the upload after a session.+ var savesSynced = 0+/// One Epic sync, asking the player when both sides changed (EpicSaves). Returns true when the/// saves end up in step, or when only the other direction has work left, so an upload after/// the game may follow; false when the player chose to decide later or the sync failed, so@@ -3708,6 +3712,7 @@ final class AppState {let outcome = await Task.detached { saves.sync(app, install: install, prefix: prefix, direction: direction, onLine: log) }.valueswitch outcome {case .synced:+ savesSynced += 1return truecase .left:appendLog(beforePlay ? "\(title): this Mac's saves are newer than Epic's cloud; they go up after you play"@@ -4298,6 +4303,7 @@ final class AppState {} }.valueswitch outcome {case .synced:+ savesSynced += 1return truecase .refused:// Before Play: this Mac's saves are newer, and the upload after the game takes them.diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swiftindex c92f2c1..1a34e1b 100644--- a/Sources/HighballApp/GameDetailView.swift+++ b/Sources/HighballApp/GameDetailView.swift@@ -18,6 +18,8 @@ struct GameDetailView: View {@State private var epicCloudSaves = false/// Where legendary keeps the game's saves, once a sync has worked it out.@State private var epicSaveFolder: URL?+ /// When this install's saves last synced with GOG or Epic, for the Cloud saves setting.+ @State private var lastSynced: Date?@State private var argsLoaded = false/// Saves a line still being typed, so the Play that follows launches with it. Skipped until the/// field has loaded, or its empty text would clear the stored arguments.@@ -105,6 +107,10 @@ struct GameDetailView: View {epicCloudSaves = found?.0 ?? falseepicSaveFolder = found?.1}+ // Read again whenever a sync ends (AppState.savesSynced).+ .task(id: "\(item.id)|\(state.savesSynced)") {+ lastSynced = await syncedAt()+ }.task(id: storeAppID) {storeDetails = nilexpandedDescription = false@@ -152,6 +158,37 @@ struct GameDetailView: View {}}+ /// A sync that worked shows nothing else, so the setting says when the last one was.+ @ViewBuilder private var lastSyncedLine: some View {+ if let lastSynced {+ Text(String(format: L("Last synced: %@"), Self.syncedFormatter.string(from: lastSynced)))+ .font(.caption).foregroundStyle(.secondary)+ }+ }++ /// "Today at 10:50", "Yesterday at 21:04", or the date.+ private static let syncedFormatter: DateFormatter = {+ let f = DateFormatter()+ f.dateStyle = .medium; f.timeStyle = .short; f.doesRelativeDateFormatting = true+ return f+ }()++ /// This install's last sync, read off the main thread (the stores keep it in JSON files).+ private func syncedAt() async -> Date? {+ switch item.source {+ case .gog:+ guard let game = item.bottleName.flatMap({ name in state.gogInstalledByBottle[name]?.first { $0.id == item.gogID } }) else { return nil }+ let saves = GOGSaves(store: state.gogStore)+ return await Task.detached { saves.lastSynced(game) }.value+ case .epic:+ guard let app = item.epicAppName, let path = state.epicInstalls[app] else { return nil }+ let saves = EpicSaves(store: state.epicStore), install = URL(fileURLWithPath: path, isDirectory: true)+ return await Task.detached { saves.lastSynced(app, install: install) }.value+ default:+ return nil+ }+ }+/// An Epic game's cloud-save setting, in the game settings like GOG's.private func epicSettings(_ app: String) -> some View {HStack(alignment: .top, spacing: 12) {@@ -166,6 +203,7 @@ struct GameDetailView: View {Text(String(format: L("Saves sync from %@."), (epicSaveFolder.path as NSString).abbreviatingWithTildeInPath)).font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true).textSelection(.enabled)}+ lastSyncedLine}}}@@ -194,6 +232,7 @@ struct GameDetailView: View {.toggleStyle(.checkbox).disabled(!state.gogSignedIn)Text(L("Saves come down from GOG's cloud before Play and go back up when the game ends. If both copies changed, Highball asks which one wins.")).font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)+ lastSyncedLineif !state.gogSignedIn {Button(L("Connect GOG")) { state.showGOGSignIn = true }.controlSize(.small)}diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex 8f10523..495c0bf 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -208,6 +208,7 @@ enum L10n {"Ce lien a expiré ou a déjà servi. Cliquez à nouveau sur Ouvrir la connexion GOG : GOG vous donne aussitôt un nouveau lien, souvent sans redemander votre mot de passe.","Achievements": "Succès","Cloud saves": "Sauvegardes dans le cloud",+ "Last synced: %@": "Dernière synchronisation : %@","Sync saves with GOG": "Synchroniser les sauvegardes avec GOG","Achievements and stats (comet)": "Succès et statistiques (comet)","comet stands in for GOG Galaxy while the game runs, so achievements, stats and play time reach your GOG account. If the game won't start with it, Highball starts it again without.":diff --git a/Sources/HighballKit/EpicSaves.swift b/Sources/HighballKit/EpicSaves.swiftindex 0e6a524..d0528aa 100644--- a/Sources/HighballKit/EpicSaves.swift+++ b/Sources/HighballKit/EpicSaves.swift@@ -271,6 +271,12 @@ public struct EpicSaves: Sendable {var recordsFile: URL { store.configDir.deletingLastPathComponent().appending(path: "epic-saves.json") }+ /// When this install's saves were last in step with Epic's cloud; nil when they never were+ /// (a download's marker alone is no sync).+ public func lastSynced(_ app: String, install: URL) -> Date? {+ records()[Self.key(app: app, install: install)].flatMap { $0.synced == .distantPast ? nil : $0.synced }+ }+public func records() -> [String: Record] {let decoder = JSONDecoder(); decoder.dateDecodingStrategy = .iso8601guard let data = try? Data(contentsOf: recordsFile) else { return [:] }diff --git a/Sources/HighballKit/GOGSaves.swift b/Sources/HighballKit/GOGSaves.swiftindex ded250c..5933be2 100644--- a/Sources/HighballKit/GOGSaves.swift+++ b/Sources/HighballKit/GOGSaves.swift@@ -469,6 +469,15 @@ public struct GOGSaves: Sendable {}}+ /// When this install's saves last synced with GOG, across its locations: gogdl's timestamp,+ /// written when a sync moved or matched files (a refusal or a failure keeps the old one).+ /// nil when it never has.+ public func lastSynced(_ game: GOGStore.InstalledGame) -> Date? {+ let suffix = "@\(game.folder.standardizedFileURL.path)"+ return timestamps().filter { $0.key.hasPrefix(game.id + ".") && $0.key.hasSuffix(suffix) }+ .compactMap { Double($0.value).flatMap { $0 > 0 ? Date(timeIntervalSince1970: $0) : nil } }.max()+ }+/// Per install, not per game: the same game in two environments has two sets of saves, each/// with its own last sync.func key(_ game: GOGStore.InstalledGame, _ location: Location) -> String {diff --git a/Tests/HighballKitTests/EpicUninstallSavesTests.swift b/Tests/HighballKitTests/EpicUninstallSavesTests.swiftindex 5350a64..d9f9242 100644--- a/Tests/HighballKitTests/EpicUninstallSavesTests.swift+++ b/Tests/HighballKitTests/EpicUninstallSavesTests.swift@@ -47,6 +47,21 @@ final class EpicUninstallSavesTests: XCTestCase {/// The first install that finishes starts the history; one that failed before it doesn't, and/// every run after it (an update, a repair, a failed one) is legendary's window.+ /// The Cloud saves setting says when this install's saves were last in step; a download's+ /// marker alone is no sync.+ func testLastSyncedReadsThisInstallsRecord() throws {+ let install = root.appending(path: "Game"), other = root.appending(path: "Other")+ XCTAssertNil(saves.lastSynced("Garlic", install: install))+ let when = Date(timeIntervalSince1970: 1793000000)+ let records: [String: EpicSaves.Record] = [EpicSaves.key(app: "Garlic", install: install): .init(synced: when),+ EpicSaves.key(app: "Garlic", install: other): .init(synced: .distantPast)]+ let encoder = JSONEncoder(); encoder.dateEncodingStrategy = .iso8601+ try FileManager.default.createDirectory(at: saves.recordsFile.deletingLastPathComponent(), withIntermediateDirectories: true)+ try encoder.encode(records).write(to: saves.recordsFile)+ XCTAssertEqual(saves.lastSynced("Garlic", install: install), when)+ XCTAssertNil(saves.lastSynced("Garlic", install: other), "a marker, not a sync")+ }+func testTheHistoryStartsAtTheFirstFinishedInstall() {let t = Date(timeIntervalSince1970: 1_800_000_000)EpicSaves.recordInstall(app: app, driveC: driveC, start: t, end: t.addingTimeInterval(60), finished: false)diff --git a/Tests/HighballKitTests/GOGSaveSafetyTests.swift b/Tests/HighballKitTests/GOGSaveSafetyTests.swiftindex ccc6e30..99ad50f 100644--- a/Tests/HighballKitTests/GOGSaveSafetyTests.swift+++ b/Tests/HighballKitTests/GOGSaveSafetyTests.swift@@ -124,6 +124,20 @@ final class GOGSaveSafetyTests: XCTestCase {XCTAssertTrue(FileManager.default.fileExists(atPath: GOGSaves.fingerprintFile(of: copy).path))}+ /// The Cloud saves setting says when this install last synced: the newest of its locations'+ /// timestamps, never another install's or another game's.+ func testLastSyncedIsThisInstallsNewest() throws {+ let (saves, game, location, _) = try fixture()+ let (_, other, _, _) = try fixture(install: "Other")+ XCTAssertNil(saves.lastSynced(game))+ let profiles = GOGSaves.Location(name: "profiles", template: "")+ let all: [String: String] = [saves.key(game, location): "1793000000.5", saves.key(game, profiles): "1793000100",+ saves.key(other, location): "1799999999", "2.saves@\(game.folder.standardizedFileURL.path)": "1799999999"]+ try FileManager.default.createDirectory(at: saves.timestampsFile.deletingLastPathComponent(), withIntermediateDirectories: true)+ try JSONEncoder().encode(all).write(to: saves.timestampsFile)+ XCTAssertEqual(saves.lastSynced(game), Date(timeIntervalSince1970: 1793000100))+ }+func testARefusalMovesNothing() {XCTAssertTrue(GOGSaves.isRefusal("[SAVES] WARNING: Refused to download files, newer files locally"))XCTAssertFalse(GOGSaves.isRefusal("[SAVES] INFO: Done"))