feat(saves): export Longshot's save folder to one .zip, whole, and import one back #181
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/LongshotLauncher!181
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/LongshotLauncher:feat/saves-zip"
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?
Players had no way to keep their saves as one file, or to send them to another PC: Export copied them into a folder, and a backup meant copying the save folder by hand. Now Export saves… zips Longshot's whole save folder into one .zip, and From an emulator… imports one back.
What changes
Export saves… > A .zip file… (new option in the picker, after Another folder…): the system's Save As picks where, starting from
Longshot saves <date>.zip. The confirm page says it is a new file (or one written over), what is in it, and that nothing in the saves changes.What the zip holds: Longshot's
savefolder, whole, as it is on the disk.save/is the zip's top folder:save/<user id>/account.sav,option.sav, everyslot_NN/with whatever it holds, any other file or folder there (nested and empty ones too), and every other profile folder beside Longshot's. No filtering of which files go in. Each file keeps its time, so every slot still says when it was saved.longshot_options.ini,mouse_sens.txtorpresent.txt. The settings are separate.It is written beside where it goes and renamed into place, so a failure leaves the file that was there. Refused while Longshot, Hookshot or an emulator runs, into the save folder itself, and for a folder above the caps below (so every zip it writes can be imported again).
From an emulator… > A .zip file… imports one. Which rule applies depends on what the zip holds:
save/, andsave/5a3c9e1f0b7d24680000000000000001/, the profile the game opens, holding a slot with aprogress.sav): taken as it is, any file, folder or profile in it, checked for safety only: no name leading out of the zip (..,/, a drive, backslashes included), no link entry, no file in it twice, the caps. It takes the place of Longshot's whole save folder: the confirm page says so ("Replaced: Longshot's whole save folder (3 slots, saved …) and every file in it"), Longshot's is backed up whole first (import-zip-<stamp>), the new one is made beside it and swapped in by two renames, so a failure leaves it as it was. Keep Longshot's game settings keeps each profile'soption.sav.HookshotSaves.Validate): onlyaccount.sav,option.sav,slot_NN/progress.sav,slot_NN/caption.sav(the folders they sit in skipped; a file manager's leftovers__MACOSX,.DS_Store,Thumbs.db,desktop.inileft out); no empty file, none above 4 MB; at least one slot with aprogress.sav; the same safety checks. Copied into Longshot's profile as an import from a folder is (Saves.Copy): its slots,account.savand (unless kept)option.savreplaced, its other files left; backupimport-zip-<stamp>.The caps (raised for a whole folder, which may hold several profiles and files nobody knows): the zip at most 512 MB; at most 512 MB unpacked in all and 10,000 entries; one file of a whole folder at most 64 MB (save files alone: 4 MB, as before). A save folder is a few hundred kilobytes for each profile, so only a bomb or a folder holding something else entirely meets them. What comes out is counted while it is unpacked, whatever sizes the zip claims.
Either way the zip is unpacked into a folder of its own in the system's temporary folder (never a save folder, never the backups), checked there, and deleted when the import is done or left; one an import never finished (the launcher closed in between) goes at the next import, a day later.
The Saves page's two buttons mention the .zip: Choose an emulator, a save folder or a .zip, Send to an emulator, a folder or a .zip.
How
Core/SaveArchive.cs:ExportSave(the save folder whole),ExportSlot(one slot's folder whole, used by #183),Read(slots, rule and problems without unpacking),Unpack(anIDisposabletemporary folder,Wholeor save files),ImportWhole(backup, beside, two renames).Saves.Zipnames the save-files import's side, so its backup isimport-zip-<stamp>too.Saves.CopyTree,DeleteTree,BesideandRefuseLinksare nowinternal.IWindowHost.PickSaveFileAsync: the system's Save As (overwrite prompt on).SavesViewModel: the picker's new option;SaveOp.Zip/Unpacked; the confirm page's zip side and texts,WholeImport,ToReplaced/ShowKeep; the result page names left-out links.tools/screenshots: asavesscene (the Saves page, from made-up save files), the two pickers, and the zip export, import and refusal.docs/saves.md: As a .zip file; README's Saves lines.Translations
Every new text is written in the 12 full catalogs (de, es, fr, it, ja, ko, nl, pl, pt-BR, ru, zh-Hans, zh-Hant). They need a native speaker's check.
scripts/translations.py: the same 30 texts per catalogmainalready lacks, nothing more, nothing left over.Testing
python -I tests/test_launcher_core.py: 1613 checks passed. NewSaveArchiveChecks:save/../, a link, a file twice, no save in Longshot's profile, above the caps) and accepted with unknown and empty files;../,slot_00/../../,/abs,C:/, backslashes, a file that is no save's, two places, empty, twice, no slot, noprogress.sav, a Unix symlink entry, a 4 MB+1 bomb, a file that is no zip), nothing written outside its folder.python -I tests/test_release.py: 37 tests OK.dotnet build App -c Releaseandtools/screenshots: 0 warnings, 0 errors.Screenshots, Before / After: the first comment; the screens whose text changed with the whole folder, in a later comment.
Related
.longshot-savezip with a manifest; this is the plain-.zipform of it, readable by any unzip tool.Screenshots from
tools/screenshots(headless, Windows layout, made-up save files),main321a9e1against this PRe103e43.The Saves page
Export saves…: the picker
From an emulator…: the picker
New, no before
Export to a new .zip: nothing in the saves changes.
Import from a .zip: its slots, what they replace, the backup first.
A .zip that is not only saves: refused, with the reason, and Import off.
Two more Saves PRs stack on this one: #182 (restore from a backup) and #183 (one slot at a time: export, copy to another slot, delete, restore one slot). Merge in that order.
The .zip is now Longshot's whole save folder, as it is (
4a9f836): save/ on top, every profile, slot, file and folder in it, nested and empty ones too; nothing from beside it (longshot_options.ini, mouse_sens.txt, present.txt: the settings are separate); links left out and named; the note moved to the zip's comment. Importing such a zip puts it in place of the whole save folder (backed up first, two-rename swap), checked for safety only; any other zip (by hand, Hookshot's, an emulator's, a slot's) keeps the save-files rule. Caps raised to 512 MB zip and unpacked, 10,000 entries, 64 MB a file. New checks: a nested folder, an empty one, an unknown file and another profile round-trip byte for byte; links skipped. 1613 checks pass. The description is updated; new screenshots of the screens whose text changed follow.The screens whose text changed with the whole save folder, from
tools/screenshots(headless): this PR's first commit (e103e43) against now (4a9f836).Export saves…: the picker
e103e43)4a9f836)Export to a .zip: what is in it
e103e43)4a9f836)Import a whole save folder: it replaces the whole folder
e103e43)4a9f836)The refusal screen is unchanged (a zip with
setup.exeamong save files keeps the save-files rule).feat(saves): export the saves to one .zip file, and import one back after checking it holds only savesto feat(saves): export Longshot's save folder to one .zip, whole, and import one back5e195fdb2c4a9f8369584a9f836958422a0166e9Rebased: #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.422a0166e93fe0c907b9Rebased onto #180 (
eca781b), itself rebased onto main7a4a61e, and force-pushed:c78d936,3fe0c90. The merge combined main's #166 and #168 with this PR: an export to a folder with no save still makes the save there (Saves.ExportTarget), and #168's tick wording ('Keep Longshot's own game settings', what each choice does) and its hiding when there is no option.sav now hold for the .zip import too; the tick also stays hidden for a .zip export. docs/saves.md says both the empty folder and the .zip in one sentence; the screenshot tool keeps main's scenes and this PR's. 1704 checks, 37 release tests, 0 warnings. Merge order: #180, #181, #182.The screens the rebase onto main changed (
tools/screenshots, headless): main's #168 now words the settings tick on a .zip import too ("Keep Longshot's own game settings", what each choice does), and hides it when Longshot's save has no option.sav. Before: as last posted (4a9f836); After:3fe0c90on main7a4a61e+ #180.Import from a .zip
A .zip refused
The zip export's confirmation is unchanged (no tick there: a .zip written replaces no settings).
3fe0c907b9a00d7d2defRebased 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 (posted after the merge). This PR merged as
0e96947(the same tree asa00d7d2d) while I was reviewing it, so the forge won't take a review any more, and this comes as a comment instead. The three blocking points below are now on main, and a follow-up fix should land before the next stable. The zip itself is built safely (zip-slip, links, bombs, duplicates and case clashes are all handled), but the whole-folder import and the export skip three save-safety rules thatSaves.Copyand main's gather already keep: a commit the game still has waiting, the recovery of a swap the PC cut short, and the gather lock on the folders beside the save. Each can leave the player with the wrong saves, or none, on a path the PR adds.For a player: one file to keep their saves in or carry to another PC, and a way to bring that file back with a backup made first. A real gain, and the code is mostly well built. The three gaps are in the one new code path that replaces the whole save folder. Each fix is small, and the simplest one is to reuse what
Saves.Copyalready does rather than keep a second copy of its swap.Reviewed:
a00d7d2dagainst main8594b470(the PR sits on current main, so no rebase was needed: it merges cleanly, including with #175 and #176). Read in full:Core/SaveArchive.cs, theCore/Saves.csdiff and the code it calls (Copy,CopyTree,DeleteTree,Beside,Real,Inside,PendingCommit,Gather/HoldGatherLock),HookshotSaves.Validate, theSavesViewModel.csdiff,MainWindow.axaml.cs,ViewModelBase.cs, both views,tests/launcher_core/SaveArchiveChecks.cs,tools/screenshots/Program.cs,docs/saves.mdand README. Skimmed: the 12 catalogs (de and ja read line by line; the rest checked for the same keys). Nothing was run (a code review).Fixed in this review: nothing.
Checked and fine:
..,.or empty parts, a leading/, any:(drives, NTFS streams), control characters and backslashes are refused before anything is unpacked. Unpack checks again that every path stays inside its own folder.InvalidDataException, and nothing is left behind.a.txt/A.TXTis tested), andFileMode.CreateNewcatches anything that gets past that. The save-files rule is case-sensitive, soAccount.savis refused.import-zip-<stamp>before anything moves, and a backup inside the save folder is refused. A save folder that is itself a link is resolved (Real), so the link stays.HookshotSaves.ValidateandSaves.Copy, so they get that function's pending-commit check, backup and swap.<user>/save. Not the settings beside it, and not the backups (save-backupandoot-save-backupsare outside it). The comment holds the launcher's version, a UTC time and slot names: no user name and no paths. No game files..longshot-partand renamed into place, and a failure deletes the part file. A zip inside the save folder is refused.Blocking (now on main: for a follow-up before the next stable)
Core/SaveArchive.cs:94and:435: neitherExportSavenorImportWholechecksSaves.PendingCommit, andSaves.Copyrefuses both sides on it. Say the game was closed mid-commit and left<user>/save-tx/ready-N(orsave-import). The export then zips the save from before that commit, and the game loads the newer one. Worse, after a whole import the next start of the game applies the waiting commit over the imported folder, so the import is partly undone, quietly. Fix: before both, checkPendingCommit(Path.Combine(saveFolder, Saves.UserId))and throwSaveFailure(..., SaveRefusal.Waiting, ...)asCopydoes. The result page already handlesWaiting. Add a check with asave-tx/ready-1folder.Core/SaveArchive.cs:439-486: the swap is a weaker copy ofSaves.Copy's. (a) If the PC goes off betweenDirectory.Move(real, aside)andDirectory.Move(staging, real), the save folder is missing, and the player's saves are only in.save.longshot-oldand the backup. The nextImportWholethen seeshad == false, makes no backup, andDeleteTree(aside)(line 441) deletes them.Copymoves a left-over aside back first (Saves.cs533). (b) If movingasideback fails (line 475), the outer catch still says "Nothing was changed: … is as it was" while the folder is missing.CopytriesRestore(backup, target)and says when it couldn't. Fix: move the aside back at the start, asCopyandGatherdo, and share the swap withCopy(one helper used by both) instead of keeping two copies of it. Add a check for the cut-short case.Core/SaveArchive.cs:439:Beside(<user>/save)gives.save.longshot-staging/.save.longshot-old, the same two foldersGatheruses (Saves.cs724). #175's rule is that everything using them holds the gather lock (HoldGatherLock; doc comment onGatherAlone).ImportWholedoesn't hold it, so on Windows a gather started from a desktop shortcut's--playduring an import can delete the staging folder, or move the aside folder back, mid-swap. Fix:using var held = Saves.HoldGatherLock(env);around the non-dry-run part.Suggestions (the author may take or leave)
Core/SaveArchive.cs:122: line 120 resolves the folder withReal, then line 122 refuses asavefolder that is itself a link. So a player who linkedsaveto a synced folder can't export, thoughImportWholehandles that case. Zipping the resolved folder would be consistent..<id>.longshot-staging/.longshot-old, whichCopyleaves there when it is cut short. They are stale saves rather than private data, but leaving out these dot-folders would keep stale copies out of the zip, and out of a later whole import.CON,NUL,COM1) and parts ending in a dot or a space, made on Linux, behave oddly when unpacked on Windows. An explicit refusal would give a clear message instead.Unpackruns on the UI thread fromRefresh(up to 512 MB in theory). It is fine for real save folders, but moving it off the UI thread would keep a large hostile zip from freezing the window.InvalidDataException, but a check would pin that down, since only IO and data exceptions are caught inRefresh's path.Questions
import-zip-<stamp>, but one holds the wholesavefolder (profiles below it) and the other holds one profile (account.sav,slot_NN). Does #182's restore tell them apart? If not,import-zip-whole-<stamp>(or similar) would make the layout clear from the name.Testing: the author ran the core checks and release tests on Windows 11. Nothing has been clicked through in the real window, and nothing has run on Linux or the Steam Deck. A Linux run of export, then a whole import, then starting the game is wanted. CI's compile-and-test was skipped (it is started by hand), so it should be run on main now. Missing from the checks: the pending commit, a swap cut short between its renames, and the gather lock.
Overlaps and merge order: this PR is merged; next comes #182 (restore from a backup), then #183 (one slot at a time), which is stacked on 182. No textual conflict with main now: the author's rebase onto
8594b47resolved it. The interplay with #175 is point 3.