feat(save): 实现 Yarn tag 自动存档判定与异步写盘

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-18 14:34:19 +08:00
co-authored by Cursor
parent de671ff94c
commit 0a6e892504
8 changed files with 291 additions and 61 deletions
+24 -6
View File
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using AibisDream.Utility;
using Newtonsoft.Json;
using UnityEngine;
@@ -109,12 +110,29 @@ namespace AibisDream.SaveSystem
private static void CommitTempFile(string tempPath, string finalPath)
{
if (File.Exists(finalPath))
{
File.Delete(finalPath);
}
const int maxAttempts = 5;
File.Move(tempPath, finalPath);
for (var attempt = 0; attempt < maxAttempts; attempt++)
{
try
{
if (File.Exists(finalPath))
{
// Unity 使用的 .NET Standard 2.0 无 File.Move(..., overwrite)Replace 为原子覆盖。
File.Replace(tempPath, finalPath, null);
}
else
{
File.Move(tempPath, finalPath);
}
return;
}
catch (IOException) when (attempt < maxAttempts - 1)
{
Thread.Sleep(20 * (attempt + 1));
}
}
}
}
}