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
|
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using XUpdater;
namespace XUtliPoolLib
{
public sealed class XTableAsyncLoader
{
public bool IsDone
{
get
{
bool flag = false;
bool flag2 = this.currentXfra == null;
if (flag2)
{
bool flag3 = XTableAsyncLoader.currentThreadCount < XTableAsyncLoader.AsyncPerTime;
if (flag3)
{
XTableAsyncLoader.currentThreadCount++;
}
flag = this.InnerExecute();
}
else
{
bool isDone = this.currentXfra.IsDone;
if (isDone)
{
bool flag4 = XTableAsyncLoader.currentThreadCount < XTableAsyncLoader.AsyncPerTime;
if (flag4)
{
XTableAsyncLoader.currentThreadCount++;
}
XBinaryReader.Return(this.currentXfra.Data, false);
this.currentXfra = null;
flag = this.InnerExecute();
}
}
bool flag5 = flag;
if (flag5)
{
bool flag6 = this._call_back != null;
if (flag6)
{
this._call_back();
this._call_back = null;
}
this._executing = false;
}
return flag;
}
}
private bool _executing = false;
private List<XFileReadAsync> _task_list = new List<XFileReadAsync>();
private OnLoadedCallback _call_back = null;
private XFileReadAsync currentXfra = null;
public static int currentThreadCount = 0;
public static readonly int AsyncPerTime = 2;
public void AddTask(string location, CVSReader reader, bool native = false)
{
INativePlugin nativePlugin = XSingleton<XUpdater.XUpdater>.singleton.XPlatform.GetNativePlugin();
bool flag = native && nativePlugin != null;
if (flag)
{
TextAsset sharedResource = XSingleton<XResourceLoaderMgr>.singleton.GetSharedResource<TextAsset>(location, ".bytes", true, false);
bool flag2 = sharedResource != null;
if (flag2)
{
nativePlugin.InputData(0, 0, sharedResource.bytes, sharedResource.bytes.Length);
XSingleton<XResourceLoaderMgr>.singleton.UnSafeDestroyShareResource(location, ".bytes", sharedResource, false);
}
}
else
{
XFileReadAsync xfileReadAsync = new XFileReadAsync();
xfileReadAsync.Location = location;
xfileReadAsync.Reader = reader;
this._task_list.Add(xfileReadAsync);
}
}
private bool InnerExecute()
{
bool flag = this._task_list.Count > 0;
bool result;
if (flag)
{
bool flag2 = XTableAsyncLoader.currentThreadCount <= 0;
if (flag2)
{
result = false;
}
else
{
XTableAsyncLoader.currentThreadCount--;
this.currentXfra = this._task_list[this._task_list.Count - 1];
this._task_list.RemoveAt(this._task_list.Count - 1);
this.ReadFileAsync(this.currentXfra);
result = false;
}
}
else
{
result = true;
}
return result;
}
public bool Execute(OnLoadedCallback callback = null)
{
bool executing = this._executing;
bool result;
if (executing)
{
result = false;
}
else
{
this._call_back = callback;
this._executing = true;
this.InnerExecute();
result = true;
}
return result;
}
private void ReadFileAsync(XFileReadAsync xfra)
{
xfra.Data = XBinaryReader.Get();
bool flag = XSingleton<XResourceLoaderMgr>.singleton.ReadText(xfra.Location, ".bytes", xfra.Data, false);
bool flag2 = !flag;
if (flag2)
{
XResourceLoaderMgr.LoadErrorLog(xfra.Location);
XBinaryReader.Return(xfra.Data, false);
xfra.Data = null;
xfra.IsDone = true;
this.currentXfra = null;
}
else
{
ThreadPool.QueueUserWorkItem(delegate(object state)
{
try
{
bool flag3 = xfra.Reader.ReadFile(xfra.Data);
bool flag4 = !flag3;
if (flag4)
{
XSingleton<XDebug>.singleton.AddErrorLog("in File: ", xfra.Location, xfra.Reader.error, null, null, null);
}
}
catch (Exception ex)
{
XSingleton<XDebug>.singleton.AddErrorLog(ex.Message, " in File: ", xfra.Location, xfra.Reader.error, null, null);
}
xfra.IsDone = true;
});
}
}
}
}
|