Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async void DownloadGameVersionFromServer(GameVersion version)
- {
- this.LaunchButton.IsEnabled = false;
- this.LaunchButton.Content = "Downloading...";
- this.MainProgressBarLabel.Content = "<server url redacted>";
- Uri uri = new Uri($"<server url redacted>");
- WebClient client = new WebClient();
- client.DownloadProgressChanged += (s, e) =>
- {
- this.MainProgressBar.Value = e.ProgressPercentage;
- this.MainProgressBarLabel.Content = $"Downloading: {e.BytesReceived}/{e.TotalBytesToReceive}bytes ({e.ProgressPercentage}%)";
- };
- client.DownloadFileCompleted += (s, e) =>
- {
- this.LaunchButton.IsEnabled = true;
- this.LaunchButton.Content = "Launch Game";
- };
- //client.DownloadProgressChanged += OnDownloadProgressChanged;
- //client.DownloadFileCompleted += OnDownloadCompleted;
- this.MainProgressBarLabel.Content = "Connecting to server...";
- try
- {
- await client.DownloadFileTaskAsync(uri, $"Versions\\{version.VersionName}.zip");
- }
- catch (Exception e)
- {
- this.MainProgressBarLabel.Content = e.Message;
- }
- //inflate zip
- try
- {
- this.MainProgressBarLabel.Content = "Unpacking...";
- ZipFile.ExtractToDirectory($"Versions\\{version.VersionName}.zip", $"Versions\\{version.VersionName}");
- this.MainProgressBarLabel.Content = "Cleaning up...";
- //File.Delete($"Versions\\{version.VersionName}");
- }
- catch (Exception e)
- {
- throw;
- }
- this.MainProgressBarLabel.Content = "Ready";
- this.LaunchButton.IsEnabled = true;
- this.LaunchButton.Content = "Launch Game";
- }
Add Comment
Please, Sign In to add comment