/// <summary> /// 批量下载 判断完成后 需要支持EasyThread.Stop /// 开线程 /// </summary> /// <param name="list">所有需要下载的内容</param> /// <param name="callback">当前文件本地大小、当前文件服务器大小、所有文件本地大小、所有文件服务器大小、当前文件</param> /// <param name="errorCallback"></param> public void BatchDownload(List <DownloadUnit> list, Action <Size, DownloadUnit, bool> callback, System.Action <DownloadUnit> errorCallback = null) { //Debug.Log("1"); EasyThread downloadThread = null; downloadThread = new EasyThread(() => { download(list, callback, downloadThread, errorCallback); downloadThread.Stop(); }); downloadThread.Start(); }
/// <summary> /// 单个下载 /// 开线程 /// </summary> /// <param name="downUnit"></param> /// <param name="precentCallback">下载进度回调</param> public void SingleDownload(DownloadUnit downUnit, System.Action <long, long, bool> callback, System.Action <DownloadUnit> errorCallback = null) { if (File.Exists(downUnit.FullPath)) { if (callback != null) { callback(1, 1, true); } return; } EasyThread downloadThread = null; downloadThread = new EasyThread(() => { download(downUnit, callback, downloadThread, errorCallback); downloadThread.Stop(); }); downloadThread.Start(); }
//private Dictionary<DownloadUnit, OSSFile> faillist; /// <summary> /// 批量下载 /// </summary> /// <param name="list"></param> /// <param name="callback"></param> public void BatchOSSDownload(Dictionary <DownloadUnit, OSSFile> list, Action <bool> callback) { Dictionary <DownloadUnit, OSSFile> faillist = new Dictionary <DownloadUnit, OSSFile>(); int cureentDownCount = 0; int fallCount = 0; //下载完成的个数统计 用于判断是否全部完成 int i = 0; foreach (var file in list) { //Debug.Log("StartDownload::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size); Loom.QueueOnMainThread((() => { WriteIntoTxt(i + "StartDownload::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size, "list"); i++; })); } int j = 0; foreach (var file in list) { EasyThread et = null; et = new EasyThread((() => { OSSdownload(file.Key, file.Value, (b => { if (b) { Loom.QueueOnMainThread((() => { WriteIntoTxt(j + "DownloadSuccess::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size, "down"); j++; })); // Debug.Log("DownloadSuccess::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size); //HttpManager.Instance.DownLoadcurSize += float.Parse(file.Key.size); } else { fallCount++; faillist.Add(file.Key, file.Value); Debug.LogError("失败:::::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size); Loom.QueueOnMainThread((() => { WriteIntoTxt(j + "DownloadFail::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size, "down"); j++; })); // if (float.Parse(file.Key.size) <= 0 || file.Key.size == null) // { // //HttpManager.Instance.DownLoadcurSize += float.Parse(file.Key.size); // if (cureentDownCount == list.Count) // { // if (callback != null) // { // callback(fallCount <= 0); // } // } // } // else // { // fallCount++; // faillist.Add(file.Key, file.Value); // Debug.LogError("失败:::::::" + file.Key.downUrl + " " + file.Value.endpoint + " " + file.Key.fileName + " " + file.Key.size); // } } cureentDownCount++; Debug.LogWarning("总共 " + list.Count + " 当前 " + cureentDownCount); HttpManager.Instance.DownloadPercent((float)cureentDownCount / (float)list.Count); if (cureentDownCount == list.Count) { callback(fallCount <= 0); } et.Stop(); })); }), ThreadPriority.Highest); et.Start(); } ; }