Beispiel #1
0
        private void startReadBtn_Click(object sender, EventArgs e)
        {
            DownLoadFile downFile = null;
            DownTask     downTask;
            ComicReader  reader = new ComicReader();

            foreach (CheckBox i in checkPanel.Controls)
            {
                if (i.Checked)
                {
                    if (downUrlDic.ContainsKey(i.Text))
                    {
                        downFile           = new DownLoadFile();
                        downFile.ComicUrl  = downUrlDic[i.Text];
                        downFile.ComicName = comicNameLabel.Text.Substring(4) + i.Text;
                        downFile.SavePath  = "temp\\";
                        break;
                    }
                }
            }

            if (downFile == null)
            {
                return;
            }

            downTask = new DownTask();
            downTask.addFileEvent += reader.AddFileToList;
            downTask.ComicName     = downFile.ComicName;
            downTask.DownLoadPath  = downFile.SavePath;
            downTask.ReferUrl      = downFile.ComicUrl;
            downTask.GetNetComic(downFile);
            reader.StartRead();
            reader.Show();
        }
Beispiel #2
0
        void StopDownTask(string taskName)
        {
            DownTask task = null;

            foreach (var i in taskQueue)
            {
                if (i.ComicName == taskName)
                {
                    i.StopDownLoad();
                    task = i;
                }
            }

            if (task != null)
            {
                taskQueue.Remove(task);
            }
        }
Beispiel #3
0
        private void startReadBtn_Click(object sender, EventArgs e)
        {
            DownLoadFile downFile = null;
            DownTask     downTask;
            ComicReader  reader = new ComicReader();

            reader.readFinishedEvent += Reader_readFinishedEvent;
            ListViewItemInfo item = currentItem as ListViewItemInfo;

            foreach (Controls.CheckBoxEx i in checkPanel.Controls)
            {
                if (i.Checked)
                {
                    if (item.UrlDictronary.ContainsKey(i.FullText))
                    {
                        downFile           = new DownLoadFile();
                        downFile.ComicUrl  = item.UrlDictronary[i.FullText];
                        downFile.ComicName = comicNameLabel.Text.Substring(4) + i.Text;
                        downFile.SavePath  = "temp\\";
                        break;
                    }
                }
            }

            if (downFile == null)
            {
                return;
            }

            downTask = new DownTask();
            downTask.addFileEvent += reader.AddFileToList;
            downTask.ComicName     = downFile.ComicName;
            downTask.DownLoadPath  = downFile.SavePath;
            downTask.SourceUrl     = downFile.ComicUrl;
            downTask.GetNetComic(downFile);
            reader.StartRead();
            reader.Show();
        }
Beispiel #4
0
        void downItem_resumeDownLoadEvent(object sender, EventArgs args)//继续下载
        {
            DownTask    task    = null;
            DownListBox listBox = sender as DownListBox;

            foreach (var i in taskQueue)
            {
                if (i.ComicName == listBox.Title)
                {
                    task = i;
                }
            }

            if (task == null)
            {
                SqlOperate operate = new SqlOperate();
                operate.CreateOrOpenDataBase("task.db");
                var list = operate.GetRecordList();

                foreach (var i in list)
                {
                    if (i.TaskName == listBox.Title)
                    {
                        List <DownLoadFile> downList = new List <DownLoadFile>();
                        DownLoadFile        file     = new DownLoadFile();
                        file.ComicName = i.TaskName;
                        file.ComicUrl  = i.Url;
                        file.SavePath  = i.Path;
                        downList.Add(file);
                        StartNewDownLoad(downList, DecoderDistrution.GiveDecoder(i.Url), i.DownLoadProgress - 1);
                    }
                }

                operate.CloseDataBase();
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }