82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using FCoroRunnable = UnityEngine.Gonbest.MagicCube.FCoroRunnable;
|
|||
|
using PathUtils = UnityEngine.Gonbest.MagicCube.PathUtils;
|
|||
|
using FileUtils = UnityEngine.Gonbest.MagicCube.FileUtils;
|
|||
|
using FWaitForMilliseconds = UnityEngine.Gonbest.MagicCube.FWaitForMilliseconds;
|
|||
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
|
|||
|
namespace Thousandto.Launcher.Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 清理Cache
|
|||
|
/// </summary>
|
|||
|
public class FUnityCacheCleanupTask : FCoroRunnable
|
|||
|
{
|
|||
|
|
|||
|
private string _unityCacheDir = "";
|
|||
|
private int _cacheCount = 0;
|
|||
|
private int _clearCount = 0;
|
|||
|
private bool _isRunning = false;
|
|||
|
|
|||
|
public int CacheCount
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _cacheCount;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public float ClearupProgress
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_cacheCount <= 0)
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return ((float)_clearCount)/((float)_cacheCount);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool IsRunning { get { return _isRunning; } set { _isRunning = value; } }
|
|||
|
|
|||
|
|
|||
|
public override IEnumerator Run()
|
|||
|
{
|
|||
|
_unityCacheDir = PathUtils.Provider.AppPersistentPath + "/UnityCache/Shared";
|
|||
|
Debug.LogError("::::::" + _unityCacheDir);
|
|||
|
if (System.IO.Directory.Exists(_unityCacheDir))
|
|||
|
{
|
|||
|
var dirs = System.IO.Directory.GetDirectories(_unityCacheDir, "*.*", System.IO.SearchOption.AllDirectories);
|
|||
|
_cacheCount = dirs.Length;
|
|||
|
_clearCount = 0;
|
|||
|
for (int i = 0; i < _cacheCount; i++)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
FileUtils.DeleteDirectory(dirs[i]);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Debug.LogError("清理缓存资源失败! " + dirs[i]);
|
|||
|
Debug.LogException(ex);
|
|||
|
}
|
|||
|
_clearCount++;
|
|||
|
yield return new FWaitForMilliseconds(5);
|
|||
|
}
|
|||
|
_clearCount = _cacheCount;
|
|||
|
|
|||
|
}
|
|||
|
_isRunning = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|