YooAsset/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskEncryption.cs

51 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
public class TaskEncryption
{
/// <summary>
/// 加密文件
/// </summary>
public void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{
var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
if (encryptionServices == null)
return;
if (encryptionServices.GetType() == typeof(EncryptionNone))
return;
int progressValue = 0;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.Collection)
{
EncryptFileInfo fileInfo = new EncryptFileInfo();
fileInfo.BundleName = bundleInfo.BundleName;
fileInfo.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
var encryptResult = encryptionServices.Encrypt(fileInfo);
if (encryptResult.Encrypted)
{
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData);
bundleInfo.EncryptedFilePath = filePath;
bundleInfo.Encrypted = true;
BuildLogger.Log($"Bundle文件加密完成{filePath}");
}
else
{
bundleInfo.Encrypted = false;
}
// 进度条
EditorTools.DisplayProgressBar("加密资源包", ++progressValue, buildMapContext.Collection.Count);
}
EditorTools.ClearProgressBar();
}
}
}