feat(saves): restore from a backup: every save the copies backed up, newest first, put back after a confirmation #182
No reviewers
Labels
No labels
area/build
area/install
area/saves
area/tooling
area/ui
area/updates
ci: approved
good first issue
gpu/amd
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
platform/linux
platform/steam-deck
platform/windows
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/LongshotLauncher!182
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/LongshotLauncher:feat/saves-restore"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Every copy of saves backs up what it replaces first, but there was no way to get a backup back short of finding the folder and copying files by hand. Now the Saves page lists those backups and restores one, after the same confirmation an import shows.
On main: #181 (the save folder as a .zip) and #180 are merged, so this branch holds only its own commits. Merge order: #182, then the Linux backups PR (issue #188, stacked on this), then #184, #185.
What changes
Restore from a backup…, a new button under the slots on the Saves page, says how many backups there are and when the newest was made (off, with "None yet: every copy makes one first", when there are none). It opens a page listing every save in the backups folder (
oot-save-backupson Windows,save-backupon Linux), newest first:5a3c9e1f…0001) is listed when it is there; else each is, with its profile named in the row ("(profile 01234567…)"), so no two rows look the same. Whichever is restored goes into the game's profile. A gather'sshared (set aside)folder reads as the shared save.Restore… opens the confirm page imports use: the backup's slots, what they replace in Longshot's save, Keep Longshot's game settings, and where Longshot's own save is backed up first (
restore-backup-<stamp>, which the list shows next time). Then the result page, as for an import. The backup itself is only read. It is refused while a game or emulator runs, as every copy is.Nothing on the page deletes a backup. That stays a file manager's job: Open the backups folder is at the bottom.
The confirm page's replaced text names only the files the backup has (one with no
account.savoroption.savleaves Longshot's), and its settings tick is hidden when the backup has nooption.sav. Back returns to the backups list. A whole save folder's import is undone only in part: a restore puts back one profile's save, not the rest of the folder (docs/saves.md says so).How
Core/SaveBackups.cs:List(env)(each backup folder's saves viaSaves.Find, one level deeper for a gather's or a delete's, withBackupKind, the other side's name, the version folder, the time from the name) andRestore(Saves.CopyintoSaves.ImportTarget, commandrestore, so every guarantee of a copy holds: backup first, two-rename swap, nothing half-done).SaveMode.RestoreandSaveOp.Backupthrough the confirm and result pages (IntoLongshotwhere they askedMode == Import);BackupsViewModelandApp/Views/BackupsView.axaml.tools/screenshots:saves-backups-listed,saves-backups,saves-restore(made-up backups, laid out as the copies make them).docs/saves.md: Restore from a backup; README's Saves lines.Left for the slot PR (stacked on this one): restoring one slot from a backup rather than the whole save.
Translations
25 new texts in the 12 full catalogs. They need a native speaker's check.
scripts/translations.py: only the 30 texts per catalogmainalready lacks.Testing
python -I tests/test_launcher_core.py: 1899 checks passed on main0e28525(newSaveBackupsChecks: no backups folder; backups made bySaves.Copy(an import, an export to a folder),Saves.BackUpForDeleteand a gather's layout, plus a staging folder, an empty one, a file and an unnamed folder; the list's order, kinds, names, version folders, paths and sizes; a dry run names the backup and makes nothing; refused while the game runs; a restore puts the backup's save back whole, leaves the backup as it was, backs Longshot's save up first; a gather's version folder's save with the game settings kept; a whole save folder's import from a .zip listed and restored; a backup deleted since it was listed; since the review: a whole-folder backup with a stray profile, a version folder with two profiles and one with the game's, an export's backup restored into Longshot, a backup with no account.sav or option.sav).python -I tests/test_release.py: 37 tests OK.dotnet build App -c Release: 0 warnings, 0 errors.Screenshots, Before / After: in the first comment.
Screenshots from
tools/screenshots(headless, Windows layout, made-up save files and backups), this PR's base #181 (e103e43) against this PR (34d9c14).The Saves page: Restore from a backup, under the slots
With no backup yet it is off and says why.
New, no before
The Saves page with backups: how many, and when the newest was made.
Restore from a backup: every save the copies backed up, newest first, what made each.
Restore…: the import's confirmation, Longshot's save backed up first.
Possibly related, for context:
34d9c14713bb44444ce9Rebased onto #181's whole-save-folder zip (
4a9f836) and force-pushed:3039613(this PR's change, unchanged but for the conflicts in the catalogs, README and docs) andbb44444(a check: a whole save folder's import from a .zip is listed among the backups and restored). 1626 checks pass, 37 release tests OK, the app builds with 0 warnings. No dialog text changed, so the screenshots stand.bb44444ce900a924e62700a924e627bb44444ce9bb44444ce9277f71ed45Rebased: #181 now sits on #180 (feat/home-version-picker @
6ed6a3e) and #182 on the new #181. Merge order: #180, #181, #182. Only the language files conflicted (both PRs added texts at their end); both sides were kept and each file checked as JSON with no duplicate key. The app builds with 0 errors; the code is otherwise unchanged, so the earlier test runs stand.277f71ed4504f099d93fRebased onto #181 (
3fe0c90) and force-pushed:dd0d0bb,04f099d. The merge kept main's #168 settings tick for a restore ('Keep Longshot's own game settings', hidden when there is no option.sav), with one text of its own: 'Camera, text speed and other game options from the backup replace them.' (the backup's name is a description, so #168's 'from {0}' would read oddly), in the 12 catalogs. 1717 checks, 37 release tests, 0 warnings. Merge order: #180, #181, #182.The restore confirmation after the rebase onto main (
tools/screenshots, headless): main's #168 settings tick, with its own wording for a restore ("…from the backup replace them"). Before: as last posted; After:04f099d.04f099d93f7c78639d14Rebased onto main (
8594b47: #180, #171 and #179 merged). Only the language files and the screenshot tool's scene list conflicted, both sides adding entries; both kept, each catalog checked as JSON with no duplicate key, the app and the screenshot tool build with 0 warnings. The code is otherwise unchanged, so the earlier test runs stand. Merge order: #181, #182, #184, #185.Verdict: Request changes. The restore itself is safe: it goes through
Saves.Copy, so Longshot's save is backed up first, put in place by two renames, and refused while a game runs. One thing to fix first: a backup that holds several profiles lists each of them under the same label, and any of them restores into the game's profile. The description says only Longshot's profile is listed. Merge after #181.For a player, this adds a way to get back any save a copy replaced, an import, an export, the versions' saves brought together or a deleted version, without digging through
oot-save-backupsby hand. That is a real gain for the data players care most about. It changes no existing path except the shared confirm and result pages, whereMode == ImportbecameIntoLongshot.Reviewed:
7c78639d(pr/182) againsta00d7d2d(pr/181's head, which sits on main8594b470), so only this PR's two commits. Read in full:Core/SaveBackups.cs, theApp/ViewModels/SavesViewModel.csdiff with the confirm and result view models around it,App/Views/BackupsView.axaml, theSavesView.axaml,MainWindow.axamlandViews.cshunks,tests/launcher_core/SaveBackupsChecks.cs, thetools/screenshotsdiff,docs/saves.mdand README. Also read, because the restore relies on them:Saves.Copy,Find,Describe,ImportTarget,Gather's backup layout,BackUpForDelete/SaveIn,SaveArchive.ImportWhole's backup name andHookshotSaves's. Translations: all 12 catalogs parsed and compared withpr/181. Each gains the same 25 keys, none is removed or changed, and the plural forms and placeholders match. The wording was skimmed, not checked by a native speaker. Nothing run (a code review).Fixed in this review: nothing.
Checked and fine:
A restore backs up what is there now.
Saves.Copy(..., "restore", "backup")copies Longshot's save whole torestore-backup-<stamp>before anything is replaced, and the list then shows it as "Before a backup was restored", so a restore can be undone. The confirm page's dry run names that same folder.Atomic. The new save is made in the hidden staging folder beside it and swapped in by two renames, and a failure leaves the target as it was and says where the backup is. The backup itself is only read: no path in the PR writes to or deletes from
BackupRootexcept the new restore backup.A game or an emulator running: the real run passes
running: null, soSaves.CopyasksRunning(Platforms.Current)and refuses withSaveRefusal.Running, and the result page then says "Close the game first". Only the dry run usesforce: true. A pending NX2navi commit is checked on both sides as before.What is listed:
<command>-<name>-<stamp>[-n],gather-,delete-) are parsed with the invariant culture;Listing a folder of the player's own is reasonable, and restoring from it still refuses links in its
slot_*,account.savandoption.sav.Backups that are partial or in an older layout:
account.sav/option.savkeeps Longshot's own (Copycopies only the files that exist);progress.savlists with no time;Copywould refuse it anyway;Fits #175 (on main): a gather's backup is
gather-<stamp>/<name>/<profile>/, and the one-level-deeper fallback finds each version folder's profiles, each with its own Part.Fits #176 (on main):
delete-<stamp>/<folder>/<profile>/, the same way. Since nothing here changes a backup,BackUpForDelete's reuse of an identical earlierdelete-*copy still holds.#168's settings tick: kept for a restore, with its own "from the backup" text.
Paths:
Path.Combinethroughout,Insidecompares case by OS, and the backup root is the platform's (oot-save-backupson Windows,longshot/save-backupon Linux), outside the save folder on both.The import, the export and the .zip paths behave as before: every
Mode == Importthat becameIntoLongshotis a place where a restore needs the same side, and theSaves.ImportExportcall still passesMode == SaveMode.Import.Blocking (to change before merge)
Core/SaveBackups.cs:64and:67: every profileSaves.Findreturns in a backup becomes a row, andRestorecopies any of them intoSaves.ImportTarget(the game's profile). A whole save folder's .zip import (import-zip-<stamp>, from #181) backs up all ofsave\, and so can a gather or a delete. If that folder also held a stray profile (a copy made by hand, whichImportTarget's comment says exists), the list shows two rows with the same "Before an import from a .zip file". Only the path tells them apart, and restoring the wrong one puts a profile the game never read over the player's own. It is backed up, but it is wrong. The description says "Longshot's profile in it is what is listed and restored", and the code doesn't do that. To fix: when a backup (or a version folder in it) holds several profiles, list onlySaves.UserId's when it is there, else name the profile in the row, as the import's(profile …)does. Add a check with a second profile in a whole-folder backup.Suggestions (the author may take or leave)
App/ViewModels/SavesViewModel.cs:684, an export's backup: "The save of Lichii, before an export to it" is Lichii's old save, and Restore puts it into Longshot, not back into Lichii. A player undoing a bad export would expect the second. The confirm page does say Longshot is the target. Saying "into Longshot" on the row or in the confirm title for this kind would avoid the surprise.account.savandoption.sav, not the rest of the save folder that the whole import replaced. One line in docs/saves.md would say so.SavesViewModel.cs:388(from before this PR): "Replaced in Longshot: …, its account.sav, and its game settings" is also shown when the backup has noaccount.sav/option.sav, and then Longshot keeps its own. A restore makes that case likelier than an import does.shared (set aside)folder reads "shared (set aside)'s own save, before…". It could share the"shared"text.SaveBackups.Listruns on every Saves page load, on the UI thread, and sums every backup's size. That is fine at today's counts, and backups are never deleted, so keep an eye on it.Questions
scripts/longshot_saves.pywrites its backups to$XDG_DATA_HOME/oot-save-backups, and the launcher reads$XDG_DATA_HOME/longshot/save-backup. This predates the PR, butBackupRoot's comment ("the script's and the launcher's backups in one place") only holds on Windows, so the script's backups are not listed on Linux. Is that intended?Testing: The author ran
tests/test_launcher_core.py(1717 checks withSaveBackupsChecks),test_release.pyanddotnet buildon Windows 11, and posted headless screenshots. CI's compile-and-test was skipped on this head, so nothing has run the build or the checks on7c78639dexcept the author's runs. The checks cover the list (kinds, order, Part, staging/empty/file/unnamed), dry run, running refusal, restore whole, backup untouched, settings kept, the whole-zip backup and a deleted backup. Missing: a backup with two profiles (the blocker), an export backup's restore, a backup with noaccount.sav, a click-through in the real window, and a Linux run. The restore uses the same code on both platforms, so Linux doesn't hold the merge once the blocker is fixed.Overlaps and merge order: #181 first (this branch carries its two commits), then this one, then #183 (stacked on this; restoring one slot). The author's last comment also names #184 and #185 after it. The forge shows it mergeable now: the author rebased the stack onto main
8594b470. It needs no rebase of its own beyond following #181 if that one moves.@ -514,0 +681,4 @@return b.Kind switch{BackupKind.Import => Tr.F("Before an import from {0}", Other()),BackupKind.Export => Tr.F("The save of {0}, before an export to it", Other()),An export's backup is the other side's old save, but Restore puts it into Longshot, not back where it came from. Say 'into Longshot' here or in the confirm title for this kind. (Suggestion.)
@ -514,0 +688,4 @@{"shared" => Tr.T("The shared save, before the versions' saves were brought together"),null => Tr.T("Before the versions' saves were brought together"),var p => Tr.F("{0}'s own save, before the versions' saves were brought together", p),nit: a gather's 'shared (set aside)' folder reads "shared (set aside)'s own save, …"; it could use the 'shared' text.
@ -0,0 +61,4 @@var found = new List<(SaveProfile Profile, string? Part)>();try{found.AddRange(Saves.Find(folder).Select(p => (p, (string?)null)));Every profile Find returns becomes a row, and Restore puts any of them into ImportTarget. A whole save folder's backup (import-zip-*) with a stray profile lists two rows with the same label, and the wrong one goes over the player's own profile. List only Saves.UserId's when it is there, else name the profile in the row. (Blocking, see the summary.)
@ -0,0 +64,4 @@found.AddRange(Saves.Find(folder).Select(p => (p, (string?)null)));if (found.Count == 0)foreach (var sub in Directory.EnumerateDirectories(folder).Order(StringComparer.Ordinal))found.AddRange(Saves.Find(sub).Select(p => (p, (string?)System.IO.Path.GetFileName(sub))));The same here for a gather's or a delete's version folder with more than one profile in it.
7c78639d14a2617e645eView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.