ClearCacheBundleFilesAsync重命名为ClearCacheFilesAsync
pull/455/head
何冠峰 2025-01-03 15:08:57 +08:00
parent 1d0c0ee7cb
commit 278b6e3cc8
56 changed files with 392 additions and 310 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ce78de82d3ce1a841a1e6bad099e0bab
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,67 +0,0 @@
using System.Collections.Generic;
namespace YooAsset
{
internal interface ICacheSystem
{
/// <summary>
/// 获取缓存文件的根目录
/// </summary>
string GetCacheFileRoot();
/// <summary>
/// 获取临时缓存文件路径
/// </summary>
string GetTempFilePath(PackageBundle bundle);
/// <summary>
/// 获取数据文件路径
/// </summary>
string GetDataFilePath(PackageBundle bundle);
/// <summary>
/// 获取信息文件路径
/// </summary>
string GetInfoFilePath(PackageBundle bundle);
/// <summary>
/// 获取所有缓存文件的GUID
/// </summary>
List<string> GetAllCachedBundleGUIDs();
/// <summary>
/// 是否记录了文件
/// </summary>
bool IsRecordFile(string bundleGUID);
/// <summary>
/// 记录指定文件
/// </summary>
bool RecordFile(string bundleGUID, CacheWrapper wrapper);
/// <summary>
/// 验证缓存文件
/// </summary>
EFileVerifyResult VerifyCacheFile(PackageBundle bundle);
/// <summary>
/// 写入缓存文件
/// </summary>
bool WriteCacheFile(PackageBundle bundle, string copyPath);
/// <summary>
/// 删除缓存文件
/// </summary>
bool DeleteCacheFile(string bundleGUID);
/// <summary>
/// 写入文件信息
/// </summary>
void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize);
/// <summary>
/// 读取文件信息
/// </summary>
void ReadInfoFile(string filePath, out string dataFileCRC, out long dataFileSize);
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 8cae5a51fced527429445b140b8a0843
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -96,9 +96,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{ {
return _unpackFileSystem.ClearCacheBundleFilesAsync(manifest, clearMode, clearParam); return _unpackFileSystem.ClearCacheFilesAsync(manifest, clearMode, clearParam);
} }
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param) public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
{ {

View File

@ -100,13 +100,13 @@ namespace YooAsset
DefaultDownloadFileOperation newDownloader; DefaultDownloadFileOperation newDownloader;
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize) if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
{ {
newDownloader = new DownloadResumeFileOperation(_fileSystem, _fileSystem, bundle, param, _fileSystem.ResumeDownloadResponseCodes); newDownloader = new DownloadResumeFileOperation(_fileSystem, bundle, param);
newDownloader.Reference(); newDownloader.Reference();
_downloaders.Add(bundle.BundleGUID, newDownloader); _downloaders.Add(bundle.BundleGUID, newDownloader);
} }
else else
{ {
newDownloader = new DownloadNormalFileOperation(_fileSystem, _fileSystem, bundle, param); newDownloader = new DownloadNormalFileOperation(_fileSystem, bundle, param);
newDownloader.Reference(); newDownloader.Reference();
_downloaders.Add(bundle.BundleGUID, newDownloader); _downloaders.Add(bundle.BundleGUID, newDownloader);
} }

View File

@ -2,7 +2,6 @@
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
@ -10,18 +9,18 @@ namespace YooAsset
/// 缓存文件系统 /// 缓存文件系统
/// 说明正在进行的下载器会在ResourcePackage销毁的时候执行Abort操作 /// 说明正在进行的下载器会在ResourcePackage销毁的时候执行Abort操作
/// </summary> /// </summary>
internal class DefaultCacheFileSystem : IFileSystem, ICacheSystem internal class DefaultCacheFileSystem : IFileSystem
{ {
protected readonly Dictionary<string, CacheWrapper> _wrappers = new Dictionary<string, CacheWrapper>(10000); protected readonly Dictionary<string, RecordFileElement> _wrappers = new Dictionary<string, RecordFileElement>(10000);
protected readonly Dictionary<string, string> _dataFilePaths = new Dictionary<string, string>(10000); protected readonly Dictionary<string, string> _bundleDataFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _infoFilePaths = new Dictionary<string, string>(10000); protected readonly Dictionary<string, string> _bundleInfoFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _tempFilePaths = new Dictionary<string, string>(10000); protected readonly Dictionary<string, string> _tempFilePaths = new Dictionary<string, string>(10000);
protected DefaultCacheDownloadCenter _downloadCenter; protected DefaultCacheDownloadCenter _downloadCenter;
protected string _packageRoot; protected string _packageRoot;
protected string _cacheFileRoot; protected string _tempFilesRoot;
protected string _tempFileRoot; protected string _cacheBundleFilesRoot;
protected string _manifestFileRoot; protected string _cacheManifestFilesRoot;
/// <summary> /// <summary>
/// 包裹名称 /// 包裹名称
@ -114,30 +113,42 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{ {
if (clearMode == EFileClearMode.ClearAllBundleFiles.ToString()) if (clearMode == EFileClearMode.ClearAllBundleFiles.ToString())
{ {
var operation = new ClearAllCacheFilesOperation(this); var operation = new ClearAllCacheBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
else if (clearMode == EFileClearMode.ClearUnusedBundleFiles.ToString()) else if (clearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
{ {
var operation = new ClearUnusedCacheFilesOperation(this, manifest); var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
else if (clearMode == EFileClearMode.ClearBundleFilesByTags.ToString()) else if (clearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
{ {
var operation = new ClearCacheFilesByTagsOperaiton(this, manifest, clearParam); var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else if (clearMode == EFileClearMode.ClearAllManifestFiles.ToString())
{
var operation = new ClearAllCacheManifestFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else if (clearMode == EFileClearMode.ClearUnusedManifestFiles.ToString())
{
var operation = new ClearUnusedCacheManifestFilesOperation(this, manifest);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
else else
{ {
string error = $"Invalid clear mode : {clearMode}"; string error = $"Invalid clear mode : {clearMode}";
var operation = new FSClearCacheBundleFilesCompleteOperation(error); var operation = new FSClearCacheFilesCompleteOperation(error);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@ -217,9 +228,9 @@ namespace YooAsset
else else
_packageRoot = packageRoot; _packageRoot = packageRoot;
_cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.SaveFilesFolderName); _cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
_tempFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName); _tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName);
_manifestFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName); _cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
_downloadCenter = new DefaultCacheDownloadCenter(this); _downloadCenter = new DefaultCacheDownloadCenter(this);
} }
public virtual void OnUpdate() public virtual void OnUpdate()
@ -257,7 +268,7 @@ namespace YooAsset
public virtual string GetBundleFilePath(PackageBundle bundle) public virtual string GetBundleFilePath(PackageBundle bundle)
{ {
return GetCacheFileLoadPath(bundle); return GetCacheBundleFileLoadPath(bundle);
} }
public virtual byte[] ReadBundleFileData(PackageBundle bundle) public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{ {
@ -272,7 +283,7 @@ namespace YooAsset
return null; return null;
} }
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var fileInfo = new DecryptFileInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
@ -283,7 +294,7 @@ namespace YooAsset
} }
else else
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
return FileUtility.ReadAllBytes(filePath); return FileUtility.ReadAllBytes(filePath);
} }
} }
@ -300,7 +311,7 @@ namespace YooAsset
return null; return null;
} }
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var fileInfo = new DecryptFileInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
@ -311,85 +322,82 @@ namespace YooAsset
} }
else else
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
return FileUtility.ReadAllText(filePath); return FileUtility.ReadAllText(filePath);
} }
} }
#region 缓存系统 #region 缓存相关
public string GetCacheFileRoot()
{
return _cacheFileRoot;
}
public string GetTempFilePath(PackageBundle bundle)
{
if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_tempFileRoot, bundle.BundleGUID);
_tempFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetDataFilePath(PackageBundle bundle)
{
if (_dataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleDataFileName);
if (AppendFileExtension)
filePath += bundle.FileExtension;
_dataFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetInfoFilePath(PackageBundle bundle)
{
if (_infoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheFileRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.SaveBundleInfoFileName);
_infoFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public List<string> GetAllCachedBundleGUIDs() public List<string> GetAllCachedBundleGUIDs()
{ {
return _wrappers.Keys.ToList(); return _wrappers.Keys.ToList();
} }
public bool IsRecordFile(string bundleGUID) public string GetTempFilePath(PackageBundle bundle)
{
if (_tempFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
filePath = PathUtility.Combine(_tempFilesRoot, bundle.BundleGUID);
_tempFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetBundleDataFilePath(PackageBundle bundle)
{
if (_bundleDataFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheBundleFilesRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.BundleDataFileName);
if (AppendFileExtension)
filePath += bundle.FileExtension;
_bundleDataFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public string GetBundleInfoFilePath(PackageBundle bundle)
{
if (_bundleInfoFilePaths.TryGetValue(bundle.BundleGUID, out string filePath) == false)
{
string folderName = bundle.FileHash.Substring(0, 2);
filePath = PathUtility.Combine(_cacheBundleFilesRoot, folderName, bundle.BundleGUID, DefaultCacheFileSystemDefine.BundleInfoFileName);
_bundleInfoFilePaths.Add(bundle.BundleGUID, filePath);
}
return filePath;
}
public bool IsRecordBundleFile(string bundleGUID)
{ {
return _wrappers.ContainsKey(bundleGUID); return _wrappers.ContainsKey(bundleGUID);
} }
public bool RecordFile(string bundleGUID, CacheWrapper wrapper) public bool RecordBundleFile(string bundleGUID, RecordFileElement element)
{ {
if (_wrappers.ContainsKey(bundleGUID)) if (_wrappers.ContainsKey(bundleGUID))
{ {
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has element : {bundleGUID}"); YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has record file element : {bundleGUID}");
return false; return false;
} }
_wrappers.Add(bundleGUID, wrapper); _wrappers.Add(bundleGUID, element);
return true; return true;
} }
public EFileVerifyResult VerifyCacheFile(PackageBundle bundle) public EFileVerifyResult VerifyCacheFile(PackageBundle bundle)
{ {
if (_wrappers.TryGetValue(bundle.BundleGUID, out CacheWrapper wrapper) == false) if (_wrappers.TryGetValue(bundle.BundleGUID, out RecordFileElement wrapper) == false)
return EFileVerifyResult.CacheNotFound; return EFileVerifyResult.CacheNotFound;
EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High); EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
return result; return result;
} }
public bool WriteCacheFile(PackageBundle bundle, string copyPath) public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
{ {
if (_wrappers.ContainsKey(bundle.BundleGUID)) if (_wrappers.ContainsKey(bundle.BundleGUID))
{ {
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
} }
string infoFilePath = GetInfoFilePath(bundle); string infoFilePath = GetBundleInfoFilePath(bundle);
string dataFilePath = GetDataFilePath(bundle); string dataFilePath = GetBundleDataFilePath(bundle);
try try
{ {
@ -405,7 +413,7 @@ namespace YooAsset
fileInfo.CopyTo(dataFilePath); fileInfo.CopyTo(dataFilePath);
// 写入文件信息 // 写入文件信息
WriteInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize); WriteBundleInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize);
} }
catch (Exception e) catch (Exception e)
{ {
@ -413,12 +421,12 @@ namespace YooAsset
return false; return false;
} }
var wrapper = new CacheWrapper(infoFilePath, dataFilePath, bundle.FileCRC, bundle.FileSize); var recordFileElement = new RecordFileElement(infoFilePath, dataFilePath, bundle.FileCRC, bundle.FileSize);
return RecordFile(bundle.BundleGUID, wrapper); return RecordBundleFile(bundle.BundleGUID, recordFileElement);
} }
public bool DeleteCacheFile(string bundleGUID) public bool DeleteCacheBundleFile(string bundleGUID)
{ {
if (_wrappers.TryGetValue(bundleGUID, out CacheWrapper wrapper)) if (_wrappers.TryGetValue(bundleGUID, out RecordFileElement wrapper))
{ {
try try
{ {
@ -442,7 +450,7 @@ namespace YooAsset
} }
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024); private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize) public void WriteBundleInfoFile(string filePath, string dataFileCRC, long dataFileSize)
{ {
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
{ {
@ -453,7 +461,7 @@ namespace YooAsset
fs.Flush(); fs.Flush();
} }
} }
public void ReadInfoFile(string filePath, out string dataFileCRC, out long dataFileSize) public void ReadBundleInfoFile(string filePath, out string dataFileCRC, out long dataFileSize)
{ {
byte[] binaryData = FileUtility.ReadAllBytes(filePath); byte[] binaryData = FileUtility.ReadAllBytes(filePath);
BufferReader buffer = new BufferReader(binaryData); BufferReader buffer = new BufferReader(binaryData);
@ -477,23 +485,31 @@ namespace YooAsset
return PathUtility.Combine(rootDirectory, packageName); return PathUtility.Combine(rootDirectory, packageName);
} }
public string GetCacheFileLoadPath(PackageBundle bundle) public string GetCacheBundleFileLoadPath(PackageBundle bundle)
{ {
return GetDataFilePath(bundle); return GetBundleDataFilePath(bundle);
} }
public string GetCachePackageHashFilePath(string packageVersion) public string GetCachePackageHashFilePath(string packageVersion)
{ {
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
return PathUtility.Combine(_manifestFileRoot, fileName); return PathUtility.Combine(_cacheManifestFilesRoot, fileName);
} }
public string GetCachePackageManifestFilePath(string packageVersion) public string GetCachePackageManifestFilePath(string packageVersion)
{ {
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(_manifestFileRoot, fileName); return PathUtility.Combine(_cacheManifestFilesRoot, fileName);
} }
public string GetSandboxAppFootPrintFilePath() public string GetSandboxAppFootPrintFilePath()
{ {
return PathUtility.Combine(_manifestFileRoot, DefaultCacheFileSystemDefine.AppFootPrintFileName); return PathUtility.Combine(_cacheManifestFilesRoot, DefaultCacheFileSystemDefine.AppFootPrintFileName);
}
public string GetCacheBundleFilesRoot()
{
return _cacheBundleFilesRoot;
}
public string GetCacheManifestFilesRoot()
{
return _cacheManifestFilesRoot;
} }
/// <summary> /// <summary>
@ -501,9 +517,9 @@ namespace YooAsset
/// </summary> /// </summary>
public void DeleteAllManifestFiles() public void DeleteAllManifestFiles()
{ {
if (Directory.Exists(_manifestFileRoot)) if (Directory.Exists(_cacheManifestFilesRoot))
{ {
Directory.Delete(_manifestFileRoot, true); Directory.Delete(_cacheManifestFilesRoot, true);
} }
} }
@ -512,7 +528,7 @@ namespace YooAsset
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle) public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var fileInfo = new DecryptFileInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
@ -527,7 +543,7 @@ namespace YooAsset
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle) public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
{ {
string filePath = GetCacheFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var fileInfo = new DecryptFileInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,

View File

@ -4,27 +4,27 @@ namespace YooAsset
internal class DefaultCacheFileSystemDefine internal class DefaultCacheFileSystemDefine
{ {
/// <summary> /// <summary>
/// 保存的数据文件名称 /// 数据文件名称
/// </summary> /// </summary>
public const string SaveBundleDataFileName = "__data"; public const string BundleDataFileName = "__data";
/// <summary> /// <summary>
/// 保存的信息文件名称 /// 信息文件名称
/// </summary> /// </summary>
public const string SaveBundleInfoFileName = "__info"; public const string BundleInfoFileName = "__info";
/// <summary> /// <summary>
/// 保存的资源文件的文件夹名称 /// 资源文件的文件夹名称
/// </summary> /// </summary>
public const string SaveFilesFolderName = "CacheFiles"; public const string BundleFilesFolderName = "BundleFiles";
/// <summary> /// <summary>
/// 下载的临时文件的文件夹名称 /// 临时文件的文件夹名称
/// </summary> /// </summary>
public const string TempFilesFolderName = "CacheTempFiles"; public const string TempFilesFolderName = "TempFiles";
/// <summary> /// <summary>
/// 保存的清单文件的文件夹名称 /// 清单文件的文件夹名称
/// </summary> /// </summary>
public const string ManifestFilesFolderName = "ManifestFiles"; public const string ManifestFilesFolderName = "ManifestFiles";

View File

@ -1,14 +1,14 @@
 
namespace YooAsset namespace YooAsset
{ {
internal class CacheWrapper internal class RecordFileElement
{ {
public string InfoFilePath { private set; get; } public string InfoFilePath { private set; get; }
public string DataFilePath { private set; get; } public string DataFilePath { private set; get; }
public string DataFileCRC { private set; get; } public string DataFileCRC { private set; get; }
public long DataFileSize { private set; get; } public long DataFileSize { private set; get; }
public CacheWrapper(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize) public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
{ {
InfoFilePath = infoFilePath; InfoFilePath = infoFilePath;
DataFilePath = dataFilePath; DataFilePath = dataFilePath;

View File

@ -2,7 +2,7 @@
namespace YooAsset namespace YooAsset
{ {
internal class CacheFileElement internal class VerifyFileElement
{ {
public string PackageName { private set; get; } public string PackageName { private set; get; }
public string BundleGUID { private set; get; } public string BundleGUID { private set; get; }
@ -18,7 +18,7 @@ namespace YooAsset
/// </summary> /// </summary>
public volatile int Result = 0; public volatile int Result = 0;
public CacheFileElement(string packageName, string bundleGUID, string fileRootPath, string dataFilePath, string infoFilePath) public VerifyFileElement(string packageName, string bundleGUID, string fileRootPath, string dataFilePath, string infoFilePath)
{ {
PackageName = packageName; PackageName = packageName;
BundleGUID = bundleGUID; BundleGUID = bundleGUID;

View File

@ -57,7 +57,7 @@ namespace YooAsset
{ {
if (_searchCacheFilesOp == null) if (_searchCacheFilesOp == null)
{ {
_searchCacheFilesOp = new SearchCacheFilesOperation(_fileSystem, _fileSystem.PackageName, _fileSystem.AppendFileExtension); _searchCacheFilesOp = new SearchCacheFilesOperation(_fileSystem);
OperationSystem.StartOperation(_fileSystem.PackageName, _searchCacheFilesOp); OperationSystem.StartOperation(_fileSystem.PackageName, _searchCacheFilesOp);
} }
@ -72,7 +72,7 @@ namespace YooAsset
{ {
if (_verifyCacheFilesOp == null) if (_verifyCacheFilesOp == null)
{ {
_verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSystem, _fileSystem.FileVerifyLevel, _searchCacheFilesOp.Result); _verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSystem, _searchCacheFilesOp.Result);
OperationSystem.StartOperation(_fileSystem.PackageName, _verifyCacheFilesOp); OperationSystem.StartOperation(_fileSystem.PackageName, _verifyCacheFilesOp);
} }

View File

@ -104,7 +104,7 @@ namespace YooAsset
} }
else else
{ {
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle); string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
_assetBundle = AssetBundle.LoadFromFile(filePath); _assetBundle = AssetBundle.LoadFromFile(filePath);
} }
} }
@ -118,7 +118,7 @@ namespace YooAsset
} }
else else
{ {
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle); string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
_createRequest = AssetBundle.LoadFromFileAsync(filePath); _createRequest = AssetBundle.LoadFromFileAsync(filePath);
} }
} }
@ -168,7 +168,7 @@ namespace YooAsset
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。 // 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发! // 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle); string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
byte[] fileData = FileUtility.ReadAllBytes(filePath); byte[] fileData = FileUtility.ReadAllBytes(filePath);
if (fileData != null && fileData.Length > 0) if (fileData != null && fileData.Length > 0)
{ {
@ -198,7 +198,7 @@ namespace YooAsset
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
_fileSystem.DeleteCacheFile(_bundle.BundleGUID); _fileSystem.DeleteCacheBundleFile(_bundle.BundleGUID);
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"Find corrupted asset bundle file and delete : {_bundle.BundleName}"; Error = $"Find corrupted asset bundle file and delete : {_bundle.BundleName}";
YooLogger.Error(Error); YooLogger.Error(Error);
@ -304,7 +304,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCacheRawBundle) if (_steps == ESteps.LoadCacheRawBundle)
{ {
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle); string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal sealed class ClearAllCacheFilesOperation : FSClearCacheBundleFilesOperation internal sealed class ClearAllCacheBundleFilesOperation : FSClearCacheFilesOperation
{ {
private enum ESteps private enum ESteps
{ {
@ -13,15 +13,15 @@ namespace YooAsset
Done, Done,
} }
private readonly ICacheSystem _cacheSystem; private readonly DefaultCacheFileSystem _fileSystem;
private List<string> _allBundleGUIDs; private List<string> _allBundleGUIDs;
private int _fileTotalCount = 0; private int _fileTotalCount = 0;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal ClearAllCacheFilesOperation(ICacheSystem cacheSystem) internal ClearAllCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem)
{ {
_cacheSystem = cacheSystem; _fileSystem = fileSystem;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
@ -34,7 +34,7 @@ namespace YooAsset
if (_steps == ESteps.GetAllCacheFiles) if (_steps == ESteps.GetAllCacheFiles)
{ {
_allBundleGUIDs = _cacheSystem.GetAllCachedBundleGUIDs(); _allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
_fileTotalCount = _allBundleGUIDs.Count; _fileTotalCount = _allBundleGUIDs.Count;
_steps = ESteps.ClearAllCacheFiles; _steps = ESteps.ClearAllCacheFiles;
YooLogger.Log($"Found all cache files count : {_fileTotalCount}"); YooLogger.Log($"Found all cache files count : {_fileTotalCount}");
@ -45,7 +45,7 @@ namespace YooAsset
for (int i = _allBundleGUIDs.Count - 1; i >= 0; i--) for (int i = _allBundleGUIDs.Count - 1; i >= 0; i--)
{ {
string bundleGUID = _allBundleGUIDs[i]; string bundleGUID = _allBundleGUIDs[i];
_cacheSystem.DeleteCacheFile(bundleGUID); _fileSystem.DeleteCacheBundleFile(bundleGUID);
_allBundleGUIDs.RemoveAt(i); _allBundleGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)
break; break;

View File

@ -0,0 +1,63 @@
using System;
using System.IO;
namespace YooAsset
{
internal sealed class ClearAllCacheManifestFilesOperation : FSClearCacheFilesOperation
{
private enum ESteps
{
None,
ClearAllCacheFiles,
Done,
}
private readonly DefaultCacheFileSystem _fileSystem;
private ESteps _steps = ESteps.None;
internal ClearAllCacheManifestFilesOperation(DefaultCacheFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearAllCacheFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearAllCacheFiles)
{
try
{
// 注意:如果正在下载资源清单,会有几率触发异常!
string directoryRoot = _fileSystem.GetCacheManifestFilesRoot();
DirectoryInfo directoryInfo = new DirectoryInfo(directoryRoot);
if (directoryInfo.Exists)
{
foreach (FileInfo fileInfo in directoryInfo.GetFiles())
{
string fileName = fileInfo.Name;
if (fileName == DefaultCacheFileSystemDefine.AppFootPrintFileName)
continue;
fileInfo.Delete();
}
}
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception ex)
{
_steps = ESteps.Done;
Error = ex.Message;
Status = EOperationStatus.Failed;
}
}
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f878bc9a12f5d2d40aee754ddfaada86 guid: 5643382e7031ba14cbb4ab0f4a9acd94
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -2,7 +2,7 @@
namespace YooAsset namespace YooAsset
{ {
internal class ClearCacheFilesByTagsOperaiton : FSClearCacheBundleFilesOperation internal class ClearCacheBundleFilesByTagsOperaiton : FSClearCacheFilesOperation
{ {
private enum ESteps private enum ESteps
{ {
@ -13,7 +13,7 @@ namespace YooAsset
Done, Done,
} }
private readonly ICacheSystem _cacheSystem; private readonly DefaultCacheFileSystem _fileSystem;
private readonly PackageManifest _manifest; private readonly PackageManifest _manifest;
private readonly object _clearParam; private readonly object _clearParam;
private string[] _tags; private string[] _tags;
@ -21,9 +21,9 @@ namespace YooAsset
private int _clearFileTotalCount = 0; private int _clearFileTotalCount = 0;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal ClearCacheFilesByTagsOperaiton(ICacheSystem cacheSystem, PackageManifest manifest, object clearParam) internal ClearCacheBundleFilesByTagsOperaiton(DefaultCacheFileSystem fileSystem, PackageManifest manifest, object clearParam)
{ {
_cacheSystem = cacheSystem; _fileSystem = fileSystem;
_manifest = manifest; _manifest = manifest;
_clearParam = clearParam; _clearParam = clearParam;
} }
@ -82,7 +82,7 @@ namespace YooAsset
for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--) for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--)
{ {
string bundleGUID = _clearBundleGUIDs[i]; string bundleGUID = _clearBundleGUIDs[i];
_cacheSystem.DeleteCacheFile(bundleGUID); _fileSystem.DeleteCacheBundleFile(bundleGUID);
_clearBundleGUIDs.RemoveAt(i); _clearBundleGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)
break; break;
@ -102,7 +102,7 @@ namespace YooAsset
} }
private List<string> GetTagsBundleGUIDs() private List<string> GetTagsBundleGUIDs()
{ {
var allBundleGUIDs = _cacheSystem.GetAllCachedBundleGUIDs(); var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
List<string> result = new List<string>(allBundleGUIDs.Count); List<string> result = new List<string>(allBundleGUIDs.Count);
foreach (var bundleGUID in allBundleGUIDs) foreach (var bundleGUID in allBundleGUIDs)
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal sealed class ClearUnusedCacheFilesOperation : FSClearCacheBundleFilesOperation internal sealed class ClearUnusedCacheBundleFilesOperation : FSClearCacheFilesOperation
{ {
private enum ESteps private enum ESteps
{ {
@ -13,16 +13,16 @@ namespace YooAsset
Done, Done,
} }
private readonly ICacheSystem _cacheSystem; private readonly DefaultCacheFileSystem _fileSystem;
private readonly PackageManifest _manifest; private readonly PackageManifest _manifest;
private List<string> _unusedBundleGUIDs; private List<string> _unusedBundleGUIDs;
private int _unusedFileTotalCount = 0; private int _unusedFileTotalCount = 0;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal ClearUnusedCacheFilesOperation(ICacheSystem cacheSystem, PackageManifest manifest) internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
{ {
_cacheSystem = cacheSystem; _fileSystem = fileSystem;
_manifest = manifest; _manifest = manifest;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
@ -47,7 +47,7 @@ namespace YooAsset
for (int i = _unusedBundleGUIDs.Count - 1; i >= 0; i--) for (int i = _unusedBundleGUIDs.Count - 1; i >= 0; i--)
{ {
string bundleGUID = _unusedBundleGUIDs[i]; string bundleGUID = _unusedBundleGUIDs[i];
_cacheSystem.DeleteCacheFile(bundleGUID); _fileSystem.DeleteCacheBundleFile(bundleGUID);
_unusedBundleGUIDs.RemoveAt(i); _unusedBundleGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)
break; break;
@ -68,7 +68,7 @@ namespace YooAsset
private List<string> GetUnusedBundleGUIDs() private List<string> GetUnusedBundleGUIDs()
{ {
var allBundleGUIDs = _cacheSystem.GetAllCachedBundleGUIDs(); var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
List<string> result = new List<string>(allBundleGUIDs.Count); List<string> result = new List<string>(allBundleGUIDs.Count);
foreach (var bundleGUID in allBundleGUIDs) foreach (var bundleGUID in allBundleGUIDs)
{ {

View File

@ -0,0 +1,70 @@
using System;
using System.IO;
namespace YooAsset
{
internal sealed class ClearUnusedCacheManifestFilesOperation : FSClearCacheFilesOperation
{
private enum ESteps
{
None,
ClearUnusedCacheFiles,
Done,
}
private readonly DefaultCacheFileSystem _fileSystem;
private readonly PackageManifest _manifest;
private ESteps _steps = ESteps.None;
internal ClearUnusedCacheManifestFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
{
_fileSystem = fileSystem;
_manifest = manifest;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearUnusedCacheFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearUnusedCacheFiles)
{
try
{
string activeManifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(_manifest.PackageName, _manifest.PackageVersion);
string activeHashFileName = YooAssetSettingsData.GetPackageHashFileName(_manifest.PackageName, _manifest.PackageVersion);
// 注意:如果正在下载资源清单,会有几率触发异常!
string directoryRoot = _fileSystem.GetCacheManifestFilesRoot();
DirectoryInfo directoryInfo = new DirectoryInfo(directoryRoot);
if (directoryInfo.Exists)
{
foreach (FileInfo fileInfo in directoryInfo.GetFiles())
{
string fileName = fileInfo.Name;
if (fileName == DefaultCacheFileSystemDefine.AppFootPrintFileName)
continue;
if (fileName == activeManifestFileName || fileName == activeHashFileName)
continue;
fileInfo.Delete();
}
}
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
catch (Exception ex)
{
_steps = ESteps.Done;
Error = ex.Message;
Status = EOperationStatus.Failed;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d911513cf97d862448df570f0c8e9b38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,22 +6,20 @@ namespace YooAsset
{ {
internal sealed class DownloadNormalFileOperation : DefaultDownloadFileOperation internal sealed class DownloadNormalFileOperation : DefaultDownloadFileOperation
{ {
private readonly IFileSystem _fileSystem; private readonly DefaultCacheFileSystem _fileSystem;
private readonly ICacheSystem _cacheSystem;
private VerifyTempFileOperation _verifyOperation; private VerifyTempFileOperation _verifyOperation;
private bool _isReuqestLocalFile; private bool _isReuqestLocalFile;
private string _tempFilePath; private string _tempFilePath;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DownloadNormalFileOperation(IFileSystem fileSystem, ICacheSystem cacheSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) internal DownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_cacheSystem = cacheSystem;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL); _isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL);
_tempFilePath = _cacheSystem.GetTempFilePath(Bundle); _tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists; _steps = ESteps.CheckExists;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
@ -106,7 +104,7 @@ namespace YooAsset
if (_verifyOperation.Status == EOperationStatus.Succeed) if (_verifyOperation.Status == EOperationStatus.Succeed)
{ {
if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath)) if (_fileSystem.WriteCacheBundleFile(Bundle, _tempFilePath))
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;

View File

@ -7,9 +7,7 @@ namespace YooAsset
{ {
internal sealed class DownloadResumeFileOperation : DefaultDownloadFileOperation internal sealed class DownloadResumeFileOperation : DefaultDownloadFileOperation
{ {
private readonly IFileSystem _fileSystem; private readonly DefaultCacheFileSystem _fileSystem;
private readonly ICacheSystem _cacheSystem;
private readonly List<long> _responseCodes;
private DownloadHandlerFileRange _downloadHandle; private DownloadHandlerFileRange _downloadHandle;
private VerifyTempFileOperation _verifyOperation; private VerifyTempFileOperation _verifyOperation;
private bool _isReuqestLocalFile; private bool _isReuqestLocalFile;
@ -18,16 +16,14 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DownloadResumeFileOperation(IFileSystem fileSystem, ICacheSystem cacheSystem, PackageBundle bundle, DownloadParam param, List<long> responseCodes) : base(bundle, param) internal DownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_cacheSystem = cacheSystem;
_responseCodes = responseCodes;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL); _isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL);
_tempFilePath = _cacheSystem.GetTempFilePath(Bundle); _tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists; _steps = ESteps.CheckExists;
} }
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
@ -129,7 +125,7 @@ namespace YooAsset
if (_verifyOperation.Status == EOperationStatus.Succeed) if (_verifyOperation.Status == EOperationStatus.Succeed)
{ {
if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath)) if (_fileSystem.WriteCacheBundleFile(Bundle, _tempFilePath))
{ {
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
_steps = ESteps.Done; _steps = ESteps.Done;
@ -247,11 +243,11 @@ namespace YooAsset
} }
private void ClearTempFileWhenError() private void ClearTempFileWhenError()
{ {
if (_responseCodes == null) if (_fileSystem.ResumeDownloadResponseCodes == null)
return; return;
//说明:如果遇到以下错误返回码,验证失败直接删除文件 //说明:如果遇到以下错误返回码,验证失败直接删除文件
if (_responseCodes.Contains(HttpCode)) if (_fileSystem.ResumeDownloadResponseCodes.Contains(HttpCode))
{ {
if (File.Exists(_tempFilePath)) if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath); File.Delete(_tempFilePath);

View File

@ -15,9 +15,7 @@ namespace YooAsset
Done, Done,
} }
private readonly ICacheSystem _cacheSystem; private readonly DefaultCacheFileSystem _fileSystem;
private readonly string _packageName;
private readonly bool _appendFileExtension;
private IEnumerator<DirectoryInfo> _filesEnumerator = null; private IEnumerator<DirectoryInfo> _filesEnumerator = null;
private float _verifyStartTime; private float _verifyStartTime;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@ -25,14 +23,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 需要验证的元素 /// 需要验证的元素
/// </summary> /// </summary>
public readonly List<CacheFileElement> Result = new List<CacheFileElement>(5000); public readonly List<VerifyFileElement> Result = new List<VerifyFileElement>(5000);
internal SearchCacheFilesOperation(ICacheSystem cacheSystem, string packageName, bool appendFileExtension) internal SearchCacheFilesOperation(DefaultCacheFileSystem fileSystem)
{ {
_cacheSystem = cacheSystem; _fileSystem = fileSystem;
_packageName = packageName;
_appendFileExtension = appendFileExtension;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
@ -46,7 +42,7 @@ namespace YooAsset
if (_steps == ESteps.Prepare) if (_steps == ESteps.Prepare)
{ {
DirectoryInfo rootDirectory = new DirectoryInfo(_cacheSystem.GetCacheFileRoot()); DirectoryInfo rootDirectory = new DirectoryInfo(_fileSystem.GetCacheBundleFilesRoot());
if (rootDirectory.Exists) if (rootDirectory.Exists)
{ {
var directorieInfos = rootDirectory.EnumerateDirectories(); var directorieInfos = rootDirectory.EnumerateDirectories();
@ -84,23 +80,23 @@ namespace YooAsset
foreach (var chidDirectory in childDirectories) foreach (var chidDirectory in childDirectories)
{ {
string bundleGUID = chidDirectory.Name; string bundleGUID = chidDirectory.Name;
if (_cacheSystem.IsRecordFile(bundleGUID)) if (_fileSystem.IsRecordBundleFile(bundleGUID))
continue; continue;
// 创建验证元素类 // 创建验证元素类
string fileRootPath = chidDirectory.FullName; string fileRootPath = chidDirectory.FullName;
string dataFilePath = $"{fileRootPath}/{ DefaultCacheFileSystemDefine.SaveBundleDataFileName}"; string dataFilePath = $"{fileRootPath}/{ DefaultCacheFileSystemDefine.BundleDataFileName}";
string infoFilePath = $"{fileRootPath}/{ DefaultCacheFileSystemDefine.SaveBundleInfoFileName}"; string infoFilePath = $"{fileRootPath}/{ DefaultCacheFileSystemDefine.BundleInfoFileName}";
// 存储的数据文件追加文件格式 // 存储的数据文件追加文件格式
if (_appendFileExtension) if (_fileSystem.AppendFileExtension)
{ {
string dataFileExtension = FindDataFileExtension(chidDirectory); string dataFileExtension = FindDataFileExtension(chidDirectory);
if (string.IsNullOrEmpty(dataFileExtension) == false) if (string.IsNullOrEmpty(dataFileExtension) == false)
dataFilePath += dataFileExtension; dataFilePath += dataFileExtension;
} }
var element = new CacheFileElement(_packageName, bundleGUID, fileRootPath, dataFilePath, infoFilePath); var element = new VerifyFileElement(_fileSystem.PackageName, bundleGUID, fileRootPath, dataFilePath, infoFilePath);
Result.Add(element); Result.Add(element);
} }
@ -116,7 +112,7 @@ namespace YooAsset
var fileInfos = directoryInfo.GetFiles(); var fileInfos = directoryInfo.GetFiles();
foreach (var fileInfo in fileInfos) foreach (var fileInfo in fileInfos)
{ {
if (fileInfo.Name.StartsWith(DefaultCacheFileSystemDefine.SaveBundleDataFileName)) if (fileInfo.Name.StartsWith(DefaultCacheFileSystemDefine.BundleDataFileName))
{ {
dataFileExtension = fileInfo.Extension; dataFileExtension = fileInfo.Extension;
break; break;

View File

@ -19,10 +19,10 @@ namespace YooAsset
Done, Done,
} }
private readonly ICacheSystem _cacheSystem; private readonly DefaultCacheFileSystem _fileSystem;
private readonly EFileVerifyLevel _verifyLevel; private readonly EFileVerifyLevel _fileVerifyLevel;
private List<CacheFileElement> _waitingList; private List<VerifyFileElement> _waitingList;
private List<CacheFileElement> _verifyingList; private List<VerifyFileElement> _verifyingList;
private int _verifyMaxNum; private int _verifyMaxNum;
private int _verifyTotalCount; private int _verifyTotalCount;
private float _verifyStartTime; private float _verifyStartTime;
@ -31,11 +31,11 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal VerifyCacheFilesOperation(ICacheSystem cacheSystem, EFileVerifyLevel verifyLevel, List<CacheFileElement> elements) internal VerifyCacheFilesOperation(DefaultCacheFileSystem fileSystem, List<VerifyFileElement> elements)
{ {
_cacheSystem = cacheSystem; _fileSystem = fileSystem;
_verifyLevel = verifyLevel;
_waitingList = elements; _waitingList = elements;
_fileVerifyLevel = fileSystem.FileVerifyLevel;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
@ -59,7 +59,7 @@ namespace YooAsset
if (_verifyMaxNum < 1) if (_verifyMaxNum < 1)
_verifyMaxNum = 1; _verifyMaxNum = 1;
_verifyingList = new List<CacheFileElement>(_verifyMaxNum); _verifyingList = new List<VerifyFileElement>(_verifyMaxNum);
_steps = ESteps.UpdateVerify; _steps = ESteps.UpdateVerify;
} }
@ -118,22 +118,21 @@ namespace YooAsset
} }
private void VerifyInThread(object obj) private void VerifyInThread(object obj)
{ {
CacheFileElement element = (CacheFileElement)obj; VerifyFileElement element = (VerifyFileElement)obj;
int verifyResult = (int)VerifyingCacheFile(element, _verifyLevel); int verifyResult = (int)VerifyingCacheFile(element, _fileVerifyLevel);
element.Result = verifyResult; element.Result = verifyResult;
} }
private void RecordVerifyFile(CacheFileElement element) private void RecordVerifyFile(VerifyFileElement element)
{ {
if (element.Result == (int)EFileVerifyResult.Succeed) if (element.Result == (int)EFileVerifyResult.Succeed)
{ {
_succeedCount++; _succeedCount++;
var fileWrapper = new CacheWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize); var recordFileElement = new RecordFileElement(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
_cacheSystem.RecordFile(element.BundleGUID, fileWrapper); _fileSystem.RecordBundleFile(element.BundleGUID, recordFileElement);
} }
else else
{ {
_failedCount++; _failedCount++;
YooLogger.Warning($"Failed to verify file {element.Result} and delete files : {element.FileRootPath}"); YooLogger.Warning($"Failed to verify file {element.Result} and delete files : {element.FileRootPath}");
element.DeleteFiles(); element.DeleteFiles();
} }
@ -142,7 +141,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 验证缓存文件(子线程内操作) /// 验证缓存文件(子线程内操作)
/// </summary> /// </summary>
private EFileVerifyResult VerifyingCacheFile(CacheFileElement element, EFileVerifyLevel verifyLevel) private EFileVerifyResult VerifyingCacheFile(VerifyFileElement element, EFileVerifyLevel verifyLevel)
{ {
try try
{ {
@ -160,7 +159,7 @@ namespace YooAsset
return EFileVerifyResult.InfoFileNotExisted; return EFileVerifyResult.InfoFileNotExisted;
// 解析信息文件获取验证数据 // 解析信息文件获取验证数据
_cacheSystem.ReadInfoFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize); _fileSystem.ReadBundleInfoFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
} }
} }
catch (Exception) catch (Exception)

View File

@ -69,9 +69,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{ {
var operation = new FSClearCacheBundleFilesCompleteOperation(null); var operation = new FSClearCacheFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -14,8 +14,8 @@ namespace YooAsset
base.OnCreate(packageName, rootDirectory); base.OnCreate(packageName, rootDirectory);
// 注意:重写保存根目录和临时目录 // 注意:重写保存根目录和临时目录
_cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName); _cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName);
_tempFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName); _tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName);
} }
} }
} }

View File

@ -71,9 +71,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{ {
var operation = new FSClearCacheBundleFilesCompleteOperation(null); var operation = new FSClearCacheFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -80,9 +80,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
{ {
var operation = new FSClearCacheBundleFilesCompleteOperation(null); var operation = new FSClearCacheFilesCompleteOperation();
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -9,17 +9,28 @@ namespace YooAsset
/// <summary> /// <summary>
/// 清理所有文件 /// 清理所有文件
/// </summary> /// </summary>
ClearAllBundleFiles = 1, ClearAllBundleFiles,
/// <summary> /// <summary>
/// 清理未在使用的文件 /// 清理未在使用的文件
/// </summary> /// </summary>
ClearUnusedBundleFiles = 2, ClearUnusedBundleFiles,
/// <summary> /// <summary>
/// 清理指定标签的文件 /// 清理指定标签的文件
/// 说明需要指定参数可选string, string[], List<string> /// 说明需要指定参数可选string, string[], List<string>
/// </summary> /// </summary>
ClearBundleFilesByTags = 3, ClearBundleFilesByTags,
/// <summary>
/// 清理所有清单
/// </summary>
ClearAllManifestFiles,
/// <summary>
/// 清理未在使用的清单
/// </summary>
ClearUnusedManifestFiles,
} }
} }

View File

@ -37,7 +37,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 清理缓存文件 /// 清理缓存文件
/// </summary> /// </summary>
FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam); FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, string clearMode, object clearParam);
/// <summary> /// <summary>
/// 下载远端文件 /// 下载远端文件
@ -48,13 +48,13 @@ namespace YooAsset
/// 加载Bundle文件 /// 加载Bundle文件
/// </summary> /// </summary>
FSLoadBundleOperation LoadBundleFile(PackageBundle bundle); FSLoadBundleOperation LoadBundleFile(PackageBundle bundle);
/// <summary> /// <summary>
/// 设置自定义参数 /// 设置自定义参数
/// </summary> /// </summary>
void SetParameter(string name, object value); void SetParameter(string name, object value);
/// <summary> /// <summary>
/// 创建缓存系统 /// 创建缓存系统
/// </summary> /// </summary>

View File

@ -1,15 +1,19 @@
 
namespace YooAsset namespace YooAsset
{ {
internal abstract class FSClearCacheBundleFilesOperation : AsyncOperationBase internal abstract class FSClearCacheFilesOperation : AsyncOperationBase
{ {
} }
internal sealed class FSClearCacheBundleFilesCompleteOperation : FSClearCacheBundleFilesOperation internal sealed class FSClearCacheFilesCompleteOperation : FSClearCacheFilesOperation
{ {
private readonly string _error; private readonly string _error;
internal FSClearCacheBundleFilesCompleteOperation(string error) internal FSClearCacheFilesCompleteOperation()
{
_error = null;
}
internal FSClearCacheFilesCompleteOperation(string error)
{ {
_error = error; _error = error;
} }

View File

@ -31,7 +31,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 清理缓存文件 /// 清理缓存文件
/// </summary> /// </summary>
ClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(string clearMode, object clearParam); ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam);
// 下载相关 // 下载相关
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout); ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);

View File

@ -1,10 +1,10 @@
 
namespace YooAsset namespace YooAsset
{ {
public abstract class ClearCacheBundleFilesOperation : AsyncOperationBase public abstract class ClearCacheFilesOperation : AsyncOperationBase
{ {
} }
internal sealed class ClearCacheBundleFilesImplOperation : ClearCacheBundleFilesOperation internal sealed class ClearCacheFilesImplOperation : ClearCacheFilesOperation
{ {
private enum ESteps private enum ESteps
{ {
@ -21,12 +21,12 @@ namespace YooAsset
private readonly IFileSystem _fileSystemC; private readonly IFileSystem _fileSystemC;
private readonly string _clearMode; private readonly string _clearMode;
private readonly object _clearParam; private readonly object _clearParam;
private FSClearCacheBundleFilesOperation _clearCacheBundleFilesOpA; private FSClearCacheFilesOperation _clearCacheFilesOpA;
private FSClearCacheBundleFilesOperation _clearCacheBundleFilesOpB; private FSClearCacheFilesOperation _clearCacheFilesOpB;
private FSClearCacheBundleFilesOperation _clearCacheBundleFilesOpC; private FSClearCacheFilesOperation _clearCacheFilesOpC;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal ClearCacheBundleFilesImplOperation(IPlayMode impl, IFileSystem fileSystemA, IFileSystem fileSystemB, IFileSystem fileSystemC, string clearMode, object clearParam) internal ClearCacheFilesImplOperation(IPlayMode impl, IFileSystem fileSystemA, IFileSystem fileSystemB, IFileSystem fileSystemC, string clearMode, object clearParam)
{ {
_impl = impl; _impl = impl;
_fileSystemA = fileSystemA; _fileSystemA = fileSystemA;
@ -52,14 +52,14 @@ namespace YooAsset
return; return;
} }
if (_clearCacheBundleFilesOpA == null) if (_clearCacheFilesOpA == null)
_clearCacheBundleFilesOpA = _fileSystemA.ClearCacheBundleFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); _clearCacheFilesOpA = _fileSystemA.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
Progress = _clearCacheBundleFilesOpA.Progress; Progress = _clearCacheFilesOpA.Progress;
if (_clearCacheBundleFilesOpA.IsDone == false) if (_clearCacheFilesOpA.IsDone == false)
return; return;
if (_clearCacheBundleFilesOpA.Status == EOperationStatus.Succeed) if (_clearCacheFilesOpA.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.ClearFileSystemB; _steps = ESteps.ClearFileSystemB;
} }
@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _clearCacheBundleFilesOpA.Error; Error = _clearCacheFilesOpA.Error;
} }
} }
@ -79,14 +79,14 @@ namespace YooAsset
return; return;
} }
if (_clearCacheBundleFilesOpB == null) if (_clearCacheFilesOpB == null)
_clearCacheBundleFilesOpB = _fileSystemB.ClearCacheBundleFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); _clearCacheFilesOpB = _fileSystemB.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
Progress = _clearCacheBundleFilesOpB.Progress; Progress = _clearCacheFilesOpB.Progress;
if (_clearCacheBundleFilesOpB.IsDone == false) if (_clearCacheFilesOpB.IsDone == false)
return; return;
if (_clearCacheBundleFilesOpB.Status == EOperationStatus.Succeed) if (_clearCacheFilesOpB.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.ClearFileSystemC; _steps = ESteps.ClearFileSystemC;
} }
@ -94,7 +94,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _clearCacheBundleFilesOpB.Error; Error = _clearCacheFilesOpB.Error;
} }
} }
@ -107,14 +107,14 @@ namespace YooAsset
return; return;
} }
if (_clearCacheBundleFilesOpC == null) if (_clearCacheFilesOpC == null)
_clearCacheBundleFilesOpC = _fileSystemC.ClearCacheBundleFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); _clearCacheFilesOpC = _fileSystemC.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
Progress = _clearCacheBundleFilesOpC.Progress; Progress = _clearCacheFilesOpC.Progress;
if (_clearCacheBundleFilesOpC.IsDone == false) if (_clearCacheFilesOpC.IsDone == false)
return; return;
if (_clearCacheBundleFilesOpC.Status == EOperationStatus.Succeed) if (_clearCacheFilesOpC.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@ -123,7 +123,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _clearCacheBundleFilesOpC.Error; Error = _clearCacheFilesOpC.Error;
} }
} }
} }

View File

@ -52,9 +52,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
ClearCacheBundleFilesOperation IPlayMode.ClearCacheBundleFilesAsync(string clearMode, object clearParam) ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{ {
var operation = new ClearCacheBundleFilesImplOperation(this, EditorFileSystem, null, null, clearMode, clearParam); var operation = new ClearCacheFilesImplOperation(this, EditorFileSystem, null, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -56,9 +56,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
ClearCacheBundleFilesOperation IPlayMode.ClearCacheBundleFilesAsync(string clearMode, object clearParam) ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{ {
var operation = new ClearCacheBundleFilesImplOperation(this, BuildinFileSystem, CacheFileSystem, null, clearMode, clearParam); var operation = new ClearCacheFilesImplOperation(this, BuildinFileSystem, CacheFileSystem, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -52,9 +52,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
ClearCacheBundleFilesOperation IPlayMode.ClearCacheBundleFilesAsync(string clearMode, object clearParam) ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{ {
var operation = new ClearCacheBundleFilesImplOperation(this, BuildinFileSystem, null, null, clearMode, clearParam); var operation = new ClearCacheFilesImplOperation(this, BuildinFileSystem, null, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -74,9 +74,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
ClearCacheBundleFilesOperation IPlayMode.ClearCacheBundleFilesAsync(string clearMode, object clearParam) ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{ {
var operation = new ClearCacheBundleFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null, clearMode, clearParam); var operation = new ClearCacheFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }

View File

@ -220,7 +220,7 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 加载指定版本的资源清单 /// 更新并加载指定版本的资源清单
/// </summary> /// </summary>
/// <param name="packageVersion">包裹版本</param> /// <param name="packageVersion">包裹版本</param>
/// <param name="timeout">超时时间默认值60秒</param> /// <param name="timeout">超时时间默认值60秒</param>
@ -253,23 +253,24 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="clearMode">清理方式</param> /// <param name="clearMode">清理方式</param>
/// <param name="clearParam">执行参数</param> /// <param name="clearParam">执行参数</param>
public ClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(EFileClearMode clearMode, object clearParam = null) public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ClearCacheBundleFilesAsync(clearMode.ToString(), clearParam); return _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
} }
/// <summary> /// <summary>
/// 清理缓存文件 /// 清理缓存文件
/// </summary> /// </summary>
/// <param name="clearMode">清理方式</param> /// <param name="clearMode">清理方式</param>
/// <param name="clearParam">执行参数</param> /// <param name="clearParam">执行参数</param>
public ClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(string clearMode, object clearParam = null) public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ClearCacheBundleFilesAsync(clearMode, clearParam); return _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
} }
#region 包裹信息 #region 包裹信息
/// <summary> /// <summary>
/// 获取当前加载包裹的版本信息 /// 获取当前加载包裹的版本信息