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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UILib;
using UnityEngine;
using XUtliPoolLib;
namespace XMainClient
{
public class XUICacheImage : XSingleton<XUICacheImage>
{
private string path = Application.temporaryCachePath + "/ImageCache/";
public string CacheKey = "CacheDate";
private ulong m_mainHash = 0UL;
private Dictionary<ulong, List<Action<bool>>> callbacks;
private Dictionary<ulong, List<IXUITexture>> textures;
private ulong mHashURL(string url)
{
return (ulong)((long)Mathf.Abs(url.GetHashCode() + DateTime.Now.Month + DateTime.Now.Day));
}
public void SetMainIcon(string url)
{
this.m_mainHash = this.mHashURL(url);
}
private void CheckCleanOldRes()
{
int num = DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day;
int @int = PlayerPrefs.GetInt(this.CacheKey, 0);
bool flag = num != @int;
if (flag)
{
try
{
bool flag2 = Directory.Exists(this.path);
if (flag2)
{
Directory.Delete(this.path, true);
}
}
catch
{
}
PlayerPrefs.SetInt(this.CacheKey, num);
}
}
private bool OnLoad(string url, IXUITexture texture, Action<bool> cb)
{
bool flag = this.callbacks == null;
if (flag)
{
this.callbacks = new Dictionary<ulong, List<Action<bool>>>();
}
bool flag2 = this.textures == null;
if (flag2)
{
this.textures = new Dictionary<ulong, List<IXUITexture>>();
}
ulong num = this.mHashURL(url);
bool flag3 = cb != null;
if (flag3)
{
bool flag4 = !this.callbacks.ContainsKey(num);
if (flag4)
{
this.callbacks[num] = new List<Action<bool>>();
}
this.callbacks[num].Add(cb);
}
texture.ID = num;
bool flag5 = this.textures.ContainsKey(num);
bool flag6 = !flag5;
if (flag6)
{
this.textures[num] = new List<IXUITexture>();
}
bool flag7 = !this.textures[num].Contains(texture);
if (flag7)
{
this.textures[num].Add(texture);
}
return flag5;
}
private void Dispacher(string url, bool succ, Texture2D img, ulong oldTexID)
{
ulong num = this.mHashURL(url);
bool flag = this.textures.ContainsKey(num);
if (flag)
{
List<IXUITexture> list = this.textures[num];
for (int i = 0; i < list.Count; i++)
{
IXUITexture ixuitexture = list[i];
bool flag2 = ixuitexture != null && !ixuitexture.Equals(null) && ixuitexture.gameObject != null;
if (flag2)
{
bool flag3 = img == null || img.Equals(null) || !succ || list[i].ID != num;
if (flag3)
{
ixuitexture.SetVisible(false);
ixuitexture.SetRuntimeTex(null, oldTexID != this.m_mainHash);
ixuitexture.ID = 0UL;
}
else
{
ixuitexture.SetVisible(true);
ixuitexture.SetRuntimeTex(img, oldTexID != this.m_mainHash);
}
}
}
bool flag4 = this.callbacks.ContainsKey(num);
if (flag4)
{
List<Action<bool>> list2 = this.callbacks[num];
for (int j = 0; j < list2.Count; j++)
{
list2[j](succ);
}
this.callbacks.Remove(num);
}
this.textures.Remove(num);
}
}
public void Load(string url, IXUITexture texture, MonoBehaviour mono)
{
this.Load(url, texture, mono, null);
}
public void Load(string url, IXUITexture texture, MonoBehaviour mono, Action<bool> cb)
{
bool flag = mono == null || string.IsNullOrEmpty(url);
if (flag)
{
texture.SetVisible(false);
texture.SetRuntimeTex(null, texture.ID != this.m_mainHash);
texture.ID = 0UL;
}
else
{
bool flag2 = texture.ID == this.mHashURL(url);
if (!flag2)
{
this.CheckCleanOldRes();
ulong id = texture.ID;
bool flag3 = this.OnLoad(url, texture, cb);
if (!flag3)
{
bool flag4 = !File.Exists(this.path + this.mHashURL(url));
if (flag4)
{
mono.StartCoroutine(this.DownloadImage(url, id));
}
else
{
mono.StartCoroutine(this.LoadLocalImage(url, id));
}
}
}
}
}
private IEnumerator DownloadImage(string url, ulong oldTexID)
{
bool flag = !Directory.Exists(this.path);
if (flag)
{
try
{
Directory.CreateDirectory(this.path);
}
catch (Exception ex)
{
Exception e = ex;
XSingleton<XDebug>.singleton.AddLog("write directory failed!", e.Message, null, null, null, null, XDebugColor.XDebug_None);
}
}
WWW www = new WWW(url);
yield return null;
while (!www.isDone)
{
yield return www;
}
bool flag2 = string.IsNullOrEmpty(url) || !string.IsNullOrEmpty(www.error);
if (flag2)
{
this.Dispacher(url, false, null, oldTexID);
www.Dispose();
www = null;
}
else
{
Texture2D image = www.texture;
byte[] pngData = image.EncodeToJPG();
bool flag3 = image.width == 8 && image.height == 8;
if (flag3)
{
this.Dispacher(url, false, null, oldTexID);
}
else
{
bool flag4 = image.width == 8 && image.height == 8;
if (flag4)
{
this.Dispacher(url, false, null, oldTexID);
}
else
{
try
{
File.WriteAllBytes(this.path + this.mHashURL(url), pngData);
}
catch (Exception ex)
{
Exception e2 = ex;
XSingleton<XDebug>.singleton.AddLog("write file local failed!", e2.Message, null, null, null, null, XDebugColor.XDebug_None);
}
this.Dispacher(url, true, image, oldTexID);
}
www.Dispose();
www = null;
}
image = null;
pngData = null;
}
yield break;
}
private IEnumerator LoadLocalImage(string url, ulong oldTexID)
{
bool flag = string.IsNullOrEmpty(url);
if (flag)
{
this.Dispacher(url, false, null, oldTexID);
}
else
{
string filePath = "file:///" + this.path + this.mHashURL(url);
WWW www = new WWW(filePath);
yield return www;
Texture2D image = www.texture;
bool flag2 = image.height == 8 && image.width == 8;
if (flag2)
{
this.Dispacher(url, false, null, oldTexID);
}
else
{
this.Dispacher(url, true, image, oldTexID);
}
www.Dispose();
www = null;
filePath = null;
www = null;
image = null;
}
yield break;
}
}
}
|