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) {