Пример #1
0
        public void DoWorkInitialize(object sender, DoWorkEventArgs e)
        {
            switch (Processing)
            {
                case Algorithm.Initialize:
                    Settings = new DialogSetting();
                    ThreadWorker.ReportProgress(-1);
                    if (!Directory.Exists(TempFiles)) Directory.CreateDirectory(TempFiles);
                    break;
                case Algorithm.Verfify:
                    Int32 iReq = 0;
                    do {
                        UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_VERUFY");
                        ThreadWorker.ReportProgress(-2);
                        Thread.Sleep(1000);
                        SyncNet dnsVerify = new SyncNet(RequestURL[iReq].ToString());
                        if (dnsVerify.Connected)
                        {
                            Int32 ContentLenght = 0;
                            Int32 NowLenght = 0;
                            Dictionary<String, String> Response = dnsVerify.ResponseHeader("");
                            if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);

                            String ResponseHTML = "";
                            if (Response["HTTP"] == "200 OK")
                            {
                                // Speed Checking kb/s Timer.
                                ThreadWorker.ReportProgress(-3);
                                do
                                {
                                    ResponseHTML += dnsVerify.Response(Int32.Parse(Settings.Configs.GetValue("Speed")) * 1024);
                                    NowLenght += dnsVerify.Downloading;
                                    UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_CONNECTING");
                                    ThreadWorker.ReportProgress((Int32)((NowLenght * 100) / ContentLenght));
                                    ResponseLenght += dnsVerify.Downloading;
                                } while (NowLenght < ContentLenght);
                                ThreadWorker.ReportProgress(-4);

                                if (ResponseHTML.Trim() != "Key missing, or incorrect key provided.")
                                {
                                    String NameManga = SplitUp.GetCenter(ResponseHTML, "<h1 id=\"gn\">", "</h1>").Trim();
                                    String PagesManga = SplitUp.GetCenter(ResponseHTML, "Images:</td><td class=\"gdt2\">", "</td>").Trim();
                                    String SizesManga = SplitUp.GetRight(PagesManga, " @ ").Trim();
                                    if (NameManga != "" && PagesManga != "" && SizesManga != "")
                                    {
                                        PagesManga = SplitUp.GetLeft(PagesManga, " @ ").Trim();
                                        // Thai Encoding
                                        Byte[] byteName = Encoding.UTF8.GetBytes(NameManga);
                                        NameManga = Encoding.UTF8.GetString(byteName, 0, byteName.Length);
                                        String RatingManga = "";
                                        for (Int16 iRating = 0; iRating < (Int32)Math.Round(Double.Parse(SplitUp.GetCenter(ResponseHTML, "original_rating = ", ";").Trim()), 0); iRating++) RatingManga += "* ";
                                        String gidToken = SplitUp.GetCenter(ResponseHTML, "gid = ", ";").Trim() + "_" + SplitUp.GetCenter(ResponseHTML, "token = \"", "\";").Trim();

                                        ListImages = new List<String>();
                                        Int32 PageLoop = 0;
                                        do
                                        {
                                            PageLoop++;
                                            ResponseHTML = SplitUp.GetRight(ResponseHTML, "<p class=\"ip\">Showing");
                                            ResponseHTML = SplitUp.GetLeft(ResponseHTML, "<table class=\"ptb\" style=\"margin:0px auto 10px\">");
                                            foreach (String list in Regex.Split(ResponseHTML, "<a href=\"http://"))
                                            {
                                                String ImageUrl = SplitUp.GetLeft(list, "\"><img alt=");
                                                if (Regex.IsMatch(ImageUrl, dnsVerify.DomainName) && !Regex.IsMatch(ImageUrl, "Images"))
                                                {
                                                    ListImages.Add(ImageUrl.Trim());
                                                    Console.WriteLine(ImageUrl.Trim());
                                                }
                                            }

                                            if (ListImages.Count < Int32.Parse(PagesManga))
                                            {
                                                ContentLenght = 0;
                                                NowLenght = 0;
                                                UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_CONNECTING")
                                                    + " " + (PageLoop + 1) + "/" + Math.Ceiling(float.Parse(PagesManga) / 20).ToString() + " " + Settings.Configs.GetValue("NOW_PAGE");
                                                ThreadWorker.ReportProgress(0);
                                                Thread.Sleep(500);
                                                dnsVerify = new SyncNet(RequestURL[iReq].ToString());
                                                if (dnsVerify.Connected)
                                                {
                                                    Response = dnsVerify.ResponseHeader("?p=" + PageLoop);
                                                    if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);

                                                    ResponseHTML = "";
                                                    ThreadWorker.ReportProgress(-3);
                                                    do
                                                    {
                                                        ResponseHTML += dnsVerify.Response(Int32.Parse(Settings.Configs.GetValue("Speed")) * 1024);
                                                        NowLenght += dnsVerify.Downloading;
                                                        UpdateTexting = "[" + (iReq + 1) + "/" + RequestURL.Count + "] " + Settings.Configs.GetValue("NOW_CONNECTING")
                                                            + " " + (PageLoop + 1) + "/" + Math.Ceiling(float.Parse(PagesManga) / 20).ToString() + " " + Settings.Configs.GetValue("NOW_PAGE");
                                                        ThreadWorker.ReportProgress((Int32)((NowLenght * 100) / ContentLenght));
                                                        ResponseLenght += dnsVerify.Downloading;
                                                    } while (NowLenght < ContentLenght);
                                                    ThreadWorker.ReportProgress(-4);
                                                }
                                            }
                                        } while (ListImages.Count < Int32.Parse(PagesManga));


                                        NewItems = new ListViewItem(new ListViewItem.ListViewSubItem[] {
                                            new ListViewItem.ListViewSubItem(null, (ListHentai.Items.Count+1).ToString()),  // ID
                                            new ListViewItem.ListViewSubItem(null, NameManga),           // Name
                                            new ListViewItem.ListViewSubItem(null, SizesManga),           // Size
                                            new ListViewItem.ListViewSubItem(null, PagesManga),         // Page
                                            new ListViewItem.ListViewSubItem(null, RatingManga.Trim(), Color.Maroon, Color.White, new Font("Segoe UI", 8.25F,FontStyle.Bold)),  // Rating
                                            new ListViewItem.ListViewSubItem(null, Settings.Configs.GetValue("STATUS_STOP") + " (0%)", Color.Brown, Color.White, new Font("Tahoma", 8.25F)),             // Status
                                            new ListViewItem.ListViewSubItem(null, ""),             // Speed
                                            new ListViewItem.ListViewSubItem(null, gidToken),   // Index Images
                                            new ListViewItem.ListViewSubItem(null, RequestURL[iReq].ToString())}, -1);   // URL

                                        ThreadWorker.ReportProgress(-5);

                                        // Save To Dump Folder
                                        String id_name = Directory.GetFiles(TempFiles).Length.ToString();
                                        while (id_name.Length < IDMax) id_name = "0" + id_name;

                                        Config NewList = new Config(NewItems.SubItems[1].Text + " Dump Files ",
                                            TempFiles + id_name + "-" + NewItems.SubItems[1].Text + ".txt");

                                        NewList.Save("URL", new String[] { NewItems.SubItems[8].Text });
                                        NewList.Save("Key", new String[] { NewItems.ImageIndex.ToString() });
                                        NewList.Save("Name", new String[] { NewItems.SubItems[1].Text });
                                        NewList.Save("Sizes", new String[] { NewItems.SubItems[2].Text });
                                        NewList.Save("Pages", new String[] { NewItems.SubItems[3].Text });
                                        NewList.Save("Rating", new String[] { NewItems.SubItems[4].Text });
                                        NewList.Save("Status", new String[] { NewItems.SubItems[5].Text });
                                        NewList.Save("ID", new String[] { NewItems.SubItems[7].Text });
                                        NewList.Save("Links", ListImages.ToArray());
                                        NewList.Write();
                                        NewList.Close();
                                    }
                                    else
                                    {
                                        ThreadWorker.ReportProgress(-8);
                                    }                                    
                                }
                                else
                                {
                                    ThreadWorker.ReportProgress(-8);
                                }
                            }
                            else
                            {
                                ThreadWorker.ReportProgress(-8);
                            }
                        }
                        else
                        {
                            Console.WriteLine("DNS Error");
                            ThreadWorker.ReportProgress(-9);
                        }
                        iReq++;
                    } while (iReq < RequestURL.Count);
                    break;
            }
        }
Пример #2
0
        public void DoWorkDownloade(object sender, DoWorkEventArgs e)
        {
            ImagesCurrent = 0;
            Int32 FileCurrent = 0;
            String[] ListFiles = Directory.GetFiles(TempFiles);
            do
            {
                if (DownloadWorker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    String FileName = ListFiles[FileCurrent];
                    Config Items = new Config("", FileName);
                    Items.Close();
                    String ImageFolder = Settings.Configs.GetValue("Folder") + Items.GetValue("Name") + "\\";
                    if (Items.GetValue("Key") != "2")
                    {
                        DownloadWorker.ReportProgress(-1);
                        CurrentItem = Items.GetValue("ID");
                        TotalImages = Items.GetList("Links").Count;
                        foreach (String url in Items.GetList("Links"))
                        {
                            Console.WriteLine("----------------------------------------------------------------");
                            if (DownloadWorker.CancellationPending == true)
                            {
                                e.Cancel = true;
                                break;
                            }
                            else
                            {                                
                                Boolean ImageFailsLoading;
                                String RetryImage = "";
                                String URLImage = "";
                                Int32 ImageError = 0;
                                do
                                {
                                    ImageFailsLoading = true;
                                    Items = new Config(Items.HeaderTitle, FileName);

                                    Thread.Sleep(100);
                                    if (DownloadWorker.CancellationPending == true)
                                    {
                                        e.Cancel = true;
                                        break;
                                    }
                                    else
                                    {
                                        Int32 ContentLenght = 0;
                                        Int32 NowLenght = 0;
                                        Int32 ImageLenght = 0;
                                        String ImageName = "";                                        
                                        String ResponseHTML = "";
                                        Boolean ReceiveLink = true;
                                        Boolean ReceiveImage = true;
                                        Dictionary<String, String> Response;
                                        List<String> Images = Items.GetList("Images");
                                        Console.WriteLine("Images: " + Images.Count + " Current: " + (ImagesCurrent + 1));

                                        if (Images.Count > ImagesCurrent)
                                        {
                                            String[] data = Regex.Split(Images[ImagesCurrent].Trim(), "#");
                                            ImageName = data[0];
                                            if (data[1] != "") ImageLenght = Int32.Parse(data[1]);
                                        }

                                        if (ImageLenght != 0 && File.Exists(ImageFolder + ImageName))
                                        { // Check Image File                                           
                                            Console.WriteLine("Exists Image: " + ImageName);
                                            FileStream ImageStream = new FileStream(ImageFolder + ImageName, FileMode.Open, FileAccess.Read);
                                            if (ImageStream.Length != ImageLenght)
                                            {
                                                ImageStream.Close();
                                                File.Delete(ImageFolder + ImageName);
                                                Console.WriteLine(" <<===== Exists: false");
                                            }
                                            else
                                            {
                                                ImagesCurrent++;
                                                ReceiveLink = false;
                                                ReceiveImage = false;
                                                ImageFailsLoading = false;
                                                Console.WriteLine(" <<===== Exists: true");
                                            }
                                            if (ImageStream.CanRead) ImageStream.Close();
                                        }

                                        if (ReceiveLink)
                                        { // Get Images From URL
                                            Console.WriteLine("Geting URL...");
                                            SyncNet DnsGetingURL = new SyncNet(url);
                                            if (DnsGetingURL.Connected)
                                            {
                                                Response = DnsGetingURL.ResponseHeader(RetryImage);
                                                // foreach (KeyValuePair<String, String> head in Response) Console.WriteLine(head.Key + ": " + head.Value);
                                                if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);

                                                if (Response["HTTP"] == "200 OK" && ContentLenght != 0)
                                                { // Start receiving data
                                                    Console.WriteLine("Start receiving URL...");
                                                    DownloadWorker.ReportProgress(-2);
                                                    do
                                                    {
                                                        ResponseHTML += DnsGetingURL.Response(Int32.Parse(Settings.Configs.GetValue("Speed")) * 1024);
                                                        NowLenght += DnsGetingURL.Downloading;
                                                        DownloadWorker.ReportProgress((NowLenght * 5) / ContentLenght);
                                                        // Console.WriteLine("Lenght:" + ContentLenght + " Speed: " + DnsGetingURL.Downloading + " | Total: " + NowLenght);
                                                    } while (NowLenght < ContentLenght && DnsGetingURL.Downloading != 0);
                                                    DownloadWorker.ReportProgress(-3);
                                                    if (RetryImage == "") RetryImage += "?nl="; else RetryImage += "&nl=";
                                                    String nlString = SplitUp.GetCenter(ResponseHTML, "onclick=\"return nl", "\">Click here if the image fails loading");
                                                    RetryImage += nlString.Substring(1, (nlString.Length - 2));

                                                    ResponseHTML = SplitUp.GetCenter(ResponseHTML, "</iframe>", "</iframe>");
                                                    ResponseHTML = SplitUp.GetCenter(ResponseHTML, "<img src=\"", "\"");
                                                    URLImage = ResponseHTML;                                                    
                                                    ImageName = SplitUp.GetRight(SplitUp.GetRight(URLImage, "keystamp="), "/");
                                                    if (ImageName == "")
                                                    {

                                                    }
                                                    if (Images.Count > ImagesCurrent) Images.RemoveAt(ImagesCurrent);
                                                    Console.WriteLine("ImageName: " + ImageName);
                                                    Images.Add(ImageName + "#");
                                                    Items.Save("Images", Images.ToArray());
                                                }
                                                else
                                                { // Error Page Connecting                                                    
                                                    Console.WriteLine(" ===>> Page :: " + Response["HTTP"] + " <<===");
                                                    ReceiveImage = false;
                                                    ImageFailsLoading = false;
                                                }
                                            }
                                            else
                                            { // Error Page Loading Image.
                                                Console.WriteLine(" ===>> Page :: Fails Connected <<===");
                                                ReceiveImage = false;
                                                ImageFailsLoading = false;
                                                e.Cancel = true;
                                            }
                                        }

                                        if (ReceiveImage)
                                        { // Start receiving data
                                            Console.WriteLine("Loading Images...");
                                            SyncNet DnsLoadImage = new SyncNet(URLImage);
                                            if (DnsLoadImage.Connected)
                                            {
                                                Response = DnsLoadImage.ResponseHeader("");
                                                // foreach (KeyValuePair<String, String> head in Response) Console.WriteLine(head.Key + ": " + head.Value);
                                                if (Response.ContainsKey("HTTP"))
                                                {
                                                    if (Response.ContainsKey("Content-Length")) ContentLenght = Int32.Parse(Response["Content-Length"]);
                                                    if (!Response.ContainsKey("Content-Disposition") && Response["HTTP"] == "200 OK")
                                                    {
                                                        Images[ImagesCurrent] = ImageName + "#" + ContentLenght;
                                                        Items.Save("Images", Images.ToArray());                                                        
                                                        Console.WriteLine("Start receiving Images...");
                                                        DownloadWorker.ReportProgress(-2);
                                                        if (!Directory.Exists(ImageFolder)) Directory.CreateDirectory(ImageFolder);
                                                        Boolean ImageExists = false;
                                                        if (File.Exists(ImageFolder + ImageName))
                                                        {
                                                            FileStream ImageStream = new FileStream(ImageFolder + ImageName, FileMode.Open, FileAccess.Read);
                                                            if (ImageStream.Length != ContentLenght)
                                                            {
                                                                ImageStream.Close();
                                                                File.Delete(ImageFolder + ImageName);
                                                            }
                                                            else
                                                            {
                                                                ImageExists = true;
                                                            }
                                                            if (ImageStream.CanRead) ImageStream.Close();
                                                        }

                                                        if (!ImageExists)
                                                        {
                                                            FileStream ImageStream = new FileStream(ImageFolder + ImageName, FileMode.CreateNew, FileAccess.ReadWrite);
                                                            do
                                                            {
                                                                DnsLoadImage.Response(ImageStream, Int32.Parse(Settings.Configs.GetValue("Speed")) * 1024);
                                                                NowLenght += DnsLoadImage.Downloading;
                                                                // Console.WriteLine("Speed: " + DnsLoadImage.Downloading + " | Total: " + NowLenght);
                                                                DownloadWorker.ReportProgress(((NowLenght * 95) / ContentLenght) + 5);
                                                                ResponseLenght += DnsLoadImage.Downloading;                                                                
                                                            } while (NowLenght < ContentLenght);
                                                            DownloadWorker.ReportProgress(-3);
                                                            ImagesCurrent++;
                                                            ImageFailsLoading = false;
                                                            Console.WriteLine("File: " + NowLenght + "<=>" + ContentLenght);
                                                            if (ImageStream.CanRead) ImageStream.Close();
                                                        }
                                                        
                                                    }
                                                    else
                                                    {
                                                        Console.WriteLine(" ===>> Image :: " + Response["HTTP"] + " <<===");
                                                        if (ImageError < 2) Images.RemoveAt(ImagesCurrent);
                                                        if (ImageError < 2) Items.Save("Images", Images.ToArray());
                                                        ImageError++;
                                                    }
                                                }
                                                else
                                                {
                                                    Console.WriteLine(" ===>> Image :: Fails Receieves <<===");
                                                    if (ImageError < 2) Images.RemoveAt(ImagesCurrent);
                                                    if (ImageError < 2) Items.Save("Images", Images.ToArray());
                                                    ImageError++;
                                                }
                                            }
                                            else
                                            { // Error Image Connecting
                                                Console.WriteLine(" ===>> Image :: Fails Connected <<===");
                                                if (ImageError < 2) Images.RemoveAt(ImagesCurrent);
                                                if (ImageError < 2) Items.Save("Images", Images.ToArray());
                                                ImageError++;
                                            }
                                        }
                                    }                                    
                                    Console.WriteLine("ERROR: " + ImageError);
                                    Items.Save("Status", new String[] { Settings.Configs.GetValue("STATUS_STOP") + " " + Math.Round((float)((ImagesCurrent + 1) * 100) / TotalImages, 0) + "%" });
                                    Items.Write();
                                    Items.Close();
                                    if (ImageError > 2) ImageFailsLoading = false; 
                                } while (ImageFailsLoading);

                            } // Endif CancellationPending
                        }
                    }
                    ListFiles = Directory.GetFiles(TempFiles);
                    FileCurrent++;                
                } // Endif CancellationPending
            } while (ImagesCurrent < ListFiles.Length);
        }