コード例 #1
0
        private void downloadBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (pathTxt.Text.Equals("") || pathTxt.Text == null)
                    throw new Exception("Path is not Valid!");

                if(!Path.IsPathRooted(pathTxt.Text))
                    throw new Exception("Path is not Valid!");

                string [] lst = PageParser.ParsePagesList(urlTxt.Text);
                Doujin doujin = new Doujin(PageParser.ParseDoujinName(urlTxt.Text));
                string directory = Path.Combine(pathTxt.Text,doujin.Name);
                doujin.DownloadPath = directory;

                int i = 0;
                foreach (var url in lst)
                {
                    string pageName = PageParser.ParsePageIndexName(i, lst.Length, url);
                    DoujinPage page = new DoujinPage(pageName, url);
                    doujin.AddPage(page);
                    i++;
                }
                Directory.CreateDirectory(directory);
                DownloadForm downloader = new DownloadForm(doujin);
                downloader.ShowDialog();

            }
            catch(Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK);
            }
        }
コード例 #2
0
 public DownloadForm(Doujin d)
 {
     InitializeComponent();
     this.doujin = d;
     this.Text = "Downloading - " + doujin.Name;
     this.PageName.Text = d.PageList.First().Name;
     PageDownloader.webClient.DownloadProgressChanged += (s, e) =>
     {
         this.DownloadProgressBar.Value = e.ProgressPercentage;
     };
     PageDownloader.webClient.DownloadFileCompleted += (s, e) =>
     {
         this.PageName.Text = PageDownloader.CurrentPage;
     };
     PageDownloader.OnDoujinDownloadFinished += (s, e) =>
     {
         MessageBox.Show("Finished downloading: " + d.Name);
         this.Dispose();
     };
 }
コード例 #3
0
 public async static void DownloadDoujin(Doujin doujin)
 {
     List<DoujinPage> pages = doujin.PageList;
     webClient.DownloadFileCompleted += (s, e) =>
     {
         webClient.Dispose();
     };
     try
     {
         foreach (var p in pages)
         {
             CurrentPage = p.Name;
             Uri url = new Uri(p.Url, UriKind.Absolute);
             await webClient.DownloadFileTaskAsync(url, Path.Combine(doujin.DownloadPath, p.Name));
         }
         CurrentPage = null;
         DownloadFinished();
     }
     catch (Exception e)
     {
         e.ToString();
     }
 }