update cache system

修复验证远端下载文件,极小概率失败的问题。
pull/122/head
hevinci 2023-05-29 19:28:07 +08:00
parent e9fa3ead04
commit c91c49465b
3 changed files with 19 additions and 15 deletions

View File

@ -6,6 +6,11 @@ namespace YooAsset
/// </summary> /// </summary>
internal enum EVerifyResult internal enum EVerifyResult
{ {
/// <summary>
/// 验证异常
/// </summary>
Exception = -7,
/// <summary> /// <summary>
/// 未找到缓存信息 /// 未找到缓存信息
/// </summary> /// </summary>
@ -37,9 +42,9 @@ namespace YooAsset
FileCrcError = -1, FileCrcError = -1,
/// <summary> /// <summary>
/// 验证异常 /// 默认状态(校验未完成)
/// </summary> /// </summary>
Exception = 0, None = 0,
/// <summary> /// <summary>
/// 验证成功 /// 验证成功

View File

@ -60,11 +60,12 @@ namespace YooAsset
if (_steps == ESteps.Waiting) if (_steps == ESteps.Waiting)
{ {
if (_element.IsDone == false) int result = _element.Result;
if (result == 0)
return; return;
VerifyResult = _element.Result; VerifyResult = (EVerifyResult)result;
if (_element.Result == EVerifyResult.Succeed) if (VerifyResult == EVerifyResult.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@ -73,7 +74,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {_element.Result}"; Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
} }
} }
} }
@ -85,8 +86,8 @@ namespace YooAsset
private void VerifyInThread(object obj) private void VerifyInThread(object obj)
{ {
VerifyTempElement element = (VerifyTempElement)obj; VerifyTempElement element = (VerifyTempElement)obj;
element.Result = CacheSystem.VerifyingTempFile(element); int result = (int)CacheSystem.VerifyingTempFile(element);
element.IsDone = true; element.Result = result;
} }
} }
@ -120,11 +121,10 @@ namespace YooAsset
if (_steps == ESteps.VerifyFile) if (_steps == ESteps.VerifyFile)
{ {
_element.Result = CacheSystem.VerifyingTempFile(_element); _element.Result = (int)CacheSystem.VerifyingTempFile(_element);
_element.IsDone = true;
VerifyResult = _element.Result; VerifyResult = (EVerifyResult)_element.Result;
if (_element.Result == EVerifyResult.Succeed) if (VerifyResult == EVerifyResult.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@ -133,7 +133,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {_element.Result}"; Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
} }
} }
} }

View File

@ -49,8 +49,7 @@ namespace YooAsset
public string FileCRC { private set; get; } public string FileCRC { private set; get; }
public long FileSize { private set; get; } public long FileSize { private set; get; }
public bool IsDone = false; public int Result = 0; // 注意:原子操作对象
public EVerifyResult Result;
public VerifyTempElement(string tempDataFilePath, string fileCRC, long fileSize) public VerifyTempElement(string tempDataFilePath, string fileCRC, long fileSize)
{ {