private void _DownloadAssets(string listFileName, string text, PreDownloader.DownlaodToComplete userCompleteCallback) { int num = 0; BackgroundInstall.DownloadAssets downloadAssets = new BackgroundInstall.DownloadAssets(listFileName); foreach (string current in this._ParseBundleList(text)) { PatchFileInfo patchFileInfo = PatchFinalList.Instance.GetPatchFileInfo(current); if (this._IsVersionCached(current, patchFileInfo.nVersion, patchFileInfo.bUseCustomCache)) { num++; } else { downloadAssets.requestFiles.Add(current); } } int num2 = downloadAssets.requestFiles.Count + num; BackgroundInstall.Progress progress = new BackgroundInstall.Progress(num2, num); BackgroundInstall.ms_ProgressCollection[listFileName] = progress; if (downloadAssets.requestFiles.Count > 0) { progress.downloading = true; if (Option.EnableTrace) { TsLog.Log("[PreDownload] Request( \"{0}\" ) => wait for downloads (Requests={1}, Cacheds={2}, Total={3})", new object[] { listFileName, downloadAssets.requestFiles.Count, num, num2 }); } downloadAssets.userCompleteCallback = userCompleteCallback; Helper.PreDownloadRequest(downloadAssets.requestFiles, new PostProcPerList(this._DownloadComplete_Assets), downloadAssets); } else { if (Option.EnableTrace) { TsLog.Log("[PreDownload] Request( \"{0}\" ) => Complete to download: All file is chached on disk. (Progress={1}%, CachedFiles={2}, Total={3})", new object[] { listFileName, (float)num / (float)num2 * 100f, num, num2 }); } if (userCompleteCallback != null) { userCompleteCallback(listFileName, (num != num2) ? ((float)num / (float)num2) : 1f); } } }
private void _DownloadComplete_Assets(List <WWWItem> downlaodList, object param) { BackgroundInstall.DownloadAssets downloadAssets = param as BackgroundInstall.DownloadAssets; if (downloadAssets == null) { TsLog.LogWarning("[PreDownload] download to complete ( <<unknown>>, downloads = {0} )", new object[] { downlaodList.Count }); return; } int count = downloadAssets.requestFiles.Count; int num = 0; StringBuilder stringBuilder = (!Option.EnableTrace) ? null : new StringBuilder(1024); if (stringBuilder != null) { stringBuilder.AppendFormat("[PreDownload] Download to complete ( PreDownloadListFile=\"{0}\", Requests={1}, Downloads={2} )", downloadAssets.listFileName, downloadAssets.requestFiles.Count, downlaodList.Count); stringBuilder.AppendLine(); stringBuilder.AppendLine("=================================================================================================="); Dictionary <string, WWWItem> dictionary = new Dictionary <string, WWWItem>(downlaodList.Count); foreach (WWWItem current in downlaodList) { dictionary[current.assetPath] = current; } foreach (string current2 in downloadAssets.requestFiles) { string text = (!dictionary.ContainsKey(current2)) ? "<<skipped>>" : "<<download>>"; PatchFileInfo patchFileInfo = PatchFinalList.Instance.GetPatchFileInfo(current2); if (patchFileInfo.nVersion != -1) { if (this._IsVersionCached(current2, patchFileInfo.nVersion, patchFileInfo.bUseCustomCache)) { num++; stringBuilder.AppendFormat(" \"{0}\" (version={1}, {2}) => chached", current2, patchFileInfo.nVersion, text); stringBuilder.AppendLine(); } else { stringBuilder.AppendFormat(" \"{0}\" (version={1}, {2}) => download to complete, but bundle-file is not cached.", current2, patchFileInfo.nVersion, text); stringBuilder.AppendLine(); } } else { stringBuilder.AppendFormat(" \"{0}\" ({1}) => not listed FinalPatchLIst", current2, text); stringBuilder.AppendLine(); } } stringBuilder.AppendLine("=================================================================================================="); stringBuilder.AppendFormat("Total = {0}, Downloads = {1}, Cached = {2}\r\n", count, downlaodList.Count, num); stringBuilder.AppendFormat("Downloads Rate = {0} %\r\n", 100f * (float)downlaodList.Count / (float)count); stringBuilder.AppendFormat("Cached Rate = {0} %\r\n", 100f * (float)num / (float)count); TsLog.Log(stringBuilder.ToString(), new object[0]); } float cachedRate = (count != 0) ? ((num != count) ? ((float)num / (float)count) : 1f) : 0f; BackgroundInstall.Progress progress; if (BackgroundInstall.ms_ProgressCollection.TryGetValue(downloadAssets.listFileName, out progress)) { progress.count = progress.total; progress.downloading = false; } if (downloadAssets.userCompleteCallback != null) { downloadAssets.userCompleteCallback(downloadAssets.listFileName, cachedRate); } }