|
- using System;
- using System.Collections;
- using System.IO;
- using UnityEngine;
-
- namespace Inno.DLC
- {
- public class DLCDownloadTask
- {
- public DLCDownloadTask(string url, string path)
- {
- this._path = path;
- this._www = new WWW(url);
- }
-
- private void FireDownloadFinishedEvent()
- {
- if (this.DownloadFinishedEvent != null)
- {
- this.DownloadFinishedEvent(this);
- }
- }
-
- public float WWWProgress
- {
- get
- {
- return (this._www == null) ? 0f : this._www.progress;
- }
- }
-
- public bool WWWIsDone
- {
- get
- {
- return this._www == null || this._www.isDone;
- }
- }
-
- public bool IsFinished
- {
- get
- {
- return this._finished;
- }
- }
-
- public bool IsSuccess
- {
- get
- {
- return this._success;
- }
- }
-
- public string ErrorMessage
- {
- get
- {
- return this._errorMessage;
- }
- }
-
- public IEnumerator WaitAndStore()
- {
- yield return this._www;
- if (string.IsNullOrEmpty(this._www.error))
- {
- try
- {
- File.WriteAllBytes(this._path, this._www.bytes);
- this._errorMessage = string.Empty;
- this._success = true;
- }
- catch (Exception ex)
- {
- UnityEngine.Debug.LogError(string.Format("Cannot save DLC file: {0}", ex.Message));
- this._errorMessage = ex.Message;
- this._success = false;
- }
- }
- else
- {
- this._errorMessage = this._www.error;
- this._success = false;
- }
- this._www = null;
- this._finished = true;
- this.FireDownloadFinishedEvent();
- yield break;
- }
-
- public Action<DLCDownloadTask> DownloadFinishedEvent;
-
- private string _path;
-
- private WWW _www;
-
- private bool _finished;
-
- private bool _success;
-
- private string _errorMessage;
- }
- }
|