IBackupStorage

Summary: Add temporary and backup copies to a custom storage so loads can recover.

Description

Implement IBackupStorage alongside ISaveStorage when your storage can keep more than one copy of a save. Save System then checks those copies when the main copy is missing or damaged, in this order: main, temporary, backup.

Without this interface, Save System reads only the main copy and cannot recover from a broken save. MemoryStorage implements both interfaces and is a complete reference.

Namespace Gley.SaveSystem.

Declaration

C#
public interface IBackupStorage

Members

MemberTypeDescription
TryReadCandidates—bool TryReadCandidates(string storageKey, List<StorageCandidate> candidates)
Adds a StorageCandidate for each copy that exists for the key: main, temporary and backup. Add a candidate with the read exception when a copy exists but cannot be read. Returns true when it added any candidate.
Quarantine—string Quarantine(string storageKey)
Moves the main copy aside as a broken copy so a backup can replace it. Returns a label for where it went, or null when there is no main copy.
Promote—void Promote(string storageKey, CandidateKind from)
Makes the temporary or backup copy the new main copy after a successful recovery.
KeepBrokenCopy—string KeepBrokenCopy(string storageKey, byte[] data)
Stores a separate broken copy of the given bytes and returns a label for it.
DeleteCompanions—void DeleteCompanions(string storageKey, bool includeBroken)
Deletes the temporary and backup copies for the key, and the broken copy when includeBroken is true.

Example

To keep a backup, make Write move the current main copy to the backup position before storing the new data. MemoryStorage works this way, and its SetRaw method lets you place a damaged main copy to test recovery.

On This Page