// 中止所有下载任务
        public void AbortAllDownloadTask()
        {
            pendingDownloads.Clear();

            List <DownloadingTask> list = new List <DownloadingTask>(this.m_DownloadingTasks.Values);

            for (int i = 0; i < list.Count; i++)
            {
                DownloadingTask task = list[i];
                if (task != null)
                {
                    HTTPRequest headRequest = task.HeadRequest;
                    if (headRequest != null)
                    {
                        //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(task.DownloadInfo.fileName, "head_abort", 0, task.DownloadInfo.retry.ToString()).Trigger();
                        headRequest.Abort();
                    }
                    if (task.Downloader != null)
                    {
                        //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(task.DownloadInfo.fileName, "abort", task.DownloadInfo.downloadedSize, task.DownloadInfo.retry.ToString()).Trigger();
                        task.Downloader.CancelDownload(false);
                    }
                    task.DownloadInfo.isFinished = true;
                    task.DownloadInfo.retry      = 0;//保证不会再被添加到下载队列里了
                }
            }

            this.m_DownloadingTasks.Clear();
            pendingDownloads.Clear();
            downloadThreads = 0;
        }
        // 开始一个下载任务
        private void StartTask(DownloadInfo taskinfo)
        {
            if (this.m_DownloadingTasks.ContainsKey(taskinfo.fileName))
            {
                Debug.LogErrorFormat("task already in progress :{0}", taskinfo.fileName);
            }
            else
            {
                DownloadingTask value = new DownloadingTask(taskinfo);
                this.m_DownloadingTasks[taskinfo.fileName] = value;

                if (!File.Exists(taskinfo.tempPath))
                {
                    FilePathTools.CreateFolderByFilePath(taskinfo.tempPath);
                    File.Create(taskinfo.tempPath).Dispose();
                }

                using (var sw = new FileStream(taskinfo.tempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    taskinfo.downloadedSize = (int)sw.Length;
                }

                HttpDownload(value);
            }
        }
        // 新建下载器开始下载
        private void HttpDownload(DownloadingTask task)
        {
            Debug.LogFormat("Start Download:{0}", task.DownloadInfo.fileName);

            DownloadingTask tmpTask     = task;
            HTTPRequest     httprequest = new HTTPRequest(new Uri(tmpTask.DownloadInfo.url), HTTPMethods.Head, (req, rep) =>
            {
                switch (req.State)
                {
                case HTTPRequestStates.ConnectionTimedOut:
                case HTTPRequestStates.TimedOut:
                    //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(tmpTask.DownloadInfo.fileName, "head_timeout", 0, tmpTask.DownloadInfo.retry.ToString()).Trigger();
                    break;

                case HTTPRequestStates.Aborted:
                    //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(tmpTask.DownloadInfo.fileName, "head_abort", 0, tmpTask.DownloadInfo.retry.ToString()).Trigger();
                    break;

                case HTTPRequestStates.Error:
                    //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(tmpTask.DownloadInfo.fileName, "head_failure", 0, tmpTask.DownloadInfo.retry.ToString()).Trigger();
                    break;

                case HTTPRequestStates.Finished:
                    if (rep != null && rep.StatusCode >= 200 && rep.StatusCode < 400)
                    {
                        //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(tmpTask.DownloadInfo.fileName, "head_finish", 0, tmpTask.DownloadInfo.retry.ToString()).Trigger();
                    }
                    else
                    {
                        //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(tmpTask.DownloadInfo.fileName, "head_failure", 0, tmpTask.DownloadInfo.retry.ToString()).Trigger();
                    }
                    break;
                }

                if (!this.m_DownloadingTasks.ContainsKey(tmpTask.DownloadInfo.fileName))
                {
                    Debug.LogErrorFormat("Cancelled Task :{0}", tmpTask.DownloadInfo.fileName);
                    return;
                }

                tmpTask.HeadRequest = null;
                if (rep == null)
                {
                    Debug.LogErrorFormat("Download failed due to network for :{0}", tmpTask.DownloadInfo.fileName);
                    tmpTask.DownloadInfo.result = DownloadResult.ServerUnreachable;
                    RetryDownload(tmpTask.DownloadInfo);
                }
                else if (rep.StatusCode == 200)
                {
                    try
                    {
                        string firstHeaderValue           = rep.GetFirstHeaderValue("Content-Length");
                        tmpTask.DownloadInfo.downloadSize = int.Parse(firstHeaderValue);
                        Debug.LogFormat("Will download {0} bytes for  '{1}'", tmpTask.DownloadInfo.downloadSize, tmpTask.DownloadInfo.fileName);
                        BreakPointDownloader downloader = new BreakPointDownloader(tmpTask.DownloadInfo, this.m_DownloadingTasks);
                        tmpTask.Downloader = downloader;
                        downloader.StartDownload();
                    }
                    catch (Exception ex)
                    {
                        Debug.LogErrorFormat("An error occured during download '{0}' due to {1}", tmpTask.DownloadInfo.fileName, ex);
                        tmpTask.DownloadInfo.result = DownloadResult.Failed;
                        RetryDownload(tmpTask.DownloadInfo);
                    }
                }
                else
                {
                    Debug.LogErrorFormat("Response is not ok! for: {0}", tmpTask.DownloadInfo.url);
                    tmpTask.DownloadInfo.result = DownloadResult.Failed;
                    RetryDownload(tmpTask.DownloadInfo);
                }
            })
            {
                DisableCache = true
            };

            this.m_DownloadingTasks[tmpTask.DownloadInfo.fileName].HeadRequest = httprequest;
            //EventManager.Instance.Trigger<SDKEvents.DownloadFileEvent>().Data(tmpTask.DownloadInfo.fileName, "head_start", 0, tmpTask.DownloadInfo.retry.ToString()).Trigger();
            httprequest.Send();
        }