Table of Contents

Class AtomicJsonFile

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

Atomic load/save for the app's JSON files (servers.json, settings.json), so a crash or power loss mid-write can never truncate them. Writes go to a ".tmp" file that atomically replaces the target, keeping the previous version as ".bak". A corrupt file is quarantined as ".bad" and the ".bak" copy is restored when possible, instead of silently starting from scratch.

public static class AtomicJsonFile
Inheritance
AtomicJsonFile
Inherited Members

Methods

Load<T>(string, JsonSerializerOptions?)

Reads and deserializes path. If the JSON is corrupt, quarantines it as "<path>.bad" and tries the last good "<path>.bak" copy (re-writing it as the real file so the next start is normal). Returns the value (null when the file is missing or unrecoverable) plus what happened, so callers can tell the user instead of failing silently.

public static (T? Value, AtomicJsonFile.LoadOutcome Outcome) Load<T>(string path, JsonSerializerOptions? options = null) where T : class

Parameters

path string
options JsonSerializerOptions

Returns

(T Value, AtomicJsonFile.LoadOutcome Outcome)

Type Parameters

T

Write<T>(string, T, JsonSerializerOptions?)

Serializes value and writes it atomically: the JSON goes to "<path>.tmp" first and then replaces path in a single filesystem operation (same volume), keeping the previous content as "<path>.bak". A crash mid-write leaves at worst a truncated .tmp — never a truncated real file.

public static void Write<T>(string path, T value, JsonSerializerOptions? options = null)

Parameters

path string
value T
options JsonSerializerOptions

Type Parameters

T