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>
public static EVerifyResult VerifyingCacheFile(VerifyElement element, EVerifyLevel verifyLevel)
public static EVerifyResult VerifyingCacheFile(VerifyElement element)
{
try
{
string infoFilePath = element.InfoFilePath;
if (File.Exists(infoFilePath) == false)
return EVerifyResult.InfoFileNotExisted;
if (InitVerifyLevel == EVerifyLevel.Low)
{
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;
// 解析信息文件获取验证数据
CacheFileInfo.ReadInfoFromFile(infoFilePath, out element.DataFileCRC, out element.DataFileSize);
// 解析信息文件获取验证数据
CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
}
}
catch (Exception)
{
return EVerifyResult.Exception;
}
return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, verifyLevel);
return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, InitVerifyLevel);
}
/// <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>

View File

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

View File

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

View File

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