parent
7b9fda2298
commit
32b5240fcc
|
@ -1,181 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 本地缓存文件验证器
|
|
||||||
/// </summary>
|
|
||||||
internal abstract class CacheVerifier
|
|
||||||
{
|
|
||||||
public abstract void InitVerifier(List<VerifyInfo> verifyInfos);
|
|
||||||
public abstract bool UpdateVerifier();
|
|
||||||
public abstract float GetVerifierProgress();
|
|
||||||
|
|
||||||
public List<VerifyInfo> VerifySuccessList { protected set; get; }
|
|
||||||
public List<VerifyInfo> VerifyFailList { protected set; get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 本地缓存文件验证器(线程版)
|
|
||||||
/// </summary>
|
|
||||||
internal class CacheVerifierWithThread : CacheVerifier
|
|
||||||
{
|
|
||||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
|
||||||
private readonly List<VerifyInfo> _waitingList = new List<VerifyInfo>(1000);
|
|
||||||
private readonly List<VerifyInfo> _verifyingList = new List<VerifyInfo>(100);
|
|
||||||
private int _verifyMaxNum;
|
|
||||||
private int _verifyTotalCount;
|
|
||||||
|
|
||||||
public override void InitVerifier(List<VerifyInfo> verifyInfos)
|
|
||||||
{
|
|
||||||
_waitingList.AddRange(verifyInfos);
|
|
||||||
VerifySuccessList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
VerifyFailList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
|
|
||||||
// 设置同时验证的最大数
|
|
||||||
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
|
||||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
|
||||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
|
||||||
_verifyTotalCount = _waitingList.Count;
|
|
||||||
if (_verifyMaxNum < 1)
|
|
||||||
_verifyMaxNum = 1;
|
|
||||||
}
|
|
||||||
public override bool UpdateVerifier()
|
|
||||||
{
|
|
||||||
_syncContext.Update();
|
|
||||||
|
|
||||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (_verifyingList.Count >= _verifyMaxNum)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public override 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);
|
|
||||||
|
|
||||||
// NOTE:不期望删除断点续传的资源文件
|
|
||||||
/*
|
|
||||||
if (File.Exists(patchBundle.CachedBundleFilePath))
|
|
||||||
File.Delete(patchBundle.CachedBundleFilePath);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
_verifyingList.Remove(verifyIno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 本地缓存文件验证器(非线程版)
|
|
||||||
/// </summary>
|
|
||||||
internal class CacheVerifierWithoutThread : CacheVerifier
|
|
||||||
{
|
|
||||||
private readonly List<VerifyInfo> _waitingList = new List<VerifyInfo>(1000);
|
|
||||||
private readonly List<VerifyInfo> _verifyingList = new List<VerifyInfo>(100);
|
|
||||||
private int _verifyMaxNum;
|
|
||||||
private int _verifyTotalCount;
|
|
||||||
|
|
||||||
public override void InitVerifier(List<VerifyInfo> verifyInfos)
|
|
||||||
{
|
|
||||||
_waitingList.AddRange(verifyInfos);
|
|
||||||
VerifySuccessList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
VerifyFailList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
|
|
||||||
// 设置同时验证的最大数
|
|
||||||
_verifyMaxNum = 32;
|
|
||||||
_verifyTotalCount = _waitingList.Count;
|
|
||||||
}
|
|
||||||
public override bool UpdateVerifier()
|
|
||||||
{
|
|
||||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
if (_verifyingList.Count >= _verifyMaxNum)
|
|
||||||
break;
|
|
||||||
|
|
||||||
var verifyIno = _waitingList[i];
|
|
||||||
VerifyFileWithoutThread(verifyIno);
|
|
||||||
_waitingList.RemoveAt(i);
|
|
||||||
_verifyingList.Add(verifyIno);
|
|
||||||
}
|
|
||||||
|
|
||||||
_verifyingList.Clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public override 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);
|
|
||||||
|
|
||||||
// NOTE:不期望删除断点续传的资源文件
|
|
||||||
/*
|
|
||||||
if (File.Exists(patchBundle.CachedBundleFilePath))
|
|
||||||
File.Delete(patchBundle.CachedBundleFilePath);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,295 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 本地缓存文件验证
|
||||||
|
/// </summary>
|
||||||
|
internal abstract class CacheFilesVerifyOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
public List<VerifyInfo> VerifySuccessList { protected set; get; }
|
||||||
|
public List<VerifyInfo> VerifyFailList { protected set; get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本地缓存文件验证(线程版)
|
||||||
|
/// </summary>
|
||||||
|
internal class CacheFilesVerifyWithThreadOperation : CacheFilesVerifyOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
InitVerify,
|
||||||
|
PrepareVerify,
|
||||||
|
UpdateVerify,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PatchManifest _patchManifest;
|
||||||
|
private readonly IQueryServices _queryServices;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||||
|
private List<VerifyInfo> _waitingList;
|
||||||
|
private List<VerifyInfo> _verifyingList;
|
||||||
|
private int _verifyMaxNum;
|
||||||
|
private int _verifyTotalCount;
|
||||||
|
|
||||||
|
public CacheFilesVerifyWithThreadOperation(PatchManifest patchManifest, IQueryServices queryServices)
|
||||||
|
{
|
||||||
|
_patchManifest = patchManifest;
|
||||||
|
_queryServices = queryServices;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.InitVerify;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.InitVerify)
|
||||||
|
{
|
||||||
|
int bundleCount = _patchManifest.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 _patchManifest.BundleList)
|
||||||
|
{
|
||||||
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isBuildinFile = IsBuildinFile(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 IsBuildinFile(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
if (_queryServices == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
|
||||||
|
}
|
||||||
|
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 CacheFilesVerifyWithoutThreadOperation : CacheFilesVerifyOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
InitVerify,
|
||||||
|
PrepareVerify,
|
||||||
|
UpdateVerify,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PatchManifest _patchManifest;
|
||||||
|
private readonly IQueryServices _queryServices;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
private List<VerifyInfo> _waitingList;
|
||||||
|
private List<VerifyInfo> _verifyingList;
|
||||||
|
private int _verifyMaxNum;
|
||||||
|
private int _verifyTotalCount;
|
||||||
|
|
||||||
|
public CacheFilesVerifyWithoutThreadOperation(PatchManifest patchManifest, IQueryServices queryServices)
|
||||||
|
{
|
||||||
|
_patchManifest = patchManifest;
|
||||||
|
_queryServices = queryServices;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.InitVerify;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.InitVerify)
|
||||||
|
{
|
||||||
|
int bundleCount = _patchManifest.BundleList.Count;
|
||||||
|
VerifySuccessList = new List<VerifyInfo>(bundleCount);
|
||||||
|
VerifyFailList = new List<VerifyInfo>(bundleCount);
|
||||||
|
|
||||||
|
// 设置同时验证的最大数
|
||||||
|
_verifyMaxNum = bundleCount;
|
||||||
|
_verifyTotalCount = _waitingList.Count;
|
||||||
|
|
||||||
|
_waitingList = new List<VerifyInfo>(bundleCount);
|
||||||
|
_verifyingList = new List<VerifyInfo>(_verifyMaxNum);
|
||||||
|
_steps = ESteps.PrepareVerify;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.PrepareVerify)
|
||||||
|
{
|
||||||
|
foreach (var patchBundle in _patchManifest.BundleList)
|
||||||
|
{
|
||||||
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isBuildinFile = IsBuildinFile(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 bool IsBuildinFile(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
if (_queryServices == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 223f217ed81460541b5ea7eb7a7d82a4
|
guid: 868188d19436b674b8c403d2d90afeaf
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -44,14 +44,14 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
CheckLoadedManifest,
|
CheckLoadedManifest,
|
||||||
InitVerifyingCache,
|
StartVerifyOperation,
|
||||||
UpdateVerifyingCache,
|
CheckVerifyOperation,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
private CacheFilesVerifyOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
private float _verifyTime;
|
||||||
|
|
||||||
|
@ -59,12 +59,6 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
|
@ -85,28 +79,33 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.StartVerifyOperation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.StartVerifyOperation)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList(true);
|
#if UNITY_WEBGL
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
|
||||||
|
#else
|
||||||
|
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
_steps = ESteps.CheckVerifyOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
if (_steps == ESteps.CheckVerifyOperation)
|
||||||
{
|
{
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
Progress = _verifyOperation.Progress;
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
if (_verifyOperation.IsDone)
|
||||||
{
|
{
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
||||||
|
|
||||||
bool verifySucceed = true;
|
bool verifySucceed = true;
|
||||||
foreach (var verifyInfo in _cacheVerifier.VerifyFailList)
|
foreach (var verifyInfo in _verifyOperation.VerifyFailList)
|
||||||
{
|
{
|
||||||
// 注意:跳过内置资源文件
|
// 注意:跳过内置资源文件
|
||||||
if (verifyInfo.IsBuildinFile)
|
if (verifyInfo.IsBuildinFile)
|
||||||
|
|
|
@ -83,16 +83,16 @@ namespace YooAsset
|
||||||
None,
|
None,
|
||||||
QueryAppPackageVersion,
|
QueryAppPackageVersion,
|
||||||
LoadAppManifest,
|
LoadAppManifest,
|
||||||
InitVerifyingCache,
|
StartVerifyOperation,
|
||||||
UpdateVerifyingCache,
|
CheckVerifyOperation,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly OfflinePlayModeImpl _impl;
|
private readonly OfflinePlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
|
||||||
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
||||||
private AppManifestLoader _appManifestLoader;
|
private AppManifestLoader _appManifestLoader;
|
||||||
|
private CacheFilesVerifyOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
private float _verifyTime;
|
||||||
|
|
||||||
|
@ -101,12 +101,6 @@ namespace YooAsset
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
|
@ -155,27 +149,32 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
InitializedPackageVersion = manifest.PackageVersion;
|
||||||
_impl.SetAppPatchManifest(manifest);
|
_impl.SetAppPatchManifest(manifest);
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.StartVerifyOperation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.StartVerifyOperation)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList();
|
#if UNITY_WEBGL
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.AppPatchManifest, null);
|
||||||
|
#else
|
||||||
|
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.AppPatchManifest, null);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
_steps = ESteps.CheckVerifyOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
if (_steps == ESteps.CheckVerifyOperation)
|
||||||
{
|
{
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
Progress = _verifyOperation.Progress;
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
if (_verifyOperation.IsDone)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,17 +194,17 @@ namespace YooAsset
|
||||||
QueryAppPackageVersion,
|
QueryAppPackageVersion,
|
||||||
CopyAppManifest,
|
CopyAppManifest,
|
||||||
LoadAppManifest,
|
LoadAppManifest,
|
||||||
InitVerifyingCache,
|
StartVerifyOperation,
|
||||||
UpdateVerifyingCache,
|
CheckVerifyOperation,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
|
||||||
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
||||||
private AppManifestCopyer _appManifestCopyer;
|
private AppManifestCopyer _appManifestCopyer;
|
||||||
private AppManifestLoader _appManifestLoader;
|
private AppManifestLoader _appManifestLoader;
|
||||||
|
private CacheFilesVerifyOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
private float _verifyTime;
|
||||||
|
|
||||||
|
@ -214,12 +213,6 @@ namespace YooAsset
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
|
@ -254,7 +247,7 @@ namespace YooAsset
|
||||||
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
InitializedPackageVersion = manifest.PackageVersion;
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
_impl.SetLocalPatchManifest(manifest);
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.StartVerifyOperation;
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
|
@ -330,27 +323,32 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
InitializedPackageVersion = manifest.PackageVersion;
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
_impl.SetLocalPatchManifest(manifest);
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.StartVerifyOperation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.StartVerifyOperation)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList(false);
|
#if UNITY_WEBGL
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
|
||||||
|
#else
|
||||||
|
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
_steps = ESteps.CheckVerifyOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
if (_steps == ESteps.CheckVerifyOperation)
|
||||||
{
|
{
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
Progress = _verifyOperation.Progress;
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
if (_verifyOperation.IsDone)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,8 @@ namespace YooAsset
|
||||||
LoadCacheManifest,
|
LoadCacheManifest,
|
||||||
LoadWebManifest,
|
LoadWebManifest,
|
||||||
CheckWebManifest,
|
CheckWebManifest,
|
||||||
InitVerifyingCache,
|
StartVerifyOperation,
|
||||||
UpdateVerifyingCache,
|
CheckVerifyOperation,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,10 +68,10 @@ namespace YooAsset
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequester _downloader1;
|
private UnityWebDataRequester _downloader1;
|
||||||
private UnityWebDataRequester _downloader2;
|
private UnityWebDataRequester _downloader2;
|
||||||
|
private CacheFilesVerifyOperation _verifyOperation;
|
||||||
|
|
||||||
private string _cacheManifestHash;
|
private string _cacheManifestHash;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
@ -83,12 +83,6 @@ namespace YooAsset
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
|
@ -158,7 +152,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
_impl.SetLocalPatchManifest(manifest);
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.StartVerifyOperation;
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
|
@ -198,7 +192,7 @@ namespace YooAsset
|
||||||
var manifest = PersistentHelper.SaveCacheManifestFile(_packageName, bytesData);
|
var manifest = PersistentHelper.SaveCacheManifestFile(_packageName, bytesData);
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
_impl.SetLocalPatchManifest(manifest);
|
||||||
FoundNewManifest = true;
|
FoundNewManifest = true;
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.StartVerifyOperation;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -210,23 +204,28 @@ namespace YooAsset
|
||||||
_downloader2.Dispose();
|
_downloader2.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.StartVerifyOperation)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList(false);
|
#if UNITY_WEBGL
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
|
||||||
|
#else
|
||||||
|
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
_steps = ESteps.CheckVerifyOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
if (_steps == ESteps.CheckVerifyOperation)
|
||||||
{
|
{
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
Progress = _verifyOperation.Progress;
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
if (_verifyOperation.IsDone)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace YooAsset
|
||||||
private bool _locationToLower;
|
private bool _locationToLower;
|
||||||
private string _defaultHostServer;
|
private string _defaultHostServer;
|
||||||
private string _fallbackHostServer;
|
private string _fallbackHostServer;
|
||||||
private IQueryServices _queryServices;
|
public IQueryServices QueryServices { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
|
@ -24,7 +24,7 @@ namespace YooAsset
|
||||||
_locationToLower = locationToLower;
|
_locationToLower = locationToLower;
|
||||||
_defaultHostServer = defaultHostServer;
|
_defaultHostServer = defaultHostServer;
|
||||||
_fallbackHostServer = fallbackHostServer;
|
_fallbackHostServer = fallbackHostServer;
|
||||||
_queryServices = queryServices;
|
QueryServices = queryServices;
|
||||||
|
|
||||||
var operation = new HostPlayModeInitializationOperation(this, packageName);
|
var operation = new HostPlayModeInitializationOperation(this, packageName);
|
||||||
OperationSystem.StartOperation(operation);
|
OperationSystem.StartOperation(operation);
|
||||||
|
@ -312,38 +312,6 @@ namespace YooAsset
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<VerifyInfo> GetVerifyInfoList(bool weaklyUpdateMode)
|
|
||||||
{
|
|
||||||
List<VerifyInfo> result = new List<VerifyInfo>(LocalPatchManifest.BundleList.Count);
|
|
||||||
|
|
||||||
// 遍历所有文件然后验证并缓存合法文件
|
|
||||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 忽略缓存文件
|
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性
|
|
||||||
if (weaklyUpdateMode)
|
|
||||||
{
|
|
||||||
bool isBuildinFile = IsBuildinPatchBundle(patchBundle);
|
|
||||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
|
||||||
result.Add(verifyInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string filePath = patchBundle.CachedFilePath;
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
{
|
|
||||||
bool isBuildinFile = IsBuildinPatchBundle(patchBundle);
|
|
||||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
|
||||||
result.Add(verifyInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
internal void SetLocalPatchManifest(PatchManifest patchManifest)
|
internal void SetLocalPatchManifest(PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
LocalPatchManifest = patchManifest;
|
LocalPatchManifest = patchManifest;
|
||||||
|
@ -351,7 +319,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
internal bool IsBuildinPatchBundle(PatchBundle patchBundle)
|
internal bool IsBuildinPatchBundle(PatchBundle patchBundle)
|
||||||
{
|
{
|
||||||
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
|
return QueryServices.QueryStreamingAssets(patchBundle.FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class OfflinePlayModeImpl : IBundleServices
|
internal class OfflinePlayModeImpl : IBundleServices
|
||||||
{
|
{
|
||||||
private PatchManifest _appPatchManifest;
|
public PatchManifest AppPatchManifest { private set; get; }
|
||||||
private bool _locationToLower;
|
private bool _locationToLower;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -26,37 +26,15 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetPackageVersion()
|
public string GetPackageVersion()
|
||||||
{
|
{
|
||||||
if (_appPatchManifest == null)
|
if (AppPatchManifest == null)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
return _appPatchManifest.PackageVersion;
|
return AppPatchManifest.PackageVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<VerifyInfo> GetVerifyInfoList()
|
|
||||||
{
|
|
||||||
List<VerifyInfo> result = new List<VerifyInfo>(_appPatchManifest.BundleList.Count);
|
|
||||||
|
|
||||||
// 遍历所有文件然后验证并缓存合法文件
|
|
||||||
foreach (var patchBundle in _appPatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 忽略缓存文件
|
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string filePath = patchBundle.CachedFilePath;
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
{
|
|
||||||
bool isBuildinFile = true;
|
|
||||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
|
||||||
result.Add(verifyInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
_appPatchManifest = patchManifest;
|
AppPatchManifest = patchManifest;
|
||||||
_appPatchManifest.InitAssetPathMapping(_locationToLower);
|
AppPatchManifest.InitAssetPathMapping(_locationToLower);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
|
@ -84,7 +62,7 @@ namespace YooAsset
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var patchBundle = _appPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
var patchBundle = AppPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
return CreateBundleInfo(patchBundle);
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
|
@ -93,7 +71,7 @@ namespace YooAsset
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = AppPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var patchBundle in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
|
@ -104,34 +82,34 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
||||||
{
|
{
|
||||||
return _appPatchManifest.GetAssetsInfoByTags(tags);
|
return AppPatchManifest.GetAssetsInfoByTags(tags);
|
||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (_appPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
if (AppPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
string IBundleServices.MappingToAssetPath(string location)
|
string IBundleServices.MappingToAssetPath(string location)
|
||||||
{
|
{
|
||||||
return _appPatchManifest.MappingToAssetPath(location);
|
return AppPatchManifest.MappingToAssetPath(location);
|
||||||
}
|
}
|
||||||
string IBundleServices.TryMappingToAssetPath(string location)
|
string IBundleServices.TryMappingToAssetPath(string location)
|
||||||
{
|
{
|
||||||
return _appPatchManifest.TryMappingToAssetPath(location);
|
return AppPatchManifest.TryMappingToAssetPath(location);
|
||||||
}
|
}
|
||||||
string IBundleServices.GetPackageName()
|
string IBundleServices.GetPackageName()
|
||||||
{
|
{
|
||||||
return _appPatchManifest.PackageName;
|
return AppPatchManifest.PackageName;
|
||||||
}
|
}
|
||||||
bool IBundleServices.IsIncludeBundleFile(string fileName)
|
bool IBundleServices.IsIncludeBundleFile(string fileName)
|
||||||
{
|
{
|
||||||
return _appPatchManifest.IsIncludeBundleFile(fileName);
|
return AppPatchManifest.IsIncludeBundleFile(fileName);
|
||||||
}
|
}
|
||||||
bool IBundleServices.IsServicesValid()
|
bool IBundleServices.IsServicesValid()
|
||||||
{
|
{
|
||||||
return _appPatchManifest != null;
|
return AppPatchManifest != null;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue