Update PatchSystem
移除了WeaklyUpdatePatchManifestAsync()方法 新增了CheckPackageContentsAsync()方法pull/51/head
parent
44ec5b3de3
commit
72f0426531
|
@ -242,27 +242,26 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 弱联网情况下加载本地的补丁清单
|
||||
/// 注意:当清单里的内容验证失败后会返回失败。
|
||||
/// 检查本地包裹内容的完整性
|
||||
/// </summary>
|
||||
public UpdateManifestOperation WeaklyUpdateManifestAsync()
|
||||
public CheckPackageContentsOperation CheckPackageContentsAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var operation = new EditorPlayModeUpdateManifestOperation();
|
||||
var operation = new EditorSimulateModeCheckPackageContentsOperation();
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var operation = new OfflinePlayModeUpdateManifestOperation();
|
||||
var operation = new OfflinePlayModeCheckPackageContentsOperation();
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
return _hostPlayModeImpl.WeaklyUpdatePatchManifestAsync(PackageName);
|
||||
return _hostPlayModeImpl.CheckPackageContentsAsync(PackageName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
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,
|
||||
CheckLoadedManifest,
|
||||
InitVerifyingCache,
|
||||
UpdateVerifyingCache,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly string _packageName;
|
||||
private readonly CacheVerifier _cacheVerifier;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private float _verifyTime;
|
||||
|
||||
internal HostPlayModeCheckPackageContentsOperation(HostPlayModeImpl impl, string packageName)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageName = packageName;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
||||
#else
|
||||
_cacheVerifier = new CacheVerifierWithThread();
|
||||
#endif
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.CheckLoadedManifest;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckLoadedManifest)
|
||||
{
|
||||
if (_impl.LocalPatchManifest == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Not found loaded package : {_packageName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitVerifyingCache)
|
||||
{
|
||||
var verifyInfos = _impl.GetVerifyInfoList(true);
|
||||
_cacheVerifier.InitVerifier(verifyInfos);
|
||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
_steps = ESteps.UpdateVerifyingCache;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UpdateVerifyingCache)
|
||||
{
|
||||
Progress = _cacheVerifier.GetVerifierProgress();
|
||||
if (_cacheVerifier.UpdateVerifier())
|
||||
{
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
||||
|
||||
bool verifySucceed = true;
|
||||
foreach (var verifyInfo in _cacheVerifier.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 !";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d400b2548d79ca42bec7370f5d66b78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -10,6 +10,10 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public abstract class InitializationOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化内部加载的包裹版本
|
||||
/// </summary>
|
||||
public string InitializedPackageVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -54,6 +58,7 @@ namespace YooAsset
|
|||
YooLogger.Log($"Load simulation manifest file : {_simulatePatchManifestPath}");
|
||||
string jsonContent = FileUtility.ReadFile(_simulatePatchManifestPath);
|
||||
var manifest = PatchManifest.Deserialize(jsonContent);
|
||||
InitializedPackageVersion = manifest.PackageVersion;
|
||||
_impl.SetSimulatePatchManifest(manifest);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
@ -148,8 +153,9 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
InitializedPackageVersion = manifest.PackageVersion;
|
||||
_impl.SetAppPatchManifest(manifest);
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,6 +236,7 @@ namespace YooAsset
|
|||
try
|
||||
{
|
||||
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
||||
InitializedPackageVersion = manifest.PackageVersion;
|
||||
_impl.SetLocalPatchManifest(manifest);
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
|
@ -305,6 +312,7 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
InitializedPackageVersion = manifest.PackageVersion;
|
||||
_impl.SetLocalPatchManifest(manifest);
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
|
|
|
@ -243,158 +243,4 @@ namespace YooAsset
|
|||
return _impl.GetPatchDownloadMainURL(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 联机模式的更新清单操作(弱联网)
|
||||
/// 注意:优先加载沙盒内的清单文件,如果不存在或加载失败,然后加载内置清单。
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeWeaklyUpdateManifestOperation : UpdateManifestOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
TryLoadSandboxManifest,
|
||||
QueryAppPackageVersion,
|
||||
LoadAppManifest,
|
||||
InitVerifyingCache,
|
||||
UpdateVerifyingCache,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly string _packageName;
|
||||
private readonly CacheVerifier _cacheVerifier;
|
||||
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
||||
private AppManifestLoader _appManifestLoader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private float _verifyTime;
|
||||
|
||||
internal HostPlayModeWeaklyUpdateManifestOperation(HostPlayModeImpl impl, string packageName)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageName = packageName;
|
||||
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
||||
#else
|
||||
_cacheVerifier = new CacheVerifierWithThread();
|
||||
#endif
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.TryLoadSandboxManifest;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.TryLoadSandboxManifest)
|
||||
{
|
||||
if (PersistentHelper.CheckCacheManifestFileExists(_packageName) == false)
|
||||
{
|
||||
_steps = ESteps.QueryAppPackageVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
||||
_impl.SetLocalPatchManifest(manifest);
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
// 注意:如果加载沙盒内的清单报错,为了避免流程被卡住,我们主动把损坏的文件删除。
|
||||
YooLogger.Warning($"Failed to load cache manifest file : {e.Message}");
|
||||
PersistentHelper.DeleteCacheManifestFile(_packageName);
|
||||
_steps = ESteps.QueryAppPackageVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.QueryAppPackageVersion)
|
||||
{
|
||||
_appPackageVersionQuerier.Update();
|
||||
if (_appPackageVersionQuerier.IsDone == false)
|
||||
return;
|
||||
|
||||
string error = _appPackageVersionQuerier.Error;
|
||||
if (string.IsNullOrEmpty(error) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = error;
|
||||
}
|
||||
else
|
||||
{
|
||||
_appManifestLoader = new AppManifestLoader(_packageName, _appPackageVersionQuerier.Version);
|
||||
_steps = ESteps.LoadAppManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAppManifest)
|
||||
{
|
||||
_appManifestLoader.Update();
|
||||
Progress = _appManifestLoader.Progress;
|
||||
if (_appManifestLoader.IsDone == false)
|
||||
return;
|
||||
|
||||
var manifest = _appManifestLoader.Manifest;
|
||||
if (manifest == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _appManifestLoader.Error;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
_impl.SetLocalPatchManifest(manifest);
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitVerifyingCache)
|
||||
{
|
||||
var verifyInfos = _impl.GetVerifyInfoList(true);
|
||||
_cacheVerifier.InitVerifier(verifyInfos);
|
||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||
_steps = ESteps.UpdateVerifyingCache;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UpdateVerifyingCache)
|
||||
{
|
||||
Progress = _cacheVerifier.GetVerifierProgress();
|
||||
if (_cacheVerifier.UpdateVerifier())
|
||||
{
|
||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
||||
|
||||
bool verifySucceed = true;
|
||||
foreach (var verifyInfo in _cacheVerifier.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 !";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using UnityEngine;
|
|||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新静态版本操作
|
||||
/// 获取包裹的最新版本
|
||||
/// </summary>
|
||||
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟运行的更新静态版本操作
|
||||
/// 编辑器下模拟运行的获取包裹的最新版本操作
|
||||
/// </summary>
|
||||
internal sealed class EditorPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离线模式的更新静态版本操作
|
||||
/// 离线模式的获取包裹的最新版本操作
|
||||
/// </summary>
|
||||
internal sealed class OfflinePlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 联机模式的更新静态版本操作
|
||||
/// 联机模式的获取包裹的最新版本操作
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
|
||||
{
|
||||
|
|
|
@ -62,11 +62,11 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步更新补丁清单(弱联网)
|
||||
/// 检查本地包裹内容的完整性
|
||||
/// </summary>
|
||||
public UpdateManifestOperation WeaklyUpdatePatchManifestAsync(string packageName)
|
||||
public CheckPackageContentsOperation CheckPackageContentsAsync(string packageName)
|
||||
{
|
||||
var operation = new HostPlayModeWeaklyUpdateManifestOperation(this, packageName);
|
||||
var operation = new HostPlayModeCheckPackageContentsOperation(this, packageName);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue