|
- using System;
- using System.Collections;
- using CIG.Translation;
- using Inno.DLC;
- using SUISS.Core;
- using SUISS.Scheduling;
- using SUISSEngine;
- using UnityEngine;
-
- public class DownloadProgressPopupState : PopupBaseState
- {
- public override void Leave(State newState)
- {
- base.Leave(newState);
- if (!this._showingConfirmPopup)
- {
- if (this._currentTaskRoutine != null)
- {
- UnityEngine.Debug.LogError("Leave: download task routine was still running");
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._currentTaskRoutine);
- this._currentTaskRoutine = null;
- }
- if (this._downloadRoutine != null)
- {
- UnityEngine.Debug.LogError("Leave: download routine was still running");
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._downloadRoutine);
- this._downloadRoutine = null;
- }
- }
- }
-
- private void OnDestroy()
- {
- if (SingletonMonobehaviour<Scheduler>.IsAvailable)
- {
- if (this._currentTaskRoutine != null)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._currentTaskRoutine);
- this._currentTaskRoutine = null;
- }
- if (this._downloadRoutine != null)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._downloadRoutine);
- this._downloadRoutine = null;
- }
- }
- }
-
- public void Setup(DLCGroup group)
- {
- this._group = group;
- this._totalSize = this._group.RemainingDownloadSize;
- this._downloadedSize = 0L;
- ((DownloadProgressPopupView)this.View).SetStart(this._totalSize);
- SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._downloadRoutine = this.DownloadRoutine(), base.gameObject);
- }
-
- public void GreenButton()
- {
- if (this._downloadedSize < this._totalSize)
- {
- if (this._downloadRoutine == null)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._downloadRoutine = this.DownloadRoutine(), base.gameObject);
- ((DownloadProgressPopupView)this.View).SetStart(this._totalSize);
- ((DownloadProgressPopupView)this.View).SetProgress((float)this._downloadedSize / (float)this._totalSize);
- }
- else
- {
- UnityEngine.Debug.LogError("Retry: download routine was still running");
- }
- }
- else
- {
- foreach (JPEGLoader jpegloader in UnityEngine.Object.FindObjectsOfType<JPEGLoader>())
- {
- foreach (DLCFile dlcfile in this._group.AllFiles)
- {
- jpegloader.DownloadCompleted(this._group.Identifier, dlcfile.Name);
- }
- }
- foreach (CityIsland cityIsland in UnityEngine.Object.FindObjectsOfType<CityIsland>())
- {
- foreach (DLCFile dlcfile2 in this._group.AllFiles)
- {
- cityIsland.DownloadCompleted(this._group.Identifier, dlcfile2.Name);
- }
- }
- base.ClosePopup();
- }
- }
-
- public void CancelRequested()
- {
- this._showingConfirmPopup = true;
- 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);
- this._showingConfirmPopup = false;
- }
-
- private void Cancel()
- {
- if (this._currentTaskRoutine != null)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._currentTaskRoutine);
- this._currentTaskRoutine = null;
- }
- if (this._downloadRoutine != null)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._downloadRoutine);
- this._downloadRoutine = null;
- }
- base.ClosePopup();
- }
-
- private IEnumerator TaskRoutine(DLCFile file, DLCDownloadTask task)
- {
- yield return Timing.time + 0.5;
- while (!task.WWWIsDone)
- {
- long x = this._downloadedSize + (long)((float)file.Bytes * task.WWWProgress);
- ((DownloadProgressPopupView)this.View).SetProgress((float)x / (float)this._totalSize);
- yield return Timing.time + 0.5;
- }
- yield return task.WaitAndStore();
- yield break;
- }
-
- private IEnumerator DownloadRoutine()
- {
- foreach (DLCFile file in this._group.AllFiles)
- {
- if (!file.Exists)
- {
- DLCDownloadTask task = file.Download();
- yield return this._currentTaskRoutine = this.TaskRoutine(file, task);
- this._currentTaskRoutine = null;
- if (!task.IsSuccess)
- {
- if (file.Exists && !file.Check())
- {
- file.Delete();
- }
- ((DownloadProgressPopupView)this.View).SetFailed();
- this._downloadRoutine = null;
- yield break;
- }
- this._downloadedSize += file.Bytes;
- ((DownloadProgressPopupView)this.View).SetProgress((float)this._downloadedSize / (float)this._totalSize);
- }
- }
- this._downloadRoutine = null;
- ((DownloadProgressPopupView)this.View).SetFinished();
- CIGDLCDownloader downloader = UnityEngine.Object.FindObjectOfType<CIGDLCDownloader>();
- downloader.Check();
- yield break;
- }
-
- protected override void OnUpdate()
- {
- }
-
- private DLCGroup _group;
-
- private long _totalSize;
-
- private long _downloadedSize;
-
- private IEnumerator _downloadRoutine;
-
- private IEnumerator _currentTaskRoutine;
-
- private bool _showingConfirmPopup;
- }
|