style : Code text indent format
This commit is contained in:
@@ -3,34 +3,34 @@ using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CacheFileInfo
|
||||
{
|
||||
private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
|
||||
internal class CacheFileInfo
|
||||
{
|
||||
private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
|
||||
|
||||
/// <summary>
|
||||
/// 写入资源包信息
|
||||
/// </summary>
|
||||
public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SharedBuffer.Clear();
|
||||
SharedBuffer.WriteUTF8(dataFileCRC);
|
||||
SharedBuffer.WriteInt64(dataFileSize);
|
||||
SharedBuffer.WriteToStream(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 写入资源包信息
|
||||
/// </summary>
|
||||
public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SharedBuffer.Clear();
|
||||
SharedBuffer.WriteUTF8(dataFileCRC);
|
||||
SharedBuffer.WriteInt64(dataFileSize);
|
||||
SharedBuffer.WriteToStream(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取资源包信息
|
||||
/// </summary>
|
||||
public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
|
||||
{
|
||||
byte[] binaryData = FileUtility.ReadAllBytes(filePath);
|
||||
BufferReader buffer = new BufferReader(binaryData);
|
||||
dataFileCRC = buffer.ReadUTF8();
|
||||
dataFileSize = buffer.ReadInt64();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取资源包信息
|
||||
/// </summary>
|
||||
public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
|
||||
{
|
||||
byte[] binaryData = FileUtility.ReadAllBytes(filePath);
|
||||
BufferReader buffer = new BufferReader(binaryData);
|
||||
dataFileCRC = buffer.ReadUTF8();
|
||||
dataFileSize = buffer.ReadInt64();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,98 +6,98 @@ using System.Diagnostics;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class CacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 禁用Unity缓存系统在WebGL平台
|
||||
/// </summary>
|
||||
public static bool DisableUnityCacheOnWebGL = false;
|
||||
internal static class CacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 禁用Unity缓存系统在WebGL平台
|
||||
/// </summary>
|
||||
public static bool DisableUnityCacheOnWebGL = false;
|
||||
|
||||
/// <summary>
|
||||
/// 验证缓存文件(子线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingCacheFile(VerifyCacheFileElement element, EVerifyLevel verifyLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (verifyLevel == EVerifyLevel.Low)
|
||||
{
|
||||
if (File.Exists(element.InfoFilePath) == false)
|
||||
return EVerifyResult.InfoFileNotExisted;
|
||||
if (File.Exists(element.DataFilePath) == false)
|
||||
return EVerifyResult.DataFileNotExisted;
|
||||
return EVerifyResult.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File.Exists(element.InfoFilePath) == false)
|
||||
return EVerifyResult.InfoFileNotExisted;
|
||||
/// <summary>
|
||||
/// 验证缓存文件(子线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingCacheFile(VerifyCacheFileElement element, EVerifyLevel verifyLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (verifyLevel == EVerifyLevel.Low)
|
||||
{
|
||||
if (File.Exists(element.InfoFilePath) == false)
|
||||
return EVerifyResult.InfoFileNotExisted;
|
||||
if (File.Exists(element.DataFilePath) == false)
|
||||
return EVerifyResult.DataFileNotExisted;
|
||||
return EVerifyResult.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File.Exists(element.InfoFilePath) == false)
|
||||
return EVerifyResult.InfoFileNotExisted;
|
||||
|
||||
// 解析信息文件获取验证数据
|
||||
CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return EVerifyResult.Exception;
|
||||
}
|
||||
// 解析信息文件获取验证数据
|
||||
CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return EVerifyResult.Exception;
|
||||
}
|
||||
|
||||
return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, verifyLevel);
|
||||
}
|
||||
return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, verifyLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证下载文件(子线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingTempFile(VerifyTempFileElement element)
|
||||
{
|
||||
return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证下载文件(子线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingTempFile(VerifyTempFileElement element)
|
||||
{
|
||||
return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证记录文件(主线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingRecordFile(CacheManager cache, string cacheGUID)
|
||||
{
|
||||
var wrapper = cache.TryGetWrapper(cacheGUID);
|
||||
if (wrapper == null)
|
||||
return EVerifyResult.CacheNotFound;
|
||||
/// <summary>
|
||||
/// 验证记录文件(主线程内操作)
|
||||
/// </summary>
|
||||
public static EVerifyResult VerifyingRecordFile(CacheManager cache, string cacheGUID)
|
||||
{
|
||||
var wrapper = cache.TryGetWrapper(cacheGUID);
|
||||
if (wrapper == null)
|
||||
return EVerifyResult.CacheNotFound;
|
||||
|
||||
EVerifyResult result = VerifyingInternal(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EVerifyLevel.High);
|
||||
return result;
|
||||
}
|
||||
EVerifyResult result = VerifyingInternal(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EVerifyLevel.High);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static EVerifyResult VerifyingInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
return EVerifyResult.DataFileNotExisted;
|
||||
private static EVerifyResult VerifyingInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
return EVerifyResult.DataFileNotExisted;
|
||||
|
||||
// 先验证文件大小
|
||||
long size = FileUtility.GetFileSize(filePath);
|
||||
if (size < fileSize)
|
||||
return EVerifyResult.FileNotComplete;
|
||||
else if (size > fileSize)
|
||||
return EVerifyResult.FileOverflow;
|
||||
// 先验证文件大小
|
||||
long size = FileUtility.GetFileSize(filePath);
|
||||
if (size < fileSize)
|
||||
return EVerifyResult.FileNotComplete;
|
||||
else if (size > fileSize)
|
||||
return EVerifyResult.FileOverflow;
|
||||
|
||||
// 再验证文件CRC
|
||||
if (verifyLevel == EVerifyLevel.High)
|
||||
{
|
||||
string crc = HashUtility.FileCRC32(filePath);
|
||||
if (crc == fileCRC)
|
||||
return EVerifyResult.Succeed;
|
||||
else
|
||||
return EVerifyResult.FileCrcError;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EVerifyResult.Succeed;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return EVerifyResult.Exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 再验证文件CRC
|
||||
if (verifyLevel == EVerifyLevel.High)
|
||||
{
|
||||
string crc = HashUtility.FileCRC32(filePath);
|
||||
if (crc == fileCRC)
|
||||
return EVerifyResult.Succeed;
|
||||
else
|
||||
return EVerifyResult.FileCrcError;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EVerifyResult.Succeed;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return EVerifyResult.Exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,132 +5,132 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CacheManager
|
||||
{
|
||||
internal class RecordWrapper
|
||||
{
|
||||
public string InfoFilePath { private set; get; }
|
||||
public string DataFilePath { private set; get; }
|
||||
public string DataFileCRC { private set; get; }
|
||||
public long DataFileSize { private set; get; }
|
||||
internal class CacheManager
|
||||
{
|
||||
internal class RecordWrapper
|
||||
{
|
||||
public string InfoFilePath { private set; get; }
|
||||
public string DataFilePath { private set; get; }
|
||||
public string DataFileCRC { private set; get; }
|
||||
public long DataFileSize { private set; get; }
|
||||
|
||||
public RecordWrapper(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
|
||||
{
|
||||
InfoFilePath = infoFilePath;
|
||||
DataFilePath = dataFilePath;
|
||||
DataFileCRC = dataFileCRC;
|
||||
DataFileSize = dataFileSize;
|
||||
}
|
||||
}
|
||||
public RecordWrapper(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
|
||||
{
|
||||
InfoFilePath = infoFilePath;
|
||||
DataFilePath = dataFilePath;
|
||||
DataFileCRC = dataFileCRC;
|
||||
DataFileSize = dataFileSize;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, RecordWrapper> _wrappers = new Dictionary<string, RecordWrapper>();
|
||||
private readonly Dictionary<string, RecordWrapper> _wrappers = new Dictionary<string, RecordWrapper>();
|
||||
|
||||
/// <summary>
|
||||
/// 所属包裹
|
||||
/// </summary>
|
||||
public readonly string PackageName;
|
||||
/// <summary>
|
||||
/// 所属包裹
|
||||
/// </summary>
|
||||
public readonly string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 验证级别
|
||||
/// </summary>
|
||||
public readonly EVerifyLevel BootVerifyLevel;
|
||||
/// <summary>
|
||||
/// 验证级别
|
||||
/// </summary>
|
||||
public readonly EVerifyLevel BootVerifyLevel;
|
||||
|
||||
|
||||
public CacheManager(string packageName, EVerifyLevel bootVerifyLevel)
|
||||
{
|
||||
PackageName = packageName;
|
||||
BootVerifyLevel = bootVerifyLevel;
|
||||
}
|
||||
public CacheManager(string packageName, EVerifyLevel bootVerifyLevel)
|
||||
{
|
||||
PackageName = packageName;
|
||||
BootVerifyLevel = bootVerifyLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有数据
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
_wrappers.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// 清空所有数据
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
_wrappers.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询缓存记录
|
||||
/// </summary>
|
||||
public bool IsCached(string cacheGUID)
|
||||
{
|
||||
return _wrappers.ContainsKey(cacheGUID);
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询缓存记录
|
||||
/// </summary>
|
||||
public bool IsCached(string cacheGUID)
|
||||
{
|
||||
return _wrappers.ContainsKey(cacheGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录验证结果
|
||||
/// </summary>
|
||||
public void Record(string cacheGUID, RecordWrapper wrapper)
|
||||
{
|
||||
if (_wrappers.ContainsKey(cacheGUID) == false)
|
||||
{
|
||||
_wrappers.Add(cacheGUID, wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Should never get here !");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 记录验证结果
|
||||
/// </summary>
|
||||
public void Record(string cacheGUID, RecordWrapper wrapper)
|
||||
{
|
||||
if (_wrappers.ContainsKey(cacheGUID) == false)
|
||||
{
|
||||
_wrappers.Add(cacheGUID, wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Should never get here !");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 丢弃验证结果并删除缓存文件
|
||||
/// </summary>
|
||||
public void Discard(string cacheGUID)
|
||||
{
|
||||
var wrapper = TryGetWrapper(cacheGUID);
|
||||
if (wrapper != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string dataFilePath = wrapper.DataFilePath;
|
||||
FileInfo fileInfo = new FileInfo(dataFilePath);
|
||||
if (fileInfo.Exists)
|
||||
fileInfo.Directory.Delete(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 丢弃验证结果并删除缓存文件
|
||||
/// </summary>
|
||||
public void Discard(string cacheGUID)
|
||||
{
|
||||
var wrapper = TryGetWrapper(cacheGUID);
|
||||
if (wrapper != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
string dataFilePath = wrapper.DataFilePath;
|
||||
FileInfo fileInfo = new FileInfo(dataFilePath);
|
||||
if (fileInfo.Exists)
|
||||
fileInfo.Directory.Delete(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
if (_wrappers.ContainsKey(cacheGUID))
|
||||
{
|
||||
_wrappers.Remove(cacheGUID);
|
||||
}
|
||||
}
|
||||
if (_wrappers.ContainsKey(cacheGUID))
|
||||
{
|
||||
_wrappers.Remove(cacheGUID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取记录对象
|
||||
/// </summary>
|
||||
public RecordWrapper TryGetWrapper(string cacheGUID)
|
||||
{
|
||||
if (_wrappers.TryGetValue(cacheGUID, out RecordWrapper value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取记录对象
|
||||
/// </summary>
|
||||
public RecordWrapper TryGetWrapper(string cacheGUID)
|
||||
{
|
||||
if (_wrappers.TryGetValue(cacheGUID, out RecordWrapper value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存文件总数
|
||||
/// </summary>
|
||||
public int GetAllCachedFilesCount()
|
||||
{
|
||||
return _wrappers.Count;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取缓存文件总数
|
||||
/// </summary>
|
||||
public int GetAllCachedFilesCount()
|
||||
{
|
||||
return _wrappers.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存GUID集合
|
||||
/// </summary>
|
||||
public List<string> GetAllCachedGUIDs()
|
||||
{
|
||||
List<string> keys = new List<string>(_wrappers.Keys.Count);
|
||||
var keyCollection = _wrappers.Keys;
|
||||
foreach (var key in keyCollection)
|
||||
{
|
||||
keys.Add(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取缓存GUID集合
|
||||
/// </summary>
|
||||
public List<string> GetAllCachedGUIDs()
|
||||
{
|
||||
List<string> keys = new List<string>(_wrappers.Keys.Count);
|
||||
var keyCollection = _wrappers.Keys;
|
||||
foreach (var key in keyCollection)
|
||||
{
|
||||
keys.Add(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载文件校验等级
|
||||
/// </summary>
|
||||
public enum EVerifyLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证文件存在
|
||||
/// </summary>
|
||||
Low,
|
||||
/// <summary>
|
||||
/// 下载文件校验等级
|
||||
/// </summary>
|
||||
public enum EVerifyLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证文件存在
|
||||
/// </summary>
|
||||
Low,
|
||||
|
||||
/// <summary>
|
||||
/// 验证文件大小
|
||||
/// </summary>
|
||||
Middle,
|
||||
/// <summary>
|
||||
/// 验证文件大小
|
||||
/// </summary>
|
||||
Middle,
|
||||
|
||||
/// <summary>
|
||||
/// 验证文件大小和CRC
|
||||
/// </summary>
|
||||
High,
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证文件大小和CRC
|
||||
/// </summary>
|
||||
High,
|
||||
}
|
||||
}
|
||||
@@ -4,68 +4,68 @@ using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理本地包裹所有的缓存文件
|
||||
/// </summary>
|
||||
public sealed class ClearAllCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetAllCacheFiles,
|
||||
ClearAllCacheFiles,
|
||||
Done,
|
||||
}
|
||||
/// <summary>
|
||||
/// 清理本地包裹所有的缓存文件
|
||||
/// </summary>
|
||||
public sealed class ClearAllCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetAllCacheFiles,
|
||||
ClearAllCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly CacheManager _cache;
|
||||
private List<string> _allCacheGUIDs;
|
||||
private int _fileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearAllCacheFilesOperation(CacheManager cache)
|
||||
{
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.GetAllCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
private readonly CacheManager _cache;
|
||||
private List<string> _allCacheGUIDs;
|
||||
private int _fileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
if (_steps == ESteps.GetAllCacheFiles)
|
||||
{
|
||||
_allCacheGUIDs = _cache.GetAllCachedGUIDs();
|
||||
_fileTotalCount = _allCacheGUIDs.Count;
|
||||
YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
|
||||
_steps = ESteps.ClearAllCacheFiles;
|
||||
}
|
||||
internal ClearAllCacheFilesOperation(CacheManager cache)
|
||||
{
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.GetAllCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.ClearAllCacheFiles)
|
||||
{
|
||||
for (int i = _allCacheGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string cacheGUID = _allCacheGUIDs[i];
|
||||
_cache.Discard(cacheGUID);
|
||||
_allCacheGUIDs.RemoveAt(i);
|
||||
if (_steps == ESteps.GetAllCacheFiles)
|
||||
{
|
||||
_allCacheGUIDs = _cache.GetAllCachedGUIDs();
|
||||
_fileTotalCount = _allCacheGUIDs.Count;
|
||||
YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
|
||||
_steps = ESteps.ClearAllCacheFiles;
|
||||
}
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
if (_steps == ESteps.ClearAllCacheFiles)
|
||||
{
|
||||
for (int i = _allCacheGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string cacheGUID = _allCacheGUIDs[i];
|
||||
_cache.Discard(cacheGUID);
|
||||
_allCacheGUIDs.RemoveAt(i);
|
||||
|
||||
if (_fileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_allCacheGUIDs.Count / _fileTotalCount);
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_allCacheGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_fileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_allCacheGUIDs.Count / _fileTotalCount);
|
||||
|
||||
if (_allCacheGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,84 +4,84 @@ using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理本地包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetUnusedCacheFiles,
|
||||
ClearUnusedCacheFiles,
|
||||
Done,
|
||||
}
|
||||
/// <summary>
|
||||
/// 清理本地包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetUnusedCacheFiles,
|
||||
ClearUnusedCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourcePackage _package;
|
||||
private readonly CacheManager _cache;
|
||||
private List<string> _unusedCacheGUIDs;
|
||||
private int _unusedFileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly ResourcePackage _package;
|
||||
private readonly CacheManager _cache;
|
||||
private List<string> _unusedCacheGUIDs;
|
||||
private int _unusedFileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearUnusedCacheFilesOperation(ResourcePackage package, CacheManager cache)
|
||||
{
|
||||
_package = package;
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.GetUnusedCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
internal ClearUnusedCacheFilesOperation(ResourcePackage package, CacheManager cache)
|
||||
{
|
||||
_package = package;
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.GetUnusedCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetUnusedCacheFiles)
|
||||
{
|
||||
_unusedCacheGUIDs = GetUnusedCacheGUIDs();
|
||||
_unusedFileTotalCount = _unusedCacheGUIDs.Count;
|
||||
YooLogger.Log($"Found unused cache file count : {_unusedFileTotalCount}");
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
}
|
||||
if (_steps == ESteps.GetUnusedCacheFiles)
|
||||
{
|
||||
_unusedCacheGUIDs = GetUnusedCacheGUIDs();
|
||||
_unusedFileTotalCount = _unusedCacheGUIDs.Count;
|
||||
YooLogger.Log($"Found unused cache file count : {_unusedFileTotalCount}");
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearUnusedCacheFiles)
|
||||
{
|
||||
for (int i = _unusedCacheGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string cacheGUID = _unusedCacheGUIDs[i];
|
||||
_cache.Discard(cacheGUID);
|
||||
_unusedCacheGUIDs.RemoveAt(i);
|
||||
if (_steps == ESteps.ClearUnusedCacheFiles)
|
||||
{
|
||||
for (int i = _unusedCacheGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string cacheGUID = _unusedCacheGUIDs[i];
|
||||
_cache.Discard(cacheGUID);
|
||||
_unusedCacheGUIDs.RemoveAt(i);
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_unusedFileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_unusedCacheGUIDs.Count / _unusedFileTotalCount);
|
||||
if (_unusedFileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_unusedCacheGUIDs.Count / _unusedFileTotalCount);
|
||||
|
||||
if (_unusedCacheGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_unusedCacheGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetUnusedCacheGUIDs()
|
||||
{
|
||||
var allCacheGUIDs = _cache.GetAllCachedGUIDs();
|
||||
List<string> result = new List<string>(allCacheGUIDs.Count);
|
||||
foreach (var cacheGUID in allCacheGUIDs)
|
||||
{
|
||||
if (_package.IsIncludeBundleFile(cacheGUID) == false)
|
||||
{
|
||||
result.Add(cacheGUID);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
private List<string> GetUnusedCacheGUIDs()
|
||||
{
|
||||
var allCacheGUIDs = _cache.GetAllCachedGUIDs();
|
||||
List<string> result = new List<string>(allCacheGUIDs.Count);
|
||||
foreach (var cacheGUID in allCacheGUIDs)
|
||||
{
|
||||
if (_package.IsIncludeBundleFile(cacheGUID) == false)
|
||||
{
|
||||
result.Add(cacheGUID);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+108
-108
@@ -5,127 +5,127 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class FindCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
UpdateCacheFiles,
|
||||
Done,
|
||||
}
|
||||
internal sealed class FindCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
UpdateCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly CacheManager _cache;
|
||||
private IEnumerator<DirectoryInfo> _filesEnumerator = null;
|
||||
private float _verifyStartTime;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly CacheManager _cache;
|
||||
private IEnumerator<DirectoryInfo> _filesEnumerator = null;
|
||||
private float _verifyStartTime;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 需要验证的元素
|
||||
/// </summary>
|
||||
public readonly List<VerifyCacheFileElement> VerifyElements = new List<VerifyCacheFileElement>(5000);
|
||||
/// <summary>
|
||||
/// 需要验证的元素
|
||||
/// </summary>
|
||||
public readonly List<VerifyCacheFileElement> VerifyElements = new List<VerifyCacheFileElement>(5000);
|
||||
|
||||
public FindCacheFilesOperation(PersistentManager persistent, CacheManager cache)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
public FindCacheFilesOperation(PersistentManager persistent, CacheManager cache)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
string rootPath = _persistent.SandboxCacheFilesRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
var directorieInfos = rootDirectory.EnumerateDirectories();
|
||||
_filesEnumerator = directorieInfos.GetEnumerator();
|
||||
}
|
||||
_steps = ESteps.UpdateCacheFiles;
|
||||
}
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
string rootPath = _persistent.SandboxCacheFilesRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
var directorieInfos = rootDirectory.EnumerateDirectories();
|
||||
_filesEnumerator = directorieInfos.GetEnumerator();
|
||||
}
|
||||
_steps = ESteps.UpdateCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UpdateCacheFiles)
|
||||
{
|
||||
if (UpdateCacheFiles())
|
||||
return;
|
||||
if (_steps == ESteps.UpdateCacheFiles)
|
||||
{
|
||||
if (UpdateCacheFiles())
|
||||
return;
|
||||
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Find cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
}
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Find cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
}
|
||||
|
||||
private bool UpdateCacheFiles()
|
||||
{
|
||||
if (_filesEnumerator == null)
|
||||
return false;
|
||||
private bool UpdateCacheFiles()
|
||||
{
|
||||
if (_filesEnumerator == null)
|
||||
return false;
|
||||
|
||||
bool isFindItem;
|
||||
while (true)
|
||||
{
|
||||
isFindItem = _filesEnumerator.MoveNext();
|
||||
if (isFindItem == false)
|
||||
break;
|
||||
bool isFindItem;
|
||||
while (true)
|
||||
{
|
||||
isFindItem = _filesEnumerator.MoveNext();
|
||||
if (isFindItem == false)
|
||||
break;
|
||||
|
||||
var rootFoder = _filesEnumerator.Current;
|
||||
var childDirectories = rootFoder.GetDirectories();
|
||||
foreach (var chidDirectory in childDirectories)
|
||||
{
|
||||
string cacheGUID = chidDirectory.Name;
|
||||
if (_cache.IsCached(cacheGUID))
|
||||
continue;
|
||||
var rootFoder = _filesEnumerator.Current;
|
||||
var childDirectories = rootFoder.GetDirectories();
|
||||
foreach (var chidDirectory in childDirectories)
|
||||
{
|
||||
string cacheGUID = chidDirectory.Name;
|
||||
if (_cache.IsCached(cacheGUID))
|
||||
continue;
|
||||
|
||||
// 创建验证元素类
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
|
||||
string dataFileExtension = FindDataFileExtension(chidDirectory);
|
||||
// 创建验证元素类
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
|
||||
string dataFileExtension = FindDataFileExtension(chidDirectory);
|
||||
|
||||
// 跳过断点续传的临时文件
|
||||
if (dataFileExtension == ".temp")
|
||||
continue;
|
||||
// 跳过断点续传的临时文件
|
||||
if (dataFileExtension == ".temp")
|
||||
continue;
|
||||
|
||||
// 注意:根据配置需求数据文件会带文件格式
|
||||
if (_persistent.AppendFileExtension)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataFileExtension) == false)
|
||||
dataFilePath += dataFileExtension;
|
||||
}
|
||||
// 注意:根据配置需求数据文件会带文件格式
|
||||
if (_persistent.AppendFileExtension)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dataFileExtension) == false)
|
||||
dataFilePath += dataFileExtension;
|
||||
}
|
||||
|
||||
VerifyCacheFileElement element = new VerifyCacheFileElement(_cache.PackageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
VerifyElements.Add(element);
|
||||
}
|
||||
VerifyCacheFileElement element = new VerifyCacheFileElement(_cache.PackageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
VerifyElements.Add(element);
|
||||
}
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
return isFindItem;
|
||||
}
|
||||
private string FindDataFileExtension(DirectoryInfo directoryInfo)
|
||||
{
|
||||
string dataFileExtension = string.Empty;
|
||||
var fileInfos = directoryInfo.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
|
||||
{
|
||||
dataFileExtension = fileInfo.Extension;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dataFileExtension;
|
||||
}
|
||||
}
|
||||
return isFindItem;
|
||||
}
|
||||
private string FindDataFileExtension(DirectoryInfo directoryInfo)
|
||||
{
|
||||
string dataFileExtension = string.Empty;
|
||||
var fileInfos = directoryInfo.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
|
||||
{
|
||||
dataFileExtension = fileInfo.Extension;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dataFileExtension;
|
||||
}
|
||||
}
|
||||
}
|
||||
+215
-215
@@ -6,249 +6,249 @@ using System.Threading;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class VerifyCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
public static VerifyCacheFilesOperation CreateOperation(CacheManager cache, List<VerifyCacheFileElement> elements)
|
||||
{
|
||||
internal abstract class VerifyCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
public static VerifyCacheFilesOperation CreateOperation(CacheManager cache, List<VerifyCacheFileElement> elements)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
var operation = new VerifyCacheFilesWithoutThreadOperation(cache, elements);
|
||||
#else
|
||||
var operation = new VerifyCacheFilesWithThreadOperation(cache, elements);
|
||||
var operation = new VerifyCacheFilesWithThreadOperation(cache, elements);
|
||||
#endif
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class VerifyCacheFilesWithThreadOperation : VerifyCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitVerify,
|
||||
UpdateVerify,
|
||||
Done,
|
||||
}
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class VerifyCacheFilesWithThreadOperation : VerifyCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitVerify,
|
||||
UpdateVerify,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||
private readonly CacheManager _cache;
|
||||
private List<VerifyCacheFileElement> _waitingList;
|
||||
private List<VerifyCacheFileElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private int _succeedCount;
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||
private readonly CacheManager _cache;
|
||||
private List<VerifyCacheFileElement> _waitingList;
|
||||
private List<VerifyCacheFileElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private int _succeedCount;
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyCacheFilesWithThreadOperation(CacheManager cache, List<VerifyCacheFileElement> elements)
|
||||
{
|
||||
_cache = cache;
|
||||
_waitingList = elements;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
public VerifyCacheFilesWithThreadOperation(CacheManager cache, List<VerifyCacheFileElement> elements)
|
||||
{
|
||||
_cache = cache;
|
||||
_waitingList = elements;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.InitVerify)
|
||||
{
|
||||
int fileCount = _waitingList.Count;
|
||||
if (_steps == ESteps.InitVerify)
|
||||
{
|
||||
int fileCount = _waitingList.Count;
|
||||
|
||||
// 设置同时验证的最大数
|
||||
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
||||
_verifyTotalCount = fileCount;
|
||||
if (_verifyMaxNum < 1)
|
||||
_verifyMaxNum = 1;
|
||||
// 设置同时验证的最大数
|
||||
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
||||
_verifyTotalCount = fileCount;
|
||||
if (_verifyMaxNum < 1)
|
||||
_verifyMaxNum = 1;
|
||||
|
||||
_verifyingList = new List<VerifyCacheFileElement>(_verifyMaxNum);
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
_verifyingList = new List<VerifyCacheFileElement>(_verifyMaxNum);
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UpdateVerify)
|
||||
{
|
||||
_syncContext.Update();
|
||||
if (_steps == ESteps.UpdateVerify)
|
||||
{
|
||||
_syncContext.Update();
|
||||
|
||||
Progress = GetProgress();
|
||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
Progress = GetProgress();
|
||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
|
||||
if (_verifyingList.Count >= _verifyMaxNum)
|
||||
break;
|
||||
if (_verifyingList.Count >= _verifyMaxNum)
|
||||
break;
|
||||
|
||||
var element = _waitingList[i];
|
||||
if (BeginVerifyFileWithThread(element))
|
||||
{
|
||||
_waitingList.RemoveAt(i);
|
||||
_verifyingList.Add(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning("The thread pool is failed queued.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var element = _waitingList[i];
|
||||
if (BeginVerifyFileWithThread(element))
|
||||
{
|
||||
_waitingList.RemoveAt(i);
|
||||
_verifyingList.Add(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning("The thread pool is failed queued.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float GetProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
|
||||
}
|
||||
private bool BeginVerifyFileWithThread(VerifyCacheFileElement element)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
|
||||
}
|
||||
private void VerifyInThread(object obj)
|
||||
{
|
||||
VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
|
||||
element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
|
||||
_syncContext.Post(VerifyCallback, element);
|
||||
}
|
||||
private void VerifyCallback(object obj)
|
||||
{
|
||||
VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
|
||||
_verifyingList.Remove(element);
|
||||
private float GetProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
|
||||
}
|
||||
private bool BeginVerifyFileWithThread(VerifyCacheFileElement element)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
|
||||
}
|
||||
private void VerifyInThread(object obj)
|
||||
{
|
||||
VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
|
||||
element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
|
||||
_syncContext.Post(VerifyCallback, element);
|
||||
}
|
||||
private void VerifyCallback(object obj)
|
||||
{
|
||||
VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
|
||||
_verifyingList.Remove(element);
|
||||
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
_succeedCount++;
|
||||
var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
|
||||
_cache.Record(element.CacheGUID, wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
_failedCount++;
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
_succeedCount++;
|
||||
var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
|
||||
_cache.Record(element.CacheGUID, wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
_failedCount++;
|
||||
|
||||
YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
|
||||
element.DeleteFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
|
||||
element.DeleteFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class VerifyCacheFilesWithoutThreadOperation : VerifyCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitVerify,
|
||||
UpdateVerify,
|
||||
Done,
|
||||
}
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class VerifyCacheFilesWithoutThreadOperation : VerifyCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitVerify,
|
||||
UpdateVerify,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly CacheManager _cache;
|
||||
private List<VerifyCacheFileElement> _waitingList;
|
||||
private List<VerifyCacheFileElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private int _succeedCount;
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyCacheFilesWithoutThreadOperation(CacheManager cache, List<VerifyCacheFileElement> elements)
|
||||
{
|
||||
_cache = cache;
|
||||
_waitingList = elements;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
private readonly CacheManager _cache;
|
||||
private List<VerifyCacheFileElement> _waitingList;
|
||||
private List<VerifyCacheFileElement> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private int _succeedCount;
|
||||
private int _failedCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
if (_steps == ESteps.InitVerify)
|
||||
{
|
||||
int fileCount = _waitingList.Count;
|
||||
public VerifyCacheFilesWithoutThreadOperation(CacheManager cache, List<VerifyCacheFileElement> elements)
|
||||
{
|
||||
_cache = cache;
|
||||
_waitingList = elements;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
// 设置同时验证的最大数
|
||||
_verifyMaxNum = fileCount;
|
||||
_verifyTotalCount = fileCount;
|
||||
if (_steps == ESteps.InitVerify)
|
||||
{
|
||||
int fileCount = _waitingList.Count;
|
||||
|
||||
_verifyingList = new List<VerifyCacheFileElement>(_verifyMaxNum);
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
// 设置同时验证的最大数
|
||||
_verifyMaxNum = fileCount;
|
||||
_verifyTotalCount = fileCount;
|
||||
|
||||
if (_steps == ESteps.UpdateVerify)
|
||||
{
|
||||
Progress = GetProgress();
|
||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Package verify elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
_verifyingList = new List<VerifyCacheFileElement>(_verifyMaxNum);
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
if (_steps == ESteps.UpdateVerify)
|
||||
{
|
||||
Progress = GetProgress();
|
||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Package verify elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
|
||||
if (_verifyingList.Count >= _verifyMaxNum)
|
||||
break;
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
|
||||
var element = _waitingList[i];
|
||||
BeginVerifyFileWithoutThread(element);
|
||||
_waitingList.RemoveAt(i);
|
||||
_verifyingList.Add(element);
|
||||
}
|
||||
if (_verifyingList.Count >= _verifyMaxNum)
|
||||
break;
|
||||
|
||||
// 主线程内验证,可以清空列表
|
||||
_verifyingList.Clear();
|
||||
}
|
||||
}
|
||||
var element = _waitingList[i];
|
||||
BeginVerifyFileWithoutThread(element);
|
||||
_waitingList.RemoveAt(i);
|
||||
_verifyingList.Add(element);
|
||||
}
|
||||
|
||||
private float GetProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
|
||||
}
|
||||
private void BeginVerifyFileWithoutThread(VerifyCacheFileElement element)
|
||||
{
|
||||
element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
_succeedCount++;
|
||||
var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
|
||||
_cache.Record(element.CacheGUID, wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
_failedCount++;
|
||||
// 主线程内验证,可以清空列表
|
||||
_verifyingList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
|
||||
element.DeleteFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
private float GetProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
|
||||
}
|
||||
private void BeginVerifyFileWithoutThread(VerifyCacheFileElement element)
|
||||
{
|
||||
element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
|
||||
if (element.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
_succeedCount++;
|
||||
var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
|
||||
_cache.Record(element.CacheGUID, wrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
_failedCount++;
|
||||
|
||||
YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
|
||||
element.DeleteFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+115
-115
@@ -6,136 +6,136 @@ using System.Threading;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class VerifyTempFileOperation : AsyncOperationBase
|
||||
{
|
||||
public EVerifyResult VerifyResult { protected set; get; }
|
||||
internal abstract class VerifyTempFileOperation : AsyncOperationBase
|
||||
{
|
||||
public EVerifyResult VerifyResult { protected set; get; }
|
||||
|
||||
public static VerifyTempFileOperation CreateOperation(VerifyTempFileElement element)
|
||||
{
|
||||
public static VerifyTempFileOperation CreateOperation(VerifyTempFileElement element)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
var operation = new VerifyTempFileWithoutThreadOperation(element);
|
||||
#else
|
||||
var operation = new VerifyTempFileWithThreadOperation(element);
|
||||
var operation = new VerifyTempFileWithThreadOperation(element);
|
||||
#endif
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class VerifyTempFileWithThreadOperation : VerifyTempFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
VerifyFile,
|
||||
Waiting,
|
||||
Done,
|
||||
}
|
||||
/// <summary>
|
||||
/// 下载文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class VerifyTempFileWithThreadOperation : VerifyTempFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
VerifyFile,
|
||||
Waiting,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly VerifyTempFileElement _element;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly VerifyTempFileElement _element;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyTempFileWithThreadOperation(VerifyTempFileElement element)
|
||||
{
|
||||
_element = element;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.VerifyFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
public VerifyTempFileWithThreadOperation(VerifyTempFileElement element)
|
||||
{
|
||||
_element = element;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.VerifyFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.VerifyFile)
|
||||
{
|
||||
if (BeginVerifyFileWithThread(_element))
|
||||
{
|
||||
_steps = ESteps.Waiting;
|
||||
}
|
||||
}
|
||||
if (_steps == ESteps.VerifyFile)
|
||||
{
|
||||
if (BeginVerifyFileWithThread(_element))
|
||||
{
|
||||
_steps = ESteps.Waiting;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Waiting)
|
||||
{
|
||||
int result = _element.Result;
|
||||
if (result == 0)
|
||||
return;
|
||||
if (_steps == ESteps.Waiting)
|
||||
{
|
||||
int result = _element.Result;
|
||||
if (result == 0)
|
||||
return;
|
||||
|
||||
VerifyResult = (EVerifyResult)result;
|
||||
if (VerifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
|
||||
}
|
||||
}
|
||||
}
|
||||
VerifyResult = (EVerifyResult)result;
|
||||
if (VerifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool BeginVerifyFileWithThread(VerifyTempFileElement element)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
|
||||
}
|
||||
private void VerifyInThread(object obj)
|
||||
{
|
||||
VerifyTempFileElement element = (VerifyTempFileElement)obj;
|
||||
int result = (int)CacheHelper.VerifyingTempFile(element);
|
||||
element.Result = result;
|
||||
}
|
||||
}
|
||||
private bool BeginVerifyFileWithThread(VerifyTempFileElement element)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
|
||||
}
|
||||
private void VerifyInThread(object obj)
|
||||
{
|
||||
VerifyTempFileElement element = (VerifyTempFileElement)obj;
|
||||
int result = (int)CacheHelper.VerifyingTempFile(element);
|
||||
element.Result = result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class VerifyTempFileWithoutThreadOperation : VerifyTempFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
VerifyFile,
|
||||
Done,
|
||||
}
|
||||
/// <summary>
|
||||
/// 下载文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class VerifyTempFileWithoutThreadOperation : VerifyTempFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
VerifyFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly VerifyTempFileElement _element;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly VerifyTempFileElement _element;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyTempFileWithoutThreadOperation(VerifyTempFileElement element)
|
||||
{
|
||||
_element = element;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.VerifyFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
public VerifyTempFileWithoutThreadOperation(VerifyTempFileElement element)
|
||||
{
|
||||
_element = element;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.VerifyFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.VerifyFile)
|
||||
{
|
||||
_element.Result = (int)CacheHelper.VerifyingTempFile(_element);
|
||||
if (_steps == ESteps.VerifyFile)
|
||||
{
|
||||
_element.Result = (int)CacheHelper.VerifyingTempFile(_element);
|
||||
|
||||
VerifyResult = (EVerifyResult)_element.Result;
|
||||
if (VerifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VerifyResult = (EVerifyResult)_element.Result;
|
||||
if (VerifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,70 +5,70 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class PackageCachingOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
FindCacheFiles,
|
||||
VerifyCacheFiles,
|
||||
Done,
|
||||
}
|
||||
internal class PackageCachingOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
FindCacheFiles,
|
||||
VerifyCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly CacheManager _cache;
|
||||
private FindCacheFilesOperation _findCacheFilesOp;
|
||||
private VerifyCacheFilesOperation _verifyCacheFilesOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly CacheManager _cache;
|
||||
private FindCacheFilesOperation _findCacheFilesOp;
|
||||
private VerifyCacheFilesOperation _verifyCacheFilesOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public PackageCachingOperation(PersistentManager persistent, CacheManager cache)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.FindCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
public PackageCachingOperation(PersistentManager persistent, CacheManager cache)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_cache = cache;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.FindCacheFiles;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.FindCacheFiles)
|
||||
{
|
||||
if (_findCacheFilesOp == null)
|
||||
{
|
||||
_findCacheFilesOp = new FindCacheFilesOperation(_persistent, _cache);
|
||||
OperationSystem.StartOperation(_cache.PackageName, _findCacheFilesOp);
|
||||
}
|
||||
if (_steps == ESteps.FindCacheFiles)
|
||||
{
|
||||
if (_findCacheFilesOp == null)
|
||||
{
|
||||
_findCacheFilesOp = new FindCacheFilesOperation(_persistent, _cache);
|
||||
OperationSystem.StartOperation(_cache.PackageName, _findCacheFilesOp);
|
||||
}
|
||||
|
||||
Progress = _findCacheFilesOp.Progress;
|
||||
if (_findCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
Progress = _findCacheFilesOp.Progress;
|
||||
if (_findCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
|
||||
_steps = ESteps.VerifyCacheFiles;
|
||||
}
|
||||
_steps = ESteps.VerifyCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyCacheFiles)
|
||||
{
|
||||
if (_verifyCacheFilesOp == null)
|
||||
{
|
||||
_verifyCacheFilesOp = VerifyCacheFilesOperation.CreateOperation(_cache, _findCacheFilesOp.VerifyElements);
|
||||
OperationSystem.StartOperation(_cache.PackageName, _verifyCacheFilesOp);
|
||||
}
|
||||
if (_steps == ESteps.VerifyCacheFiles)
|
||||
{
|
||||
if (_verifyCacheFilesOp == null)
|
||||
{
|
||||
_verifyCacheFilesOp = VerifyCacheFilesOperation.CreateOperation(_cache, _findCacheFilesOp.VerifyElements);
|
||||
OperationSystem.StartOperation(_cache.PackageName, _verifyCacheFilesOp);
|
||||
}
|
||||
|
||||
Progress = _verifyCacheFilesOp.Progress;
|
||||
if (_verifyCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
Progress = _verifyCacheFilesOp.Progress;
|
||||
if (_verifyCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
int totalCount = _cache.GetAllCachedFilesCount();
|
||||
YooLogger.Log($"Package '{_cache.PackageName}' cached files count : {totalCount}");
|
||||
}
|
||||
}
|
||||
}
|
||||
int totalCount = _cache.GetAllCachedFilesCount();
|
||||
YooLogger.Log($"Package '{_cache.PackageName}' cached files count : {totalCount}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class PersistentHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取WWW加载本地资源的路径
|
||||
/// </summary>
|
||||
public static string ConvertToWWWPath(string path)
|
||||
{
|
||||
internal static class PersistentHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取WWW加载本地资源的路径
|
||||
/// </summary>
|
||||
public static string ConvertToWWWPath(string path)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_WEBGL
|
||||
return path;
|
||||
#elif UNITY_IPHONE
|
||||
@@ -23,6 +23,6 @@ namespace YooAsset
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,207 +5,207 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class PersistentManager
|
||||
{
|
||||
private readonly Dictionary<string, string> _cachedDataFilePaths = new Dictionary<string, string>(10000);
|
||||
private readonly Dictionary<string, string> _cachedInfoFilePaths = new Dictionary<string, string>(10000);
|
||||
private readonly Dictionary<string, string> _tempDataFilePaths = new Dictionary<string, string>(10000);
|
||||
private readonly Dictionary<string, string> _buildinFilePaths = new Dictionary<string, string>(10000);
|
||||
internal class PersistentManager
|
||||
{
|
||||
private readonly Dictionary<string, string> _cachedDataFilePaths = new Dictionary<string, string>(10000);
|
||||
private readonly Dictionary<string, string> _cachedInfoFilePaths = new Dictionary<string, string>(10000);
|
||||
private readonly Dictionary<string, string> _tempDataFilePaths = new Dictionary<string, string>(10000);
|
||||
private readonly Dictionary<string, string> _buildinFilePaths = new Dictionary<string, string>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 所属包裹
|
||||
/// </summary>
|
||||
public readonly string PackageName;
|
||||
/// <summary>
|
||||
/// 所属包裹
|
||||
/// </summary>
|
||||
public readonly string PackageName;
|
||||
|
||||
public string BuildinRoot { private set; get; }
|
||||
public string BuildinPackageRoot { private set; get; }
|
||||
public string BuildinRoot { private set; get; }
|
||||
public string BuildinPackageRoot { private set; get; }
|
||||
|
||||
public string SandboxRoot { private set; get; }
|
||||
public string SandboxPackageRoot { private set; get; }
|
||||
public string SandboxCacheFilesRoot { private set; get; }
|
||||
public string SandboxManifestFilesRoot { private set; get; }
|
||||
public string SandboxAppFootPrintFilePath { private set; get; }
|
||||
public string SandboxRoot { private set; get; }
|
||||
public string SandboxPackageRoot { private set; get; }
|
||||
public string SandboxCacheFilesRoot { private set; get; }
|
||||
public string SandboxManifestFilesRoot { private set; get; }
|
||||
public string SandboxAppFootPrintFilePath { private set; get; }
|
||||
|
||||
public bool AppendFileExtension { private set; get; }
|
||||
public bool AppendFileExtension { private set; get; }
|
||||
|
||||
|
||||
public PersistentManager(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
public PersistentManager(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public void Initialize(string buildinRoot, string sandboxRoot, bool appendFileExtension)
|
||||
{
|
||||
if (string.IsNullOrEmpty(buildinRoot))
|
||||
BuildinRoot = CreateDefaultBuildinRoot();
|
||||
else
|
||||
BuildinRoot = buildinRoot;
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public void Initialize(string buildinRoot, string sandboxRoot, bool appendFileExtension)
|
||||
{
|
||||
if (string.IsNullOrEmpty(buildinRoot))
|
||||
BuildinRoot = CreateDefaultBuildinRoot();
|
||||
else
|
||||
BuildinRoot = buildinRoot;
|
||||
|
||||
if (string.IsNullOrEmpty(sandboxRoot))
|
||||
SandboxRoot = CreateDefaultSandboxRoot();
|
||||
else
|
||||
SandboxRoot = sandboxRoot;
|
||||
if (string.IsNullOrEmpty(sandboxRoot))
|
||||
SandboxRoot = CreateDefaultSandboxRoot();
|
||||
else
|
||||
SandboxRoot = sandboxRoot;
|
||||
|
||||
BuildinPackageRoot = PathUtility.Combine(BuildinRoot, PackageName);
|
||||
SandboxPackageRoot = PathUtility.Combine(SandboxRoot, PackageName);
|
||||
SandboxCacheFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CacheFilesFolderName);
|
||||
SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
|
||||
SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
|
||||
AppendFileExtension = appendFileExtension;
|
||||
}
|
||||
private static string CreateDefaultBuildinRoot()
|
||||
{
|
||||
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
}
|
||||
private static string CreateDefaultSandboxRoot()
|
||||
{
|
||||
BuildinPackageRoot = PathUtility.Combine(BuildinRoot, PackageName);
|
||||
SandboxPackageRoot = PathUtility.Combine(SandboxRoot, PackageName);
|
||||
SandboxCacheFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CacheFilesFolderName);
|
||||
SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
|
||||
SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
|
||||
AppendFileExtension = appendFileExtension;
|
||||
}
|
||||
private static string CreateDefaultBuildinRoot()
|
||||
{
|
||||
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
}
|
||||
private static string CreateDefaultSandboxRoot()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
|
||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
projectPath = PathUtility.RegularPath(projectPath);
|
||||
return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
|
||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
projectPath = PathUtility.RegularPath(projectPath);
|
||||
return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#elif UNITY_STANDALONE
|
||||
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#else
|
||||
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public string GetCachedDataFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_cachedDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
string folderName = bundle.FileHash.Substring(0, 2);
|
||||
filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
||||
if (AppendFileExtension)
|
||||
filePath += bundle.FileExtension;
|
||||
_cachedDataFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetCachedInfoFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_cachedInfoFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
string folderName = bundle.FileHash.Substring(0, 2);
|
||||
filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
||||
_cachedInfoFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetTempDataFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_tempDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
string cachedDataFilePath = GetCachedDataFilePath(bundle);
|
||||
filePath = $"{cachedDataFilePath}.temp";
|
||||
_tempDataFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetBuildinFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_buildinFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
filePath = PathUtility.Combine(BuildinPackageRoot, bundle.FileName);
|
||||
_buildinFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetCachedDataFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_cachedDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
string folderName = bundle.FileHash.Substring(0, 2);
|
||||
filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
||||
if (AppendFileExtension)
|
||||
filePath += bundle.FileExtension;
|
||||
_cachedDataFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetCachedInfoFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_cachedInfoFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
string folderName = bundle.FileHash.Substring(0, 2);
|
||||
filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
||||
_cachedInfoFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetTempDataFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_tempDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
string cachedDataFilePath = GetCachedDataFilePath(bundle);
|
||||
filePath = $"{cachedDataFilePath}.temp";
|
||||
_tempDataFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
public string GetBuildinFilePath(PackageBundle bundle)
|
||||
{
|
||||
if (_buildinFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
|
||||
{
|
||||
filePath = PathUtility.Combine(BuildinPackageRoot, bundle.FileName);
|
||||
_buildinFilePaths.Add(bundle.CacheGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒里的包裹目录
|
||||
/// </summary>
|
||||
public void DeleteSandboxPackageFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxPackageRoot))
|
||||
Directory.Delete(SandboxPackageRoot, true);
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除沙盒里的包裹目录
|
||||
/// </summary>
|
||||
public void DeleteSandboxPackageFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxPackageRoot))
|
||||
Directory.Delete(SandboxPackageRoot, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的缓存文件夹
|
||||
/// </summary>
|
||||
public void DeleteSandboxCacheFilesFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxCacheFilesRoot))
|
||||
Directory.Delete(SandboxCacheFilesRoot, true);
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除沙盒内的缓存文件夹
|
||||
/// </summary>
|
||||
public void DeleteSandboxCacheFilesFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxCacheFilesRoot))
|
||||
Directory.Delete(SandboxCacheFilesRoot, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除沙盒内的清单文件夹
|
||||
/// </summary>
|
||||
public void DeleteSandboxManifestFilesFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxManifestFilesRoot))
|
||||
Directory.Delete(SandboxManifestFilesRoot, true);
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除沙盒内的清单文件夹
|
||||
/// </summary>
|
||||
public void DeleteSandboxManifestFilesFolder()
|
||||
{
|
||||
if (Directory.Exists(SandboxManifestFilesRoot))
|
||||
Directory.Delete(SandboxManifestFilesRoot, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的清单文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的清单文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取沙盒内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public string GetSandboxPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
|
||||
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存沙盒内默认的包裹版本
|
||||
/// </summary>
|
||||
public void SaveSandboxPackageVersionFile(string version)
|
||||
{
|
||||
string filePath = GetSandboxPackageVersionFilePath();
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存沙盒内默认的包裹版本
|
||||
/// </summary>
|
||||
public void SaveSandboxPackageVersionFile(string version)
|
||||
{
|
||||
string filePath = GetSandboxPackageVersionFilePath();
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的清单文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的清单文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageManifestFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的哈希文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageHashFilePath(string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取APP内包裹的版本文件的路径
|
||||
/// </summary>
|
||||
public string GetBuildinPackageVersionFilePath()
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
|
||||
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,59 +2,59 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存文件验证元素
|
||||
/// </summary>
|
||||
internal class VerifyCacheFileElement
|
||||
{
|
||||
public string PackageName { private set; get; }
|
||||
public string CacheGUID { private set; get; }
|
||||
public string FileRootPath { private set; get; }
|
||||
public string DataFilePath { private set; get; }
|
||||
public string InfoFilePath { private set; get; }
|
||||
/// <summary>
|
||||
/// 缓存文件验证元素
|
||||
/// </summary>
|
||||
internal class VerifyCacheFileElement
|
||||
{
|
||||
public string PackageName { private set; get; }
|
||||
public string CacheGUID { private set; get; }
|
||||
public string FileRootPath { private set; get; }
|
||||
public string DataFilePath { private set; get; }
|
||||
public string InfoFilePath { private set; get; }
|
||||
|
||||
public EVerifyResult Result;
|
||||
public string DataFileCRC;
|
||||
public long DataFileSize;
|
||||
public EVerifyResult Result;
|
||||
public string DataFileCRC;
|
||||
public long DataFileSize;
|
||||
|
||||
public VerifyCacheFileElement(string packageName, string cacheGUID, string fileRootPath, string dataFilePath, string infoFilePath)
|
||||
{
|
||||
PackageName = packageName;
|
||||
CacheGUID = cacheGUID;
|
||||
FileRootPath = fileRootPath;
|
||||
DataFilePath = dataFilePath;
|
||||
InfoFilePath = infoFilePath;
|
||||
}
|
||||
public VerifyCacheFileElement(string packageName, string cacheGUID, string fileRootPath, string dataFilePath, string infoFilePath)
|
||||
{
|
||||
PackageName = packageName;
|
||||
CacheGUID = cacheGUID;
|
||||
FileRootPath = fileRootPath;
|
||||
DataFilePath = dataFilePath;
|
||||
InfoFilePath = infoFilePath;
|
||||
}
|
||||
|
||||
public void DeleteFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(FileRootPath, true);
|
||||
}
|
||||
catch(System.Exception e)
|
||||
{
|
||||
YooLogger.Warning($"Failed delete cache bundle folder : {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void DeleteFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(FileRootPath, true);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
YooLogger.Warning($"Failed delete cache bundle folder : {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件验证元素
|
||||
/// </summary>
|
||||
internal class VerifyTempFileElement
|
||||
{
|
||||
public string TempDataFilePath { private set; get; }
|
||||
public string FileCRC { private set; get; }
|
||||
public long FileSize { private set; get; }
|
||||
/// <summary>
|
||||
/// 下载文件验证元素
|
||||
/// </summary>
|
||||
internal class VerifyTempFileElement
|
||||
{
|
||||
public string TempDataFilePath { private set; get; }
|
||||
public string FileCRC { private set; get; }
|
||||
public long FileSize { private set; get; }
|
||||
|
||||
public int Result = 0; // 注意:原子操作对象
|
||||
public int Result = 0; // 注意:原子操作对象
|
||||
|
||||
public VerifyTempFileElement(string tempDataFilePath, string fileCRC, long fileSize)
|
||||
{
|
||||
TempDataFilePath = tempDataFilePath;
|
||||
FileCRC = fileCRC;
|
||||
FileSize = fileSize;
|
||||
}
|
||||
}
|
||||
public VerifyTempFileElement(string tempDataFilePath, string fileCRC, long fileSize)
|
||||
{
|
||||
TempDataFilePath = tempDataFilePath;
|
||||
FileCRC = fileCRC;
|
||||
FileSize = fileSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user