Class JsonEnvelopeFile

Namespace
SurvivorsMaker.Presentation
Assembly
SurvivorsMaker.Presentation.dll

One save domain (options, profile or run) in one JSON file, written as a SaveEnvelope with JsonUtility and read through Read(SaveEnvelope, SaveDomain).

  • Writes go to a temporary file that is read back and then swapped in with Replace(string, string, string) (a plain copy only where the platform has no replace).
  • A corrupt or incompatible file is moved aside (*.corrupt / *.incompatible) and kept; the store then starts from defaults.
  • A file from a newer schema, or an unreadable file, is left untouched and the store refuses to write over it for the rest of the session.
public sealed class JsonEnvelopeFile
Inheritance
JsonEnvelopeFile
Inherited Members

Constructors

JsonEnvelopeFile(string, SaveDomain)

public JsonEnvelopeFile(string path, SaveDomain domain)

Parameters

path string
domain SaveDomain

Fields

CorruptSuffix

public const string CorruptSuffix = ".corrupt"

Field Value

string

IncompatibleSuffix

public const string IncompatibleSuffix = ".incompatible"

Field Value

string

TemporarySuffix

public const string TemporarySuffix = ".tmp"

Field Value

string

Properties

Domain

public SaveDomain Domain { get; }

Property Value

SaveDomain

HasRead

public bool HasRead { get; }

Property Value

bool

LastRead

Result of the last read (Missing before the first one).

public SaveReadResult LastRead { get; }

Property Value

SaveReadResult

Path

public string Path { get; }

Property Value

string

PreservedPath

Where a corrupt or incompatible file was moved, or empty.

public string PreservedPath { get; }

Property Value

string

WriteBlocked

True when the file on disk must be preserved as it is (newer schema, unreadable).

public bool WriteBlocked { get; }

Property Value

bool

Methods

Delete(bool)

Removes the file (an empty run slot). Blocked files are kept unless force (an explicit reset).

public bool Delete(bool force = false)

Parameters

force bool

Returns

bool

Read(SaveMigrationRegistry)

Reads, validates and migrates the file. Never throws for file or data problems.

public SaveReadResult Read(SaveMigrationRegistry migrations)

Parameters

migrations SaveMigrationRegistry

Returns

SaveReadResult

Write(SaveEnvelope, SaveMigrationRegistry)

Writes envelope as the next generation. False when blocked or the write failed.

public bool Write(SaveEnvelope envelope, SaveMigrationRegistry migrationsForFirstRead)

Parameters

envelope SaveEnvelope
migrationsForFirstRead SaveMigrationRegistry

Returns

bool