using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Project1.interfaces.observer; using Project1.utilities; using Project1.globals; namespace Project1.GUI { public partial class DownloadForm : Form,IObserver { private string strUri; private string strfileName; private string strDownloadPath; Int64 kbFileSize; FileGrabber fg; public DownloadForm(Uri uri, String downloadPath) { InitializeComponent(); this.Show(); lblKBDownloaded.Text = "0KB"; lblPercentComplete.Text = "0% complete"; strUri = uri.ToString(); this.strDownloadPath = downloadPath; strfileName = uri.Segments[uri.Segments.Length - 1]; lblFileName.Text = strfileName; this.Show(); initialiseDownload(uri); } private void initialiseDownload(Uri uri){ try { fg = new FileGrabber(uri); fg.RegisterObserver(this); kbFileSize = fg.FileSize / 1024; lblSize.Text = kbFileSize.ToString() + "KB"; if (fg.downloadFile(strDownloadPath)) { MessageBox.Show("Download Complete"); } this.Close(); } catch (Exception e) { MessageBox.Show(e.Message); this.Close(); } } public void update() { Int64 kbRead = fg.BytesRead / 1024; lblPercentComplete.Text = fg.PercentComplete.ToString() + "% Complete"; lblKBDownloaded.Text = kbRead.ToString() + " / " + kbFileSize; } } }