pull/229/head
hevinci 2023-11-01 16:30:58 +08:00
parent 81a98ded8a
commit 2626cb6750
5 changed files with 49 additions and 21 deletions

View File

@ -44,9 +44,9 @@ namespace YooAsset.Editor
{ {
bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context); bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context);
bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context); bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context);
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo.PackageSourceFilePath, buildParametersContext); bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, buildParametersContext);
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo.PackageSourceFilePath, buildParametersContext); bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext);
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo.PackageSourceFilePath, buildParametersContext); bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext);
} }
// 4.更新补丁包输出的文件路径 // 4.更新补丁包输出的文件路径
@ -62,9 +62,9 @@ namespace YooAsset.Editor
protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context); protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context); protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext); protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
protected abstract string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext); protected abstract string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
protected abstract long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext); protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
protected string GetFilePathTempHash(string filePath) protected string GetFilePathTempHash(string filePath)
{ {
@ -74,5 +74,23 @@ namespace YooAsset.Editor
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法 // 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}"; //return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
} }
protected long GetBundleTempSize(BuildBundleInfo bundleInfo)
{
long tempSize = 0;
var assetPaths = bundleInfo.GetAllMainAssetPaths();
foreach (var assetPath in assetPaths)
{
long size = FileUtility.GetFileSize(assetPath);
tempSize += size;
}
if (tempSize == 0)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleTempSizeIsZero, $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}");
throw new Exception(message);
}
return tempSize;
}
} }
} }

View File

@ -29,7 +29,7 @@ namespace YooAsset.Editor
if (hash.isValid) if (hash.isValid)
{ {
return hash.ToString(); return hash.ToString();
} }
else else
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}"); string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}");
@ -57,30 +57,33 @@ namespace YooAsset.Editor
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}"); string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}");
throw new Exception(message); throw new Exception(message);
} }
} }
} }
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return GetFilePathTempHash(filePath); return GetFilePathTempHash(filePath);
else else
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位 return "00000000"; //8位
else else
return HashUtility.FileCRC32(filePath); return HashUtility.FileCRC32(filePath);
} }
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return 0; return GetBundleTempSize(bundleInfo);
else else
return FileUtility.GetFileSize(filePath); return FileUtility.GetFileSize(filePath);
} }

View File

@ -32,27 +32,30 @@ namespace YooAsset.Editor
{ {
return 0; return 0;
} }
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return GetFilePathTempHash(filePath); return GetFilePathTempHash(filePath);
else else
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位 return "00000000"; //8位
else else
return HashUtility.FileCRC32(filePath); return HashUtility.FileCRC32(filePath);
} }
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return 0; return GetBundleTempSize(bundleInfo);
else else
return FileUtility.GetFileSize(filePath); return FileUtility.GetFileSize(filePath);
} }

View File

@ -60,27 +60,30 @@ namespace YooAsset.Editor
} }
} }
} }
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return GetFilePathTempHash(filePath); return GetFilePathTempHash(filePath);
else else
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位 return "00000000"; //8位
else else
return HashUtility.FileCRC32(filePath); return HashUtility.FileCRC32(filePath);
} }
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath;
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return 0; return GetBundleTempSize(bundleInfo);
else else
return FileUtility.GetFileSize(filePath); return FileUtility.GetFileSize(filePath);
} }

View File

@ -29,7 +29,8 @@ namespace YooAsset.Editor
CharactersOverTheLimit = 400, CharactersOverTheLimit = 400,
NotFoundUnityBundleHash = 401, NotFoundUnityBundleHash = 401,
NotFoundUnityBundleCRC = 402, NotFoundUnityBundleCRC = 402,
BundleTempSizeIsZero = 403,
// TaskVerifyBuildResult // TaskVerifyBuildResult
UnintendedBuildBundle = 500, UnintendedBuildBundle = 500,
UnintendedBuildResult = 501, UnintendedBuildResult = 501,