update new cache system
重新设计了资源缓存系统
This commit is contained in:
@@ -1,150 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 检查包裹内容的完整性
|
||||
/// </summary>
|
||||
public abstract class CheckPackageContentsOperation : AsyncOperationBase
|
||||
{
|
||||
}
|
||||
|
||||
internal sealed class EditorSimulateModeCheckPackageContentsOperation : CheckPackageContentsOperation
|
||||
{
|
||||
internal EditorSimulateModeCheckPackageContentsOperation()
|
||||
{
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
internal sealed class OfflinePlayModeCheckPackageContentsOperation : CheckPackageContentsOperation
|
||||
{
|
||||
internal OfflinePlayModeCheckPackageContentsOperation()
|
||||
{
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
internal sealed class HostPlayModeCheckPackageContentsOperation : CheckPackageContentsOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckActiveManifest,
|
||||
LoadCacheManifest,
|
||||
VerifyPackage,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private VerifyPackageOperation _verifyOperation;
|
||||
private PatchManifest _verifyManifest;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal HostPlayModeCheckPackageContentsOperation(HostPlayModeImpl impl, string packageName, string packageVersion)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageName = packageName;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||
{
|
||||
_verifyManifest = _impl.ActiveManifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadCacheManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheManifest)
|
||||
{
|
||||
if (_loadCacheManifestOp == null)
|
||||
{
|
||||
_loadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
|
||||
OperationSystem.StartOperation(_loadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_loadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_verifyManifest = _loadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadCacheManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyPackage)
|
||||
{
|
||||
if (_verifyOperation == null)
|
||||
{
|
||||
_verifyOperation = VerifyPackageOperation.CreateOperation(_verifyManifest, _impl);
|
||||
OperationSystem.StartOperation(_verifyOperation);
|
||||
}
|
||||
|
||||
Progress = _verifyOperation.Progress;
|
||||
if (_verifyOperation.IsDone == false)
|
||||
return;
|
||||
|
||||
bool verifySucceed = true;
|
||||
foreach (var verifyInfo in _verifyOperation.VerifyFailList)
|
||||
{
|
||||
// 注意:跳过内置资源文件
|
||||
if (verifyInfo.IsBuildinFile)
|
||||
continue;
|
||||
|
||||
verifySucceed = false;
|
||||
YooLogger.Warning($"Failed verify file : {verifyInfo.VerifyFilePath}");
|
||||
}
|
||||
|
||||
if (verifySucceed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The package resource {_packageName} content has verify failed file !";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d400b2548d79ca42bec7370f5d66b78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,104 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理本地包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetUnusedCacheFiles,
|
||||
ClearUnusedCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AssetsPackage _package;
|
||||
private List<string> _unusedCacheFilePaths;
|
||||
private int _unusedFileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearUnusedCacheFilesOperation(AssetsPackage package)
|
||||
{
|
||||
_package = package;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.GetUnusedCacheFiles;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetUnusedCacheFiles)
|
||||
{
|
||||
_unusedCacheFilePaths = GetUnusedCacheFilePaths();
|
||||
_unusedFileTotalCount = _unusedCacheFilePaths.Count;
|
||||
YooLogger.Log($"Found unused cache file count : {_unusedFileTotalCount}");
|
||||
_steps = ESteps.ClearUnusedCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearUnusedCacheFiles)
|
||||
{
|
||||
for (int i = _unusedCacheFilePaths.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string filePath = _unusedCacheFilePaths[i];
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filePath);
|
||||
YooLogger.Log($"Delete unused cache file : {filePath}");
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
YooLogger.Warning($"Failed delete cache file : {filePath} ! {e.Message}");
|
||||
}
|
||||
}
|
||||
_unusedCacheFilePaths.RemoveAt(i);
|
||||
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_unusedFileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_unusedCacheFilePaths.Count / _unusedFileTotalCount);
|
||||
|
||||
if (_unusedCacheFilePaths.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取未被使用的缓存文件路径集合
|
||||
/// </summary>
|
||||
private List<string> GetUnusedCacheFilePaths()
|
||||
{
|
||||
string cacheFolderPath = PersistentHelper.GetCacheFolderPath(_package.PackageName);
|
||||
if (Directory.Exists(cacheFolderPath) == false)
|
||||
return new List<string>();
|
||||
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(cacheFolderPath);
|
||||
FileInfo[] fileInfos = directoryInfo.GetFiles();
|
||||
List<string> result = new List<string>(fileInfos.Length);
|
||||
foreach (FileInfo fileInfo in fileInfos)
|
||||
{
|
||||
if (_package.IsIncludeBundleFile(fileInfo.Name) == false)
|
||||
{
|
||||
result.Add(fileInfo.FullName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d188c50fd00bf941b2eeebb374dc0d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -79,7 +79,7 @@ namespace YooAsset
|
||||
None,
|
||||
QueryBuildinPackageVersion,
|
||||
LoadBuildinManifest,
|
||||
VerifyPackage,
|
||||
PackageCaching,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace YooAsset
|
||||
private readonly string _packageName;
|
||||
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
|
||||
private LoadBuildinManifestOperation _loadBuildinManifestOp;
|
||||
private VerifyPackageOperation _verifyOperation;
|
||||
private PackageCachingOperation _cachingOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, string packageName)
|
||||
@@ -143,7 +143,7 @@ namespace YooAsset
|
||||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -153,16 +153,16 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyPackage)
|
||||
if (_steps == ESteps.PackageCaching)
|
||||
{
|
||||
if (_verifyOperation == null)
|
||||
if (_cachingOperation == null)
|
||||
{
|
||||
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl);
|
||||
OperationSystem.StartOperation(_verifyOperation);
|
||||
_cachingOperation = new PackageCachingOperation(_packageName);
|
||||
OperationSystem.StartOperation(_cachingOperation);
|
||||
}
|
||||
|
||||
Progress = _verifyOperation.Progress;
|
||||
if (_verifyOperation.IsDone)
|
||||
Progress = _cachingOperation.Progress;
|
||||
if (_cachingOperation.IsDone)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
@@ -186,7 +186,7 @@ namespace YooAsset
|
||||
QueryBuildinPackageVersion,
|
||||
UnpackBuildinManifest,
|
||||
LoadBuildinManifest,
|
||||
VerifyPackage,
|
||||
PackageCaching,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace YooAsset
|
||||
private UnpackBuildinManifestOperation _unpackBuildinManifestOp;
|
||||
private LoadBuildinManifestOperation _loadBuildinManifestOp;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private VerifyPackageOperation _verifyOperation;
|
||||
private PackageCachingOperation _cachingOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, string packageName)
|
||||
@@ -265,7 +265,7 @@ namespace YooAsset
|
||||
{
|
||||
PackageVersion = _loadCacheManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -284,15 +284,14 @@ namespace YooAsset
|
||||
if (_queryBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
// 注意:为了兼容MOD模式,初始化动态新增的包裹的时候,如果内置清单不存在也不需要报错!
|
||||
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.UnpackBuildinManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
// 注意:为了兼容MOD模式,初始化动态新增的包裹的时候,如果内置清单不存在也不需要报错!
|
||||
_steps = ESteps.PackageCaching;
|
||||
string error = _queryBuildinPackageVersionOp.Error;
|
||||
YooLogger.Log($"Failed to load buildin package version file : {error}");
|
||||
}
|
||||
@@ -337,7 +336,7 @@ namespace YooAsset
|
||||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -347,16 +346,16 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyPackage)
|
||||
if (_steps == ESteps.PackageCaching)
|
||||
{
|
||||
if (_verifyOperation == null)
|
||||
if (_cachingOperation == null)
|
||||
{
|
||||
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl);
|
||||
OperationSystem.StartOperation(_verifyOperation);
|
||||
_cachingOperation = new PackageCachingOperation(_packageName);
|
||||
OperationSystem.StartOperation(_cachingOperation);
|
||||
}
|
||||
|
||||
Progress = _verifyOperation.Progress;
|
||||
if (_verifyOperation.IsDone)
|
||||
Progress = _cachingOperation.Progress;
|
||||
if (_cachingOperation.IsDone)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
@@ -1,294 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class VerifyPackageOperation : AsyncOperationBase
|
||||
{
|
||||
public List<VerifyInfo> VerifySuccessList { protected set; get; }
|
||||
public List<VerifyInfo> VerifyFailList { protected set; get; }
|
||||
|
||||
public static VerifyPackageOperation CreateOperation(PatchManifest manifest, IPlayModeServices playModeServices)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
VerifyPackageOperation operation = new VerifyPackageWithoutThreadOperation(manifest, playModeServices);
|
||||
#else
|
||||
VerifyPackageOperation operation = new VerifyPackageWithThreadOperation(manifest, playModeServices);
|
||||
#endif
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(线程版)
|
||||
/// </summary>
|
||||
internal class VerifyPackageWithThreadOperation : VerifyPackageOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitVerify,
|
||||
PrepareVerify,
|
||||
UpdateVerify,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PatchManifest _manifest;
|
||||
private readonly IPlayModeServices _playModeServices;
|
||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||
private List<VerifyInfo> _waitingList;
|
||||
private List<VerifyInfo> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyPackageWithThreadOperation(PatchManifest manifest, IPlayModeServices playModeServices)
|
||||
{
|
||||
_manifest = manifest;
|
||||
_playModeServices = playModeServices;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.InitVerify)
|
||||
{
|
||||
int bundleCount = _manifest.BundleList.Count;
|
||||
VerifySuccessList = new List<VerifyInfo>(bundleCount);
|
||||
VerifyFailList = new List<VerifyInfo>(bundleCount);
|
||||
|
||||
// 设置同时验证的最大数
|
||||
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
||||
_verifyTotalCount = bundleCount;
|
||||
if (_verifyMaxNum < 1)
|
||||
_verifyMaxNum = 1;
|
||||
|
||||
_waitingList = new List<VerifyInfo>(bundleCount);
|
||||
_verifyingList = new List<VerifyInfo>(_verifyMaxNum);
|
||||
_steps = ESteps.PrepareVerify;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.PrepareVerify)
|
||||
{
|
||||
foreach (var patchBundle in _manifest.BundleList)
|
||||
{
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
continue;
|
||||
|
||||
bool isBuildinFile = _playModeServices.IsBuildinPatchBundle(patchBundle);
|
||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
||||
_waitingList.Add(verifyInfo);
|
||||
}
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UpdateVerify)
|
||||
{
|
||||
_syncContext.Update();
|
||||
|
||||
Progress = GetVerifierProgress();
|
||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Verify elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
|
||||
if (_verifyingList.Count >= _verifyMaxNum)
|
||||
break;
|
||||
|
||||
var verifyIno = _waitingList[i];
|
||||
if (VerifyFileWithThread(verifyIno))
|
||||
{
|
||||
_waitingList.RemoveAt(i);
|
||||
_verifyingList.Add(verifyIno);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning("The thread pool is failed queued.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float GetVerifierProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
|
||||
}
|
||||
private bool VerifyFileWithThread(VerifyInfo verifyInfo)
|
||||
{
|
||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), verifyInfo);
|
||||
}
|
||||
private void VerifyInThread(object infoObj)
|
||||
{
|
||||
VerifyInfo verifyInfo = (VerifyInfo)infoObj;
|
||||
verifyInfo.Result = CacheSystem.VerifyBundle(verifyInfo.VerifyBundle, CacheSystem.InitVerifyLevel);
|
||||
_syncContext.Post(VerifyCallback, verifyInfo);
|
||||
}
|
||||
private void VerifyCallback(object obj)
|
||||
{
|
||||
VerifyInfo verifyIno = (VerifyInfo)obj;
|
||||
if (verifyIno.Result == EVerifyResult.Succeed)
|
||||
{
|
||||
VerifySuccessList.Add(verifyIno);
|
||||
CacheSystem.CacheBundle(verifyIno.VerifyBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyFailList.Add(verifyIno);
|
||||
|
||||
// 删除验证失败的缓存文件
|
||||
if (File.Exists(verifyIno.VerifyBundle.CachedFilePath))
|
||||
{
|
||||
YooLogger.Warning($"Delete verify failed bundle file : {verifyIno.VerifyBundle.CachedFilePath}");
|
||||
File.Delete(verifyIno.VerifyBundle.CachedFilePath);
|
||||
}
|
||||
}
|
||||
_verifyingList.Remove(verifyIno);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地缓存文件验证(非线程版)
|
||||
/// </summary>
|
||||
internal class VerifyPackageWithoutThreadOperation : VerifyPackageOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitVerify,
|
||||
PrepareVerify,
|
||||
UpdateVerify,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PatchManifest _manifest;
|
||||
private readonly IPlayModeServices _playModeServices;
|
||||
private List<VerifyInfo> _waitingList;
|
||||
private List<VerifyInfo> _verifyingList;
|
||||
private int _verifyMaxNum;
|
||||
private int _verifyTotalCount;
|
||||
private float _verifyStartTime;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VerifyPackageWithoutThreadOperation(PatchManifest manifest, IPlayModeServices playModeServices)
|
||||
{
|
||||
_manifest = manifest;
|
||||
_playModeServices = playModeServices;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.InitVerify;
|
||||
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.InitVerify)
|
||||
{
|
||||
int bundleCount = _manifest.BundleList.Count;
|
||||
VerifySuccessList = new List<VerifyInfo>(bundleCount);
|
||||
VerifyFailList = new List<VerifyInfo>(bundleCount);
|
||||
|
||||
// 设置同时验证的最大数
|
||||
_verifyMaxNum = bundleCount;
|
||||
_verifyTotalCount = bundleCount;
|
||||
|
||||
_waitingList = new List<VerifyInfo>(bundleCount);
|
||||
_verifyingList = new List<VerifyInfo>(_verifyMaxNum);
|
||||
_steps = ESteps.PrepareVerify;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.PrepareVerify)
|
||||
{
|
||||
foreach (var patchBundle in _manifest.BundleList)
|
||||
{
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
continue;
|
||||
|
||||
bool isBuildinFile = _playModeServices.IsBuildinPatchBundle(patchBundle);
|
||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
||||
_waitingList.Add(verifyInfo);
|
||||
}
|
||||
_steps = ESteps.UpdateVerify;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UpdateVerify)
|
||||
{
|
||||
Progress = GetVerifierProgress();
|
||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||
YooLogger.Log($"Verify elapsed time {costTime:f1} seconds");
|
||||
}
|
||||
|
||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
|
||||
if (_verifyingList.Count >= _verifyMaxNum)
|
||||
break;
|
||||
|
||||
var verifyIno = _waitingList[i];
|
||||
VerifyFileWithoutThread(verifyIno);
|
||||
_waitingList.RemoveAt(i);
|
||||
_verifyingList.Add(verifyIno);
|
||||
}
|
||||
|
||||
_verifyingList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private float GetVerifierProgress()
|
||||
{
|
||||
if (_verifyTotalCount == 0)
|
||||
return 1f;
|
||||
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
|
||||
}
|
||||
private void VerifyFileWithoutThread(VerifyInfo verifyIno)
|
||||
{
|
||||
var verifyResult = CacheSystem.VerifyAndCacheLocalBundleFile(verifyIno.VerifyBundle, CacheSystem.InitVerifyLevel);
|
||||
if (verifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
VerifySuccessList.Add(verifyIno);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyFailList.Add(verifyIno);
|
||||
|
||||
// 删除验证失败的缓存文件
|
||||
if (File.Exists(verifyIno.VerifyBundle.CachedFilePath))
|
||||
{
|
||||
YooLogger.Warning($"Delete verify failed bundle file : {verifyIno.VerifyBundle.CachedFilePath}");
|
||||
File.Delete(verifyIno.VerifyBundle.CachedFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 868188d19436b674b8c403d2d90afeaf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -47,7 +47,7 @@ namespace YooAsset
|
||||
|
||||
/// <summary>
|
||||
/// 联机模式的更新清单操作
|
||||
/// 注意:优先加载沙盒里缓存的清单文件,如果有变化就更新远端清单文件,并保存到本地。
|
||||
/// 注意:优先加载沙盒里缓存的清单文件,如果缓存没找到就下载远端清单文件,并保存到本地。
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||
{
|
||||
@@ -59,7 +59,6 @@ namespace YooAsset
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
CheckDeserializeManifest,
|
||||
VerifyPackage,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -70,7 +69,6 @@ namespace YooAsset
|
||||
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private DownloadManifestOperation _downloadManifestOp;
|
||||
private VerifyPackageOperation _verifyOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
@@ -118,7 +116,8 @@ namespace YooAsset
|
||||
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_impl.ActiveManifest = _tryLoadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -163,7 +162,8 @@ namespace YooAsset
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.VerifyPackage;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -172,22 +172,6 @@ namespace YooAsset
|
||||
Error = _loadCacheManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyPackage)
|
||||
{
|
||||
if (_verifyOperation == null)
|
||||
{
|
||||
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl);
|
||||
OperationSystem.StartOperation(_verifyOperation);
|
||||
}
|
||||
|
||||
Progress = _verifyOperation.Progress;
|
||||
if (_verifyOperation.IsDone)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,22 +45,63 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 所属的包裹名称
|
||||
/// </summary>
|
||||
private string _packageName;
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存文件路径
|
||||
/// 缓存GUID
|
||||
/// </summary>
|
||||
private string _cachedFilePath;
|
||||
public string CachedFilePath
|
||||
public string CacheGUID
|
||||
{
|
||||
get { return FileHash; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓存的数据文件路径
|
||||
/// </summary>
|
||||
private string _cachedDataFilePath;
|
||||
public string CachedDataFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_cachedFilePath) == false)
|
||||
return _cachedFilePath;
|
||||
if (string.IsNullOrEmpty(_cachedDataFilePath) == false)
|
||||
return _cachedDataFilePath;
|
||||
|
||||
string cacheRoot = PersistentHelper.GetCacheFolderPath(_packageName);
|
||||
_cachedFilePath = $"{cacheRoot}/{FileName}";
|
||||
return _cachedFilePath;
|
||||
string cacheRoot = PersistentHelper.GetCacheFolderPath(PackageName);
|
||||
_cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}";
|
||||
return _cachedDataFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓存的信息文件路径
|
||||
/// </summary>
|
||||
private string _cachedInfoFilePath;
|
||||
public string CachedInfoFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_cachedInfoFilePath) == false)
|
||||
return _cachedInfoFilePath;
|
||||
|
||||
string cacheRoot = PersistentHelper.GetCacheFolderPath(PackageName);
|
||||
_cachedInfoFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
|
||||
return _cachedInfoFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临时的数据文件路径
|
||||
/// </summary>
|
||||
private string _tempDataFilePath;
|
||||
public string TempDataFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_tempDataFilePath) == false)
|
||||
return _tempDataFilePath;
|
||||
|
||||
_tempDataFilePath = $"{CachedDataFilePath}.temp";
|
||||
return _tempDataFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +122,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称
|
||||
/// 文件名称(远端文件名和内置文件名)
|
||||
/// </summary>
|
||||
private string _fileName;
|
||||
public string FileName
|
||||
@@ -94,20 +135,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缓存查询Key
|
||||
/// </summary>
|
||||
private string _cacheKey;
|
||||
public string CacheKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_cacheKey))
|
||||
throw new Exception("Should never get here !");
|
||||
return _cacheKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PatchBundle()
|
||||
{
|
||||
@@ -118,8 +145,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void ParseBundle(string packageName, int nameStype)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_cacheKey = $"{packageName}-{FileHash}";
|
||||
PackageName = packageName;
|
||||
_fileName = PatchManifestTools.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -239,11 +239,11 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
/// </summary>
|
||||
public bool IsIncludeBundleFile(string fileName)
|
||||
public bool IsIncludeBundleFile(string cacheGUID)
|
||||
{
|
||||
foreach (var patchBundle in BundleList)
|
||||
{
|
||||
if (patchBundle.FileName == fileName)
|
||||
if (patchBundle.CacheGUID == cacheGUID)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -159,13 +159,13 @@ namespace YooAsset
|
||||
{
|
||||
if (nameStyle == 1) //HashName
|
||||
{
|
||||
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
|
||||
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawBundleFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
|
||||
return StringUtility.Format("{0}.{1}", fileHash, fileExtension);
|
||||
}
|
||||
else if (nameStyle == 4) //BundleName_HashName
|
||||
{
|
||||
string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
|
||||
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
|
||||
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawBundleFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
|
||||
return StringUtility.Format("{0}_{1}.{2}", fileName, fileHash, fileExtension);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -56,12 +56,6 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
|
||||
{
|
||||
var operation = new EditorSimulateModeCheckPackageContentsOperation();
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
|
||||
@@ -95,7 +95,11 @@ namespace YooAsset
|
||||
{
|
||||
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
|
||||
}
|
||||
|
||||
public bool IsCachedPatchBundle(PatchBundle patchBundle)
|
||||
{
|
||||
return CacheSystem.IsCached(patchBundle.PackageName, patchBundle.CacheGUID);
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout);
|
||||
@@ -114,12 +118,6 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
|
||||
{
|
||||
var operation = new HostPlayModeCheckPackageContentsOperation(this, _packageName, packageVersion);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
@@ -133,7 +131,7 @@ namespace YooAsset
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (IsCachedPatchBundle(patchBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
@@ -158,7 +156,7 @@ namespace YooAsset
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (IsCachedPatchBundle(patchBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
@@ -219,7 +217,7 @@ namespace YooAsset
|
||||
foreach (var patchBundle in checkList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (IsCachedPatchBundle(patchBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
@@ -244,7 +242,7 @@ namespace YooAsset
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (IsCachedPatchBundle(patchBundle))
|
||||
continue;
|
||||
|
||||
if (IsBuildinPatchBundle(patchBundle))
|
||||
@@ -268,7 +266,7 @@ namespace YooAsset
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (IsCachedPatchBundle(patchBundle))
|
||||
continue;
|
||||
|
||||
// 查询DLC资源
|
||||
@@ -292,7 +290,7 @@ namespace YooAsset
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 查询沙盒资源
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (IsCachedPatchBundle(patchBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
|
||||
return bundleInfo;
|
||||
|
||||
@@ -56,12 +56,6 @@ namespace YooAsset
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
|
||||
{
|
||||
var operation = new OfflinePlayModeCheckPackageContentsOperation();
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
@@ -93,7 +87,7 @@ namespace YooAsset
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 查询沙盒资源
|
||||
if (CacheSystem.IsCached(patchBundle))
|
||||
if (CacheSystem.IsCached(patchBundle.PackageName, patchBundle.CacheGUID))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
|
||||
return bundleInfo;
|
||||
|
||||
Reference in New Issue
Block a user