Exemple #1
0
        private async void Download()
        {
            groupBox1.Text = "开始下载";
            ChapterInfoData cif = new ChapterInfoData(book);

            List <ChapterInfo> chapterInfos = cif.GetChapterInfos();

            progressBar1.Maximum = chapterInfos.Count;

            HttpClient client = new HttpClient();

            for (int i = 0; i < chapterInfos.Count; i++)
            {
download:
                {
                    try
                    {
                        ChapterInfo item = chapterInfos[i];
                        string      html = await client.GetStringAsync(item.Url);

                        Match macth = Regex.Match(html, "<script>window.location.href='(.*)';</script>");
                        if (macth.Length > 0 && macth.Groups.Count > 1)
                        {
                            html = await client.GetStringAsync(macth.Groups[1].Value);
                        }
                        groupBox1.Text = item.Title;
                        item.Content   = NSoupClient.Parse(html).Select("div[id=content]").Html()
                                         .Replace(" ", "")
                                         .Replace("&nbsp;", " ")
                                         .Replace("<br>", "\r\n")
                                         .Replace("<br/>", "\r\n")
                                         .Replace("<scripttype=\"text/javascript\"src=\"/js/chaptererror.js\"></script>", "");
                        progressBar1.Value++;
                    }
                    catch (HttpRequestException httpRequestException)
                    {
                        Log.Info(httpRequestException.Message);
                        if (MessageBox.Show("下载遇到问题,是否重试", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            goto download;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            cif.Save(chapterInfos);
            this.Close();
        }
Exemple #2
0
        private void FrmRead_Load(object sender, EventArgs e)
        {
            ChapterInfoData cif = new ChapterInfoData(book);

            chapterInfos = cif.GetChapterInfos();

            LoadListBox();

            if (listBox1.Items.Count > 0)
            {
                listBox1.SelectedIndex = 0;
                LoadContent();
                LoadTitle();
            }

            FrmRead_Resize(null, null);

            RecoveryConfiguration();
        }