private void UnZipThread(object o) { ZipParameters p = o as ZipParameters; string _str = Ionic.Zlib.GZipStream.UncompressString(p.bytes); string filePath = p.filePath; string directoryName = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } StreamWriter _sw = new StreamWriter(filePath); _sw.Write(_str); _sw.Close(); mAssetTable[p.key] = _str; foreach (AssetLoadedCallBack cb in p.callbacks) { cb(_str); } }
public void Update(float deltaTime) { if (mCallBackTable.Count == 0) { return; } keys.Clear(); foreach (string key in mCallBackTable.Keys) { keys.Add(key); } foreach (string key in keys) { if (!mCallBackTable.ContainsKey(key)) { continue; } List <AssetLoadedCallBack> callbacks = mCallBackTable[key]; if (DownLoader.Instance.Loaded(key)) { mCallBackTable.Remove(key); DownLoadUnit dlu = DownLoader.Instance.Fetch(key); if (dlu != null) { if (dlu.GetWWW().error == null) { string _str = ""; if (dlu.mReq.mType == ResourceType.RT_ZIP) { ZipParameters param = new ZipParameters(); param.bytes = DownLoadResultFetcher.Instance.FetchByte(dlu); param.key = key; param.callbacks = callbacks; param.filePath = GameInfo.FilePath + key + ".byte"; if (!ThreadMgr.Instance.disableThread) { ThreadMgr.Instance.Start("UnzipData", new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(UnZipThread)), param as object); } else { UnZipThread(param); } //return; } else if (dlu.mReq.mType == ResourceType.RT_TEXT) { _str = DownLoadResultFetcher.Instance.FetchString(dlu); string filePath = GameInfo.FilePath + key + ".byte"; string directoryName = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } StreamWriter _sw = new StreamWriter(filePath); _sw.Write(_str); _sw.Close(); mAssetTable[key] = _str; foreach (AssetLoadedCallBack cb in callbacks) { cb(_str); } } } else { foreach (AssetLoadedCallBack cb in callbacks) { cb(null); } } dlu.ReleaseRes(); } } } }