Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

Epic saves: a leftover download keeps what the folder held before putting its backup back, Keep copies what the exclude list leaves in an install save folder, and Last synced follows the player's pick

Gabe63b6caebd5fb
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 8ccc31c..ea5a7cd 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -3526,6 +3526,8 @@ final class AppState {
} else if FileManager.default.fileExists(atPath: saveFolder.path) {
appendLog("\(title): saves at \(saveFolder.path) left in place: they are outside this environment, or hold other things Highball keeps")
}
+ } else if deleteSaves {
+ appendLog("\(title): Highball found no save folder for it to delete, so no saves outside the game's folder were deleted")
}
// Recorded once legendary's record is gone, so this install is never offered its own saves.
saves.keep(kept, of: app)
@@ -3744,6 +3746,7 @@ final class AppState {
let again = await Task.detached { saves.sync(app, install: install, prefix: prefix, direction: forced, keepBackups: true, onLine: log) }.value
switch again {
case .synced:
+ savesSynced += 1
appendLog("\(title): \(choice == .useCloud ? "Epic's cloud saves replaced this Mac's, after a backup of them" : "Epic's cloud now has this Mac's saves as its newest")")
return true
case let .restored(why):
@@ -4339,7 +4342,9 @@ final class AppState {
// The backup made before the side the player picked replaces the other is kept for good.
let again = await Task.detached { saves.sync(game, location: location, folder: folder, direction: forced, keepBackups: true) }.value
switch again {
- case .synced: appendLog("\(title): cloud saves \(choice == .useCloud ? "replaced with GOG's copy" : "uploaded from this Mac"), a copy of what was replaced kept first")
+ case .synced:
+ savesSynced += 1
+ appendLog("\(title): cloud saves \(choice == .useCloud ? "replaced with GOG's copy" : "uploaded from this Mac"), a copy of what was replaced kept first")
case let .failed(why): appendLog("\(title): cloud saves did not sync (\(why))")
case .conflict, .refused: appendLog("\(title): cloud saves did not sync")
}
diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swift
index 1a34e1b..1c49fcf 100644
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@ -158,9 +158,10 @@ 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 {
+ /// A sync that worked shows nothing else, so the setting says when the last one was; not
+ /// while sync is turned off for the game (`on` false), when no sync runs.
+ @ViewBuilder private func lastSyncedLine(on: Bool) -> some View {
+ if on, let lastSynced {
Text(String(format: L("Last synced: %@"), Self.syncedFormatter.string(from: lastSynced)))
.font(.caption).foregroundStyle(.secondary)
}
@@ -203,7 +204,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
+ lastSyncedLine(on: !state.epicCloudSavesOff.contains(app))
}
}
}
@@ -232,7 +233,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)
- lastSyncedLine
+ lastSyncedLine(on: !state.gogSettings.cloudSavesOff.contains(game.id))
if !state.gogSignedIn {
Button(L("Connect GOG")) { state.showGOGSignIn = true }.controlSize(.small)
}
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index ef92f7d..4545625 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -646,7 +646,7 @@ private extension View {
Button(L("Remove anyway"), role: .destructive) { state.epicRemoveWithoutCopy() }
Button(L("Cancel"), role: .cancel) { state.epicRemovalWithoutCopy = nil }
} message: { pending in
- Text(String(format: L("Highball can't tell which files in %@'s folder the game wrote: the Epic tools have no file list for it, and it was installed before Highball kept a record of installs. Its save folder is still copied to save-backups first, but any other save the game kept in its folder is deleted with it. Saves in Epic's cloud are not affected."), pending.title))
+ Text(String(format: L("Highball can't tell which files in %@'s folder the game wrote: the Epic tools have no file list for it, and it was installed before Highball kept a record of installs. Its save folder is copied to save-backups first when Highball can find it, but any other save the game kept in its folder is deleted with it. Saves in Epic's cloud are not affected."), pending.title))
}
}
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 495c0bf..6a6939f 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -260,8 +260,8 @@ enum L10n {
"Put them back": "Les remettre",
"Don't ask again": "Ne plus demander",
"Remove %@ without a copy of its folder?": "Supprimer %@ sans copie de son dossier ?",
- "Highball can't tell which files in %@'s folder the game wrote: the Epic tools have no file list for it, and it was installed before Highball kept a record of installs. Its save folder is still copied to save-backups first, but any other save the game kept in its folder is deleted with it. Saves in Epic's cloud are not affected.":
- "Highball ne peut pas savoir quels fichiers du dossier de %@ le jeu a écrits : les outils Epic n’en ont pas la liste, et il a été installé avant que Highball ne garde une trace des installations. Son dossier de sauvegardes est tout de même copié d’abord dans save-backups, mais toute autre sauvegarde que le jeu gardait dans son dossier est supprimée avec lui. Les sauvegardes dans le cloud Epic ne sont pas touchées.",
+ "Highball can't tell which files in %@'s folder the game wrote: the Epic tools have no file list for it, and it was installed before Highball kept a record of installs. Its save folder is copied to save-backups first when Highball can find it, but any other save the game kept in its folder is deleted with it. Saves in Epic's cloud are not affected.":
+ "Highball ne peut pas savoir quels fichiers du dossier de %@ le jeu a écrits : les outils Epic n’en ont pas la liste, et il a été installé avant que Highball ne garde une trace des installations. Son dossier de sauvegardes est d’abord copié dans save-backups quand Highball le trouve, mais toute autre sauvegarde que le jeu gardait dans son dossier est supprimée avec lui. Les sauvegardes dans le cloud Epic ne sont pas touchées.",
"Highball kept %@'s saves when it was removed. Put them back copies them into the game's folder; anything already there is copied to save-backups first. Not now asks again the next time Highball starts.": "Highball a gardé les sauvegardes de %@ lors de sa suppression. Les remettre les copie dans le dossier du jeu ; ce qui s’y trouve déjà est d’abord copié dans save-backups. Pas maintenant redemandera au prochain lancement de Highball.",
"Highball kept %@'s saves when it was removed. Put them back copies them to where they were; anything already there is copied to save-backups first. Not now asks again the next time Highball starts.": "Highball a gardé les sauvegardes de %@ lors de sa suppression. Les remettre les copie là où elles étaient ; ce qui s’y trouve déjà est d’abord copié dans save-backups. Pas maintenant redemandera au prochain lancement de Highball.",
"Highball couldn't reach GOG to find out where %@ keeps its saves, and can't tell which files in the game's folder the game wrote, because nothing records when it was installed. So nothing in the game's folder is copied first, and saves there are deleted with it. Saves already in GOG's cloud are not affected. To keep its save folders, cancel and try again once GOG can be reached.":
diff --git a/Sources/HighballKit/EpicSaves.swift b/Sources/HighballKit/EpicSaves.swift
index d0528aa..6a12fa8 100644
--- a/Sources/HighballKit/EpicSaves.swift
+++ b/Sources/HighballKit/EpicSaves.swift
@@ -417,14 +417,20 @@ public struct EpicSaves: Sendable {
let filter = catalog(app)?.filter ?? .everything
let backupDir = backups.folder("epic-\(app)", install: install)
- // A download that never finished: its backup goes back first.
+ // A download that never finished: its backup goes back first. What the folder holds now
+ // is copied first (kept): saves written since, while sync was off or signed out, are
+ // never replaced without a copy.
if let pending = records()[key]?.restoring, let folder = savePath(app) {
do {
- let backup = pending.isEmpty ? nil : URL(fileURLWithPath: pending)
+ let current = try backups.backUpLocal(folder, into: backupDir, filter: filter, kept: true)
+ var backup = pending.isEmpty ? nil : URL(fileURLWithPath: pending)
+ // Nothing changed since the download's backup: that copy is now the kept one.
+ if let pinned = backup, !FileManager.default.fileExists(atPath: pinned.path) { backup = current }
try SaveBackups.restore(backup, into: folder, filter: filter)
if let backup { SaveBackups.unpin(backup) }
clearRestoring(key)
- onLine?("Highball: an earlier download of these saves didn't finish, so this Mac's saves were put back from their backup")
+ onLine?("Highball: an earlier download of these saves didn't finish, so this Mac's saves were put back from their backup"
+ + (current.map { "; what the save folder held first was copied to \($0.path)" } ?? ""))
} catch {
return .failed("an earlier download didn't finish, and the saves couldn't be put back from \((pending as NSString).abbreviatingWithTildeInPath) (\(error.localizedDescription))")
}
@@ -663,8 +669,8 @@ extension EpicSaves {
/// Before an uninstall, copies as kept backups (never pruned): the save folder's files the
/// catalog's include and exclude lists pick, when `saveFolder` is given, and every file the
- /// game wrote in its install folder (gameFiles), leaving out the save folder. Nothing tells
- /// them apart: no install-folder copy. Returns what was kept, each with where it came from;
+ /// game wrote in its install folder (gameFiles), leaving out the ones the save-folder copy
+ /// took. Nothing tells them apart: no install-folder copy. Returns what was kept, each with where it came from;
/// throws when a copy fails, and the uninstall must then stop.
public func backUpForUninstall(_ app: String, install: URL, prefix: URL, saveFolder: URL?) throws -> [KeptSaves.Entry] {
try backUpForUninstall(app, install: install, prefix: prefix, saveFolder: saveFolder,
@@ -681,9 +687,15 @@ extension EpicSaves {
kept.append(KeptSaves.Entry(name: Self.savesName, folder: saveFolder, backup: copy, install: install, environment: prefix))
}
guard let gameFiles else { return kept }
- let skipped = saveFolder.map { $0.standardizedFileURL.path + "/" }
+ // Only the files the save-folder copy took: what the include and exclude lists leave out
+ // of a save folder inside the install folder is still the game's, and removeLeftover
+ // deletes it with the folder.
+ let filter = catalog(app)?.filter ?? .everything
+ let taken = Set(try saveFolder.map { folder in
+ try SaveBackups.walk(folder).filter { filter.matches(SaveBackups.relativePath($0, in: folder)) }.map(\.standardizedFileURL.path)
+ } ?? [])
let written = try SaveBackups.walk(install).filter { file in
- guard skipped.map({ !file.standardizedFileURL.path.hasPrefix($0) }) ?? true else { return false }
+ guard !taken.contains(file.standardizedFileURL.path) else { return false }
let changed = try? file.resolvingSymlinksInPath().resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate
return gameFiles.isGameWritten(SaveBackups.relativePath(file, in: install), changed: changed)
}
diff --git a/Sources/HighballKit/GOGLibrary.swift b/Sources/HighballKit/GOGLibrary.swift
index 0b4adad..8c5a9f6 100644
--- a/Sources/HighballKit/GOGLibrary.swift
+++ b/Sources/HighballKit/GOGLibrary.swift
@@ -541,9 +541,9 @@ extension GOGStore {
}
/// 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
+ /// 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.
public static func history(for game: InstalledGame, driveC: URL) -> InstallHistory {
var history = storedHistory(for: game, driveC: driveC)
diff --git a/Tests/HighballKitTests/EpicFakeLegendaryTests.swift b/Tests/HighballKitTests/EpicFakeLegendaryTests.swift
index dbe8a27..f744c7a 100644
--- a/Tests/HighballKitTests/EpicFakeLegendaryTests.swift
+++ b/Tests/HighballKitTests/EpicFakeLegendaryTests.swift
@@ -219,6 +219,33 @@ final class EpicFakeLegendaryTests: XCTestCase {
XCTAssertNil(saves.records()[EpicSaves.key(app: app, install: install)]?.restoring)
}
+ /// A leftover download marker restores its old backup, but what the folder holds now (saves
+ /// written while sync was off or signed out) is copied first, kept. With nothing changed since
+ /// the download's backup, that backup becomes the kept copy and still goes back.
+ func testAnInterruptedDownloadKeepsWhatTheFolderHeldFirst() throws {
+ try syncedOnce()
+ let key = EpicSaves.key(app: app, install: install), dir = saves.backups.folder("epic-\(app)", install: install)
+ let backup = try XCTUnwrap(try saves.backups.backUpLocal(folder, into: dir))
+ try SaveBackups.pin(backup)
+ saves.update(key) { $0?.restoring = backup.path }
+ try write("played while sync was off", to: folder.appending(path: "slot.sav"), at: Date())
+ _ = sync(.download)
+ XCTAssertEqual(read(folder.appending(path: "slot.sav")), "v1")
+ let kept = saves.backups.backups(in: dir).filter(SaveBackups.isKept)
+ XCTAssertEqual(kept.count, 1)
+ XCTAssertEqual(read(kept[0].appending(path: "slot.sav")), "played while sync was off")
+ XCTAssertFalse(SaveBackups.isPinned(backup))
+
+ // Nothing changed since the marker's backup: reused as the kept copy, and put back.
+ let again = try XCTUnwrap(try saves.backups.backUpLocal(folder, into: dir))
+ try SaveBackups.pin(again)
+ saves.update(key) { $0?.restoring = again.path }
+ _ = sync(.download)
+ XCTAssertEqual(read(folder.appending(path: "slot.sav")), "v1")
+ XCTAssertNil(saves.records()[key]?.restoring)
+ XCTAssertTrue(saves.backups.backups(in: dir).filter(SaveBackups.isKept).allSatisfy { !SaveBackups.isPinned($0) })
+ }
+
/// Epic's backups are named like GOG's (<date>-mac), so they rotate per kind; the one made
/// for the player's pick in a conflict is kept, never pruned.
func testThePlayersPickKeepsItsBackup() throws {
diff --git a/Tests/HighballKitTests/EpicUninstallSavesTests.swift b/Tests/HighballKitTests/EpicUninstallSavesTests.swift
index d9f9242..b4d4021 100644
--- a/Tests/HighballKitTests/EpicUninstallSavesTests.swift
+++ b/Tests/HighballKitTests/EpicUninstallSavesTests.swift
@@ -27,9 +27,10 @@ final class EpicUninstallSavesTests: XCTestCase {
if let root { try? FileManager.default.removeItem(at: root) }
}
- private func catalog(include: String?) throws {
- var attributes: [String: Any] = ["CloudSaveFolder": ["type": "STRING", "value": "{AppData}/Game/Saved"]]
+ private func catalog(include: String?, exclude: String? = nil, folder: String = "{AppData}/Game/Saved") throws {
+ var attributes: [String: Any] = ["CloudSaveFolder": ["type": "STRING", "value": folder]]
if let include { attributes["CloudIncludeList"] = ["type": "STRING", "value": include] }
+ if let exclude { attributes["CloudExcludeList"] = ["type": "STRING", "value": exclude] }
let obj: [String: Any] = ["app_name": app, "metadata": ["customAttributes": attributes]]
try JSONSerialization.data(withJSONObject: obj).write(to: config.appending(path: "metadata/\(app).json"))
}
@@ -107,6 +108,22 @@ final class EpicUninstallSavesTests: XCTestCase {
XCTAssertTrue(SaveBackups.isKept(kept[1].backup))
}
+ /// A save folder inside the install folder whose exclude list leaves some of it out: the
+ /// game-folder copy skips only the files the save-folder copy took, so the rest (Saved/Config)
+ /// is still kept before the leftover folder is removed.
+ func testKeepCopiesWhatTheExcludeListLeavesOutOfASaveFolderInTheInstall() throws {
+ try catalog(include: nil, exclude: "Config/", folder: "{InstallDir}/Saved")
+ let now = Date()
+ EpicSaves.recordInstall(app: app, driveC: driveC, start: now.addingTimeInterval(-7260), end: now.addingTimeInterval(-7200), finished: true)
+ try write("exe", to: install.appending(path: "Game.exe"), dated: now.addingTimeInterval(-7230))
+ try write("save", to: install.appending(path: "Saved/SaveGames/slot1.sav"), dated: now.addingTimeInterval(-60))
+ try write("settings", to: install.appending(path: "Saved/Config/Windows/GameUserSettings.ini"), dated: now.addingTimeInterval(-60))
+ let kept = try saves.backUpForUninstall(app, install: install, prefix: prefix, saveFolder: install.appending(path: "Saved"))
+ XCTAssertEqual(kept.map(\.name), [EpicSaves.savesName, EpicSaves.gameFolderName])
+ XCTAssertEqual(relative(kept[0].backup), ["SaveGames/slot1.sav"])
+ XCTAssertEqual(relative(kept[1].backup), ["Saved/Config/Windows/GameUserSettings.ini"], "what the save copy left out, and only that")
+ }
+
/// A save folder that can't be read stops the removal.
/// legendary leaves the game's folder when it holds files it didn't install, and a reinstall
/// there fails: once the record is gone the folder goes, but never a shared one.