pub struct SaveManager<'a> { /* private fields */ }Expand description
Manages save files using a git-backed vault per game.
Each game gets a git repository at <modde_data>/saves/<game_id>/.
Each profile is a branch in that repository. This gives us branching,
history, and stacking for free.
The caller is responsible for resolving the game’s save directory
(e.g. via GamePlugin::save_directory()) and passing it in.
Implementations§
Source§impl<'a> SaveManager<'a>
impl<'a> SaveManager<'a>
pub fn new(db: &'a ModdeDb) -> Self
Sourcepub fn init_vault(game_id: &GameId) -> Result<Repository>
pub fn init_vault(game_id: &GameId) -> Result<Repository>
Initialize a git-backed save vault for a game if it doesn’t exist.
Sourcepub fn vault_repo(game_id: &GameId) -> Result<Repository>
pub fn vault_repo(game_id: &GameId) -> Result<Repository>
Open an existing vault repo, or initialize it if it doesn’t exist.
Sourcepub fn ensure_branch(game_id: &GameId, profile_name: &str) -> Result<()>
pub fn ensure_branch(game_id: &GameId, profile_name: &str) -> Result<()>
Ensure a branch exists for a profile. Creates a branch if needed.
Sourcepub fn checkout_branch(game_id: &GameId, profile_name: &str) -> Result<()>
pub fn checkout_branch(game_id: &GameId, profile_name: &str) -> Result<()>
Checkout a profile’s branch, updating the working directory.
Sourcepub fn capture_with_fingerprint(
&self,
game_id: &GameId,
profile_name: &str,
game_save_dir: &Path,
fingerprint: Option<&SaveFingerprint>,
) -> Result<usize>
pub fn capture_with_fingerprint( &self, game_id: &GameId, profile_name: &str, game_save_dir: &Path, fingerprint: Option<&SaveFingerprint>, ) -> Result<usize>
Capture saves from the game’s save directory into the vault, committing them. Returns the number of files captured.
If fingerprint is provided, it is embedded in the commit message as
trailer lines so that future restores can warn about mod mismatches.
Sourcepub fn capture(
&self,
game_id: &GameId,
profile_name: &str,
game_save_dir: &Path,
) -> Result<usize>
pub fn capture( &self, game_id: &GameId, profile_name: &str, game_save_dir: &Path, ) -> Result<usize>
Capture saves without a fingerprint (backwards-compatible convenience method).
Sourcepub fn deploy(
&self,
game_id: &GameId,
profile_name: &str,
game_save_dir: &Path,
) -> Result<usize>
pub fn deploy( &self, game_id: &GameId, profile_name: &str, game_save_dir: &Path, ) -> Result<usize>
Deploy saves from the vault to the game’s save directory. Returns the number of files deployed.
Sourcepub fn activate(
&self,
game_id: &GameId,
new_profile: &str,
current_profile: Option<&str>,
game_save_dir: &Path,
) -> Result<()>
pub fn activate( &self, game_id: &GameId, new_profile: &str, current_profile: Option<&str>, game_save_dir: &Path, ) -> Result<()>
Full activate flow: capture current profile’s saves, checkout + deploy new.
If fingerprint is provided, it is embedded in the capture commit for
the current profile’s saves (the ones being put away).
Sourcepub fn activate_with_fingerprint(
&self,
game_id: &GameId,
new_profile: &str,
current_profile: Option<&str>,
game_save_dir: &Path,
fingerprint: Option<&SaveFingerprint>,
) -> Result<()>
pub fn activate_with_fingerprint( &self, game_id: &GameId, new_profile: &str, current_profile: Option<&str>, game_save_dir: &Path, fingerprint: Option<&SaveFingerprint>, ) -> Result<()>
Full activate flow with an optional mod fingerprint.
Sourcepub fn fork_saves(
game_id: &GameId,
source_profile: &str,
target_profile: &str,
) -> Result<()>
pub fn fork_saves( game_id: &GameId, source_profile: &str, target_profile: &str, ) -> Result<()>
Fork saves from one profile’s branch to a new profile’s branch.
Sourcepub fn history(
game_id: &GameId,
profile_name: &str,
limit: usize,
) -> Result<Vec<SaveSnapshot>>
pub fn history( game_id: &GameId, profile_name: &str, limit: usize, ) -> Result<Vec<SaveSnapshot>>
List commit history for a profile’s save branch.
Sourcepub fn check_restore_compatibility(
game_id: &GameId,
_profile_name: &str,
commit_id: &str,
current_fingerprint: &SaveFingerprint,
) -> Result<FingerprintCheck>
pub fn check_restore_compatibility( game_id: &GameId, _profile_name: &str, commit_id: &str, current_fingerprint: &SaveFingerprint, ) -> Result<FingerprintCheck>
Check whether restoring a snapshot is compatible with the current mod fingerprint.
Returns FingerprintCheck without performing the restore — use this
to warn the user before calling restore.
Sourcepub fn restore(
game_id: &GameId,
profile_name: &str,
commit_id: &str,
game_save_dir: &Path,
) -> Result<usize>
pub fn restore( game_id: &GameId, profile_name: &str, commit_id: &str, game_save_dir: &Path, ) -> Result<usize>
Restore saves from a specific commit to the game save directory.
Sourcepub fn snapshot_file_list(
game_id: &GameId,
commit_id: &str,
) -> Result<Vec<String>>
pub fn snapshot_file_list( game_id: &GameId, commit_id: &str, ) -> Result<Vec<String>>
List file paths in a specific snapshot’s git tree.
Sourcepub fn detect_unadopted(
&self,
game_id: &GameId,
game_save_dir: &Path,
) -> Result<Option<usize>>
pub fn detect_unadopted( &self, game_id: &GameId, game_save_dir: &Path, ) -> Result<Option<usize>>
Check if a game save directory has saves but no profile is active. Returns the number of unadopted saves, or None if no saves found.
Sourcepub fn adopt(
&self,
game_id: &GameId,
profile_name: &str,
game_save_dir: &Path,
) -> Result<usize>
pub fn adopt( &self, game_id: &GameId, profile_name: &str, game_save_dir: &Path, ) -> Result<usize>
Adopt existing saves from the game’s save directory into a profile’s vault. Returns the number of files adopted.
Sourcepub fn assign(
&self,
profile_id: i64,
path: &Path,
label: Option<&str>,
) -> Result<()>
pub fn assign( &self, profile_id: i64, path: &Path, label: Option<&str>, ) -> Result<()>
Assign a save file or directory to a profile.