SHARE
TWEET

Untitled

a guest Jul 20th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         private void StartDownload(string URL, string fileName)
  2.         {
  3.             Thread thread = new Thread(() =>
  4.             {                
  5.                 WebClient wc = new WebClient();
  6.                 wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ClientDownloadProgressChanged);
  7.                 wc.DownloadFileCompleted += (sender, e) => ClientDownloadFileCompleted(sender, e, fileName);
  8.                 wc.DownloadFileAsync(new Uri(URL), fileName);                
  9.             });
  10.             thread.Start();
  11.             rtBox.Text = fileName.Replace(directory, "") + " está sendo baixado";
  12.         }
  13.         void ClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  14.         {
  15.             BeginInvoke((MethodInvoker)delegate
  16.             {
  17.                 rtBox.Text += ".";
  18.                 if (rtBox.Text == "data.rar está sendo baixado.....")
  19.                     rtBox.Text = "data.rar está sendo baixado";
  20.  
  21.                 double bytesIn = double.Parse(e.BytesReceived.ToString());
  22.                 double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
  23.                 double percentage = bytesIn / totalBytes * 100;
  24.                 label2.Text = "Baixado " + (e.BytesReceived) / 1024 + " KBs de " + (e.TotalBytesToReceive) / 1024 + " KBs";
  25.                 progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
  26.             });
  27.         }
  28.         void ClientDownloadFileCompleted(object sender, AsyncCompletedEventArgs e, string fileName)
  29.         {
  30.             BeginInvoke((MethodInvoker)delegate
  31.             {
  32.                 rtBox.Text = string.Empty;
  33.                 rtBox.Text += "Arquivo " + fileName.Replace(directory, "") + " baixado\n";
  34.  
  35.                 if (fileName.Replace(directory, "") == "data.rar")
  36.                 {
  37.                     label2.Text = "Atualização completa!";
  38.                     UnRAR(fileName);
  39.                     LineChanger(server_version, "pid.txt", 4);              
  40.                     Process.Start(File.ReadLines("pid.txt").Skip(5).Take(1).First());
  41.                     Application.Exit();
  42.                 }                    
  43.             });
  44.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top