Update AssetBundleBuilder

修复加密文件下载验证失败问题。
pull/40/head
hevinci 2022-09-13 11:48:57 +08:00
parent fb4910e265
commit 4975d3b1ba
4 changed files with 34 additions and 28 deletions

View File

@ -40,21 +40,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string ContentHash { set; get; } = "00000000000000000000000000000000"; //32位 public string ContentHash { set; get; } = "00000000000000000000000000000000"; //32位
/// <summary>
/// 文件哈希值
/// </summary>
public string FileHash { set; get; } = "00000000000000000000000000000000"; //32位
/// <summary>
/// 文件CRC32
/// </summary>
public string FileCRC { set; get; } = "00000000"; //8位
/// <summary>
/// 文件大小
/// </summary>
public long FileSize { set; get; } = 0;
public BuildBundleInfo(string bundleName) public BuildBundleInfo(string bundleName)
{ {

View File

@ -68,13 +68,10 @@ namespace YooAsset.Editor
{ {
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
bundleInfo.FileHash = HashUtility.FileMD5(filePath);
bundleInfo.FileCRC = HashUtility.FileCRC32(filePath);
bundleInfo.FileSize = FileUtility.GetFileSize(filePath);
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
bundleInfo.ContentHash = bundleInfo.FileHash; string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
bundleInfo.ContentHash = HashUtility.FileMD5(filePath);
} }
else else
{ {

View File

@ -79,13 +79,10 @@ namespace YooAsset.Editor
{ {
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
bundleInfo.FileHash = HashUtility.FileMD5(filePath);
bundleInfo.FileCRC = HashUtility.FileCRC32(filePath);
bundleInfo.FileSize = FileUtility.GetFileSize(filePath);
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
bundleInfo.ContentHash = bundleInfo.FileHash; string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
bundleInfo.ContentHash = HashUtility.FileMD5(filePath);
} }
else else
{ {

View File

@ -74,9 +74,9 @@ namespace YooAsset.Editor
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
var bundleName = bundleInfo.BundleName; var bundleName = bundleInfo.BundleName;
string fileHash = bundleInfo.FileHash; string fileHash = GetBundleFileHash(bundleInfo, buildParameters);
string fileCRC = bundleInfo.FileCRC; string fileCRC = GetBundleFileCRC(bundleInfo, buildParameters);
long fileSize = bundleInfo.FileSize; long fileSize = GetBundleFileSize(bundleInfo, buildParameters);
string[] tags = buildMapContext.GetBundleTags(bundleName); string[] tags = buildMapContext.GetBundleTags(bundleName);
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName); bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isBuildin = IsBuildinBundle(tags, buildinTags);
@ -102,6 +102,33 @@ namespace YooAsset.Editor
} }
return false; return false;
} }
private string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return "00000000000000000000000000000000"; //32位
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
return HashUtility.FileMD5(filePath);
}
private string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
return HashUtility.FileCRC32(filePath);
}
private long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return 0;
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
return FileUtility.GetFileSize(filePath);
}
/// <summary> /// <summary>
/// 获取资源列表 /// 获取资源列表