DCFSInitializeOperation.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 
  2. namespace YooAsset
  3. {
  4. internal class DCFSInitializeOperation : FSInitializeFileSystemOperation
  5. {
  6. private enum ESteps
  7. {
  8. None,
  9. CheckAppFootPrint,
  10. SearchCacheFiles,
  11. VerifyCacheFiles,
  12. CreateDownloadCenter,
  13. Done,
  14. }
  15. private readonly DefaultCacheFileSystem _fileSystem;
  16. private SearchCacheFilesOperation _searchCacheFilesOp;
  17. private VerifyCacheFilesOperation _verifyCacheFilesOp;
  18. private ESteps _steps = ESteps.None;
  19. internal DCFSInitializeOperation(DefaultCacheFileSystem fileSystem)
  20. {
  21. _fileSystem = fileSystem;
  22. }
  23. internal override void InternalStart()
  24. {
  25. #if UNITY_WEBGL
  26. _steps = ESteps.Done;
  27. Status = EOperationStatus.Failed;
  28. Error = $"{nameof(DefaultCacheFileSystem)} is not support WEBGL platform !";
  29. #else
  30. _steps = ESteps.CheckAppFootPrint;
  31. #endif
  32. }
  33. internal override void InternalUpdate()
  34. {
  35. if (_steps == ESteps.None || _steps == ESteps.Done)
  36. return;
  37. if (_steps == ESteps.CheckAppFootPrint)
  38. {
  39. var appFootPrint = new ApplicationFootPrint(_fileSystem);
  40. appFootPrint.Load(_fileSystem.PackageName);
  41. // 如果水印发生变化,则说明覆盖安装后首次打开游戏
  42. if (appFootPrint.IsDirty())
  43. {
  44. _fileSystem.DeleteAllManifestFiles();
  45. appFootPrint.Coverage(_fileSystem.PackageName);
  46. YooLogger.Warning("Delete manifest files when application foot print dirty !");
  47. }
  48. _steps = ESteps.SearchCacheFiles;
  49. }
  50. if (_steps == ESteps.SearchCacheFiles)
  51. {
  52. if (_searchCacheFilesOp == null)
  53. {
  54. _searchCacheFilesOp = new SearchCacheFilesOperation(_fileSystem);
  55. _searchCacheFilesOp.StartOperation();
  56. AddChildOperation(_searchCacheFilesOp);
  57. }
  58. _searchCacheFilesOp.UpdateOperation();
  59. Progress = _searchCacheFilesOp.Progress;
  60. if (_searchCacheFilesOp.IsDone == false)
  61. return;
  62. _steps = ESteps.VerifyCacheFiles;
  63. }
  64. if (_steps == ESteps.VerifyCacheFiles)
  65. {
  66. if (_verifyCacheFilesOp == null)
  67. {
  68. _verifyCacheFilesOp = new VerifyCacheFilesOperation(_fileSystem, _searchCacheFilesOp.Result);
  69. _verifyCacheFilesOp.StartOperation();
  70. AddChildOperation(_verifyCacheFilesOp);
  71. }
  72. _verifyCacheFilesOp.UpdateOperation();
  73. Progress = _verifyCacheFilesOp.Progress;
  74. if (_verifyCacheFilesOp.IsDone == false)
  75. return;
  76. if (_verifyCacheFilesOp.Status == EOperationStatus.Succeed)
  77. {
  78. _steps = ESteps.CreateDownloadCenter;
  79. YooLogger.Log($"Package '{_fileSystem.PackageName}' cached files count : {_fileSystem.FileCount}");
  80. }
  81. else
  82. {
  83. _steps = ESteps.Done;
  84. Status = EOperationStatus.Failed;
  85. Error = _verifyCacheFilesOp.Error;
  86. }
  87. }
  88. if (_steps == ESteps.CreateDownloadCenter)
  89. {
  90. // 注意:下载中心作为独立任务运行!
  91. if (_fileSystem.DownloadCenter == null)
  92. {
  93. _fileSystem.DownloadCenter = new DownloadCenterOperation(_fileSystem);
  94. OperationSystem.StartOperation(_fileSystem.PackageName, _fileSystem.DownloadCenter);
  95. }
  96. _steps = ESteps.Done;
  97. Status = EOperationStatus.Succeed;
  98. }
  99. }
  100. }
  101. }