예제 #1
0
 private long DownloadFile(string url, string path)
 {
     try
     {
         this.ItemName.Text = string.Format(this.downloadLabelTemplate,this.itemsDownloaded, this.photosInAlbum, Path.GetFileName(url));
         httpDownloader = new HttpDownloaderFactory(url);
         httpDownloader.DownloadProgress += (s, e) =>
         {
             this.CurrentProgress.Value = (int)e.PercentComplete;
             Application.DoEvents();
         };
         return httpDownloader.DownloadToFile(path + Path.GetFileName(url), true);
     }
     catch
     {
         return 0;
     }
 }
예제 #2
0
        // аццке метод загрузки файлов
        private void Download()
        {
            try
            {
                if (FB.ShowDialog() == DialogResult.OK)
                {
                    this.downloadInProgress = true;
                    this.itemsToDownload = this.AudioList.CheckedItems.Count;
                    this.TotalProgress.Maximum = this.itemsToDownload;
                    this.DownloadPanel.Visible = true;
                    this.TotalProgress.Value = 0;
                    this.AudioList.Enabled = false;

                    int itemsDownloaded = 1;

                    for (int itemId = 0; itemId < this.AudioList.Items.Count; itemId++)
                    {
                        if (!this.exitPending)
                        {
                            if (this.AudioList.GetItemCheckState(itemId) == CheckState.Checked)
                            {
                                AudioEntry a = this.AudioList.Items[itemId] as AudioEntry;
                                this.SongName.Text = Convert.ToString(itemsDownloaded) + "/" + this.itemsToDownload.ToString() + " " + a.ToString();

                                httpDownloader = new HttpDownloaderFactory(a.Url);
                                httpDownloader.DownloadProgress += (s, e) =>
                                    {

                                        this.CurrentProgress.Value = (int)e.PercentComplete;
                                        Application.DoEvents();
                                    };
                                // Убираем из названий песен все символы, кроме букв алфавита, знаков препинания,
                                // и прочих разрешенных
                                Regex r = new Regex(@"[^A-Za-zA-Яа-я0-9\ \,\.\!\+\=\)\(\&\%\$\#\@\-\{\}\[\]]");
                                httpDownloader.DownloadToFile(FB.SelectedPath + "\\" + r.Replace(a.ToString(), "") + Path.GetExtension(a.Url));

                                this.TotalProgress.Value++;
                                this.AudioList.SetItemChecked(itemId, false);
                                itemsDownloaded++;
                            }
                        }
                    }

                    this.DownloadPanel.Visible = false;
                    this.AudioList.Enabled = true;
                    this.downloadInProgress = false;
                }
                else
                {

                }
            }
            catch (Exception e)
            {
                this.DownloadPanel.Visible = false;
                this.AudioList.Enabled = true;
                this.downloadInProgress = false;
                MessageBox.Show("Some errors ocurred while downloading songs:\n"+e.Message);
            }
        }