Stillkill

Download and extract zip

Nov 16th, 2019
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. private async void DownloadGameVersionFromServer(GameVersion version)
  2. {
  3.     this.LaunchButton.IsEnabled = false;
  4.     this.LaunchButton.Content = "Downloading...";
  5.     this.MainProgressBarLabel.Content = "<server url redacted>";
  6.     Uri uri = new Uri($"<server url redacted>");
  7.     WebClient client = new WebClient();
  8.     client.DownloadProgressChanged += (s, e) =>
  9.     {
  10.         this.MainProgressBar.Value = e.ProgressPercentage;
  11.         this.MainProgressBarLabel.Content = $"Downloading: {e.BytesReceived}/{e.TotalBytesToReceive}bytes ({e.ProgressPercentage}%)";
  12.     };
  13.     client.DownloadFileCompleted += (s, e) =>
  14.     {
  15.         this.LaunchButton.IsEnabled = true;
  16.         this.LaunchButton.Content = "Launch Game";
  17.     };
  18.     //client.DownloadProgressChanged += OnDownloadProgressChanged;
  19.     //client.DownloadFileCompleted += OnDownloadCompleted;
  20.     this.MainProgressBarLabel.Content = "Connecting to server...";
  21.     try
  22.     {
  23.         await client.DownloadFileTaskAsync(uri, $"Versions\\{version.VersionName}.zip");
  24.     }
  25.     catch (Exception e)
  26.     {
  27.         this.MainProgressBarLabel.Content = e.Message;
  28.     }
  29.     //inflate zip
  30.     try
  31.     {
  32.         this.MainProgressBarLabel.Content = "Unpacking...";
  33.         ZipFile.ExtractToDirectory($"Versions\\{version.VersionName}.zip", $"Versions\\{version.VersionName}");
  34.         this.MainProgressBarLabel.Content = "Cleaning up...";
  35.         //File.Delete($"Versions\\{version.VersionName}");
  36.     }
  37.     catch (Exception e)
  38.     {
  39.  
  40.         throw;
  41.     }
  42.  
  43.     this.MainProgressBarLabel.Content = "Ready";
  44.     this.LaunchButton.IsEnabled = true;
  45.     this.LaunchButton.Content = "Launch Game";
  46. }
Add Comment
Please, Sign In to add comment