Add manual-save script (closes DFHack/dfhack#5792)#1583
Conversation
…ss autosaves Adds a new 'manual-save' command that creates persistent, named save snapshots by triggering a native autosave and then safely duplicating the result into a timestamped folder. This bypasses the 3-slot autosave restriction in DF v50+. Features: - Automatic fortress-name + timestamp naming - Custom name support via positional argument - --cleanup N flag to prune old snapshots (only touches -Manual- folders) - Safe 4MB chunked file copy to avoid memory spikes - Handles both AppData (Premium) and portable save locations - Compatible with the 'repeat' command for rolling saves Closes DFHack/dfhack#5792
|
It may be better to use |
Addresses feedback from Bumber64 to use simulateInput. Bypasses file system entirely by injecting the save name directly into df.global.game.main_interface.options and simulating the 'SELECT' key to execute a native named save sequence.
|
|
||
| -- Inject the text and trigger the save UI natively | ||
| local options = df.global.game.main_interface.options | ||
| options.open = true |
There was a problem hiding this comment.
It's my understanding that this isn't safe. Viewscreens need to be opened via simulated input to initialize properly.
There was a problem hiding this comment.
@Bumber64 fixed, now uses simulated input to open options menu instead of options.open=true
…options.open=true
|
|
||
| -- DF Premium stores saves under %APPDATA%/Bay 12 Games/Dwarf Fortress/save. | ||
| -- Classic/portable installs keep them next to the executable. | ||
| local function getTrueSaveDir() |
There was a problem hiding this comment.
I am not at all confident that this is safe across all platforms and it does not reflect portable mode behavior correctly. It also replicates code found in Filesystem::getBaseDir which should be used instead
| -- File helpers | ||
| -- --------------------------------------------------------------------------- | ||
|
|
||
| -- Recursively delete a directory tree. Returns true on success. |
There was a problem hiding this comment.
I don't like using os.remove, and furthermore std::filesystem already has a recursive directory delete which I'd prefer to proxy into Lua (via the Filesystem module, if needed) instead of replicating an already implemented mechanic in obscure Lua code
There was a problem hiding this comment.
ive refactored this to use dfhack.filesystem.rmdir_recursive as requested, with a graceful qerror fallback for now since it hasnt been exposed to lua yet, let me know if you plan to proxy that api in the c++ core, or if youd like me to open a separate PR on the main dfhack repo to add it
There was a problem hiding this comment.
actually I just did create dfhack.filesystem.rmdir_recursive, heres the link to the pull
DFHack/dfhack#5834

Adds a
manual-savecommand that creates persistent, named save snapshots that won't be overwritten by autosaves. Works by triggering a native autosave and then duplicating the result into a timestamped folder. Includes a--cleanupflag to prune old snapshots. Compatible with therepeatcommand for rolling saves.