Browse Source

replaced WebClient on HttpClient on MainWindow

Veloe 2 years ago
parent
commit
2220055d4a

+ 1 - 1
VeloeMinecraftLauncher/MinecraftLauncher/Downloader.cs

@@ -675,7 +675,7 @@ internal static class Downloader
         }       
     }
 
-    private static async Task DownloadFileAsync(string url, string path, CancellationToken ct, HttpClient? client = null)
+    public static async Task DownloadFileAsync(string url, string path, CancellationToken ct, HttpClient? client = null)
     {
         if (client == null) client = _httpClient;
         using HttpResponseMessage response = await client.GetAsync(new System.Uri(url),HttpCompletionOption.ResponseHeadersRead, ct);

+ 2 - 4
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -788,7 +788,6 @@ public class MainWindowViewModel : ViewModelBase
                 }
             }
                            
-            WebClient webClient = new WebClient();
             try
             {
                 _logger.Information("Downloading updater.zip");
@@ -803,14 +802,13 @@ public class MainWindowViewModel : ViewModelBase
                 if (url == String.Empty)
                     return;
 
-                webClient.DownloadFile(new System.Uri(url), "updater.zip");
+                await Downloader.DownloadFileAsync(url, "updater.zip", _tokenSource.Token);
             }
-            catch (Exception ex)
+            catch (Exception)
             {
                 _logger.Error("Error occured on getting updater.zip from the server.");
                 throw;
             }
-            webClient.Dispose();
             _logger.Information("Unpacking updater.zip");
             ZipFile.ExtractToDirectory($"updater.zip", Directory.GetCurrentDirectory(), true);