Add clear unused cache files method.

增加清空缓存文件的方法。
This commit is contained in:
hevinci
2022-05-02 15:03:36 +08:00
parent 2c9819762a
commit 873d873194
12 changed files with 191 additions and 162 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace YooAsset
{
@@ -69,6 +70,35 @@ namespace YooAsset
return LocalPatchManifest.ResourceVersion;
}
/// <summary>
/// 清空未被使用的缓存文件
/// </summary>
public void ClearUnusedCacheFiles()
{
string cacheFolderPath = SandboxHelper.GetCacheFolderPath();
if (Directory.Exists(cacheFolderPath) == false)
return;
DirectoryInfo directoryInfo = new DirectoryInfo(cacheFolderPath);
foreach (FileInfo fileInfo in directoryInfo.GetFiles())
{
bool used = false;
foreach (var patchBundle in LocalPatchManifest.BundleList)
{
if (fileInfo.Name == patchBundle.Hash)
{
used = true;
break;
}
}
if(used == false)
{
YooLogger.Log($"Delete unused cache file : {fileInfo.Name}");
File.Delete(fileInfo.FullName);
}
}
}
/// <summary>
/// 创建下载器
/// </summary>