Skip to main content

SaveManager

Struct SaveManager 

Source
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>

Source

pub fn new(db: &'a ModdeDb) -> Self

Source

pub fn init_vault(game_id: &GameId) -> Result<Repository>

Initialize a git-backed save vault for a game if it doesn’t exist.

Source

pub fn vault_repo(game_id: &GameId) -> Result<Repository>

Open an existing vault repo, or initialize it if it doesn’t exist.

Source

pub fn ensure_branch(game_id: &GameId, profile_name: &str) -> Result<()>

Ensure a branch exists for a profile. Creates a branch if needed.

Source

pub fn checkout_branch(game_id: &GameId, profile_name: &str) -> Result<()>

Checkout a profile’s branch, updating the working directory.

Source

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.

Source

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).

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn history( game_id: &GameId, profile_name: &str, limit: usize, ) -> Result<Vec<SaveSnapshot>>

List commit history for a profile’s save branch.

Source

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.

Source

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.

Source

pub fn snapshot_file_list( game_id: &GameId, commit_id: &str, ) -> Result<Vec<String>>

List file paths in a specific snapshot’s git tree.

Source

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.

Source

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.

Source

pub fn assign( &self, profile_id: i64, path: &Path, label: Option<&str>, ) -> Result<()>

Assign a save file or directory to a profile.

Source

pub fn unassign(&self, path: &Path) -> Result<()>

Remove a save assignment.

Source

pub fn list(&self, profile_id: i64) -> Result<Vec<SaveEntry>>

List all saves assigned to a profile.

Source

pub fn list_unassigned(&self, game_save_dir: &Path) -> Result<Vec<PathBuf>>

Scan a save directory and return paths not yet assigned to any profile.

Auto Trait Implementations§

§

impl<'a> Freeze for SaveManager<'a>

§

impl<'a> !RefUnwindSafe for SaveManager<'a>

§

impl<'a> !Send for SaveManager<'a>

§

impl<'a> !Sync for SaveManager<'a>

§

impl<'a> Unpin for SaveManager<'a>

§

impl<'a> UnsafeUnpin for SaveManager<'a>

§

impl<'a> !UnwindSafe for SaveManager<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more