TaskEncryption.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. namespace YooAsset.Editor
  7. {
  8. public class TaskEncryption
  9. {
  10. /// <summary>
  11. /// 加密文件
  12. /// </summary>
  13. public void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
  14. {
  15. var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
  16. if (encryptionServices == null)
  17. return;
  18. if (encryptionServices.GetType() == typeof(EncryptionNone))
  19. return;
  20. int progressValue = 0;
  21. string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
  22. foreach (var bundleInfo in buildMapContext.Collection)
  23. {
  24. EncryptFileInfo fileInfo = new EncryptFileInfo();
  25. fileInfo.BundleName = bundleInfo.BundleName;
  26. fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
  27. var encryptResult = encryptionServices.Encrypt(fileInfo);
  28. if (encryptResult.Encrypted)
  29. {
  30. string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
  31. FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData);
  32. bundleInfo.EncryptedFilePath = filePath;
  33. bundleInfo.Encrypted = true;
  34. BuildLogger.Log($"Bundle file encryption complete: {filePath}");
  35. }
  36. else
  37. {
  38. bundleInfo.Encrypted = false;
  39. }
  40. // 进度条
  41. EditorTools.DisplayProgressBar("Encrypting bundle", ++progressValue, buildMapContext.Collection.Count);
  42. }
  43. EditorTools.ClearProgressBar();
  44. }
  45. }
  46. }