diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs b/Assets/YooAsset/Runtime/AssetsPackage.cs
index d8a0a82..90862ca 100644
--- a/Assets/YooAsset/Runtime/AssetsPackage.cs
+++ b/Assets/YooAsset/Runtime/AssetsPackage.cs
@@ -242,27 +242,26 @@ namespace YooAsset
}
///
- /// 弱联网情况下加载本地的补丁清单
- /// 注意:当清单里的内容验证失败后会返回失败。
+ /// 检查本地包裹内容的完整性
///
- 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
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs
new file mode 100644
index 0000000..7d5ddd5
--- /dev/null
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs
@@ -0,0 +1,134 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using UnityEngine;
+
+namespace YooAsset
+{
+ ///
+ /// 检查本地包裹内容的完整性
+ ///
+ 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 !";
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs.meta
new file mode 100644
index 0000000..b128bc4
--- /dev/null
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3d400b2548d79ca42bec7370f5d66b78
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs
index 9738523..4ffdb53 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs
@@ -10,6 +10,10 @@ namespace YooAsset
///
public abstract class InitializationOperation : AsyncOperationBase
{
+ ///
+ /// 初始化内部加载的包裹版本
+ ///
+ public string InitializedPackageVersion;
}
///
@@ -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;
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
index e23a43d..0f485fb 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
@@ -243,158 +243,4 @@ namespace YooAsset
return _impl.GetPatchDownloadMainURL(fileName);
}
}
-
- ///
- /// 联机模式的更新清单操作(弱联网)
- /// 注意:优先加载沙盒内的清单文件,如果不存在或加载失败,然后加载内置清单。
- ///
- 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 !";
- }
- }
- }
- }
- }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs
index 0d79803..f86fc6a 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs
@@ -5,7 +5,7 @@ using UnityEngine;
namespace YooAsset
{
///
- /// 更新静态版本操作
+ /// 获取包裹的最新版本
///
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
{
@@ -16,7 +16,7 @@ namespace YooAsset
}
///
- /// 编辑器下模拟运行的更新静态版本操作
+ /// 编辑器下模拟运行的获取包裹的最新版本操作
///
internal sealed class EditorPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
{
@@ -30,7 +30,7 @@ namespace YooAsset
}
///
- /// 离线模式的更新静态版本操作
+ /// 离线模式的获取包裹的最新版本操作
///
internal sealed class OfflinePlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
{
@@ -44,7 +44,7 @@ namespace YooAsset
}
///
- /// 联机模式的更新静态版本操作
+ /// 联机模式的获取包裹的最新版本操作
///
internal sealed class HostPlayModeUpdateStaticVersionOperation : UpdateStaticVersionOperation
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index 259be1e..79de18d 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -62,11 +62,11 @@ namespace YooAsset
}
///
- /// 异步更新补丁清单(弱联网)
+ /// 检查本地包裹内容的完整性
///
- 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;
}