Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void StartDownload(string URL, string fileName)
- {
- Thread thread = new Thread(() =>
- {
- WebClient wc = new WebClient();
- wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ClientDownloadProgressChanged);
- wc.DownloadFileCompleted += (sender, e) => ClientDownloadFileCompleted(sender, e, fileName);
- wc.DownloadFileAsync(new Uri(URL), fileName);
- });
- thread.Start();
- rtBox.Text = fileName.Replace(directory, "") + " está sendo baixado";
- }
- void ClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- BeginInvoke((MethodInvoker)delegate
- {
- rtBox.Text += ".";
- if (rtBox.Text == "data.rar está sendo baixado.....")
- rtBox.Text = "data.rar está sendo baixado";
- double bytesIn = double.Parse(e.BytesReceived.ToString());
- double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
- double percentage = bytesIn / totalBytes * 100;
- label2.Text = "Baixado " + (e.BytesReceived) / 1024 + " KBs de " + (e.TotalBytesToReceive) / 1024 + " KBs";
- progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
- });
- }
- void ClientDownloadFileCompleted(object sender, AsyncCompletedEventArgs e, string fileName)
- {
- BeginInvoke((MethodInvoker)delegate
- {
- rtBox.Text = string.Empty;
- rtBox.Text += "Arquivo " + fileName.Replace(directory, "") + " baixado\n";
- if (fileName.Replace(directory, "") == "data.rar")
- {
- label2.Text = "Atualização completa!";
- UnRAR(fileName);
- LineChanger(server_version, "pid.txt", 4);
- Process.Start(File.ReadLines("pid.txt").Skip(5).Take(1).First());
- Application.Exit();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement