ApplicationFootPrint.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.IO;
  2. using UnityEngine;
  3. namespace YooAsset
  4. {
  5. /// <summary>
  6. /// 应用程序水印
  7. /// </summary>
  8. internal class ApplicationFootPrint
  9. {
  10. private readonly DefaultCacheFileSystem _fileSystem;
  11. private string _footPrint;
  12. public ApplicationFootPrint(DefaultCacheFileSystem fileSystem)
  13. {
  14. _fileSystem = fileSystem;
  15. }
  16. /// <summary>
  17. /// 读取应用程序水印
  18. /// </summary>
  19. public void Load(string packageName)
  20. {
  21. string footPrintFilePath = _fileSystem.GetSandboxAppFootPrintFilePath();
  22. if (File.Exists(footPrintFilePath))
  23. {
  24. _footPrint = FileUtility.ReadAllText(footPrintFilePath);
  25. }
  26. else
  27. {
  28. Coverage(packageName);
  29. }
  30. }
  31. /// <summary>
  32. /// 检测水印是否发生变化
  33. /// </summary>
  34. public bool IsDirty()
  35. {
  36. #if UNITY_EDITOR
  37. return _footPrint != Application.version;
  38. #else
  39. return _footPrint != Application.buildGUID;
  40. #endif
  41. }
  42. /// <summary>
  43. /// 覆盖掉水印
  44. /// </summary>
  45. public void Coverage(string packageName)
  46. {
  47. #if UNITY_EDITOR
  48. _footPrint = Application.version;
  49. #else
  50. _footPrint = Application.buildGUID;
  51. #endif
  52. string footPrintFilePath = _fileSystem.GetSandboxAppFootPrintFilePath();
  53. FileUtility.WriteAllText(footPrintFilePath, _footPrint);
  54. YooLogger.Log($"Save application foot print : {_footPrint}");
  55. }
  56. }
  57. }