Esempio n. 1
0
        private void StartNewDownLoad(List <DownLoadFile> downloadFile, PublicThing decoder)//开始全新下载
        {
            var fullPath = "";

            downlistCollection = new List <DownListBox>();

            try
            {
                Task task = new Task(() =>
                {
                    DownListBox downlist = null;

                    foreach (var i in downloadFile)
                    {
                        DownTask downTask = new DownTask();
                        var url           = i.ComicUrl;
                        var response      = AnalyseTool.HttpGet(url);
                        var down          = decoder.GetDownImageList(response);//解析图片真实地址

                        if (filePanel.InvokeRequired)
                        {
                            this.Invoke(new Action(() =>
                            {
                                downlist          = new DownListBox();
                                downTask.ReferUrl = url;
                                downlist.SetMaxPage(down.ImageList.Count); //下载最大值
                                downlist.Title    = i.ComicName;           //漫画名字
                                downlist.Location = new Point(0, panelPos);
                                downlist.Pages    = down.ImageList.Count;
                                filePanel.Controls.Add(downlist);
                            }));
                        }

                        downlistCollection.Add(downlist);                //添加到控件集合
                        downTask.ComicName            = i.ComicName;
                        downTask.downLoadOneFinished += DownOneFinsihed; //下载完成一个图片
                        downTask.downFinished        += DownAllFinished;
                        downTask.downPaused          += DownPause;
                        downTask.ImageFiles           = down.ImageList;

                        if (File.Exists(i.SavePath) == false)
                        {
                            fullPath = i.SavePath + i.ComicName + "\\";
                            Directory.CreateDirectory(i.SavePath + i.ComicName + "\\");
                        }

                        downlist.FilePath     = fullPath;
                        downTask.DownLoadPath = fullPath;
                        time = DateTime.Now;
                        downTask.DownLoadStart();
                        panelPos = panelPos + downlist.Height;
                    }
                });

                task.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine("开始下载出错:{0}", ex.Message);
            }
        }
Esempio n. 2
0
        private void StartNewDownLoad(List <DownLoadFile> downloadFile, PublicThing decoder, int startIndex = 0)//开始全新下载
        {
            var fullPath = "";

            try
            {
                Task task = new Task(() =>
                {
                    DownListBox downItem = null;
                    List <DownListBox> downList;
                    downList = new List <DownListBox>();
                    ShowBallTip("正在解析,请稍等!", "提示");

                    foreach (var i in downloadFile)
                    {
                        DownTask downTask  = new DownTask();
                        var url            = i.ComicUrl;
                        var response       = AnalyseTool.HttpGet(url, url);
                        decoder.currentUrl = url;

                        if (response == "")
                        {
                            MessageBox.Show("下载时获取网页错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        var down = decoder.GetDownImageList(response);//解析图片真实地址

                        if (down == null || down.ImageList == null || down.Count == 0)
                        {
                            MessageBox.Show("获取网页数据失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        this.Invoke(new Action(() =>
                        {
                            downItem                      = SearchDownListBox(i.ComicName);
                            downTask.SourceUrl            = url;
                            downItem.deleteEvent         += downItem_deleteEvent;
                            downItem.resumeDownLoadEvent += downItem_resumeDownLoadEvent;
                            downItem.SetMaxPage(down.ImageList.Count); //下载最大值
                            downItem.Title = i.ComicName;              //漫画名字
                            downItem.Pages = down.ImageList.Count;
                            filePanel.Controls.Add(downItem);
                        }));


                        if (downlistCollection.Contains(downItem) == false)
                        {
                            downlistCollection.Add(downItem);//添加到控件集合
                        }
                        downTask.ComicName            = i.ComicName;
                        downTask.downLoadOneFinished += DownOnePicFinsihed;//下载完成一个图片
                        downTask.downFinished        += DownAllFinished;
                        downTask.downPaused          += DownPause;
                        downTask.ImageFiles           = down.ImageList;

                        if (File.Exists(i.SavePath) == false)
                        {
                            fullPath = i.SavePath + "\\" + i.ComicName + "\\";
                            Directory.CreateDirectory(i.SavePath + "\\" + i.ComicName + "\\");
                        }

                        downItem.FilePath     = fullPath;
                        downTask.DownLoadPath = fullPath;
                        downTask.DownLoadStart(startIndex);
                        taskQueue.Add(downTask);
                        AddDownRecord(downTask.ComicName, downTask.SourceUrl, downTask.DownLoadPath, downTask.ImageFiles.Count, 0, 0);//添加记录到数据库
                        downList.Add(downItem);
                    }

                    ShowBallTip("解析完成,开始下载!", "提示");
                });

                task.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine("开始下载出错:{0}", ex.Message);
            }
        }