feat(save): 实现 Yarn tag 自动存档判定与异步写盘
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user