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 _task_list = new List(); 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.singleton.XPlatform.GetNativePlugin(); bool flag = native && nativePlugin != null; if (flag) { TextAsset sharedResource = XSingleton.singleton.GetSharedResource(location, ".bytes", true, false); bool flag2 = sharedResource != null; if (flag2) { nativePlugin.InputData(0, 0, sharedResource.bytes, sharedResource.bytes.Length); XSingleton.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.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.singleton.AddErrorLog("in File: ", xfra.Location, xfra.Reader.error, null, null, null); } } catch (Exception ex) { XSingleton.singleton.AddErrorLog(ex.Message, " in File: ", xfra.Location, xfra.Reader.error, null, null); } xfra.IsDone = true; }); } } } }