From a1450ee78a9109c142cc80ec1e5d59af6e1ea595 Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 2 Apr 2024 13:04:11 +0800 Subject: [PATCH] refactor : build System Stability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 工具类新增了FileSHA1Safely,FileMD5Safely,FileCRC32Safely等方法。 --- .../Runtime/CacheSystem/CacheHelper.cs | 2 +- .../Internal/LoadCacheManifestOperation.cs | 2 +- Assets/YooAsset/Runtime/Utility/YooUtility.cs | 48 ++++++++++++++----- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs b/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs index 7bed804..f99cb6e 100644 --- a/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs +++ b/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs @@ -111,7 +111,7 @@ namespace YooAsset // 再验证文件CRC if (verifyLevel == EVerifyLevel.High) { - string crc = HashUtility.FileCRC32(filePath); + string crc = HashUtility.FileCRC32Safely(filePath); if (crc == fileCRC) return EVerifyResult.Succeed; else diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs index 57baf65..9ff63e1 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/LoadCacheManifestOperation.cs @@ -77,7 +77,7 @@ namespace YooAsset return; } - string fileHash = HashUtility.FileMD5(_manifestFilePath); + string fileHash = HashUtility.FileMD5Safely(_manifestFilePath); if (fileHash != _queryCachePackageHashOp.PackageHash) { _steps = ESteps.Done; diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index 550a682..8069b23 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -214,13 +214,21 @@ namespace YooAsset /// 获取文件的Hash值 /// public static string FileSHA1(string filePath) + { + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return StreamSHA1(fs); + } + } + + /// + /// 获取文件的Hash值 + /// + public static string FileSHA1Safely(string filePath) { try { - using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return StreamSHA1(fs); - } + return FileSHA1(filePath); } catch (Exception e) { @@ -266,13 +274,21 @@ namespace YooAsset /// 获取文件的MD5 /// public static string FileMD5(string filePath) + { + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return StreamMD5(fs); + } + } + + /// + /// 获取文件的MD5 + /// + public static string FileMD5Safely(string filePath) { try { - using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return StreamMD5(fs); - } + return FileMD5(filePath); } catch (Exception e) { @@ -316,13 +332,21 @@ namespace YooAsset /// 获取文件的CRC32 /// public static string FileCRC32(string filePath) + { + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + return StreamCRC32(fs); + } + } + + /// + /// 获取文件的CRC32 + /// + public static string FileCRC32Safely(string filePath) { try { - using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - return StreamCRC32(fs); - } + return FileCRC32(filePath); } catch (Exception e) {