Esempio n. 1
0
 public Chapters(Chapters old)
 {
     this.index      = old.index;
     this.is_chapter = old.is_chapter;
     this.number     = old.number;
     this.link       = old.link;
     if (old.tome != null)
     {
         this.tome = new Tome(old.tome);
     }
     else
     {
         this.tome = null;
     }
     this.title      = old.title;
     this.total_page = old.total_page;
     this.date       = old.date;
 }
        private void ButtonStart_Click(object sender, RoutedEventArgs e)
        {
            String textpath = textPath.Text;

            if (textpath == "")
            {
                return;
            }
            isStart = true;
            ButtonStart.IsEnabled = false;
            Buttonstop.IsEnabled  = true;
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;

                while (listDownload.Count > 0 && isStart == true)
                {
                    Download d  = listDownload[0];
                    d.name      = d.name.Replace("/", "-");
                    d.name      = d.name.Replace("\\", "-");
                    d.name      = d.name.Replace(":", "-");
                    d.name      = d.name.Replace("*", ".");
                    d.name      = d.name.Replace("?", "!");
                    d.name      = d.name.Replace("\"", "-");
                    d.name      = d.name.Replace("<", "-");
                    d.name      = d.name.Replace(">", "-");
                    d.name      = d.name.Replace("|", "-");
                    String path = textpath + d.name + "\\";
                    System.IO.Directory.CreateDirectory(path);
                    while (d.chapters.Count > 0 && isStart == true)
                    {
                        Chapters c   = d.chapters[0];
                        String path2 = path;
                        if (c.getTome() != null && isStart == true)
                        {
                            if (c.getTome().getTitle() != null && c.getTome().getTitle() != "" && isStart == true)
                            {
                                c.getTome().title = c.getTome().title.Replace(":", "-");
                                c.getTome().title = c.getTome().title.Replace("*", ".");
                                c.getTome().title = c.getTome().title.Replace("?", "!");
                                c.getTome().title = c.getTome().title.Replace("<", "-");
                                c.getTome().title = c.getTome().title.Replace(">", "-");
                                c.getTome().title = c.getTome().title.Replace("|", "-");

                                path2 = path2 + "Tome " + c.getTome().getNumber() + " - " + c.getTome().getTitle() + "\\";
                            }
                            else if (isStart == true)
                            {
                                path2 = path2 + "Tome " + c.getTome().getNumber() + "\\";
                            }

                            System.IO.Directory.CreateDirectory(path2);
                        }

                        List <String> pages_link = null;
                        int error = 0;

                        pages_link = allSites[d.site - 1].prepareDownload(c);

                        if (error == 0)
                        {
                            int nb_page_real = 0;
                            int nb_page_max  = c.getMax();

                            foreach (String l in pages_link)
                            {
                                int nb_try = 0;

                                while (nb_try < 3)
                                {
                                    try
                                    {
                                        if (nb_try == 0)
                                        {
                                            nb_page_real++;
                                        }
                                        allSites[d.site - 1].downloadScan(l, nb_page_real - 1, c, path2);
                                        pg1Val = (int)((double)((double)(nb_page_real) / (double)(nb_page_max)) * 100.0);
                                        nb_try = 3;
                                    }
                                    catch (Exception g)
                                    {
                                        Debug.WriteLine("Error : " + d.name + " " + c.getNumber() + " page " + nb_page_real);
                                        //listBoxErrors.Items.Add("Error : " + d.name + " " + c.getNumber() + " page " + nb_page_real);
                                        nb_try++;
                                    }
                                }
                            }
                        }
                        d.total_to_dl_real++;
                        pg2Val = (int)((double)((double)(d.total_to_dl_real) / (double)(d.total_to_dl)) * 100.0);
                        if (d.chapters[0].is_chapter)
                        {
                            d.nb_chapter--;
                        }
                        else
                        {
                            d.nb_tome--;
                        }
                        dl_text_val   = d.nb_tome + " Tomes - " + d.nb_chapter + " Chapitres";
                        isTextRefresh = true;
                        d.chapters.RemoveAt(0);
                        saveDownload();
                    }

                    if (listDownload[0].chapters.Count <= 0)
                    {
                        pg1Val = 0;
                        pg2Val = 0;
                        listDownload.RemoveAt(0);
                    }

                    saveDownload();
                    isDownloadRefresh = true;
                }
                isStart = false;
            }).Start();
        }