update cache system

缓存系统支持后缀名存储方式
pull/70/head
hevinci 2023-02-22 16:46:36 +08:00
parent 8958317f61
commit d1f2712e5f
5 changed files with 38 additions and 16 deletions

View File

@ -13,7 +13,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 初始化时的验证级别 /// 初始化时的验证级别
/// </summary> /// </summary>
public static EVerifyLevel InitVerifyLevel { set; get; } = EVerifyLevel.Low; public static EVerifyLevel InitVerifyLevel { set; get; } = EVerifyLevel.Middle;
/// <summary> /// <summary>
/// 清空所有数据 /// 清空所有数据
@ -37,6 +37,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void RecordFile(string packageName, string cacheGUID, PackageCache.RecordWrapper wrapper) public static void RecordFile(string packageName, string cacheGUID, PackageCache.RecordWrapper wrapper)
{ {
//YooLogger.Log($"Record file : {packageName} = {cacheGUID}");
var cache = GetOrCreateCache(packageName); var cache = GetOrCreateCache(packageName);
cache.Record(cacheGUID, wrapper); cache.Record(cacheGUID, wrapper);
} }

View File

@ -67,8 +67,23 @@ namespace YooAsset
if (CacheSystem.IsCached(_packageName, cacheGUID)) if (CacheSystem.IsCached(_packageName, cacheGUID))
continue; continue;
// 获取数据文件的后缀名
string dataFileExtension = string.Empty;
var fileInfos = fileFoder.GetFiles();
foreach (var fileInfo in fileInfos)
{
if (fileInfo.Extension == ".temp")
continue;
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
{
dataFileExtension = fileInfo.Extension;
break;
}
}
string fileRootPath = fileFoder.FullName; string fileRootPath = fileFoder.FullName;
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}"; string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}";
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
result.Add(element); result.Add(element);

View File

@ -139,12 +139,8 @@ namespace YooAsset
{ {
_failedCount++; _failedCount++;
// 删除验证失败的缓存文件 YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
if (Directory.Exists(element.FileRootPath)) element.DeleteFiles();
{
YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
Directory.Delete(element.FileRootPath, true);
}
} }
} }
} }
@ -246,12 +242,8 @@ namespace YooAsset
{ {
_failedCount++; _failedCount++;
// 删除验证失败的缓存文件 YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
if (Directory.Exists(element.FileRootPath)) element.DeleteFiles();
{
YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
Directory.Delete(element.FileRootPath, true);
}
} }
} }
} }

View File

@ -1,4 +1,5 @@
 using System.IO;
namespace YooAsset namespace YooAsset
{ {
internal class VerifyElement internal class VerifyElement
@ -21,5 +22,18 @@ namespace YooAsset
DataFilePath = dataFilePath; DataFilePath = dataFilePath;
InfoFilePath = infoFilePath; InfoFilePath = infoFilePath;
} }
public void DeleteFiles()
{
if (File.Exists(DataFilePath))
{
File.Delete(DataFilePath);
}
if (File.Exists(InfoFilePath))
{
File.Delete(InfoFilePath);
}
}
} }
} }

View File

@ -72,7 +72,7 @@ namespace YooAsset
return _cachedDataFilePath; return _cachedDataFilePath;
string cacheRoot = PersistentHelper.GetCacheFolderPath(PackageName); string cacheRoot = PersistentHelper.GetCacheFolderPath(PackageName);
_cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}"; _cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}";
return _cachedDataFilePath; return _cachedDataFilePath;
} }
} }