WIP: feat(saves): one slot at a time: export it, copy it to another slot, delete it, or restore it alone from a backup #183
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!183
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/LongshotLauncher:feat/saves-slots"
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 save action in the launcher worked on the whole save: there was no way to send one adventure, to make a second copy of one before a risky part, to clear one slot, or to get one slot back from a backup without the rest. Now a slot on the Saves page has its own actions.
Stacked on #182 (restore from a backup), which is stacked on #181 (the save folder as a .zip): this branch holds both their commits, so merge it after them.
What changes
Select a slot on the Saves page (it highlights, as a version's row does on the home) for:
slot_NN/on top and whatever it holds, links left out, what made it in the zip's comment, through #181'sSaveArchive.ExportSlot; Save As starts fromLongshot Slot 2 <date>.zip) or A folder… (itsslot_NNfolder copied in whole; never over aslot_NNalready there, never into the save itself; a link in the slot refuses it). Such a .zip is not a whole save folder, so importing it follows #181's save-files rule: onlyprogress.savandcaption.savin the slot (anything else in it refuses the import), and it replaces the slots of Longshot's save, as any import of save files does; the confirm page shows that.Restore from a backup gains Only one slot: under each backup: its slots as links. One opens "Restore Slot 2 from this backup? Only this slot changes: Slot 2 now, saved yesterday 12:30, is replaced by the one saved 13 Nov." The save's other slots and files stay as they are.
Each action that changes the save:
slotcopy-,slotrestore-,slotdelete-<slot>-<stamp>, which the backups page lists ("Before a slot was copied to Slot 5", "Before Slot 2 was restored from a backup", "Before Slot 4 was deleted");Saves.Copyputs a save: made beside it, then two renames, so a failure leaves the slot as it was. A deleted slot is renamed out of the game's sight (hidden) first, then deleted;Done: the dialog closes, the page reloads, and a toast says what happened ("Slot 1 copied to Slot 5. Your saves from before are backed up.").
How
Core/SaveSlots.cs:Copy(within the save, or from a backup's save: commandslotrestore),Delete,ExportToFolder,LongshotSave(the save the page shows),Shown(slot_00 to slot_05).Saves.CopyTree,DeleteTreeandBesideare nowinternalfor it.SaveBackups:BackupKind.SlotCopy,SlotRestore,SlotDelete.App/ViewModels/SlotActionViewModel.cs(SlotRowViewModel,SlotActionViewModelfor the four dialogs) andApp/Views/SlotActionView.axaml; the Saves page's slot rows; the backups page's Only one slot: links.tools/screenshots:saves-slot-selected,-export,-copy,-delete,-restore.docs/saves.md: One slot; README's Saves lines.Translations
34 new texts in the 12 full catalogs. They need a native speaker's check (es, fr and pt-BR put an article before "Slot {0}"'s translation; worth a look).
scripts/translations.py: only the 30 texts per catalogmainalready lacks.Testing
python -I tests/test_launcher_core.py: 1658 checks passed (newSaveSlotsChecks: copy into an empty and a used slot with the backup whole first, two in one second; refused: onto itself, slot_06,../slot_00, a slot with no game, no save, a game running, a link; a failure between the renames leaves the slot; one slot from a backup leaves the other slots and the backup as they were; delete, its backup, a missing slot, an emulator running, a failed rename; the backups page lists the three kinds; export to a folder, never over one there, never into the save, refused while running; a slot's .zip holds its folder whole, a nested file included, and nothing else; its folder export copies it whole).python -I tests/test_release.py: 37 tests OK.dotnet build App -c Releaseandtools/screenshots: 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 (34d9c14, restore from a backup) against this PR (43e7662).The Saves page: a slot selected
Restore from a backup: Only one slot
New, no before
Export one slot: a .zip, or its slot folder into a folder.
Copy to another slot: what is there, and what gets replaced.
Delete a slot.
Restore only one slot from a backup.
Possibly related, for context:
43e7662e2219f43f08d8Rebased onto #182 (
bb44444), itself on #181's whole-save-folder zip, and force-pushed:2f55cfa(this PR's change) and19f43f0(a slot's export is its folder whole, everything in it, through SaveArchive.ExportSlot; links left out; docs say which import rule such a zip follows). 1658 checks pass (a slot's .zip holds a nested file and nothing else; the folder export copies it whole), 37 release tests OK, 0 warnings. The export dialog's text changed: its new screenshot follows.The slot's Export dialog, whose text changed with the slot folder exported whole (
tools/screenshots, headless):2f55cfaagainst19f43f0.2f55cfa)19f43f0)feat(saves): one slot at a time: export it, copy it to another slot, delete it, or restore it alone from a backupto WIP: feat(saves): one slot at a time: export it, copy it to another slot, delete it, or restore it alone from a backupBack to WIP: the one-slot actions are on hold while we decide whether the Saves page should have them. #181 and #182 (whole save folder export, import and restore) go ahead without this one.
19f43f08d88fe35896fb8fe35896fbbe68020a0fRebased 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. Copy, Delete and the one-slot Restore write to the first profile folder in Longshot's
save\, and that is not always the save the game opens. When a stray profile sorts ahead of it, the player changes a save the game never reads, while the whole-save Restore on the same page writes to the other folder.For a player, this lets them export one slot, copy it into another slot, delete it, or put back one slot from a backup without touching the rest. Each action is confirmed, backed up whole first and swapped in by renames, so it would be a real gain. Apart from the profile it writes to, the core is careful and I see nothing that regresses for players. One more thing a maintainer should know: the author's comment of 20:11 puts these actions on hold until the team decides whether the Saves page should have them, and the 21:14 merge order (181, 182, 184, 185) leaves this PR out. That decision is still open and is not part of this verdict.
Reviewed:
be68020a0fagainst7c78639d14(the head of #182; this PR's own two commits only). Read in full:Core/SaveSlots.cs,Core/SaveBackups.cs(diff and file),App/ViewModels/SlotActionViewModel.cs, theSavesViewModel.cschanges,SlotActionView.axaml,SavesView.axaml,BackupsView.axaml,tests/launcher_core/SaveSlotsChecks.cs, thetools/screenshotsscenes,docs/saves.mdand README. Also read the helpers they rely on inCore/Saves.cs(Beside,CopyTree,DeleteTree,Real,Inside,RefuseLinks,Running,Shared,ImportTarget, and main's slot-by-slotGatherfrom #175),LauncherService.SaveSlotsandSaveArchive.ExportSlot's signature. Translations: every new key was checked mechanically in all 15 catalogs (presence and placeholders), and the French was read. Nothing was run; this is a code review.Fixed in this review: nothing.
Checked and fine:
slotdelete-<slot>-<stamp>), and the backups page lists it as "Before Slot N was deleted". The slot is renamed out of the game's sight before it is deleted. A failed rename leaves the slot in place.swapfault). Copying a slot onto itself, toslot_06+, or with../in the name is refused.account.sav,option.savand the other slots stay as they are, and the backup is only read (tested).Gather(#175) already moves a slot to anotherslot_NN, and Longshot's repo saves load from a slot renamedslot_00with noaccount.sav. No checksum or header outside the slot ties it to its number, and the PR rewrites no file contents, so no checksum can go stale.slot_NN, never into the save itself, links refused, staged and then renamed.SaveBackups.Named(slotcopy-slot_04-…gives Nameslot_04), and a second backup in the same second gets-2. All 34 new texts are present in the 12 full catalogs with matching{n}placeholders. The en-GB, es-419 and fr-CA catalogs add none, as elsewhere. No new dependencies, and nothing reaches outside the save and backups folders.Blocking (to change before merge)
Core/SaveSlots.cs:17:LongshotSaveisSaves.Shared(env).Profiles[0], the first profile folder in ordinal order. The game opens onlySaves.ImportTarget(env)(save\5a3c9e1f…0001, per the comment onImportTarget: "Another profile folder in save\ (a stray one, a copy made by hand) is never read by the game"). Here is a case where it goes wrong. A player once copied a Hookshot profile by hand into Longshot'ssave\as0123456789abcdef…. That folder sorts first, so the Saves page shows its slots (LauncherService.SaveSlots, unchanged). Delete, Copy and Restore-one-slot then change that folder, the toast says it worked, and the game shows the save as it was. The whole-save Restore and every import in the same window write toImportTarget, so the two restores on one page put saves in different places. To fix it, makeLongshotSavereturnImportTarget(env)when that folder exists, and haveLauncherService.SaveSlots(and the page's "Every build" row) describe the same folder, so the dialogs' "what is replaced" text matches what gets written. A check with two profiles insave\, the stray one sorting first, would cover it.Suggestions (the author may take or leave)
Gatherplaces a slot, would match what the export promises. Until then, the export dialog could say how the receiver gets it in.SaveSlots.Copyis new work, not a duplicate. Two pieces do repeat, though. The stage, rename-aside, rename-in and roll-back block is now inSaves.Copy,Saves.GatherandSaveSlots.Copy, and one helper inSavescould serve all three. The six-slot count also exists twice:Saves.GameSlots(const int GameSlots = 6) andSaveSlots.Shown.Showncould be built fromGameSlots.Core/SaveSlots.cs:96: if the roll-back rename itself fails, the exception reaches this catch and the message still says "Nothing was changed: slot_NN is as it was", while the slot may actually be sitting in.slot_NN.longshot-old. That is rare, and the backup holds it. Saying "it may be in …" whentargetis missing would be accurate.BackupsViewModel.Rowswas built once frompage.Backups, so the new "Before Slot 2 was restored" backup doesn't appear until the page is reopened. Rebuilding that page after the modal closes would fix it.Questions
SaveArchive.ExportSlotin #182 has no caller outside the tests, which the reviewers of that PR may want to know.Testing: per the author, 1658 core checks and 37 release tests pass on Windows 11, and
dotnet buildgives 0 warnings. CI's compile-and-test was skipped for this head, and nothing was run here. The newSaveSlotsCheckscover copy into an empty and an occupied slot, the refusals, a failure between the renames, a one-slot restore, delete and its failures, the backup listing, and both exports. They don't model a second profile insave\(the blocker above) or a failed roll-back. Missing: a click-through in the real window (the screenshots were drawn headless), any run on Linux or the Steam Deck, and a run in the game showing a slot copied to another number, or restored alone, loading. That game run should come before this leaves WIP, since it is the first time players move a slot by hand.Overlaps and merge order: stacked on #181, then #182, then this one; merge in that order. The head sits on main
8594b47with no textual conflict I could see, and it is not mergeable only because it is WIP and stacked. It touches the same export and confirm code as #166 (already merged).@ -514,0 +692,4 @@void Restore(BackupSave b) => Page.Main.Navigate(new SavesConfirmViewModel(Page, new SaveOp { Mode = SaveMode.Restore, Backup = b }));static string SlotOf(string? name) => name != null && SaveText.Number(name) > 0 ? Tr.F("Slot {0}", SaveText.Number(name)) : Tr.T("a slot");Nit: the fallback "a slot" ends up in French as "Avant la copie d'un emplacement vers l'un emplacement". It is only reached for a backup name the launcher didn't write, but a separate sentence for that case would read better.
@ -0,0 +100,4 @@{SlotAction.Export => Tr.T("One slot to keep or to send: its folder whole, everything in it, as a .zip or copied into a folder you pick."),SlotAction.Copy => Tr.T("The game shows six slots. A slot copied over is replaced, and your saves are backed up first."),SlotAction.Delete => Tr.F("Saved {0}. Your saves are backed up first, so Restore from a backup can bring it back.", When),Nit: a slot with no
progress.sav(Saved null) reads "Saved . Your saves…". Leaving the first sentence out whenWhenis empty would avoid that.@ -0,0 +11,4 @@static readonly Regex SlotName = new("^slot_[0-9]{2,3}$", RegexOptions.CultureInvariant);/// The slots the game shows: slot_00 to slot_05 (Slot 1 to Slot 6), the ones a slot can be copied intopublic static readonly IReadOnlyList<string> Shown = Enumerable.Range(0, 6).Select(i => $"slot_{i:00}").ToList();The same six slots as
Saves.GameSlots(from #175). One constant would keep them from drifting apart.@ -0,0 +14,4 @@public static readonly IReadOnlyList<string> Shown = Enumerable.Range(0, 6).Select(i => $"slot_{i:00}").ToList();/// Longshot's save, the one the Saves page shows (LauncherService.SaveSlots: the shared folder's first profile); null: none yetpublic static string? LongshotSave(SaveEnvironment env) => Saves.Shared(env) is { Found: true } s ? s.Profiles[0].Path : null;Blocking:
Profiles[0]is the first profile folder in ordinal order, not necessarilySaves.ImportTarget(env), the only one the game opens. With a stray profile that sorts first (a Hookshot profile copied in by hand,0123…), Copy, Delete and Restore-one-slot change a save the game never reads. UseImportTargetwhen it exists, and haveLauncherService.SaveSlotsdescribe the same folder.@ -0,0 +93,4 @@catch (Exception e) when (e is IOException or UnauthorizedAccessException){Saves.DeleteTree(staging);throw new SaveFailure($"The slot could not be copied ({e.Message}). Nothing was changed: {toSlot} is as it was. A backup of the save is in {backup}.",If the roll-back
Directory.Move(aside, target)fails too, this still says the slot "is as it was", while it may be in.slot_NN.longshot-old. That is rare (the backup has it), but the message could say so whentargetis missing.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.