暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ObfuscationMigration.cs 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. namespace UnityEditor.Purchasing
  5. {
  6. internal class ObfuscationMigration
  7. {
  8. /// <summary>
  9. /// Since we are changing the obfuscation files' location, it may be necessary to migrate existing tangle files to the new location.
  10. /// Also in 2.0.0, a poor choice of new location was used and has been corrected. If that path exists, its contents are to be moved as well.
  11. /// </summary>
  12. [InitializeOnLoadMethod]
  13. internal static void MigrateObfuscations()
  14. {
  15. try
  16. {
  17. if (CheckPreviousObfuscationFilesExist())
  18. {
  19. MoveObfuscatorFiles(TangleFileConsts.k_PrevOutputPath);
  20. }
  21. else if (CheckBadObfuscationFilesExist())
  22. {
  23. MoveObfuscatorFiles(TangleFileConsts.k_BadOutputPath);
  24. }
  25. }
  26. catch (Exception ex)
  27. {
  28. Debug.LogException(ex);
  29. }
  30. }
  31. private static void MoveObfuscatorFiles(string oldPath)
  32. {
  33. Directory.CreateDirectory(TangleFileConsts.k_OutputPath);
  34. foreach (var prevFile in Directory.GetFiles(oldPath))
  35. {
  36. MoveObfuscatorFile(prevFile);
  37. }
  38. }
  39. static void MoveObfuscatorFile(string file)
  40. {
  41. var fileName = Path.GetFileName(file);
  42. if (fileName.EndsWith(TangleFileConsts.k_ObfuscationClassSuffix))
  43. {
  44. var newFile = $"{TangleFileConsts.k_OutputPath}/{fileName}";
  45. if (!File.Exists(newFile))
  46. {
  47. AssetDatabase.MoveAsset(file, newFile);
  48. }
  49. }
  50. }
  51. internal static bool CheckPreviousObfuscationFilesExist()
  52. {
  53. return Directory.Exists(TangleFileConsts.k_PrevOutputPath) && (Directory.GetFiles(TangleFileConsts.k_PrevOutputPath).Length > 0);
  54. }
  55. internal static bool CheckBadObfuscationFilesExist()
  56. {
  57. return Directory.Exists(TangleFileConsts.k_BadOutputPath) && (Directory.GetFiles(TangleFileConsts.k_BadOutputPath).Length > 0);
  58. }
  59. }
  60. }