Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

174 řádky
5.0 KiB

  1. using System;
  2. using System.Collections;
  3. using CIG.Translation;
  4. using Inno.DLC;
  5. using SUISS.Core;
  6. using SUISS.Scheduling;
  7. using SUISSEngine;
  8. using UnityEngine;
  9. public class DownloadProgressPopupState : PopupBaseState
  10. {
  11. public override void Leave(State newState)
  12. {
  13. base.Leave(newState);
  14. if (!this._showingConfirmPopup)
  15. {
  16. if (this._currentTaskRoutine != null)
  17. {
  18. UnityEngine.Debug.LogError("Leave: download task routine was still running");
  19. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._currentTaskRoutine);
  20. this._currentTaskRoutine = null;
  21. }
  22. if (this._downloadRoutine != null)
  23. {
  24. UnityEngine.Debug.LogError("Leave: download routine was still running");
  25. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._downloadRoutine);
  26. this._downloadRoutine = null;
  27. }
  28. }
  29. }
  30. private void OnDestroy()
  31. {
  32. if (SingletonMonobehaviour<Scheduler>.IsAvailable)
  33. {
  34. if (this._currentTaskRoutine != null)
  35. {
  36. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._currentTaskRoutine);
  37. this._currentTaskRoutine = null;
  38. }
  39. if (this._downloadRoutine != null)
  40. {
  41. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._downloadRoutine);
  42. this._downloadRoutine = null;
  43. }
  44. }
  45. }
  46. public void Setup(DLCGroup group)
  47. {
  48. this._group = group;
  49. this._totalSize = this._group.RemainingDownloadSize;
  50. this._downloadedSize = 0L;
  51. ((DownloadProgressPopupView)this.View).SetStart(this._totalSize);
  52. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._downloadRoutine = this.DownloadRoutine(), base.gameObject);
  53. }
  54. public void GreenButton()
  55. {
  56. if (this._downloadedSize < this._totalSize)
  57. {
  58. if (this._downloadRoutine == null)
  59. {
  60. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._downloadRoutine = this.DownloadRoutine(), base.gameObject);
  61. ((DownloadProgressPopupView)this.View).SetStart(this._totalSize);
  62. ((DownloadProgressPopupView)this.View).SetProgress((float)this._downloadedSize / (float)this._totalSize);
  63. }
  64. else
  65. {
  66. UnityEngine.Debug.LogError("Retry: download routine was still running");
  67. }
  68. }
  69. else
  70. {
  71. foreach (JPEGLoader jpegloader in UnityEngine.Object.FindObjectsOfType<JPEGLoader>())
  72. {
  73. foreach (DLCFile dlcfile in this._group.AllFiles)
  74. {
  75. jpegloader.DownloadCompleted(this._group.Identifier, dlcfile.Name);
  76. }
  77. }
  78. foreach (CityIsland cityIsland in UnityEngine.Object.FindObjectsOfType<CityIsland>())
  79. {
  80. foreach (DLCFile dlcfile2 in this._group.AllFiles)
  81. {
  82. cityIsland.DownloadCompleted(this._group.Identifier, dlcfile2.Name);
  83. }
  84. }
  85. base.ClosePopup();
  86. }
  87. }
  88. public void CancelRequested()
  89. {
  90. this._showingConfirmPopup = true;
  91. this._fsm.SwitchState<GenericPopupState>().UpdateInfo(null, Localization.Key("download_manager_download_hd_content"), Localization.Key("download_manager_confirm_cancel"), Localization.Key("transfer_accept_confirm_no"), Localization.Key("download_manager_confirm"), null, new Action(this.Cancel), null, true);
  92. this._showingConfirmPopup = false;
  93. }
  94. private void Cancel()
  95. {
  96. if (this._currentTaskRoutine != null)
  97. {
  98. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._currentTaskRoutine);
  99. this._currentTaskRoutine = null;
  100. }
  101. if (this._downloadRoutine != null)
  102. {
  103. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._downloadRoutine);
  104. this._downloadRoutine = null;
  105. }
  106. base.ClosePopup();
  107. }
  108. private IEnumerator TaskRoutine(DLCFile file, DLCDownloadTask task)
  109. {
  110. yield return Timing.time + 0.5;
  111. while (!task.WWWIsDone)
  112. {
  113. long x = this._downloadedSize + (long)((float)file.Bytes * task.WWWProgress);
  114. ((DownloadProgressPopupView)this.View).SetProgress((float)x / (float)this._totalSize);
  115. yield return Timing.time + 0.5;
  116. }
  117. yield return task.WaitAndStore();
  118. yield break;
  119. }
  120. private IEnumerator DownloadRoutine()
  121. {
  122. foreach (DLCFile file in this._group.AllFiles)
  123. {
  124. if (!file.Exists)
  125. {
  126. DLCDownloadTask task = file.Download();
  127. yield return this._currentTaskRoutine = this.TaskRoutine(file, task);
  128. this._currentTaskRoutine = null;
  129. if (!task.IsSuccess)
  130. {
  131. if (file.Exists && !file.Check())
  132. {
  133. file.Delete();
  134. }
  135. ((DownloadProgressPopupView)this.View).SetFailed();
  136. this._downloadRoutine = null;
  137. yield break;
  138. }
  139. this._downloadedSize += file.Bytes;
  140. ((DownloadProgressPopupView)this.View).SetProgress((float)this._downloadedSize / (float)this._totalSize);
  141. }
  142. }
  143. this._downloadRoutine = null;
  144. ((DownloadProgressPopupView)this.View).SetFinished();
  145. CIGDLCDownloader downloader = UnityEngine.Object.FindObjectOfType<CIGDLCDownloader>();
  146. downloader.Check();
  147. yield break;
  148. }
  149. protected override void OnUpdate()
  150. {
  151. }
  152. private DLCGroup _group;
  153. private long _totalSize;
  154. private long _downloadedSize;
  155. private IEnumerator _downloadRoutine;
  156. private IEnumerator _currentTaskRoutine;
  157. private bool _showingConfirmPopup;
  158. }