+
+void MyFrame::Download(wxInputStream *input)
+{
+ wxProgressDialog progress("Downloading ...", "0% downloaded");
+ wxBufferedInputStream buf_in(*input);
+ wxFileOutputStream f_out("test.url");
+
+ size_t file_size = input->StreamSize();
+ size_t downloaded;
+ int BUFSIZE = (file_size > 100) ? (file_size / 100) : file_size;
+ int bytes_read = BUFSIZE;
+ wxString message;
+ int percents;
+
+ char *buf;
+
+// TODO: Support for streams which don't support StreamSize
+
+ buf = new char[BUFSIZE];
+
+ downloaded = 0;
+ bytes_read = BUFSIZE;
+ while (downloaded < file_size && bytes_read != 0) {
+ bytes_read = buf_in.Read(buf, BUFSIZE).LastRead();
+ f_out.Write(buf, bytes_read);
+ downloaded += bytes_read;
+
+ percents = downloaded * 100 / file_size;
+
+ message = _T("");
+ message << percents << _T("% downloaded");
+ progress.Update(percents, message);
+ }
+
+ delete[] buf;
+}
+