2023-05-12 14:30:08 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace YooAsset
|
|
|
|
|
|
{
|
2025-01-03 15:08:57 +08:00
|
|
|
|
internal sealed class ClearAllCacheBundleFilesOperation : FSClearCacheFilesOperation
|
2023-12-21 19:10:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
private enum ESteps
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
|
|
|
|
|
GetAllCacheFiles,
|
|
|
|
|
|
ClearAllCacheFiles,
|
|
|
|
|
|
Done,
|
|
|
|
|
|
}
|
2023-05-12 14:30:08 +08:00
|
|
|
|
|
2025-01-03 15:08:57 +08:00
|
|
|
|
private readonly DefaultCacheFileSystem _fileSystem;
|
2024-07-04 20:36:26 +08:00
|
|
|
|
private List<string> _allBundleGUIDs;
|
2023-12-21 19:10:46 +08:00
|
|
|
|
private int _fileTotalCount = 0;
|
|
|
|
|
|
private ESteps _steps = ESteps.None;
|
2023-05-12 14:30:08 +08:00
|
|
|
|
|
2024-07-04 20:36:26 +08:00
|
|
|
|
|
2025-01-03 15:08:57 +08:00
|
|
|
|
internal ClearAllCacheBundleFilesOperation(DefaultCacheFileSystem fileSystem)
|
2023-12-21 19:10:46 +08:00
|
|
|
|
{
|
2025-01-03 15:08:57 +08:00
|
|
|
|
_fileSystem = fileSystem;
|
2023-12-21 19:10:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
internal override void InternalOnStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.GetAllCacheFiles;
|
|
|
|
|
|
}
|
|
|
|
|
|
internal override void InternalOnUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
|
|
|
|
return;
|
2023-05-12 14:30:08 +08:00
|
|
|
|
|
2023-12-21 19:10:46 +08:00
|
|
|
|
if (_steps == ESteps.GetAllCacheFiles)
|
|
|
|
|
|
{
|
2025-01-03 15:08:57 +08:00
|
|
|
|
_allBundleGUIDs = _fileSystem.GetAllCachedBundleGUIDs();
|
2024-07-04 20:36:26 +08:00
|
|
|
|
_fileTotalCount = _allBundleGUIDs.Count;
|
2023-12-21 19:10:46 +08:00
|
|
|
|
_steps = ESteps.ClearAllCacheFiles;
|
2024-07-07 00:52:17 +08:00
|
|
|
|
YooLogger.Log($"Found all cache files count : {_fileTotalCount}");
|
2023-12-21 19:10:46 +08:00
|
|
|
|
}
|
2023-05-12 14:30:08 +08:00
|
|
|
|
|
2023-12-21 19:10:46 +08:00
|
|
|
|
if (_steps == ESteps.ClearAllCacheFiles)
|
|
|
|
|
|
{
|
2024-07-04 20:36:26 +08:00
|
|
|
|
for (int i = _allBundleGUIDs.Count - 1; i >= 0; i--)
|
2023-12-21 19:10:46 +08:00
|
|
|
|
{
|
2024-07-04 20:36:26 +08:00
|
|
|
|
string bundleGUID = _allBundleGUIDs[i];
|
2025-01-03 15:08:57 +08:00
|
|
|
|
_fileSystem.DeleteCacheBundleFile(bundleGUID);
|
2024-07-04 20:36:26 +08:00
|
|
|
|
_allBundleGUIDs.RemoveAt(i);
|
2023-12-21 19:10:46 +08:00
|
|
|
|
if (OperationSystem.IsBusy)
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-05-12 14:30:08 +08:00
|
|
|
|
|
2023-12-21 19:10:46 +08:00
|
|
|
|
if (_fileTotalCount == 0)
|
|
|
|
|
|
Progress = 1.0f;
|
|
|
|
|
|
else
|
2024-07-04 20:36:26 +08:00
|
|
|
|
Progress = 1.0f - (_allBundleGUIDs.Count / _fileTotalCount);
|
2023-12-21 19:10:46 +08:00
|
|
|
|
|
2024-07-04 20:36:26 +08:00
|
|
|
|
if (_allBundleGUIDs.Count == 0)
|
2023-12-21 19:10:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
_steps = ESteps.Done;
|
|
|
|
|
|
Status = EOperationStatus.Succeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-12 14:30:08 +08:00
|
|
|
|
}
|