Skip to content

Add manual-save script (closes DFHack/dfhack#5792)#1583

Open
sizzlins wants to merge 6 commits into
DFHack:masterfrom
sizzlins:feature/manual-save
Open

Add manual-save script (closes DFHack/dfhack#5792)#1583
sizzlins wants to merge 6 commits into
DFHack:masterfrom
sizzlins:feature/manual-save

Conversation

@sizzlins

Copy link
Copy Markdown

Adds a manual-save command 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 --cleanup flag to prune old snapshots. Compatible with the repeat command for rolling saves.

…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
@Bumber64

Copy link
Copy Markdown
Contributor

It may be better to use simulateInput to press the buttons required to perform a manual save. (Hopefully there's a way to set the save name on the viewscreen rather than simulating the name inputs.) It's clunky, but better than messing with the file system.

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.
@sizzlins

Copy link
Copy Markdown
Author
image

Comment thread manual-save.lua Outdated

-- Inject the text and trigger the save UI natively
local options = df.global.game.main_interface.options
options.open = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my understanding that this isn't safe. Viewscreens need to be opened via simulated input to initialize properly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bumber64 fixed, now uses simulated input to open options menu instead of options.open=true

Comment thread manual-save.lua Outdated

-- DF Premium stores saves under %APPDATA%/Bay 12 Games/Dwarf Fortress/save.
-- Classic/portable installs keep them next to the executable.
local function getTrueSaveDir()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread manual-save.lua Outdated
-- File helpers
-- ---------------------------------------------------------------------------

-- Recursively delete a directory tree. Returns true on success.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I just did create dfhack.filesystem.rmdir_recursive, heres the link to the pull
DFHack/dfhack#5834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants