/// <summary> /// 下载取消确认. /// </summary> /// <param name="iYesOrNo">是否取消下载(true:取消下载;false:不取消下载;).</param> private void DownloadCancelConfirm(bool iYesOrNo) { if (iYesOrNo == true) { // 清空错误列表 if (this._errors != null) { this._errors.Clear(); } return; } // 打断标志位 isCanceled = true; // 导出已下载完成信息 // 取得导出目录 string ExportDir = ServersConf.BundlesDir; // 导出最新的下载列表信息 DownloadList.GetInstance().ExportToJsonFile(ExportDir); // 继续下载 StartCoroutine(DownloadContinue()); }
/// <summary> /// 下载重置. /// </summary> public void DownloadReset() { // 打断当前线程并停止所有协同进程 isCanceled = true; this.StopAllCoroutines(); // 清空错误列表 if (this._errors != null) { this._errors.Clear(); } this._State = TRunState.OK; this._isCompleted = false; this.isStarted = false; // 清空上传列表 UploadList.GetInstance().Clear(); // 下载列表清空 DownloadList.GetInstance().Reset(); // 进度条重置 if (this._downloadBar != null) { this._downloadBar.Reset(); } }
/// <summary> /// 下载完成确认. /// </summary> /// <param name="iIsDidDownloaded">是否下载过.</param> private void DownloadCompleteNotification(bool iIsDidDownloaded) { if ((this._downloadEvents != null) && (this._downloadEvents.OnCompletedNotification != null)) { this._downloadEvents.OnCompletedNotification.Invoke(); } this._isCompleted = true; if (iIsDidDownloaded == true) { // 取得导出目录 string ExportDir = ServersConf.BundlesDir; // 导出最新的下载列表信息 DownloadList.GetInstance().ExportToJsonFile(ExportDir); // 导入Bundle包依赖关系 BundlesMap.GetInstance().ExportToJsonFile(ExportDir); // 清空下载文件夹 this.ClearDownloadDir(); } }
/// <summary> /// 初始化下载队列. /// </summary> private IEnumerator initDownloadQueue() { // 初始化清空 this.DownloadQueue.Clear(); List <DownloadTargetInfo> targets = DownloadList.GetInstance().Targets; DownloadTargetInfo[] downloadTargets = targets .Where(o => (false == o.Downloaded)) .ToArray(); if ((downloadTargets == null) || (downloadTargets.Length <= 0)) { this._State = TRunState.NoDownloadTarget; this.Warning("initDownloadQueue()::There is no target to download!!!"); } yield return(new WaitForEndOfFrame()); if (TRunState.OK == this._State) { this.DownloaderCount = 0; int targetsCount = downloadTargets.Length; int maxCount = ServersConf.GetInstance().ThreadMaxCount; this.DownloaderMaxCount = (targetsCount > maxCount) ? maxCount : targetsCount; // 遍历下载列表,并压进下载队列 foreach (DownloadTargetInfo loop in downloadTargets) { if (loop == null) { continue; } DownloaderBase downloader = CreateDownloader(loop); if (downloader != null) { this.DownloadQueue.Enqueue(downloader); } } } }
/// <summary> /// 下载成功回调函数. /// </summary> /// <param name="iDownloadInfo">下载信息.</param> /// <param name="iRetries">重试次数.</param> public void OnDownloadSuccessed(DownloaderBase iDownloader, DownloadTargetInfo iDownloadInfo, int iRetries) { this.Info("OnDownloadSuccessed()::Download Successed. {0} Retries:{1}", iDownloadInfo.toString(), iRetries); DownloadList.GetInstance().DownloadCompleted(iDownloadInfo.ID, iDownloadInfo.FileType); if (true == iDownloadInfo.Downloaded) { // 文件拷贝 iDownloadInfo.CopyTargetWhenDownloadCompleted(); if (iDownloader != null) { iDownloader.Dispose(); GC.Collect(); } lock (_downloaderCountLock) { --this.DownloaderCount; } } }
/// <summary> /// 下载检测. /// </summary> /// <returns>The check.</returns> /// <param name="iDownloadPreCheck">下载预检查.</param> private IEnumerator DownloadCheck(bool iDownloadPreCheck) { // 下载开始 this.isStarted = true; if (false == iDownloadPreCheck) { // 检测下载文件夹 // 下载根目录 this.CheckDownloadDirs(ServersConf.DownloadRootDir); yield return(new WaitForEndOfFrame()); // 下载目录 this.CheckDownloadDirs(ServersConf.DownloadDir); yield return(new WaitForEndOfFrame()); // 下载目录(Normal) this.CheckDownloadDirs(ServersConf.DownloadDirOfNormal); yield return(new WaitForEndOfFrame()); // 下载目录(Scenes) this.CheckDownloadDirs(ServersConf.DownloadDirOfScenes); yield return(new WaitForEndOfFrame()); // Bundles目录 this.CheckDownloadDirs(ServersConf.BundlesDir); yield return(new WaitForEndOfFrame()); // Bundles目录(Normal) this.CheckDownloadDirs(ServersConf.BundlesDirOfNormal); yield return(new WaitForEndOfFrame()); // Bundles目录(Scene) this.CheckDownloadDirs(ServersConf.BundlesDirOfScenes); yield return(new WaitForEndOfFrame()); // 解压缩目录 this.CheckDownloadDirs(ServersConf.DecompressedDir); yield return(new WaitForEndOfFrame()); // 解压缩目录(Normal) this.CheckDownloadDirs(ServersConf.DecompressedDirOfNormal); yield return(new WaitForEndOfFrame()); // 解压缩目录(Scenes) this.CheckDownloadDirs(ServersConf.DecompressedDirOfScenes); yield return(new WaitForEndOfFrame()); } // 下载Bundle包依赖文件 if (false == iDownloadPreCheck) { yield return(DownloadBundlesMap()); yield return(new WaitForEndOfFrame()); } if (TRunState.OK == this._State) { // 检测下载用上传列表 if (false == iDownloadPreCheck) { yield return(DownloadUploadlist()); yield return(new WaitForEndOfFrame()); } } else { this.Warning("DownloadCheck()::Failed:State:{0}", this._State); } if ((false == iDownloadPreCheck) && (TRunState.OK == this._State)) { // 更新下载文件 UploadList.GetInstance().UpdateFromUploadlistFile(); yield return(new WaitForEndOfFrame()); // 更新下载列表 UploadList.GetInstance().UpdateLocalInfoForDownload(); yield return(new WaitForEndOfFrame()); } if (TRunState.OK == this._State) { // 需要下载时 if (DownloadList.GetInstance().isDownloadNecessary == true) { // 下载前确认提示 this.DownloadPreConfirmNotification( DownloadList.GetInstance().GetTotalCount(), DownloadList.GetInstance().GetTotalDatasize()); } else { this.isStarted = false; this._isCompleted = false; this.Info("DownloadCheck()::There is no download target or all already be downloaded!"); this.DownloadCompleteNotification(false); } } yield return(null); }
private int GetDownloadedCount() { return(DownloadList.GetInstance().GetDownloadedCount()); }
private float GetDownloadedProgress() { return(DownloadList.GetInstance().GetCompletedProgress()); }