mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TEngine 6
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class FileVerifyHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件校验
|
||||
/// </summary>
|
||||
public static EFileVerifyResult FileVerify(string filePath, long fileSize, string fileCRC, EFileVerifyLevel verifyLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
return EFileVerifyResult.DataFileNotExisted;
|
||||
|
||||
// 先验证文件大小
|
||||
long size = FileUtility.GetFileSize(filePath);
|
||||
if (size < fileSize)
|
||||
return EFileVerifyResult.FileNotComplete;
|
||||
else if (size > fileSize)
|
||||
return EFileVerifyResult.FileOverflow;
|
||||
|
||||
// 再验证文件CRC
|
||||
if (verifyLevel == EFileVerifyLevel.High)
|
||||
{
|
||||
string crc = HashUtility.FileCRC32(filePath);
|
||||
if (crc == fileCRC)
|
||||
return EFileVerifyResult.Succeed;
|
||||
else
|
||||
return EFileVerifyResult.FileCrcError;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EFileVerifyResult.Succeed;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return EFileVerifyResult.Exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user