using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Net; using System.Windows.Forms; namespace GamerServices { public partial class FormFileDownloader : Form { public string URL = ""; public string FilePath = ""; public bool AutoExec = false; public bool Completed = false; public FormFileDownloader() { InitializeComponent(); } public void StartDownload() { WebClient c = new WebClient(); c.Proxy = null; c.DownloadProgressChanged += new DownloadProgressChangedEventHandler(c_DownloadProgressChanged); c.DownloadFileCompleted += new AsyncCompletedEventHandler(c_DownloadFileCompleted); c.DownloadFileAsync(new Uri(URL), FilePath); } void c_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { this.Completed = true; if (e.Cancelled) { MessageBox.Show("Error while downloading file: \"" + URL + "\" to \"" + FilePath + "\""); return; } if (this.AutoExec) System.Diagnostics.Process.Start(FilePath); this.Close(); } void c_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (e.ProgressPercentage > -1 && e.ProgressPercentage < 101) this.progressBar1.Value = e.ProgressPercentage; } } }