using System.IO;
using AibisDream.Utility;
using Newtonsoft.Json.Linq;
namespace AibisDream.SaveSystem
{
///
/// 快照与磁盘的边界:读写 JSON 文件、检测旧档格式。
///
/// P1 使用固定测试路径();
/// P2 将扩展为槽位目录、原子写、sidecar,接口可保持不变。
///
///
public static class SnapshotPersistence
{
/// P1 自测落盘:SnapshotTestPath/latest_snapshot.json。
public static string GetTestFilePath()
{
return Path.Combine(ConstRef.SnapshotTestPath, ConstRef.SnapshotTestFileName);
}
/// 将快照序列化并写入 path(自动补 .json 后缀)。
public static void Save(SaveSnapshot snapshot, string pathWithoutExtension)
{
SnapshotSerializer.SaveToFile(snapshot, pathWithoutExtension);
}
/// 从 path 读取并反序列化为 。
public static SaveSnapshot Load(string pathWithoutExtension)
{
return SnapshotSerializer.LoadFromFile(pathWithoutExtension);
}
///
/// 是否为旧 StorageSystem 格式(含 systemData、无 schemaVersion)。
/// 此类文件应走 的 legacy 分支。
///
public static bool IsLegacyFormat(string savePath)
{
var json = File.ReadAllText(JsonUtil.FormatAsJsonPath(savePath));
var jobj = JObject.Parse(json);
return jobj.Value("schemaVersion") == null && jobj["systemData"] != null;
}
/// 读取旧格式存档根 JObject,供 legacy 还原使用。
public static JObject ReadLegacySaveRoot(string savePath)
{
return JsonUtil.ReadJObject(savePath);
}
}
}