update cache system

EVerifyLevel 新增Middle等级
pull/70/head
hevinci 2023-02-21 14:35:02 +08:00
parent fa0dc48993
commit 17c6158478
4 changed files with 29 additions and 14 deletions

View File

@ -69,31 +69,41 @@ namespace YooAsset
/// <summary> /// <summary>
/// 验证缓存文件(子线程内操作) /// 验证缓存文件(子线程内操作)
/// </summary> /// </summary>
public static EVerifyResult VerifyingCacheFile(VerifyElement element, EVerifyLevel verifyLevel) public static EVerifyResult VerifyingCacheFile(VerifyElement element)
{ {
try try
{ {
string infoFilePath = element.InfoFilePath; if (InitVerifyLevel == EVerifyLevel.Low)
if (File.Exists(infoFilePath) == false) {
if (File.Exists(element.InfoFilePath) == false)
return EVerifyResult.InfoFileNotExisted;
if (File.Exists(element.DataFilePath) == false)
return EVerifyResult.DataFileNotExisted;
return EVerifyResult.Succeed;
}
else
{
if (File.Exists(element.InfoFilePath) == false)
return EVerifyResult.InfoFileNotExisted; return EVerifyResult.InfoFileNotExisted;
// 解析信息文件获取验证数据 // 解析信息文件获取验证数据
CacheFileInfo.ReadInfoFromFile(infoFilePath, out element.DataFileCRC, out element.DataFileSize); CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
}
} }
catch (Exception) catch (Exception)
{ {
return EVerifyResult.Exception; return EVerifyResult.Exception;
} }
return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, verifyLevel); return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, InitVerifyLevel);
} }
/// <summary> /// <summary>
/// 验证下载文件 /// 验证下载文件
/// </summary> /// </summary>
public static EVerifyResult VerifyingTempFile(PatchBundle patchBundle, EVerifyLevel verifyLevel) public static EVerifyResult VerifyingTempFile(PatchBundle patchBundle)
{ {
return VerifyingInternal(patchBundle.TempDataFilePath, patchBundle.FileSize, patchBundle.FileCRC, verifyLevel); return VerifyingInternal(patchBundle.TempDataFilePath, patchBundle.FileSize, patchBundle.FileCRC, EVerifyLevel.High);
} }
/// <summary> /// <summary>

View File

@ -7,10 +7,15 @@ namespace YooAsset
public enum EVerifyLevel public enum EVerifyLevel
{ {
/// <summary> /// <summary>
/// 验证文件大小 /// 验证文件存在
/// </summary> /// </summary>
Low, Low,
/// <summary>
/// 验证文件大小
/// </summary>
Middle,
/// <summary> /// <summary>
/// 验证文件大小和CRC /// 验证文件大小和CRC
/// </summary> /// </summary>

View File

@ -121,7 +121,7 @@ namespace YooAsset
private void VerifyInThread(object obj) private void VerifyInThread(object obj)
{ {
VerifyElement element = (VerifyElement)obj; VerifyElement element = (VerifyElement)obj;
element.Result = CacheSystem.VerifyingCacheFile(element, CacheSystem.InitVerifyLevel); element.Result = CacheSystem.VerifyingCacheFile(element);
_syncContext.Post(VerifyCallback, element); _syncContext.Post(VerifyCallback, element);
} }
private void VerifyCallback(object obj) private void VerifyCallback(object obj)
@ -235,7 +235,7 @@ namespace YooAsset
} }
private void BeginVerifyFileWithoutThread(VerifyElement element) private void BeginVerifyFileWithoutThread(VerifyElement element)
{ {
element.Result = CacheSystem.VerifyingCacheFile(element, CacheSystem.InitVerifyLevel); element.Result = CacheSystem.VerifyingCacheFile(element);
if (element.Result == EVerifyResult.Succeed) if (element.Result == EVerifyResult.Succeed)
{ {
_succeedCount++; _succeedCount++;

View File

@ -37,7 +37,7 @@ namespace YooAsset
// 检测本地临时文件 // 检测本地临时文件
if (_steps == ESteps.CheckTempFile) if (_steps == ESteps.CheckTempFile)
{ {
var verifyResult = CacheSystem.VerifyingTempFile(_bundleInfo.Bundle, EVerifyLevel.High); var verifyResult = CacheSystem.VerifyingTempFile(_bundleInfo.Bundle);
if (verifyResult == EVerifyResult.Succeed) if (verifyResult == EVerifyResult.Succeed)
{ {
_steps = ESteps.CachingFile; _steps = ESteps.CachingFile;
@ -198,7 +198,7 @@ namespace YooAsset
// 验证下载文件 // 验证下载文件
if (_steps == ESteps.VerifyingFile) if (_steps == ESteps.VerifyingFile)
{ {
var verifyResult = CacheSystem.VerifyingTempFile(_bundleInfo.Bundle, EVerifyLevel.High); var verifyResult = CacheSystem.VerifyingTempFile(_bundleInfo.Bundle);
if (verifyResult == EVerifyResult.Succeed) if (verifyResult == EVerifyResult.Succeed)
{ {
_steps = ESteps.CachingFile; _steps = ESteps.CachingFile;