mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-28 03:28:47 +00:00
fix #402
This commit is contained in:
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class ClearAllCacheFilesOperation : FSClearAllBundleFilesOperation
|
||||
internal sealed class ClearAllCacheFilesOperation : FSClearCacheBundleFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class ClearCacheFilesByTagsOperaiton : FSClearCacheBundleFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckArgs,
|
||||
GetTagsCacheFiles,
|
||||
ClearTagsCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ICacheSystem _cacheSystem;
|
||||
private readonly PackageManifest _manifest;
|
||||
private readonly object _clearParam;
|
||||
private string[] _tags;
|
||||
private List<string> _clearBundleGUIDs;
|
||||
private int _clearFileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearCacheFilesByTagsOperaiton(ICacheSystem cacheSystem, PackageManifest manifest, object clearParam)
|
||||
{
|
||||
_cacheSystem = cacheSystem;
|
||||
_manifest = manifest;
|
||||
_clearParam = clearParam;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckArgs;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckArgs)
|
||||
{
|
||||
if (_clearParam == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Clear param is null !";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clearParam is string)
|
||||
{
|
||||
_tags = new string[] { _clearParam as string };
|
||||
}
|
||||
else if (_clearParam is List<string>)
|
||||
{
|
||||
var tempList = _clearParam as List<string>;
|
||||
_tags = tempList.ToArray();
|
||||
}
|
||||
else if (_clearParam is string[])
|
||||
{
|
||||
_tags = _clearParam as string[];
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Invalid clear param : {_clearParam.GetType().FullName}";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.GetTagsCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.GetTagsCacheFiles)
|
||||
{
|
||||
_clearBundleGUIDs = GetTagsBundleGUIDs();
|
||||
_clearFileTotalCount = _clearBundleGUIDs.Count;
|
||||
_steps = ESteps.ClearTagsCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearTagsCacheFiles)
|
||||
{
|
||||
for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string bundleGUID = _clearBundleGUIDs[i];
|
||||
_cacheSystem.DeleteCacheFile(bundleGUID);
|
||||
_clearBundleGUIDs.RemoveAt(i);
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_clearFileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_clearBundleGUIDs.Count / _clearFileTotalCount);
|
||||
|
||||
if (_clearBundleGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
private List<string> GetTagsBundleGUIDs()
|
||||
{
|
||||
var allBundleGUIDs = _cacheSystem.GetAllCachedBundleGUIDs();
|
||||
List<string> result = new List<string>(allBundleGUIDs.Count);
|
||||
foreach (var bundleGUID in allBundleGUIDs)
|
||||
{
|
||||
if (_manifest.TryGetPackageBundleByBundleGUID(bundleGUID, out PackageBundle bundle))
|
||||
{
|
||||
if (bundle.HasTag(_tags))
|
||||
{
|
||||
result.Add(bundleGUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9fe9171073a87746a7393f7d1fcb924
|
||||
guid: c42345c14a903274fb160a813ee174dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class ClearUnusedCacheFilesOperation : FSClearUnusedBundleFilesOperation
|
||||
internal sealed class ClearUnusedCacheFilesOperation : FSClearCacheBundleFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
|
||||
@@ -97,13 +97,9 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync()
|
||||
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
|
||||
{
|
||||
return _unpackFileSystem.ClearAllBundleFilesAsync();
|
||||
}
|
||||
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest)
|
||||
{
|
||||
return _unpackFileSystem.ClearUnusedBundleFilesAsync(manifest);
|
||||
return _unpackFileSystem.ClearCacheBundleFilesAsync(manifest, clearMode, clearParam);
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
|
||||
{
|
||||
|
||||
@@ -111,17 +111,33 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync()
|
||||
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
|
||||
{
|
||||
var operation = new ClearAllCacheFilesOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest)
|
||||
{
|
||||
var operation = new ClearUnusedCacheFilesOperation(this, manifest);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
if(clearMode == EFileClearMode.ClearAllBundleFiles.ToString())
|
||||
{
|
||||
var operation = new ClearAllCacheFilesOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
else if(clearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
|
||||
{
|
||||
var operation = new ClearUnusedCacheFilesOperation(this, manifest);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
else if(clearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
|
||||
{
|
||||
var operation = new ClearCacheFilesByTagsOperaiton(this, manifest, clearParam);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Invalid clear mode : {clearMode}";
|
||||
var operation = new FSClearCacheBundleFilesCompleteOperation(error);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
|
||||
{
|
||||
|
||||
@@ -69,15 +69,9 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync()
|
||||
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
|
||||
{
|
||||
var operation = new FSClearAllBundleFilesCompleteOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest)
|
||||
{
|
||||
var operation = new FSClearUnusedBundleFilesCompleteOperation();
|
||||
var operation = new FSClearCacheBundleFilesCompleteOperation(null);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -71,15 +71,9 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync()
|
||||
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
|
||||
{
|
||||
var operation = new FSClearAllBundleFilesCompleteOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest)
|
||||
{
|
||||
var operation = new FSClearUnusedBundleFilesCompleteOperation();
|
||||
var operation = new FSClearCacheBundleFilesCompleteOperation(null);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -80,15 +80,9 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync()
|
||||
public virtual FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam)
|
||||
{
|
||||
var operation = new FSClearAllBundleFilesCompleteOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest)
|
||||
{
|
||||
var operation = new FSClearUnusedBundleFilesCompleteOperation();
|
||||
var operation = new FSClearCacheBundleFilesCompleteOperation(null);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
25
Assets/YooAsset/Runtime/FileSystem/EFileClearMode.cs
Normal file
25
Assets/YooAsset/Runtime/FileSystem/EFileClearMode.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件清理方式
|
||||
/// </summary>
|
||||
public enum EFileClearMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理所有文件
|
||||
/// </summary>
|
||||
ClearAllBundleFiles = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 清理未在使用的文件
|
||||
/// </summary>
|
||||
ClearUnusedBundleFiles = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 清理指定标签的文件
|
||||
/// 说明:需要指定参数,可选:string, string[], List<string>
|
||||
/// </summary>
|
||||
ClearBundleFilesByTags = 3,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 857423cdfd4f9184eab094be01c62480
|
||||
guid: 2930435fc2ba91c4ba511260b9d119d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -35,14 +35,9 @@ namespace YooAsset
|
||||
FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有的文件
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
FSClearAllBundleFilesOperation ClearAllBundleFilesAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 清空未使用的文件
|
||||
/// </summary>
|
||||
FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest);
|
||||
FSClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(PackageManifest manifest, string clearMode, object clearParam);
|
||||
|
||||
/// <summary>
|
||||
/// 下载远端文件
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class FSClearAllBundleFilesOperation : AsyncOperationBase
|
||||
{
|
||||
}
|
||||
|
||||
internal sealed class FSClearAllBundleFilesCompleteOperation : FSClearAllBundleFilesOperation
|
||||
{
|
||||
internal FSClearAllBundleFilesCompleteOperation()
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class FSClearCacheBundleFilesOperation : AsyncOperationBase
|
||||
{
|
||||
}
|
||||
|
||||
internal sealed class FSClearCacheBundleFilesCompleteOperation : FSClearCacheBundleFilesOperation
|
||||
{
|
||||
private readonly string _error;
|
||||
|
||||
internal FSClearCacheBundleFilesCompleteOperation(string error)
|
||||
{
|
||||
_error = error;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_error))
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _error;
|
||||
}
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b39545a4da23ce34abdf8da069198426
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class FSClearUnusedBundleFilesOperation : AsyncOperationBase
|
||||
{
|
||||
}
|
||||
|
||||
internal sealed class FSClearUnusedBundleFilesCompleteOperation : FSClearUnusedBundleFilesOperation
|
||||
{
|
||||
internal FSClearUnusedBundleFilesCompleteOperation()
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user