From d67fc31c2634a3bbd689a9b78d4eb193d595c818 Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 13 Dec 2022 11:29:22 +0800 Subject: [PATCH] update patch system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 初始化的时候检测覆盖安装 --- .../Operations/InitializationOperation.cs | 69 ++++++++++++++++++- Assets/YooAsset/Runtime/Utility/YooHelper.cs | 22 +++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs index 58e4126..a26e0a3 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs @@ -190,6 +190,7 @@ namespace YooAsset private enum ESteps { None, + CheckAppFootPrint, TryLoadCacheManifest, QueryAppPackageVersion, CopyAppManifest, @@ -222,13 +223,28 @@ namespace YooAsset } internal override void Start() { - _steps = ESteps.TryLoadCacheManifest; + _steps = ESteps.CheckAppFootPrint; } internal override void Update() { if (_steps == ESteps.None || _steps == ESteps.Done) return; + if (_steps == ESteps.CheckAppFootPrint) + { + var appFootPrint = new AppFootPrint(); + appFootPrint.Load(); + + // 如果水印发生变化,则说明覆盖安装后首次打开游戏 + if (appFootPrint.IsDirty()) + { + PersistentHelper.DeleteManifestFolder(); + appFootPrint.Coverage(); + YooLogger.Log("Delete manifest files when application foot print dirty !"); + } + _steps = ESteps.TryLoadCacheManifest; + } + if (_steps == ESteps.TryLoadCacheManifest) { if (PersistentHelper.CheckCacheManifestFileExists(_packageName)) @@ -341,6 +357,57 @@ namespace YooAsset } + /// + /// 应用程序水印 + /// + internal class AppFootPrint + { + private string _footPrint; + + /// + /// 读取应用程序水印 + /// + public void Load() + { + string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath(); + if (File.Exists(footPrintFilePath)) + { + _footPrint = FileUtility.ReadAllText(footPrintFilePath); + } + else + { + Coverage(); + } + } + + /// + /// 检测水印是否发生变化 + /// + public bool IsDirty() + { +#if UNITY_EDITOR + return _footPrint != Application.version; +#else + return _footPrint != Application.buildGUID; +#endif + } + + /// + /// 覆盖掉水印 + /// + public void Coverage() + { +#if UNITY_EDITOR + _footPrint = Application.version; +#else + _footPrint = Application.buildGUID; +#endif + string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath(); + FileUtility.CreateFile(footPrintFilePath, _footPrint); + YooLogger.Log($"Save application foot print : {_footPrint}"); + } + } + /// /// 内置补丁清单版本查询器 /// diff --git a/Assets/YooAsset/Runtime/Utility/YooHelper.cs b/Assets/YooAsset/Runtime/Utility/YooHelper.cs index f7d7027..030f037 100644 --- a/Assets/YooAsset/Runtime/Utility/YooHelper.cs +++ b/Assets/YooAsset/Runtime/Utility/YooHelper.cs @@ -84,6 +84,8 @@ namespace YooAsset internal static class PersistentHelper { private const string CacheFolderName = "CacheFiles"; + private const string ManifestFolderName = "ManifestFiles"; + private const string AppFootPrintFileName = "ApplicationFootPrint.bytes"; /// /// 删除沙盒总目录 @@ -105,6 +107,16 @@ namespace YooAsset Directory.Delete(root, true); } + /// + /// 删除沙盒内的清单文件夹 + /// + public static void DeleteManifestFolder() + { + string root = PathHelper.MakePersistentLoadPath(ManifestFolderName); + if (Directory.Exists(root)) + Directory.Delete(root, true); + } + /// /// 获取缓存文件夹路径 /// @@ -114,6 +126,14 @@ namespace YooAsset return $"{root}/{packageName}"; } + /// + /// 获取应用程序的水印文件路径 + /// + public static string GetAppFootPrintFilePath() + { + return PathHelper.MakePersistentLoadPath(AppFootPrintFileName); + } + #region 沙盒内清单相关 /// /// 获取沙盒内清单文件的路径 @@ -121,7 +141,7 @@ namespace YooAsset public static string GetCacheManifestFilePath(string packageName) { string fileName = YooAssetSettingsData.GetPatchManifestFileNameWithoutVersion(packageName); - return PathHelper.MakePersistentLoadPath(fileName); + return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}"); } ///