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);
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)
{

View File

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

View File

@ -2,7 +2,6 @@
using System.IO;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace YooAsset
{
@ -10,18 +9,18 @@ namespace YooAsset
/// 缓存文件系统
/// 说明正在进行的下载器会在ResourcePackage销毁的时候执行Abort操作
/// </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, string> _dataFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _infoFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, RecordFileElement> _wrappers = new Dictionary<string, RecordFileElement>(10000);
protected readonly Dictionary<string, string> _bundleDataFilePaths = 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 DefaultCacheDownloadCenter _downloadCenter;
protected string _packageRoot;
protected string _cacheFileRoot;
protected string _tempFileRoot;
protected string _manifestFileRoot;
protected string _tempFilesRoot;
protected string _cacheBundleFilesRoot;
protected string _cacheManifestFilesRoot;
/// <summary>
/// 包裹名称
@ -114,30 +113,42 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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())
{
var operation = new ClearAllCacheFilesOperation(this);
var operation = new ClearAllCacheBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else if (clearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
{
var operation = new ClearUnusedCacheFilesOperation(this, manifest);
var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
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);
return operation;
}
else
{
string error = $"Invalid clear mode : {clearMode}";
var operation = new FSClearCacheBundleFilesCompleteOperation(error);
var operation = new FSClearCacheFilesCompleteOperation(error);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@ -217,9 +228,9 @@ namespace YooAsset
else
_packageRoot = packageRoot;
_cacheFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.SaveFilesFolderName);
_tempFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName);
_manifestFileRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
_cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
_tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName);
_cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
_downloadCenter = new DefaultCacheDownloadCenter(this);
}
public virtual void OnUpdate()
@ -257,7 +268,7 @@ namespace YooAsset
public virtual string GetBundleFilePath(PackageBundle bundle)
{
return GetCacheFileLoadPath(bundle);
return GetCacheBundleFileLoadPath(bundle);
}
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{
@ -272,7 +283,7 @@ namespace YooAsset
return null;
}
string filePath = GetCacheFileLoadPath(bundle);
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
{
BundleName = bundle.BundleName,
@ -283,7 +294,7 @@ namespace YooAsset
}
else
{
string filePath = GetCacheFileLoadPath(bundle);
string filePath = GetCacheBundleFileLoadPath(bundle);
return FileUtility.ReadAllBytes(filePath);
}
}
@ -300,7 +311,7 @@ namespace YooAsset
return null;
}
string filePath = GetCacheFileLoadPath(bundle);
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
{
BundleName = bundle.BundleName,
@ -311,85 +322,82 @@ namespace YooAsset
}
else
{
string filePath = GetCacheFileLoadPath(bundle);
string filePath = GetCacheBundleFileLoadPath(bundle);
return FileUtility.ReadAllText(filePath);
}
}
#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;
}
#region 缓存相关
public List<string> GetAllCachedBundleGUIDs()
{
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);
}
public bool RecordFile(string bundleGUID, CacheWrapper wrapper)
public bool RecordBundleFile(string bundleGUID, RecordFileElement element)
{
if (_wrappers.ContainsKey(bundleGUID))
{
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has element : {bundleGUID}");
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has record file element : {bundleGUID}");
return false;
}
_wrappers.Add(bundleGUID, wrapper);
_wrappers.Add(bundleGUID, element);
return true;
}
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;
EFileVerifyResult result = FileVerifyHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
return result;
}
public bool WriteCacheFile(PackageBundle bundle, string copyPath)
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)
{
if (_wrappers.ContainsKey(bundle.BundleGUID))
{
throw new Exception("Should never get here !");
}
string infoFilePath = GetInfoFilePath(bundle);
string dataFilePath = GetDataFilePath(bundle);
string infoFilePath = GetBundleInfoFilePath(bundle);
string dataFilePath = GetBundleDataFilePath(bundle);
try
{
@ -405,7 +413,7 @@ namespace YooAsset
fileInfo.CopyTo(dataFilePath);
// 写入文件信息
WriteInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize);
WriteBundleInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize);
}
catch (Exception e)
{
@ -413,12 +421,12 @@ namespace YooAsset
return false;
}
var wrapper = new CacheWrapper(infoFilePath, dataFilePath, bundle.FileCRC, bundle.FileSize);
return RecordFile(bundle.BundleGUID, wrapper);
var recordFileElement = new RecordFileElement(infoFilePath, dataFilePath, bundle.FileCRC, bundle.FileSize);
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
{
@ -442,7 +450,7 @@ namespace YooAsset
}
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))
{
@ -453,7 +461,7 @@ namespace YooAsset
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);
BufferReader buffer = new BufferReader(binaryData);
@ -477,23 +485,31 @@ namespace YooAsset
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)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
return PathUtility.Combine(_manifestFileRoot, fileName);
return PathUtility.Combine(_cacheManifestFilesRoot, fileName);
}
public string GetCachePackageManifestFilePath(string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
return PathUtility.Combine(_manifestFileRoot, fileName);
return PathUtility.Combine(_cacheManifestFilesRoot, fileName);
}
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>
@ -501,9 +517,9 @@ namespace YooAsset
/// </summary>
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>
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
{
string filePath = GetCacheFileLoadPath(bundle);
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
{
BundleName = bundle.BundleName,
@ -527,7 +543,7 @@ namespace YooAsset
/// </summary>
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
{
string filePath = GetCacheFileLoadPath(bundle);
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
{
BundleName = bundle.BundleName,

View File

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

View File

@ -1,14 +1,14 @@

namespace YooAsset
{
internal class CacheWrapper
internal class RecordFileElement
{
public string InfoFilePath { private set; get; }
public string DataFilePath { private set; get; }
public string DataFileCRC { 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;
DataFilePath = dataFilePath;

View File

@ -2,7 +2,7 @@
namespace YooAsset
{
internal class CacheFileElement
internal class VerifyFileElement
{
public string PackageName { private set; get; }
public string BundleGUID { private set; get; }
@ -18,7 +18,7 @@ namespace YooAsset
/// </summary>
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;
BundleGUID = bundleGUID;

View File

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

View File

@ -104,7 +104,7 @@ namespace YooAsset
}
else
{
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
_assetBundle = AssetBundle.LoadFromFile(filePath);
}
}
@ -118,7 +118,7 @@ namespace YooAsset
}
else
{
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
_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);
if (fileData != null && fileData.Length > 0)
{
@ -198,7 +198,7 @@ namespace YooAsset
else
{
_steps = ESteps.Done;
_fileSystem.DeleteCacheFile(_bundle.BundleGUID);
_fileSystem.DeleteCacheBundleFile(_bundle.BundleGUID);
Status = EOperationStatus.Failed;
Error = $"Find corrupted asset bundle file and delete : {_bundle.BundleName}";
YooLogger.Error(Error);
@ -304,7 +304,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCacheRawBundle)
{
string filePath = _fileSystem.GetCacheFileLoadPath(_bundle);
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
if (File.Exists(filePath))
{
_steps = ESteps.Done;

View File

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

View File

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

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace YooAsset
{
internal sealed class ClearUnusedCacheFilesOperation : FSClearCacheBundleFilesOperation
internal sealed class ClearUnusedCacheBundleFilesOperation : FSClearCacheFilesOperation
{
private enum ESteps
{
@ -13,16 +13,16 @@ namespace YooAsset
Done,
}
private readonly ICacheSystem _cacheSystem;
private readonly DefaultCacheFileSystem _fileSystem;
private readonly PackageManifest _manifest;
private List<string> _unusedBundleGUIDs;
private int _unusedFileTotalCount = 0;
private ESteps _steps = ESteps.None;
internal ClearUnusedCacheFilesOperation(ICacheSystem cacheSystem, PackageManifest manifest)
internal ClearUnusedCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem, PackageManifest manifest)
{
_cacheSystem = cacheSystem;
_fileSystem = fileSystem;
_manifest = manifest;
}
internal override void InternalOnStart()
@ -47,7 +47,7 @@ namespace YooAsset
for (int i = _unusedBundleGUIDs.Count - 1; i >= 0; i--)
{
string bundleGUID = _unusedBundleGUIDs[i];
_cacheSystem.DeleteCacheFile(bundleGUID);
_fileSystem.DeleteCacheBundleFile(bundleGUID);
_unusedBundleGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy)
break;
@ -68,7 +68,7 @@ namespace YooAsset
private List<string> GetUnusedBundleGUIDs()
{
var allBundleGUIDs = _cacheSystem.GetAllCachedBundleGUIDs();
var allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
List<string> result = new List<string>(allBundleGUIDs.Count);
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
{
private readonly IFileSystem _fileSystem;
private readonly ICacheSystem _cacheSystem;
private readonly DefaultCacheFileSystem _fileSystem;
private VerifyTempFileOperation _verifyOperation;
private bool _isReuqestLocalFile;
private string _tempFilePath;
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;
_cacheSystem = cacheSystem;
}
internal override void InternalOnStart()
{
_isReuqestLocalFile = DownloadSystemHelper.IsRequestLocalFile(Param.MainURL);
_tempFilePath = _cacheSystem.GetTempFilePath(Bundle);
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists;
}
internal override void InternalOnUpdate()
@ -106,7 +104,7 @@ namespace YooAsset
if (_verifyOperation.Status == EOperationStatus.Succeed)
{
if (_cacheSystem.WriteCacheFile(Bundle, _tempFilePath))
if (_fileSystem.WriteCacheBundleFile(Bundle, _tempFilePath))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;

View File

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

View File

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

View File

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

View File

@ -69,9 +69,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

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

View File

@ -71,9 +71,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

@ -80,9 +80,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

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

View File

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

View File

@ -1,15 +1,19 @@

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;
internal FSClearCacheBundleFilesCompleteOperation(string error)
internal FSClearCacheFilesCompleteOperation()
{
_error = null;
}
internal FSClearCacheFilesCompleteOperation(string error)
{
_error = error;
}

View File

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

View File

@ -1,10 +1,10 @@

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
{
@ -21,12 +21,12 @@ namespace YooAsset
private readonly IFileSystem _fileSystemC;
private readonly string _clearMode;
private readonly object _clearParam;
private FSClearCacheBundleFilesOperation _clearCacheBundleFilesOpA;
private FSClearCacheBundleFilesOperation _clearCacheBundleFilesOpB;
private FSClearCacheBundleFilesOperation _clearCacheBundleFilesOpC;
private FSClearCacheFilesOperation _clearCacheFilesOpA;
private FSClearCacheFilesOperation _clearCacheFilesOpB;
private FSClearCacheFilesOperation _clearCacheFilesOpC;
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;
_fileSystemA = fileSystemA;
@ -52,14 +52,14 @@ namespace YooAsset
return;
}
if (_clearCacheBundleFilesOpA == null)
_clearCacheBundleFilesOpA = _fileSystemA.ClearCacheBundleFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
if (_clearCacheFilesOpA == null)
_clearCacheFilesOpA = _fileSystemA.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
Progress = _clearCacheBundleFilesOpA.Progress;
if (_clearCacheBundleFilesOpA.IsDone == false)
Progress = _clearCacheFilesOpA.Progress;
if (_clearCacheFilesOpA.IsDone == false)
return;
if (_clearCacheBundleFilesOpA.Status == EOperationStatus.Succeed)
if (_clearCacheFilesOpA.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearFileSystemB;
}
@ -67,7 +67,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheBundleFilesOpA.Error;
Error = _clearCacheFilesOpA.Error;
}
}
@ -79,14 +79,14 @@ namespace YooAsset
return;
}
if (_clearCacheBundleFilesOpB == null)
_clearCacheBundleFilesOpB = _fileSystemB.ClearCacheBundleFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
if (_clearCacheFilesOpB == null)
_clearCacheFilesOpB = _fileSystemB.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
Progress = _clearCacheBundleFilesOpB.Progress;
if (_clearCacheBundleFilesOpB.IsDone == false)
Progress = _clearCacheFilesOpB.Progress;
if (_clearCacheFilesOpB.IsDone == false)
return;
if (_clearCacheBundleFilesOpB.Status == EOperationStatus.Succeed)
if (_clearCacheFilesOpB.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearFileSystemC;
}
@ -94,7 +94,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheBundleFilesOpB.Error;
Error = _clearCacheFilesOpB.Error;
}
}
@ -107,14 +107,14 @@ namespace YooAsset
return;
}
if (_clearCacheBundleFilesOpC == null)
_clearCacheBundleFilesOpC = _fileSystemC.ClearCacheBundleFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
if (_clearCacheFilesOpC == null)
_clearCacheFilesOpC = _fileSystemC.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
Progress = _clearCacheBundleFilesOpC.Progress;
if (_clearCacheBundleFilesOpC.IsDone == false)
Progress = _clearCacheFilesOpC.Progress;
if (_clearCacheFilesOpC.IsDone == false)
return;
if (_clearCacheBundleFilesOpC.Status == EOperationStatus.Succeed)
if (_clearCacheFilesOpC.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
@ -123,7 +123,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheBundleFilesOpC.Error;
Error = _clearCacheFilesOpC.Error;
}
}
}

View File

@ -52,9 +52,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

@ -56,9 +56,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

@ -52,9 +52,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

@ -74,9 +74,9 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, 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);
return operation;
}

View File

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