浏览代码

replaced WebClient on HttpClient on MainWindow

Veloe 2 年之前
父节点
当前提交
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;
         if (client == null) client = _httpClient;
         using HttpResponseMessage response = await client.GetAsync(new System.Uri(url),HttpCompletionOption.ResponseHeadersRead, ct);
         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
             try
             {
             {
                 _logger.Information("Downloading updater.zip");
                 _logger.Information("Downloading updater.zip");
@@ -803,14 +802,13 @@ public class MainWindowViewModel : ViewModelBase
                 if (url == String.Empty)
                 if (url == String.Empty)
                     return;
                     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.");
                 _logger.Error("Error occured on getting updater.zip from the server.");
                 throw;
                 throw;
             }
             }
-            webClient.Dispose();
             _logger.Information("Unpacking updater.zip");
             _logger.Information("Unpacking updater.zip");
             ZipFile.ExtractToDirectory($"updater.zip", Directory.GetCurrentDirectory(), true);
             ZipFile.ExtractToDirectory($"updater.zip", Directory.GetCurrentDirectory(), true);