private void BeginDownload(string remoteURL, string downloadToPath, string version, string executeTarget) { string filePath = Versions.CreateTargetLocation(downloadToPath, version); Uri remoteURI = new Uri(remoteURL); WebClient downloader = new WebClient(); downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wb_DownloadProgressChanged); downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.DownloadFileCompleted += wc_DownloadFileCompleted2; downloader.DownloadFileAsync(remoteURI, filePath + ".zip", new string[] { version, downloadToPath, executeTarget }); }
private void BeginDownload(string remoteURL, string downloadToPath, string version, string executeTarget, string localVersion) { string filePath = Versions.CreateTargetLocation(downloadToPath, version); Uri remoteURI = new Uri(remoteURL); WebClient downloader = new WebClient(); downloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.DownloadFileAsync(remoteURI, filePath + ".zip", new string[] { version, downloadToPath, executeTarget, localVersion }); }
private async void ShowProgressDialog(object sender, RoutedEventArgs e) { var mySettings = new MetroDialogSettings() { NegativeButtonText = "Close now", AnimateShow = false, AnimateHide = false }; TextVer = "radar.version"; string downloadToPath = Environment.CurrentDirectory; string localVersion = Versions.LocalVersion(downloadToPath + "/radar.version"); string remoteURL = "https://lafkomods.ru/update/radar/"; string remoteVersion = Versions.RemoteVersion(remoteURL + "radar.version"); string remoteFile = remoteURL + remoteVersion + ".zip"; if (localVersion != remoteVersion) { Button1.IsEnabled = false; string filePath = Versions.CreateTargetLocation(downloadToPath, remoteVersion); var controller = await this.ShowProgressAsync("Please wait...", "We are finding some radar!", settings : mySettings); controller.SetIndeterminate(); await System.Threading.Tasks.Task.Delay(2000); Uri remoteURI = new Uri(remoteFile); WebClient downloader = new WebClient(); downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wb_DownloadProgressChanged); downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.DownloadFileCompleted += wc_DownloadFileCompleted2; downloader.DownloadFileAsync(remoteURI, filePath + ".zip", new string[] { remoteVersion, downloadToPath, "update.txt" }); controller.SetCancelable(false); double i = 1.0; while (i < 99.9) { double val = progressBar1.Value; controller.SetProgress(val / 100); controller.SetMessage("Downloading radar: " + val + "%..."); i = val; await System.Threading.Tasks.Task.Delay(500); } await controller.CloseAsync(); if (controller.IsCanceled) { await this.ShowMessageAsync("No radar!", "You stopped downloading radar!"); } else { MessageDialogResult result = await this.ShowMessageAsync("Downloading Radar finished!", "Clear the directory from zip files?", MessageDialogStyle.AffirmativeAndNegative); if (result == MessageDialogResult.Affirmative) { var v = Directory.GetFiles(Environment.CurrentDirectory, "*.zip", SearchOption.AllDirectories); foreach (var s in v) { File.Delete(s); } } } } }