protected override void OnDownLoadFileInfoSuccessful(AssetDownInfo downInfo) { string version = _all_version[downInfo.Index]; string context = Encoding.Default.GetString(downInfo.Buffer.Bytes); //Debug.Log("AssetBundle下载:" + version); string[] abInfos = context.Split('\n'); for (int i = 0; i < abInfos.Length; i++) { if (abInfos[i] == string.Empty || abInfos[i] == " ") { continue; // 写入数据的时候没写好 } string[] abInfo = abInfos[i].Split('|'); AssetDataInfo info = new AssetDataInfo(); info.Name = abInfo[0]; info.MD5 = abInfo[1]; info.Size = Convert.ToInt32(abInfo[2]); info.Version = version; _data_infos[version].Add(info); } }
protected override void OnDownLoadFileInfoSuccessful(AssetDownInfo downInfo) { string version = _all_version[downInfo.Index]; string context = System.Text.Encoding.Default.GetString(downInfo.Buffer.Bytes); string[] fenBaoStrs = context.Split('\n'); //Debug.Log("分包下载:" + version); for (int i = 0; i < fenBaoStrs.Length; i++) { if (fenBaoStrs[i] == string.Empty || fenBaoStrs[i] == " ") { continue; } string[] infoStr = fenBaoStrs[i].Split('|'); AssetDataInfo info = new AssetDataInfo(); info.Name = infoStr[0]; info.MD5 = infoStr[1]; info.Size = System.Convert.ToInt32(infoStr[2]); info.Version = version; _all_zip[version].Add(info); } }
public override void StartDownLoad() { VersionInfo info = FileManifestManager.Get <IServerVersionFileManifest>().GetLastVersin(); if (info == null) { return; } if (info.AssetBundleManifestNames == null) { return; } for (int i = 0; i < info.AssetBundleManifestNames.Length; i++) { AssetBundleDownLoadParam param = new AssetBundleDownLoadParam(info.AssetBundleManifestNames[i]); HttpDownLoadAsync httpDownLoadAsync = CreateHttpDownLoad(); AssetDownInfo downInfo = new AssetDownInfo(); downInfo.AssetName = info.AssetBundleManifestNames[i]; downInfo.Buffer.ByteSize = int.Parse(info.AssetBundleManifestLengths[i]); downInfo.MD5 = info.AssetBundleManifestMD5s[i]; downInfo.Index = i; _version_index.Add(i); httpDownLoadAsync.Setup(downInfo); httpDownLoadAsync.StartDownLoad(param); } }
protected override void OnDownloadSuccessful(AssetDownInfo info, HttpDownLoadAsync loadAsync) { lock (LOCK_OBJ) { if (info.Buffer.Bytes.Length != info.BufferNumber) { byte[] bytes = new byte[info.BufferNumber]; for (int i = 0; i < info.BufferNumber; i++) { bytes[i] = info.Buffer.Bytes[i]; } info.Buffer.Bytes = bytes; } OnDownLoadFileInfoSuccessful(info); versionIndex.Remove(info.Index); if (httpDownloadAsyncs.Contains(loadAsync)) { httpDownloadAsyncs.Remove(loadAsync); } if (IsDownloadABatch()) { OnAllDownLoadComplete(); ClearHttpDownLoad(); isDone = true; } } }
protected override void OnDownLoadError(AssetDownInfo info) { Debug.Log("ZIP下载错误!"); // 回炉重造 _current_strategy.GoBackDownLoadFileResultInfo(info); // 下载错误 if (info.ErrorNumber < DownloaderConstant.MAX_DOWNLOAD_ERROR_NUMBER) { StartDownLoad(info); } else { if (_current_strategy.AssetType == eUpdateAssetType.Zip) { FileManifestManager.RemoveLocalFenBaoData(info.ToAssetDataInfo()); } else { FileManifestManager.RemoveLocalABData(info.ToAssetDataInfo()); } AssetDownLoads.StopALLDownLoad(); } if (!_downLoad_error.Contains(info)) { _downLoad_error.Add(info); } }
void StartDownLoad(AssetDownInfo info) { HttpDownLoadAsync loadAsync = CreateHttpDownLoad(); loadAsync.Setup(info); loadAsync.StartDownLoad(_current_strategy.GetDownLoadParam(info)); }
protected void OnAddAssets(string version, AssetDownInfo info) { if (!sourceData.ContainsKey(version)) { sourceData.Add(version, new List <AssetDownInfo>()); } sourceData[version].Add(info); }
public override void TryRemove(AssetDownInfo info) { if (currentQueue.Count > 0) { _zip_decompress.Enqueue(info); } base.TryRemove(info); }
protected AssetDownInfo NewAssetDownInfo(int i) { AssetDownInfo downInfo = new AssetDownInfo(); downInfo.Index = i; versionIndex.Add(i); return(downInfo); }
// 如果下载错误则回退 public void GoBackDownLoadFileResultInfo(AssetDownInfo info) { long currentSize = UpdateStageResult.DownLoad.DownLoadFileInfos[info.AssetName].CurrentFileSize; UpdateStageResult.DownLoad.DownLoadFileInfos[info.AssetName].CurrentFileSize = 0; UpdateStageResult.DownLoad.CurrentSize -= currentSize; UpdateStageResult.DownLoad.CurrentCount--; info.Reset(); }
protected override void OnDownloadSuccessful(AssetDownInfo info, HttpDownLoadAsync loadAsync) { Debug.Log("Asset下载成功!"); if (_downLoad_error.Contains(info)) { _downLoad_error.Remove(info); } if (StageDataBase.CheckVersionIsDownLoadComplete(info.Version)) { // 一个版本下载完毕 VersionDownLoadComplete(info.Version); } _current_strategy.TryRemove(info); if (IsDone) { if (_stage_index < (_strategy_bases.Length - 1)) { _stage_index++; Debug.Log("换阶段了 STAGE_INDEX=" + _stage_index); } else { if (_downLoad_error.Count <= 0) { UpdateStageResult.DownLoad.ClearAll(); } OnAllDownLoadComplete(); if (DownLoadCompleteEvent != null) { DownLoadCompleteEvent(this); } FileManifestManager.WriteABDataByCurrent(); isDone = true; Debug.Log("全部下载完成!!!!!!!"); } } else { AssetDataInfo dataInfo = info.ToAssetDataInfo(); if (_current_strategy.AssetType == eUpdateAssetType.Zip) { FileManifestManager.UpdateLocalFenBaoData(dataInfo); } else { FileManifestManager.UpdateLocalABData(dataInfo); } } TryStartDownLoad(); }
// 开始下载 public void Setup(AssetDownInfo downInfo) { _down_info = downInfo; _is_stop_download = false; _is_done = false; _local_fileName = _local_path + "/" + downInfo.AssetName; _buffer = new byte[BUFFER_SIZE]; }
protected override void OnDownLoadFileInfoSuccessful(AssetDownInfo downInfo) { string version = _all_versions[downInfo.Index]; string context = System.Text.Encoding.Default.GetString(downInfo.Buffer.Bytes); VersionInfo info = JsonUtility.FromJson <VersionInfo>(context); _version_infos[version] = info; //Debug.Log("版本文件:" + context); }
public void InitializeData() { if (_cache_server_data.Count <= 0) { return; } int i = StartIndex; int queueIndex = 0; Dictionary <string, List <AssetDataInfo> > packages = new Dictionary <string, List <AssetDataInfo> >(); var itr = _cache_server_data.Keys.GetEnumerator(); while (itr.MoveNext()) { Queue <AssetDataInfo> datas = _cache_server_data[itr.Current]; downloadQueue.Add(new Queue <AssetDownInfo>()); while (datas.Count > 0) { AssetDataInfo serverInfo = datas.Dequeue(); UpdateStageResult.DownLoad.TotalSize += serverInfo.Size; UpdateStageResult.DownLoad.FileCount++; if (IsDownloaded(serverInfo) || IsCompressed(serverInfo)) { UpdateStageResult.DownLoad.CurrentSize += serverInfo.Size; UpdateStageResult.DownLoad.CurrentCount++; continue; } AssetDownInfo download = serverInfo.ToAssetDownInfo(i); download.QueueIndex = queueIndex; download.Version = itr.Current; if (!VersionRecord.ContainsKey(itr.Current)) { VersionRecord.Add(itr.Current, 0); } VersionRecord[itr.Current]++; InitDownLoadInfo(download); OnAddAssets(itr.Current, download); downloadQueue[downloadQueue.Count - 1].Enqueue(download); i++; } queueIndex++; } itr.Dispose(); _cache_server_data.Clear(); }
public static void UpdateDownLoadFileResultInfo(AssetDownInfo downInfo, long increment) { if (downInfo == AssetDownInfo.Empty) { return; } DownLoad.CurrentSize += increment; if (DownLoad.DownLoadFileInfos.ContainsKey(downInfo.AssetName)) { DownLoad.DownLoadFileInfos[downInfo.AssetName].CurrentFileSize += increment; } }
protected override void OnDownloadSuccessful(AssetDownInfo info, HttpDownLoadAsync loadAsync) { _version_index.Remove(info.Index); if (_version_index.Count <= 0) { OnAllDownLoadComplete(); if (DownLoadCompleteEvent != null) { DownLoadCompleteEvent(this); } } }
public AssetDownInfo ToAssetDownInfo(int index) { AssetDownInfo info = new AssetDownInfo(); info.AssetName = Name; info.MD5 = MD5; info.Version = Version; info.TotalSize = Size; info.BufferNumber = 0; info.ErrorNumber = 0; info.Index = index; return(info); }
public static void RemoveDownLoadFileResultInfo(AssetDownInfo downInfo) { if (downInfo == AssetDownInfo.Empty) { return; } if (DownLoad.DownLoadFileInfos == null) { DownLoad.DownLoadFileInfos = new Dictionary <string, DownLoadFileResultInfo>(); } if (DownLoad.DownLoadFileInfos.ContainsKey(downInfo.AssetName)) { DownLoad.DownLoadFileInfos.Remove(downInfo.AssetName); } }
public void DownLoadError(AssetDownInfo info, HttpDownLoadAsync loadAsync) { lock (LOCK_OBJ) { DownLoadErrorEvent errorEvent = new DownLoadErrorEvent(info); errorEvent.Event = (dio) => { OnDownLoadError(dio); if (httpDownloadAsyncs.Contains(loadAsync)) { httpDownloadAsyncs.Remove(loadAsync); } }; downLoad_error_events.Enqueue(errorEvent); } }
void TryStartDownLoad() { UpdateStageResult.DownLoad.IsEnable = true; _current_strategy.InitializeData(); List <AssetDownInfo> downInfos = _current_strategy.TryGetDownLoadData(); int count = downInfos == null ? 0 : downInfos.Count; if (count <= 0) { return; } for (int i = 0; i < count; i++) { AssetDownInfo info = downInfos[i]; StartDownLoad(info); } }
public virtual void TryRemove(AssetDownInfo info) { UpdateStageResult.RemoveDownLoadFileResultInfo(info); if (sourceData.ContainsKey(info.Version)) { if (sourceData[info.Version].Contains(info)) { sourceData[info.Version].Remove(info); } } if (currentQueue.Count > 0) { currentQueue.Remove(info); UpdateStageResult.DownLoad.CurrentCount++; } }
public void DownloadSuccessful(AssetDownInfo info, HttpDownLoadAsync loadAsync) { lock (LOCK_OBJ) { DownloadSuccessfulEvent successfulEvent = new DownloadSuccessfulEvent(info, loadAsync); successfulEvent.Event = (dif, la) => { OnDownloadSuccessful(dif, la); if (httpDownloadAsyncs.Contains(loadAsync)) { httpDownloadAsyncs.Remove(loadAsync); } }; download_successful_events.Enqueue(successfulEvent); } }
protected override void OnDownLoadFileInfoSuccessful(AssetDownInfo downInfo) { string context = System.Text.Encoding.Default.GetString(downInfo.Buffer.Bytes); Debug.Log("版本列表:\n" + context); string[] versionList = context.Split('\n'); for (int i = 0; i < versionList.Length; i++) { if (versionList[i] == string.Empty || versionList[i] == " ") { continue; } string versionName = versionList[i]; _all_versions.Add(versionName.Trim()); } isDone = true; }
void InitDownLoadInfo(AssetDownInfo info) { string localFileName = _local_path + "/" + info.AssetName; if (File.Exists(localFileName)) { try { using (FileStream fs = File.Open(localFileName, FileMode.Open)) { if (fs.Length >= info.TotalSize) // 需要删除 { fs.Close(); File.Delete(localFileName); } else { info.DownloadedBuffer = new AssetBuffer(); info.DownloadedBuffer.ByteSize = (int)fs.Length; info.DownloadedBuffer.Bytes = new byte[fs.Length]; fs.Read(info.DownloadedBuffer.Bytes, 0, (int)fs.Length); fs.Close(); } } } catch (System.Exception ex) { Debug.LogError(ex.Message); } } info.ErrorCode = eDownErrorCode.None; info.Buffer.ByteSize = info.TotalSize; if (info.DownloadedBuffer != null) { UpdateStageResult.DownLoad.CurrentSize += info.DownloadedBuffer.ByteSize; } }
public static void AddDownLoadFileResultInfo(AssetDownInfo downInfo) { if (downInfo == AssetDownInfo.Empty) { return; } if (DownLoad.DownLoadFileInfos == null) { DownLoad.DownLoadFileInfos = new Dictionary <string, DownLoadFileResultInfo>(); } if (!DownLoad.DownLoadFileInfos.ContainsKey(downInfo.AssetName)) { DownLoadFileResultInfo resultInfo = new DownLoadFileResultInfo(); resultInfo.TotalFileSize = downInfo.Buffer.ByteSize; if (downInfo.DownloadedBuffer != null) { resultInfo.CurrentFileSize = downInfo.DownloadedBuffer.ByteSize; } resultInfo.AssetName = downInfo.AssetName; DownLoad.DownLoadFileInfos.Add(downInfo.AssetName, resultInfo); } }
public override List <AssetDownInfo> TryGetDownLoadData() { if (downloadQueue.Count <= 0) { return(null); } List <AssetDownInfo> datas = new List <AssetDownInfo>(); for (int i = 0; i < downloadQueue.Count; i++) { int number = currentQueue.Count; while (downloadQueue[i].Count > 0) { if (number >= DownloaderConstant.MAX_DOWNLOAD_QUEUE_COUNT) { break; } AssetDownInfo info = downloadQueue[i].Dequeue(); datas.Add(info); currentQueue.Add(info); number++; } } if (datas.Count > 0) { for (int i = 0; i < datas.Count; i++) { UpdateStageResult.AddDownLoadFileResultInfo(datas[i]); } } return(datas); }
public override IDownLoadParam GetDownLoadParam(AssetDownInfo info) { return(new ZipDownLoadParam(info.Version, info.AssetName)); }
public abstract IDownLoadParam GetDownLoadParam(AssetDownInfo info);
public void UpdateDownloadInfo(AssetDownInfo info, long increment) { UpdateStageResult.UpdateDownLoadFileResultInfo(info, increment); }
// 开始解压缩 public void StartDecompress() { UpdateStageResult.DownLoad.IsEnable = false; UpdateStageResult.Compression.IsEnable = true; UpdateStageResult.Compression.ClearAll(); var deItr = _decompress_queue.GetEnumerator(); while (deItr.MoveNext()) { UpdateStageResult.Compression.TotalSize += deItr.Current.TotalSize; UpdateStageResult.Compression.FileCount++; } deItr.Dispose(); string localPath = AssetsCommon.LocalAssetPath; if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } AssetDownInfo[] tempDatas = new AssetDownInfo[_decompress_queue.Count]; for (int i = 0; i < tempDatas.Length; i++) { int index = _decompress_queue[i].Index; tempDatas[index] = _decompress_queue[i]; } for (int i = 0; i < tempDatas.Length; i++) { AssetDownInfo downInfo = tempDatas[i]; string zipFileName = string.Format("{0}/{1}", localPath, downInfo.AssetName); List <AssetDataInfo> assetNames = ZipHelper.Decompress( zipFileName, localPath); AssetDataInfo dataInfo = downInfo.ToAssetDataInfo(); dataInfo.IsCompressed = true; UpdateStageResult.Compression.CurrentCount++; FileManifestManager.UpdateLocalFenBaoData(dataInfo); for (int j = 0; j < assetNames.Count; j++) { FileManifestManager.UpdateLocalABData(assetNames[j]); } if (File.Exists(zipFileName)) { File.Delete(zipFileName); } } UpdateStageResult.Compression.IsEnable = false; if (_owner.IsDownLoadAllVersion) { FileManifestManager.WriteFenBaoDataByServer(); } else { FileManifestManager.WriteFenBaoDataByCurrent(); } FileManifestManager.WriteABDataByCurrent(); }