78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public static class DailyTaskSaveService
|
|
{
|
|
private const string SaveCategory = "daily_task";
|
|
private const string SaveKey = "runtime";
|
|
private const string RecoverySlotKey = "daily_task_runtime";
|
|
|
|
private static string LegacySaveFilePath
|
|
{
|
|
get { return Path.Combine(Application.persistentDataPath, "daily_tasks.json"); }
|
|
}
|
|
|
|
public static bool HasAnyRecoverableState()
|
|
{
|
|
return SecureSaveVault.HasAnyRecoverableState(SaveCategory, SaveKey, LegacySaveFilePath)
|
|
|| LocalRecoveryMirror.HasSlotData(RecoverySlotKey);
|
|
}
|
|
|
|
public static DailyTaskSaveData Load()
|
|
{
|
|
try
|
|
{
|
|
DailyTaskSaveData data;
|
|
if (SecureSaveVault.TryLoadJson(SaveCategory, SaveKey, out data, LegacySaveFilePath))
|
|
{
|
|
return data ?? new DailyTaskSaveData();
|
|
}
|
|
|
|
if (LocalRecoveryMirror.TryLoadJson(RecoverySlotKey, out data) && data != null)
|
|
{
|
|
SecureSaveVault.SaveJson(SaveCategory, SaveKey, data, LegacySaveFilePath);
|
|
return data;
|
|
}
|
|
|
|
return new DailyTaskSaveData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogWarning($"[DailyTaskSaveService] Load failed: {ex.Message}");
|
|
return new DailyTaskSaveData();
|
|
}
|
|
}
|
|
|
|
public static void Save(DailyTaskSaveData data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
SecureSaveVault.SaveJson(SaveCategory, SaveKey, data, LegacySaveFilePath);
|
|
LocalRecoveryMirror.SaveJson(RecoverySlotKey, data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogWarning($"[DailyTaskSaveService] Save failed: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public static void ClearPersistentState()
|
|
{
|
|
try
|
|
{
|
|
SecureSaveVault.Delete(SaveCategory, SaveKey, LegacySaveFilePath);
|
|
LocalRecoveryMirror.DeleteSlot(RecoverySlotKey);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogWarning($"[DailyTaskSaveService] Clear failed: {ex.Message}");
|
|
}
|
|
}
|
|
}
|