File storage
using GFramework.Game.Serializer;
using GFramework.Game.Storage;
using var files = new FileStorage("GameData", new JsonSerializer(), ".json");
var profile = new ScopedStorage(files, "profile");
await profile.WriteAsync("score", 42);
int score = await profile.ReadAsync<int>("score");FileStorage uses relative keys under a root directory. Define keys as application identifiers and use ScopedStorage to assign a prefix to each subsystem sharing the store. The creator disposes the underlying storage.
Preserve raw snapshots and replace a save safely
Install GeWuYou.GFramework.Game in a .NET project for FileStorage and IStorageBackup. This console example seeds a save, preserves its exact bytes in a recovery file, and replaces the save with already serialized JSON. Run it in a scratch project because it writes and replaces the same files on each run.
using System.Text;
using GFramework.Game.Abstractions.Storage;
using GFramework.Game.Serializer;
using GFramework.Game.Storage;
using var files = new FileStorage("GameData", new JsonSerializer(), ".json");
IStorageBackup snapshots = files;
const string saveKey = "profile/progress";
const string recoveryKey = "recovery/progress-before-update";
await snapshots.WriteSnapshotAsync(saveKey,
new StorageSnapshot(Encoding.UTF8.GetBytes("""{"level":2,"extra":"keep me"}"""))).ConfigureAwait(false);
StorageSnapshot original = await snapshots.ReadSnapshotAsync(saveKey).ConfigureAwait(false);
await snapshots.WriteSnapshotAsync(recoveryKey, original).ConfigureAwait(false);
await snapshots.WriteSnapshotAsync(saveKey,
new StorageSnapshot(Encoding.UTF8.GetBytes("""{"level":3,"extra":"keep me"}"""))).ConfigureAwait(false);Expect GameData/recovery/progress-before-update.json to contain level 2 and the current save to contain level 3. In an existing game, use your configured serializer for typed reads and writes. Use snapshots for already serialized text or bytes and for a byte-for-byte backup that preserves fields outside the game's DTO.
Reuse one storage instance for a save root. FileStorage serializes operations for the same resolved path and writes the full payload to a sibling temporary file before replacing the destination. The path lock covers one call at a time. Another writer can update the save between the read and the replacement, leaving that update out of the backup. Coordinate the entire read, backup, and replace sequence with an application-level lock for that save, and have every writer to that save use the same lock. Await completion and surface I/O errors to the caller. Atomic replacement covers one file and provides no guarantee of recovery after power loss. Independent processes need shared coordination.
The game owns which saves are obsolete, when to delete them, backup retention and the meaning of resetting progress. Scope deletion to application-owned keys and use DeleteAsync only after that policy selects a file. SaveRepository<TSaveData> provides a workflow for versioned slots, migration, confirmation and recovery. When a Godot project needs user:// or res://, use GodotFileStorage from GeWuYou.GFramework.Godot and follow its thread and path rules.
For game saves and settings, choose a repository over storage. See Godot storage for native path mapping.