mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-24 09:40:11 +00:00
Add clear unused cache files method.
增加清空缓存文件的方法。
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user