From 4e759134bd54463b82d35e00199a51be514345fe Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 20 Dec 2022 16:17:01 +0800 Subject: [PATCH] update runtime code --- Assets/YooAsset/Runtime/AssetsPackage.cs | 16 +- .../CheckContentsIntegrityOperation.cs | 123 +++++++++ ...> CheckContentsIntegrityOperation.cs.meta} | 0 .../CheckPackageContentsOperation.cs | 133 ---------- ...n.cs => ClearUnusedCacheFilesOperation.cs} | 6 +- ...=> ClearUnusedCacheFilesOperation.cs.meta} | 0 .../Operations/DownloaderOperation.cs | 2 +- .../Operations/InitializationOperation.cs | 53 ++-- .../PatchSystem/Operations/Internal.meta | 8 + .../CopyBuildinManifestOperation.cs} | 4 +- .../CopyBuildinManifestOperation.cs.meta} | 0 .../DeserializeManifestOperation.cs | 16 +- .../DeserializeManifestOperation.cs.meta | 0 .../LoadBuildinManifestOperation.cs} | 4 +- .../LoadBuildinManifestOperation.cs.meta} | 0 .../LoadCacheManifestOperation.cs} | 6 +- .../LoadCacheManifestOperation.cs.meta} | 0 .../QueryBuildinPackageVersionOperation.cs} | 4 +- ...eryBuildinPackageVersionOperation.cs.meta} | 0 .../VerifyCacheFilesOperation.cs} | 36 ++- .../VerifyCacheFilesOperation.cs.meta} | 0 .../UpdatePackageManifestOperation.cs | 237 +++++------------- .../UpdatePackageVersionOperation.cs | 16 +- .../PlayMode/EditorSimulateModeImpl.cs | 31 +-- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 38 +-- .../PlayMode/OfflinePlayModeImpl.cs | 31 +-- .../Runtime/Services/IPlayModeServices.cs | 11 +- .../YooAsset/Runtime/Utility/BufferReader.cs | 14 ++ 28 files changed, 302 insertions(+), 487 deletions(-) create mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/CheckContentsIntegrityOperation.cs rename Assets/YooAsset/Runtime/PatchSystem/Operations/{CheckPackageContentsOperation.cs.meta => CheckContentsIntegrityOperation.cs.meta} (100%) delete mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs rename Assets/YooAsset/Runtime/PatchSystem/Operations/{ClearPackageUnusedCacheFilesOperation.cs => ClearUnusedCacheFilesOperation.cs} (94%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{ClearPackageUnusedCacheFilesOperation.cs.meta => ClearUnusedCacheFilesOperation.cs.meta} (100%) create mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/Internal.meta rename Assets/YooAsset/Runtime/PatchSystem/Operations/{BuildinManifestCopyOperation.cs => Internal/CopyBuildinManifestOperation.cs} (92%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{BuildinManifestCopyOperation.cs.meta => Internal/CopyBuildinManifestOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{ => Internal}/DeserializeManifestOperation.cs (94%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{ => Internal}/DeserializeManifestOperation.cs.meta (100%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{BuildinManifestLoadOperation.cs => Internal/LoadBuildinManifestOperation.cs} (94%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{BuildinManifestLoadOperation.cs.meta => Internal/LoadBuildinManifestOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{CacheManifestLoadOperation.cs => Internal/LoadCacheManifestOperation.cs} (94%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{CacheManifestLoadOperation.cs.meta => Internal/LoadCacheManifestOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{BuildinPackageVersionQueryOperation.cs => Internal/QueryBuildinPackageVersionOperation.cs} (92%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{BuildinPackageVersionQueryOperation.cs.meta => Internal/QueryBuildinPackageVersionOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{CacheFilesVerifyOperation.cs => Internal/VerifyCacheFilesOperation.cs} (85%) rename Assets/YooAsset/Runtime/PatchSystem/Operations/{CacheFilesVerifyOperation.cs.meta => Internal/VerifyCacheFilesOperation.cs.meta} (100%) diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs b/Assets/YooAsset/Runtime/AssetsPackage.cs index 6e7fd18..36947fd 100644 --- a/Assets/YooAsset/Runtime/AssetsPackage.cs +++ b/Assets/YooAsset/Runtime/AssetsPackage.cs @@ -211,29 +211,29 @@ namespace YooAsset /// 更新的包裹版本 /// 自动激活清单 /// 超时时间(默认值:60秒) - public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifest = true, bool autoActiveManifest = true, int timeout = 60) + public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifestFile = true, int timeout = 60) { DebugCheckInitialize(); DebugCheckUpdateManifest(); - return _playModeServices.UpdatePackageManifestAsync(packageVersion, autoSaveManifest, autoActiveManifest, timeout); + return _playModeServices.UpdatePackageManifestAsync(packageVersion, autoSaveManifestFile, timeout); } /// - /// 检查本地包裹内容的完整性 + /// 检查包裹内容的完整性 /// - public CheckPackageContentsOperation CheckPackageContentsAsync() + public CheckContentsIntegrityOperation CheckContentsIntegrityAsync() { DebugCheckInitialize(); - return _playModeServices.CheckPackageContentsAsync(); + return _playModeServices.CheckContentsIntegrityAsync(); } /// - /// 清理本地包裹未使用的缓存文件 + /// 清理包裹未使用的缓存文件 /// - public ClearPackageUnusedCacheFilesOperation ClearPackageUnusedCacheFilesAsync() + public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync() { DebugCheckInitialize(); - var operation = new ClearPackageUnusedCacheFilesOperation(this); + var operation = new ClearUnusedCacheFilesOperation(this); OperationSystem.StartOperation(operation); return operation; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckContentsIntegrityOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckContentsIntegrityOperation.cs new file mode 100644 index 0000000..40e42d1 --- /dev/null +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckContentsIntegrityOperation.cs @@ -0,0 +1,123 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace YooAsset +{ + /// + /// 检查包裹内容的完整性 + /// + public abstract class CheckContentsIntegrityOperation : AsyncOperationBase + { + } + + internal sealed class EditorSimulateModeCheckContentsIntegrityOperation : CheckContentsIntegrityOperation + { + internal EditorSimulateModeCheckContentsIntegrityOperation() + { + } + internal override void Start() + { + Status = EOperationStatus.Succeed; + } + internal override void Update() + { + } + } + internal sealed class OfflinePlayModeCheckContentsIntegrityOperation : CheckContentsIntegrityOperation + { + internal OfflinePlayModeCheckContentsIntegrityOperation() + { + } + internal override void Start() + { + Status = EOperationStatus.Succeed; + } + internal override void Update() + { + } + } + internal sealed class HostPlayModeCheckContentsIntegrityOperation : CheckContentsIntegrityOperation + { + private enum ESteps + { + None, + CheckLoadedManifest, + StartVerifyOperation, + CheckVerifyOperation, + Done, + } + + private readonly HostPlayModeImpl _impl; + private readonly string _packageName; + private VerifyCacheFilesOperation _verifyOperation; + private ESteps _steps = ESteps.None; + + internal HostPlayModeCheckContentsIntegrityOperation(HostPlayModeImpl impl, string packageName) + { + _impl = impl; + _packageName = packageName; + } + 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.ActivePatchManifest == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Not found loaded package : {_packageName}"; + } + else + { + _steps = ESteps.StartVerifyOperation; + } + } + + if (_steps == ESteps.StartVerifyOperation) + { + _verifyOperation = VerifyCacheFilesOperation.CreateOperation(_impl.ActivePatchManifest, _impl); + OperationSystem.StartOperation(_verifyOperation); + _steps = ESteps.CheckVerifyOperation; + } + + if (_steps == ESteps.CheckVerifyOperation) + { + 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 !"; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckContentsIntegrityOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/CheckContentsIntegrityOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs deleted file mode 100644 index fd0c9cc..0000000 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/CheckPackageContentsOperation.cs +++ /dev/null @@ -1,133 +0,0 @@ -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, - StartVerifyOperation, - CheckVerifyOperation, - Done, - } - - private readonly HostPlayModeImpl _impl; - private readonly string _packageName; - private CacheFilesVerifyOperation _verifyOperation; - private ESteps _steps = ESteps.None; - private float _verifyTime; - - internal HostPlayModeCheckPackageContentsOperation(HostPlayModeImpl impl, string packageName) - { - _impl = impl; - _packageName = packageName; - } - 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.ActivePatchManifest == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = $"Not found loaded package : {_packageName}"; - } - else - { - _steps = ESteps.StartVerifyOperation; - } - } - - if (_steps == ESteps.StartVerifyOperation) - { -#if UNITY_WEBGL - _verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.ActivePatchManifest, _impl); -#else - _verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl); -#endif - - OperationSystem.StartOperation(_verifyOperation); - _verifyTime = UnityEngine.Time.realtimeSinceStartup; - _steps = ESteps.CheckVerifyOperation; - } - - if (_steps == ESteps.CheckVerifyOperation) - { - Progress = _verifyOperation.Progress; - if (_verifyOperation.IsDone) - { - float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime; - YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds"); - - 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 !"; - } - } - } - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearPackageUnusedCacheFilesOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/ClearPackageUnusedCacheFilesOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs index 0091afc..2255bdf 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearPackageUnusedCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs @@ -7,7 +7,7 @@ namespace YooAsset /// /// 清理本地包裹未使用的缓存文件 /// - public sealed class ClearPackageUnusedCacheFilesOperation : AsyncOperationBase + public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase { private enum ESteps { @@ -18,11 +18,11 @@ namespace YooAsset } private readonly AssetsPackage _package; - private ESteps _steps = ESteps.None; private List _unusedCacheFilePaths; private int _unusedFileTotalCount = 0; + private ESteps _steps = ESteps.None; - internal ClearPackageUnusedCacheFilesOperation(AssetsPackage package) + internal ClearUnusedCacheFilesOperation(AssetsPackage package) { _package = package; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearPackageUnusedCacheFilesOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/ClearPackageUnusedCacheFilesOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs index 100b4bd..b748549 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs @@ -29,10 +29,10 @@ namespace YooAsset private readonly List _failedList = new List(MAX_LOADER_COUNT); // 数据相关 - private ESteps _steps = ESteps.None; private bool _isPause = false; private long _lastDownloadBytes = 0; private int _lastDownloadCount = 0; + private ESteps _steps = ESteps.None; /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs index 53559fe..f7d19ea 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs @@ -101,17 +101,15 @@ namespace YooAsset private readonly OfflinePlayModeImpl _impl; private readonly string _packageName; - private BuildinPackageVersionQueryOperation _buildinPackageVersionQuery; - private BuildinManifestLoadOperation _buildinManifestLoad; - private CacheFilesVerifyOperation _verifyOperation; + private QueryBuildinPackageVersionOperation _buildinPackageVersionQuery; + private LoadBuildinManifestOperation _buildinManifestLoad; + private VerifyCacheFilesOperation _verifyOperation; private ESteps _steps = ESteps.None; - private float _verifyTime; - + internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, string packageName) { _impl = impl; _packageName = packageName; - } internal override void Start() { @@ -126,7 +124,7 @@ namespace YooAsset { if (_buildinPackageVersionQuery == null) { - _buildinPackageVersionQuery = new BuildinPackageVersionQueryOperation(_packageName); + _buildinPackageVersionQuery = new QueryBuildinPackageVersionOperation(_packageName); OperationSystem.StartOperation(_buildinPackageVersionQuery); } @@ -149,7 +147,7 @@ namespace YooAsset { if (_buildinManifestLoad == null) { - _buildinManifestLoad = new BuildinManifestLoadOperation(_packageName, _buildinPackageVersionQuery.Version); + _buildinManifestLoad = new LoadBuildinManifestOperation(_packageName, _buildinPackageVersionQuery.Version); OperationSystem.StartOperation(_buildinManifestLoad); } @@ -173,14 +171,8 @@ namespace YooAsset if (_steps == ESteps.StartVerifyOperation) { -#if UNITY_WEBGL - _verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.ActivePatchManifest, _impl); -#else - _verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl); -#endif - + _verifyOperation = VerifyCacheFilesOperation.CreateOperation(_impl.ActivePatchManifest, _impl); OperationSystem.StartOperation(_verifyOperation); - _verifyTime = UnityEngine.Time.realtimeSinceStartup; _steps = ESteps.CheckVerifyOperation; } @@ -191,8 +183,6 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Succeed; - float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime; - YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds"); } } } @@ -219,13 +209,12 @@ namespace YooAsset private readonly HostPlayModeImpl _impl; private readonly string _packageName; - private BuildinPackageVersionQueryOperation _buildinPackageVersionQuery; - private BuildinManifestCopyOperation _buildinManifestCopy; - private BuildinManifestLoadOperation _buildinManifestLoad; - private CacheManifestLoadOperation _cacheManifestLoad; - private CacheFilesVerifyOperation _verifyOperation; + private QueryBuildinPackageVersionOperation _buildinPackageVersionQuery; + private CopyBuildinManifestOperation _buildinManifestCopy; + private LoadBuildinManifestOperation _buildinManifestLoad; + private LoadCacheManifestOperation _cacheManifestLoad; + private VerifyCacheFilesOperation _verifyOperation; private ESteps _steps = ESteps.None; - private float _verifyTime; internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, string packageName) { @@ -260,7 +249,7 @@ namespace YooAsset { if (_cacheManifestLoad == null) { - _cacheManifestLoad = new CacheManifestLoadOperation(_packageName); + _cacheManifestLoad = new LoadCacheManifestOperation(_packageName); OperationSystem.StartOperation(_cacheManifestLoad); } @@ -283,7 +272,7 @@ namespace YooAsset { if (_buildinPackageVersionQuery == null) { - _buildinPackageVersionQuery = new BuildinPackageVersionQueryOperation(_packageName); + _buildinPackageVersionQuery = new QueryBuildinPackageVersionOperation(_packageName); OperationSystem.StartOperation(_buildinPackageVersionQuery); } @@ -308,7 +297,7 @@ namespace YooAsset { if (_buildinManifestCopy == null) { - _buildinManifestCopy = new BuildinManifestCopyOperation(_packageName, _buildinPackageVersionQuery.Version); + _buildinManifestCopy = new CopyBuildinManifestOperation(_packageName, _buildinPackageVersionQuery.Version); OperationSystem.StartOperation(_buildinManifestCopy); } @@ -332,7 +321,7 @@ namespace YooAsset { if (_buildinManifestLoad == null) { - _buildinManifestLoad = new BuildinManifestLoadOperation(_packageName, _buildinPackageVersionQuery.Version); + _buildinManifestLoad = new LoadBuildinManifestOperation(_packageName, _buildinPackageVersionQuery.Version); OperationSystem.StartOperation(_buildinManifestLoad); } @@ -356,14 +345,8 @@ namespace YooAsset if (_steps == ESteps.StartVerifyOperation) { -#if UNITY_WEBGL - _verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.ActivePatchManifest, _impl); -#else - _verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl); -#endif - + _verifyOperation = VerifyCacheFilesOperation.CreateOperation(_impl.ActivePatchManifest, _impl); OperationSystem.StartOperation(_verifyOperation); - _verifyTime = UnityEngine.Time.realtimeSinceStartup; _steps = ESteps.CheckVerifyOperation; } @@ -374,8 +357,6 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Succeed; - float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime; - YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds"); } } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal.meta new file mode 100644 index 0000000..7a107f4 --- /dev/null +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ba3f4fc8cf6941f4a96ab928cec547e3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestCopyOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/CopyBuildinManifestOperation.cs similarity index 92% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestCopyOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/CopyBuildinManifestOperation.cs index 90b810f..68fa3d0 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestCopyOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/CopyBuildinManifestOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 内置补丁清单复制器 /// - internal class BuildinManifestCopyOperation : AsyncOperationBase + internal class CopyBuildinManifestOperation : AsyncOperationBase { private enum ESteps { @@ -20,7 +20,7 @@ namespace YooAsset private ESteps _steps = ESteps.None; - public BuildinManifestCopyOperation(string buildinPackageName, string buildinPackageVersion) + public CopyBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion) { _buildinPackageName = buildinPackageName; _buildinPackageVersion = buildinPackageVersion; diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestCopyOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/CopyBuildinManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestCopyOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/CopyBuildinManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/DeserializeManifestOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs index dc27008..2f621dc 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DeserializeManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs @@ -19,15 +19,13 @@ namespace YooAsset public PatchManifest Manifest { private set; get; } private readonly BufferReader _buffer; - private ESteps _steps = ESteps.None; private int _patchAssetCount; private int _patchBundleCount; private int _progressTotalValue; - + private ESteps _steps = ESteps.None; public DeserializeManifestOperation(byte[] binaryData) { - // 创建缓存器 _buffer = new BufferReader(binaryData); } internal override void Start() @@ -43,13 +41,21 @@ namespace YooAsset { if (_steps == ESteps.DeserializeFileHeader) { + if (_buffer.IsValid == false) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "Buffer is invalid !"; + return; + } + // 读取文件标记 uint fileSign = _buffer.ReadUInt32(); if (fileSign != YooAssetSettings.PatchManifestFileSign) { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = "Invalid manifest file format !"; + Error = "The manifest file format is invalid !"; return; } @@ -151,7 +157,7 @@ namespace YooAsset } } } - catch(System.Exception e) + catch (System.Exception e) { Manifest = null; _steps = ESteps.Done; diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DeserializeManifestOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/DeserializeManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/DeserializeManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestLoadOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestLoadOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs index e1e4120..a878068 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestLoadOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 内置补丁清单加载器 /// - internal class BuildinManifestLoadOperation : AsyncOperationBase + internal class LoadBuildinManifestOperation : AsyncOperationBase { private enum ESteps { @@ -27,7 +27,7 @@ namespace YooAsset public PatchManifest Manifest { private set; get; } - public BuildinManifestLoadOperation(string buildinPackageName, string buildinPackageVersion) + public LoadBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion) { _buildinPackageName = buildinPackageName; _buildinPackageVersion = buildinPackageVersion; diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestLoadOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinManifestLoadOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadBuildinManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CacheManifestLoadOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs similarity index 94% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/CacheManifestLoadOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs index b2f9280..9120573 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/CacheManifestLoadOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs @@ -5,7 +5,7 @@ namespace YooAsset /// /// 沙盒补丁清单加载器 /// - internal class CacheManifestLoadOperation : AsyncOperationBase + internal class LoadCacheManifestOperation : AsyncOperationBase { private enum ESteps { @@ -17,8 +17,8 @@ namespace YooAsset private readonly string _packageName; private DeserializeManifestOperation _deserializer; - private ESteps _steps = ESteps.None; private string _manifestFilePath; + private ESteps _steps = ESteps.None; /// /// 加载结果 @@ -26,7 +26,7 @@ namespace YooAsset public PatchManifest Manifest { private set; get; } - public CacheManifestLoadOperation(string packageName) + public LoadCacheManifestOperation(string packageName) { _packageName = packageName; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CacheManifestLoadOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/CacheManifestLoadOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/LoadCacheManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinPackageVersionQueryOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs similarity index 92% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinPackageVersionQueryOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs index bc8c704..a8ac6dd 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinPackageVersionQueryOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs @@ -4,7 +4,7 @@ namespace YooAsset /// /// 内置补丁清单版本查询器 /// - internal class BuildinPackageVersionQueryOperation : AsyncOperationBase + internal class QueryBuildinPackageVersionOperation : AsyncOperationBase { private enum ESteps { @@ -24,7 +24,7 @@ namespace YooAsset public string Version { private set; get; } - public BuildinPackageVersionQueryOperation(string packageName) + public QueryBuildinPackageVersionOperation(string packageName) { _packageName = packageName; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinPackageVersionQueryOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/BuildinPackageVersionQueryOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/QueryBuildinPackageVersionOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CacheFilesVerifyOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/VerifyCacheFilesOperation.cs similarity index 85% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/CacheFilesVerifyOperation.cs rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/VerifyCacheFilesOperation.cs index 87a10c6..a3769a9 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/CacheFilesVerifyOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/VerifyCacheFilesOperation.cs @@ -9,16 +9,26 @@ namespace YooAsset /// /// 本地缓存文件验证 /// - internal abstract class CacheFilesVerifyOperation : AsyncOperationBase + internal abstract class VerifyCacheFilesOperation : AsyncOperationBase { public List VerifySuccessList { protected set; get; } public List VerifyFailList { protected set; get; } - } + public static VerifyCacheFilesOperation CreateOperation(PatchManifest patchManifest, IPlayModeServices playModeServices) + { +#if UNITY_WEBGL + VerifyCacheFilesOperation operation = new VerifyCacheFilesWithoutThreadOperation(patchManifest, playModeServices); +#else + VerifyCacheFilesOperation operation = new VerifyCacheFilesWithThreadOperation(patchManifest, playModeServices); +#endif + return operation; + } + } + /// /// 本地缓存文件验证(线程版) /// - internal class CacheFilesVerifyWithThreadOperation : CacheFilesVerifyOperation + internal class VerifyCacheFilesWithThreadOperation : VerifyCacheFilesOperation { private enum ESteps { @@ -31,15 +41,15 @@ namespace YooAsset private readonly PatchManifest _patchManifest; private readonly IPlayModeServices _playModeServices; - private ESteps _steps = ESteps.None; - private readonly ThreadSyncContext _syncContext = new ThreadSyncContext(); private List _waitingList; private List _verifyingList; private int _verifyMaxNum; private int _verifyTotalCount; + private float _verifyStartTime; + private ESteps _steps = ESteps.None; - public CacheFilesVerifyWithThreadOperation(PatchManifest patchManifest, IPlayModeServices playModeServices) + public VerifyCacheFilesWithThreadOperation(PatchManifest patchManifest, IPlayModeServices playModeServices) { _patchManifest = patchManifest; _playModeServices = playModeServices; @@ -47,6 +57,7 @@ namespace YooAsset internal override void Start() { _steps = ESteps.InitVerify; + _verifyStartTime = UnityEngine.Time.realtimeSinceStartup; } internal override void Update() { @@ -95,6 +106,8 @@ namespace YooAsset { _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--) @@ -162,7 +175,7 @@ namespace YooAsset /// /// 本地缓存文件验证(非线程版) /// - internal class CacheFilesVerifyWithoutThreadOperation : CacheFilesVerifyOperation + internal class VerifyCacheFilesWithoutThreadOperation : VerifyCacheFilesOperation { private enum ESteps { @@ -175,14 +188,14 @@ namespace YooAsset private readonly PatchManifest _patchManifest; private readonly IPlayModeServices _playModeServices; - private ESteps _steps = ESteps.None; - private List _waitingList; private List _verifyingList; private int _verifyMaxNum; private int _verifyTotalCount; + private float _verifyStartTime; + private ESteps _steps = ESteps.None; - public CacheFilesVerifyWithoutThreadOperation(PatchManifest patchManifest, IPlayModeServices playModeServices) + public VerifyCacheFilesWithoutThreadOperation(PatchManifest patchManifest, IPlayModeServices playModeServices) { _patchManifest = patchManifest; _playModeServices = playModeServices; @@ -190,6 +203,7 @@ namespace YooAsset internal override void Start() { _steps = ESteps.InitVerify; + _verifyStartTime = UnityEngine.Time.realtimeSinceStartup; } internal override void Update() { @@ -232,6 +246,8 @@ namespace YooAsset { _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--) diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/CacheFilesVerifyOperation.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/VerifyCacheFilesOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/PatchSystem/Operations/CacheFilesVerifyOperation.cs.meta rename to Assets/YooAsset/Runtime/PatchSystem/Operations/Internal/VerifyCacheFilesOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs index 3898513..94fb64f 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageManifestOperation.cs @@ -10,131 +10,20 @@ namespace YooAsset /// public abstract class UpdatePackageManifestOperation : AsyncOperationBase { - internal IPlayModeServices _playModeServices; - internal PatchManifest _patchManifest; - /// - /// 是否发现了新的补丁清单 + /// 发现了新的清单 /// public bool FoundNewManifest { protected set; get; } = false; - #region 资源下载 /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 手动保存清单文件 /// - /// 资源标签 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call downloader !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } - return _playModeServices.CreatePatchDownloaderByTags(_patchManifest, new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout); - } + public virtual void SaveManifestFile() { } /// - /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件 + /// 还原补丁清单 /// - /// 资源标签列表 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call downloader !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } - return _playModeServices.CreatePatchDownloaderByTags(_patchManifest, tags, downloadingMaxNumber, failedTryAgain, timeout); - } - - /// - /// 创建补丁下载器,用于下载更新当前资源版本所有的资源包文件 - /// - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call downloader !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } - return _playModeServices.CreatePatchDownloaderByAll(_patchManifest, downloadingMaxNumber, failedTryAgain, timeout); - } - - /// - /// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件 - /// - /// 资源信息列表 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call downloader !"); - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } - return _playModeServices.CreatePatchDownloaderByPaths(_patchManifest, assetInfos, downloadingMaxNumber, failedTryAgain, timeout); - } - #endregion - - #region 资源解压 - /// - /// 创建补丁解压器 - /// - /// 资源标签 - /// 同时解压的最大文件数 - /// 解压失败的重试次数 - public PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call unpacker !"); - return PatchUnpackerOperation.CreateEmptyUnpacker(unpackingMaxNumber, failedTryAgain, int.MaxValue); - } - return _playModeServices.CreatePatchUnpackerByTags(_patchManifest, new string[] { tag }, unpackingMaxNumber, failedTryAgain, int.MaxValue); - } - - /// - /// 创建补丁解压器 - /// - /// 资源标签列表 - /// 同时解压的最大文件数 - /// 解压失败的重试次数 - public PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call unpacker !"); - return PatchUnpackerOperation.CreateEmptyUnpacker(unpackingMaxNumber, failedTryAgain, int.MaxValue); - } - return _playModeServices.CreatePatchUnpackerByTags(_patchManifest, tags, unpackingMaxNumber, failedTryAgain, int.MaxValue); - } - - /// - /// 创建补丁解压器 - /// - /// 同时解压的最大文件数 - /// 解压失败的重试次数 - public PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Error($"Please check { nameof(UpdatePackageManifestOperation)} status before call unpacker !"); - return PatchUnpackerOperation.CreateEmptyUnpacker(unpackingMaxNumber, failedTryAgain, int.MaxValue); - } - return _playModeServices.CreatePatchUnpackerByAll(_patchManifest, unpackingMaxNumber, failedTryAgain, int.MaxValue); - } - #endregion + public virtual void RevertManifest() { } } /// @@ -142,9 +31,8 @@ namespace YooAsset /// internal sealed class EditorPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation { - public EditorPlayModeUpdatePackageManifestOperation(EditorSimulateModeImpl impl) + public EditorPlayModeUpdatePackageManifestOperation() { - _playModeServices = impl; } internal override void Start() { @@ -160,9 +48,8 @@ namespace YooAsset /// internal sealed class OfflinePlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation { - public OfflinePlayModeUpdatePackageManifestOperation(OfflinePlayModeImpl impl) + public OfflinePlayModeUpdatePackageManifestOperation() { - _playModeServices = impl; } internal override void Start() { @@ -197,27 +84,24 @@ namespace YooAsset private readonly HostPlayModeImpl _impl; private readonly string _packageName; private readonly string _packageVersion; - private bool _autoSaveManifest; - private bool _autoActiveManifest; + private readonly bool _autoSaveManifestFile; private readonly int _timeout; private UnityWebDataRequester _downloader1; private UnityWebDataRequester _downloader2; private DeserializeManifestOperation _deserializer; - private CacheFilesVerifyOperation _verifyOperation; + private VerifyCacheFilesOperation _verifyOperation; + internal PatchManifest _prePatchManifest; private string _cacheManifestHash; + private byte[] _fileBytesData = null; private ESteps _steps = ESteps.None; - private byte[] _fileBytes = null; - private float _verifyTime; - internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, bool autoSaveManifest, bool autoActiveManifest, int timeout) + internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, bool autoSaveManifestFile, int timeout) { - _playModeServices = impl; _impl = impl; _packageName = packageName; _packageVersion = packageVersion; - _autoSaveManifest = autoSaveManifest; - _autoActiveManifest = autoActiveManifest; + _autoSaveManifestFile = autoSaveManifestFile; _timeout = timeout; } internal override void Start() @@ -234,7 +118,7 @@ namespace YooAsset { string filePath = PersistentHelper.GetCacheManifestFilePath(_packageName); if (File.Exists(filePath)) - { + { _cacheManifestHash = HashUtility.FileMD5(filePath); _steps = ESteps.DownloadWebHash; } @@ -271,7 +155,6 @@ namespace YooAsset if (_cacheManifestHash == webManifestHash) { YooLogger.Log($"Not found new package : {_packageName}"); - _patchManifest = _impl.ActivePatchManifest; FoundNewManifest = false; _steps = ESteps.Done; Status = EOperationStatus.Succeed; @@ -310,16 +193,13 @@ namespace YooAsset else { byte[] bytesData = _downloader2.GetData(); - - // 保存文件到沙盒内 - if (_autoSaveManifest) + if (_autoSaveManifestFile) { - string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName); - FileUtility.CreateFile(savePath, bytesData); + SaveManifestFileInternal(bytesData); } else { - _fileBytes = bytesData; + _fileBytesData = bytesData; } // 解析二进制数据 @@ -334,37 +214,27 @@ namespace YooAsset if (_steps == ESteps.CheckDeserializeWebManifest) { Progress = _deserializer.Progress; - if (_deserializer.IsDone) - { - if (_deserializer.Status == EOperationStatus.Succeed) - { - if (_autoActiveManifest) - { - _impl.ActivePatchManifest = _deserializer.Manifest; - } + if (_deserializer.IsDone == false) + return; - _patchManifest = _deserializer.Manifest; - _steps = ESteps.StartVerifyOperation; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _deserializer.Error; - } + if (_deserializer.Status == EOperationStatus.Succeed) + { + _prePatchManifest = _impl.ActivePatchManifest; + _impl.ActivePatchManifest = _deserializer.Manifest; + _steps = ESteps.StartVerifyOperation; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _deserializer.Error; } } if (_steps == ESteps.StartVerifyOperation) { -#if UNITY_WEBGL - _verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_deserializer.Manifest, _impl); -#else - _verifyOperation = new CacheFilesVerifyWithThreadOperation(_deserializer.Manifest, _impl); -#endif - + _verifyOperation = VerifyCacheFilesOperation.CreateOperation(_deserializer.Manifest, _impl); OperationSystem.StartOperation(_verifyOperation); - _verifyTime = UnityEngine.Time.realtimeSinceStartup; _steps = ESteps.CheckVerifyOperation; } @@ -375,8 +245,6 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Succeed; - float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime; - YooLogger.Log($"Verify result : Success {_verifyOperation.VerifySuccessList.Count}, Fail {_verifyOperation.VerifyFailList.Count}, Elapsed time {costTime} seconds"); } } } @@ -384,37 +252,50 @@ namespace YooAsset /// /// 手动保存清单文件 /// - public void SaveManifest() + public override void SaveManifestFile() { - if (_autoSaveManifest == false) + if (IsDone == false) { - if (_fileBytes != null) + YooLogger.Warning($"{nameof(UpdatePackageManifestOperation)} is not done !"); + return; + } + + if (Status == EOperationStatus.Succeed) + { + if (_fileBytesData != null) { - _autoSaveManifest = true; - string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName); - FileUtility.CreateFile(savePath, _fileBytes); + SaveManifestFileInternal(_fileBytesData); + _fileBytesData = null; } } } /// - /// 手动激活清单文件 + /// 还原补丁清单 /// - public void ActiveManifest() + public override void RevertManifest() { - if (_autoActiveManifest == false) + if (IsDone == false) { - if (_deserializer.Status == EOperationStatus.Succeed) + YooLogger.Warning($"{nameof(UpdatePackageManifestOperation)} is not done !"); + return; + } + + if (Status == EOperationStatus.Succeed) + { + if (_prePatchManifest != null) { - _autoActiveManifest = true; - _impl.ActivePatchManifest = _deserializer.Manifest; + _impl.ActivePatchManifest = _prePatchManifest; + _prePatchManifest = null; } } } - /// - /// 获取补丁清单请求地址 - /// + private void SaveManifestFileInternal(byte[] bytesData) + { + string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName); + FileUtility.CreateFile(savePath, bytesData); + } private string GetPatchManifestRequestURL(string fileName) { // 轮流返回请求地址 diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageVersionOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageVersionOperation.cs index 959c792..9ca4cf7 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageVersionOperation.cs @@ -51,8 +51,8 @@ namespace YooAsset private enum ESteps { None, - LoadStaticVersion, - CheckStaticVersion, + LoadPackageVersion, + CheckLoadPackageVersion, Done, } @@ -74,24 +74,24 @@ namespace YooAsset internal override void Start() { RequestCount++; - _steps = ESteps.LoadStaticVersion; + _steps = ESteps.LoadPackageVersion; } internal override void Update() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.LoadStaticVersion) + if (_steps == ESteps.LoadPackageVersion) { string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(_packageName); - string webURL = GetStaticVersionRequestURL(fileName); + string webURL = GetPackageVersionRequestURL(fileName); YooLogger.Log($"Beginning to request package version : {webURL}"); _downloader = new UnityWebDataRequester(); _downloader.SendRequest(webURL, _timeout); - _steps = ESteps.CheckStaticVersion; + _steps = ESteps.CheckLoadPackageVersion; } - if (_steps == ESteps.CheckStaticVersion) + if (_steps == ESteps.CheckLoadPackageVersion) { Progress = _downloader.Progress(); if (_downloader.IsDone() == false) @@ -123,7 +123,7 @@ namespace YooAsset } } - private string GetStaticVersionRequestURL(string fileName) + private string GetPackageVersionRequestURL(string fileName) { string url; diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs index d19ae19..1332285 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs @@ -52,59 +52,36 @@ namespace YooAsset OperationSystem.StartOperation(operation); return operation; } - UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifest, bool autoActiveManifest, int timeout) + UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifestFile, int timeout) { - var operation = new EditorPlayModeUpdatePackageManifestOperation(this); + var operation = new EditorPlayModeUpdatePackageManifestOperation(); OperationSystem.StartOperation(operation); return operation; } - CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsAsync() + CheckContentsIntegrityOperation IPlayModeServices.CheckContentsIntegrityAsync() { - var operation = new EditorSimulateModeCheckPackageContentsOperation(); + var operation = new EditorSimulateModeCheckContentsIntegrityOperation(); OperationSystem.StartOperation(operation); return operation; } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(PatchManifest patchManifest, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(PatchManifest patchManifest, string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(PatchManifest patchManifest, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(PatchManifest patchManifest, int upackingMaxNumber, int failedTryAgain, int timeout) - { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); - } PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); } - - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(PatchManifest patchManifest, string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); - } PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 177cd90..3a229a9 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -109,25 +109,19 @@ namespace YooAsset OperationSystem.StartOperation(operation); return operation; } - UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifest, bool autoActiveManifest, int timeout) + UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifestFile, int timeout) { - var operation = new HostPlayModeUpdatePackageManifestOperation(this, _packageName, packageVersion, autoSaveManifest, autoActiveManifest, timeout); + var operation = new HostPlayModeUpdatePackageManifestOperation(this, _packageName, packageVersion, autoSaveManifestFile, timeout); OperationSystem.StartOperation(operation); return operation; } - CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsAsync() + CheckContentsIntegrityOperation IPlayModeServices.CheckContentsIntegrityAsync() { - var operation = new HostPlayModeCheckPackageContentsOperation(this, _packageName); + var operation = new HostPlayModeCheckContentsIntegrityOperation(this, _packageName); OperationSystem.StartOperation(operation); return operation; } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(PatchManifest patchManifest, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = GetDownloadListByAll(patchManifest); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByAll(_activePatchManifest); @@ -153,12 +147,6 @@ namespace YooAsset return ConvertToDownloadList(downloadList); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(PatchManifest patchManifest, string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = GetDownloadListByTags(patchManifest, tags); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByTags(_activePatchManifest, tags); @@ -196,12 +184,6 @@ namespace YooAsset return ConvertToDownloadList(downloadList); } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(PatchManifest patchManifest, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = GetDownloadListByPaths(patchManifest, assetInfos); - var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { List downloadList = GetDownloadListByPaths(_activePatchManifest, assetInfos); @@ -251,12 +233,6 @@ namespace YooAsset return ConvertToDownloadList(downloadList); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(PatchManifest patchManifest, int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = GetUnpackListByAll(patchManifest); - var operation = new PatchUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByAll(_activePatchManifest); @@ -281,12 +257,6 @@ namespace YooAsset return ConvertToUnpackList(downloadList); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(PatchManifest patchManifest, string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = GetUnpackListByTags(patchManifest, tags); - var operation = new PatchUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { List unpcakList = GetUnpackListByTags(_activePatchManifest, tags); diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index 7305629..e959477 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -52,59 +52,36 @@ namespace YooAsset OperationSystem.StartOperation(operation); return operation; } - UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifest, bool autoActiveManifest, int timeout) + UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifestFile, int timeout) { - var operation = new OfflinePlayModeUpdatePackageManifestOperation(this); + var operation = new OfflinePlayModeUpdatePackageManifestOperation(); OperationSystem.StartOperation(operation); return operation; } - CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsAsync() + CheckContentsIntegrityOperation IPlayModeServices.CheckContentsIntegrityAsync() { - var operation = new OfflinePlayModeCheckPackageContentsOperation(); + var operation = new OfflinePlayModeCheckContentsIntegrityOperation(); OperationSystem.StartOperation(operation); return operation; } - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(PatchManifest patchManifest, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(PatchManifest patchManifest, string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) { return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - - PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(PatchManifest patchManifest, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); - } PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout); } - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(PatchManifest patchManifest, int upackingMaxNumber, int failedTryAgain, int timeout) - { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); - } PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) { return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); } - - PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(PatchManifest patchManifest, string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); - } PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) { return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout); diff --git a/Assets/YooAsset/Runtime/Services/IPlayModeServices.cs b/Assets/YooAsset/Runtime/Services/IPlayModeServices.cs index 8c65125..4098c1d 100644 --- a/Assets/YooAsset/Runtime/Services/IPlayModeServices.cs +++ b/Assets/YooAsset/Runtime/Services/IPlayModeServices.cs @@ -26,25 +26,20 @@ namespace YooAsset /// /// 向网络端请求并更新补丁清单 /// - UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifest, bool autoActiveManifest, int timeout); + UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveManifestFile, int timeout); /// - /// 检查本地包裹内容的完整性 + /// 检查包裹内容的完整性 /// - CheckPackageContentsOperation CheckPackageContentsAsync(); + CheckContentsIntegrityOperation CheckContentsIntegrityAsync(); // 下载相关方法 - PatchDownloaderOperation CreatePatchDownloaderByAll(PatchManifest patchManifest, int downloadingMaxNumber, int failedTryAgain, int timeout); PatchDownloaderOperation CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout); - PatchDownloaderOperation CreatePatchDownloaderByTags(PatchManifest patchManifest, string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout); PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout); - PatchDownloaderOperation CreatePatchDownloaderByPaths(PatchManifest patchManifest, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout); PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout); // 解压相关方法 - PatchUnpackerOperation CreatePatchUnpackerByAll(PatchManifest patchManifest, int upackingMaxNumber, int failedTryAgain, int timeout); PatchUnpackerOperation CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout); - PatchUnpackerOperation CreatePatchUnpackerByTags(PatchManifest patchManifest, string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout); PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Utility/BufferReader.cs b/Assets/YooAsset/Runtime/Utility/BufferReader.cs index a628b46..bd37abb 100644 --- a/Assets/YooAsset/Runtime/Utility/BufferReader.cs +++ b/Assets/YooAsset/Runtime/Utility/BufferReader.cs @@ -16,6 +16,20 @@ namespace YooAsset _buffer = data; } + /// + /// 是否有效 + /// + public bool IsValid + { + get + { + if (_buffer == null || _buffer.Length == 0) + return false; + else + return true; + } + } + /// /// 缓冲区容量 ///