Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Updater()
- {
- InitializeComponent();
- }
- WebClient webClient;
- Stopwatch staphxD = new Stopwatch();
- private void Updater_Load(object sender, string urlAddress, string location, EventArgs e)
- {
- DownloadUpdate(urlAddress, location);
- }
- public void DownloadUpdate(string urlAddress, string location)
- {
- using (webClient = new WebClient())
- {
- string path = @"LoaderPath.txt";
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText(path))
- {
- sw.WriteLine(System.Reflection.Assembly.GetEntryAssembly().Location);
- }
- }
- webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
- webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
- Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri("google.com/idk.exe") : new Uri("http://" + urlAddress);
- staphxD.Start();
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- var stringChars = new char[20];
- var random = new Random();
- for (int i = 0; i < stringChars.Length; i++)
- {
- stringChars[i] = chars[random.Next(chars.Length)];
- }
- var finalString = new String(stringChars);
- location = Directory.GetCurrentDirectory() + "/" + finalString + ".exe";
- try
- {
- webClient.DownloadFileAsync(URL, location);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- private void ProgressChanged(object sender , DownloadProgressChangedEventArgs e)
- {
- label6.Text = string.Format("{0} MB's / {1} MB's",(e.BytesReceived / 1024d / 1024d).ToString("0.00"),(e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));
- label5.Text = string.Format("{0} kb/s", (e.BytesReceived / 1024d / staphxD.Elapsed.TotalSeconds).ToString("0.00"));
- progressBar1.Value = e.ProgressPercentage;
- label7.Text = e.ProgressPercentage.ToString() + "%";
- }
- private void Completed(object sender,AsyncCompletedEventArgs e)
- {
- staphxD.Reset();
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- var stringChars = new char[20];
- var random = new Random();
- for (int i = 0; i < stringChars.Length; i++)
- {
- stringChars[i] = chars[random.Next(chars.Length)];
- }
- var finalString = new String(stringChars);
- string location = Directory.GetCurrentDirectory() + "/" + finalString + ".exe";
- if (e.Cancelled == true)
- {
- MessageBox.Show("Download has been canceled.");
- }
- else
- {
- MessageBox.Show("Download completed!");
- Process.Start(location);
- Application.Exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement