2026-04-28 10:23:58 +08:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Json;
|
2026-05-15 17:30:30 +08:00
|
|
|
using YY.Admin.Core.Util;
|
2026-04-28 10:23:58 +08:00
|
|
|
|
|
|
|
|
namespace YY.Admin.Services.Service.Jeecg
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2026-05-15 17:30:30 +08:00
|
|
|
/// 读写本地 Jeecg 同步状态文件(用户可写目录,避免 Program Files 无写权限)。
|
2026-04-28 10:23:58 +08:00
|
|
|
/// </summary>
|
|
|
|
|
public class JeecgSyncStateStore
|
|
|
|
|
{
|
|
|
|
|
private readonly string _filePath;
|
|
|
|
|
|
|
|
|
|
public JeecgSyncStateStore()
|
|
|
|
|
{
|
2026-05-15 17:30:30 +08:00
|
|
|
var dir = AppWritablePaths.EnsureDirectoryExists(AppWritablePaths.ConfigurationDirectory);
|
2026-04-28 10:23:58 +08:00
|
|
|
_filePath = Path.Combine(dir, "jeecg-sync-state.json");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JeecgSyncState Load()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(_filePath))
|
|
|
|
|
{
|
|
|
|
|
return new JeecgSyncState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = File.ReadAllText(_filePath);
|
|
|
|
|
return JsonSerializer.Deserialize<JeecgSyncState>(json) ?? new JeecgSyncState();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return new JeecgSyncState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save(JeecgSyncState state)
|
|
|
|
|
{
|
|
|
|
|
var dir = Path.GetDirectoryName(_filePath);
|
|
|
|
|
if (!string.IsNullOrEmpty(dir))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = JsonSerializer.Serialize(state, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
|
File.WriteAllText(_filePath, json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|