1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
using System;
using System.Collections;
using System.Text;
using UnityEngine;
using XUtliPoolLib;
namespace XUpdater
{
public sealed class XDownloader : MonoBehaviour
{
private StringBuilder _log = new StringBuilder();
private WWW _downloader = null;
private bool _download = true;
private uint _token = 0u;
private float _total_percent = 0f;
private string _current_name = null;
private XTimerMgr.ElapsedEventHandler _progressCb = null;
public delegate void HandleBytesDownload(WWW www, string error);
private void Awake()
{
this._progressCb = new XTimerMgr.ElapsedEventHandler(this.Progress);
}
internal void GetBundle(XBundleData bundle, string url, HandleBundleDownload callback1, HandleFetchBundle callback2, float percent)
{
this._download = url.Contains("?token=");
this._current_name = bundle.Name;
this._total_percent = percent;
base.StartCoroutine(this.Download(bundle, url, callback1, callback2));
}
public void GetMeta(string url, string name, XDownloader.HandleBytesDownload callback, float percent)
{
this._download = true;
this._current_name = name;
this._total_percent = percent;
base.StartCoroutine(this.MetaDownload(url, callback));
}
public void GetBytes(string url, XDownloader.HandleBytesDownload callback)
{
base.StartCoroutine(this.BytesDownload(url, callback));
}
private IEnumerator MetaDownload(string url, XDownloader.HandleBytesDownload callback)
{
XSingleton<XTimerMgr>.singleton.KillTimer(this._token);
this._token = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, this._progressCb, null);
this._downloader = new WWW(url);
yield return this._downloader;
XSingleton<XTimerMgr>.singleton.KillTimer(this._token);
this.Progress(null);
XSingleton<XTimerMgr>.singleton.KillTimer(this._token);
bool flag = callback != null;
if (flag)
{
callback(this._downloader, this._downloader.error);
}
this._downloader.Dispose();
this._downloader = null;
yield break;
}
private IEnumerator BytesDownload(string url, XDownloader.HandleBytesDownload callback)
{
WWW www = new WWW(url);
yield return www;
bool flag = callback != null;
if (flag)
{
callback(www, www.error);
}
www.Dispose();
www = null;
yield break;
}
private IEnumerator Download(XBundleData bundle, string url, HandleBundleDownload callback1, HandleFetchBundle callback2)
{
XSingleton<XTimerMgr>.singleton.KillTimer(this._token);
this._token = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, this._progressCb, null);
this._downloader = new WWW(url);
yield return this._downloader;
XSingleton<XTimerMgr>.singleton.KillTimer(this._token);
this.Progress(null);
XSingleton<XTimerMgr>.singleton.KillTimer(this._token);
bool error = false;
bool flag = callback1 != null;
if (flag)
{
AsyncWriteRequest awr = callback1(this._downloader, bundle, this._downloader.error);
while (!awr.IsDone)
{
bool hasError = awr.HasError;
if (hasError)
{
error = true;
break;
}
yield return null;
}
XSingleton<XUpdater>.singleton.XPlatform.SetNoBackupFlag(awr.Location);
awr = null;
}
bool flag2 = error;
if (flag2)
{
this._log.Length = 0;
this._log.AppendFormat(XSingleton<XStringTable>.singleton.GetString("XUPDATE_ERROR_DOWNLOADRESFAILED"), bundle.Name);
XSingleton<XLoadingUI>.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue);
}
else
{
bool flag3 = callback2 != null;
if (flag3)
{
callback2(this._downloader, this._downloader.bytes, bundle, this._download);
}
}
this._downloader = null;
yield break;
}
private void Progress(object o)
{
this._log.Remove(0, this._log.Length);
int num = Mathf.FloorToInt(this._total_percent * 100f);
bool download = this._download;
if (download)
{
this._log.AppendFormat(XSingleton<XStringTable>.singleton.GetString("XUPDATE_INFO_DOWNLOADING"), num);
}
else
{
this._log.AppendFormat(XSingleton<XStringTable>.singleton.GetString("XUPDATE_INFO_EXTRACTING"), num);
}
XSingleton<XLoadingUI>.singleton.SetStatus(this._log.ToString(), byte.MaxValue, byte.MaxValue, byte.MaxValue);
this._token = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, this._progressCb, o);
}
}
}
|