From 965f2142ff173829d98af00e3fd787b0f6007570 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:04:26 -0400 Subject: [PATCH] Replace WebClient with HttpClient --- Dalamud/Plugin/Internal/PluginManager.cs | 9 +++++---- Dalamud/Plugin/Internal/PluginRepository.cs | 9 ++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index a3f4f250e..d3b7dbbd4 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -359,16 +359,17 @@ namespace Dalamud.Plugin.Internal // ignored, since the plugin may be loaded already } - using var client = new WebClient(); - var tempZip = new FileInfo(Path.GetTempFileName()); try { Log.Debug($"Downloading plugin to {tempZip} from {downloadUrl}"); - client.DownloadFile(downloadUrl, tempZip.FullName); + using var client = new HttpClient(); + var response = client.GetAsync(downloadUrl).Result; + using var fs = new FileStream(tempZip.FullName, FileMode.CreateNew); + response.Content.CopyToAsync(fs).GetAwaiter().GetResult(); } - catch (WebException ex) + catch (HttpRequestException ex) { Log.Error(ex, $"Download of plugin {repoManifest.Name} failed unexpectedly."); throw; diff --git a/Dalamud/Plugin/Internal/PluginRepository.cs b/Dalamud/Plugin/Internal/PluginRepository.cs index e76aa67d1..d90efaee8 100644 --- a/Dalamud/Plugin/Internal/PluginRepository.cs +++ b/Dalamud/Plugin/Internal/PluginRepository.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Net; +using System.Net.Http; using System.Threading.Tasks; using Dalamud.Logging.Internal; @@ -74,11 +74,10 @@ namespace Dalamud.Plugin.Internal return Task.Run(() => { - using var client = new WebClient(); - Log.Information($"Fetching repo: {this.PluginMasterUrl}"); - - var data = client.DownloadString(this.PluginMasterUrl); + using var client = new HttpClient(); + using var response = client.GetAsync(this.PluginMasterUrl).Result; + var data = response.Content.ReadAsStringAsync().Result; var pluginMaster = JsonConvert.DeserializeObject>(data); pluginMaster.Sort((pm1, pm2) => pm1.Name.CompareTo(pm2.Name));