mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Text.Json;
|
|
|
|
namespace LanMountainDesktop.Services.Update;
|
|
|
|
internal sealed class UpdateSnapshotStore(PlondsApplyPaths paths)
|
|
{
|
|
public string CreateSnapshotPath(string snapshotId) => paths.GetSnapshotPath(snapshotId);
|
|
|
|
public void Save(string path, ApplySnapshotMetadata snapshot)
|
|
{
|
|
File.WriteAllText(path, JsonSerializer.Serialize(snapshot, UpdateApplyJsonContext.Default.ApplySnapshotMetadata));
|
|
}
|
|
|
|
public (string Path, ApplySnapshotMetadata Snapshot)? LoadLatest()
|
|
{
|
|
if (!Directory.Exists(paths.SnapshotsRoot))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var snapshotPath = Directory
|
|
.EnumerateFiles(paths.SnapshotsRoot, "*.json", SearchOption.TopDirectoryOnly)
|
|
.OrderByDescending(File.GetCreationTimeUtc)
|
|
.FirstOrDefault();
|
|
if (string.IsNullOrWhiteSpace(snapshotPath))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var snapshot = JsonSerializer.Deserialize(File.ReadAllText(snapshotPath), UpdateApplyJsonContext.Default.ApplySnapshotMetadata);
|
|
return snapshot is null ? null : (snapshotPath, snapshot);
|
|
}
|
|
}
|