From 4c927a42253b0f1b3b236aeb515e7495f0dde2af Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Sat, 5 Feb 2022 11:58:19 +0100 Subject: [PATCH] [Feature] Fix warning SYSLIB0014 - Replace WebClient with HttpClient (#313), version 1.2.3.8 --- Helpers/DragDropHelper.cs | 21 ++++++++++++++++----- Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Helpers/DragDropHelper.cs b/Helpers/DragDropHelper.cs index 2a31081..258eddb 100644 --- a/Helpers/DragDropHelper.cs +++ b/Helpers/DragDropHelper.cs @@ -63,8 +63,6 @@ namespace SystemTrayMenu.Helper private static void CreateShortcut(string url, string pathToStoreFile) { string pathToStoreIcons = Path.Combine(pathToStoreFile, "ico"); - - using WebClient client = new(); if (!Directory.Exists(pathToStoreIcons)) { Directory.CreateDirectory(pathToStoreIcons); @@ -74,9 +72,22 @@ namespace SystemTrayMenu.Helper string hostname = uri.Host.ToString(); string pathIconPng = Path.Combine(pathToStoreIcons, $"{hostname}.png"); - client.DownloadFile( - @"http://www.google.com/s2/favicons?sz=32&domain=" + url, - pathIconPng); + + string urlGoogleIconDownload = @"http://www.google.com/s2/favicons?sz=32&domain=" + url; + HttpClient client = new HttpClient(); + using (HttpResponseMessage response = client.GetAsync(urlGoogleIconDownload).Result) + { + using (HttpContent content = response.Content) + { + Stream stream = content.ReadAsStreamAsync().Result; + using (var fileStream = File.Create(pathIconPng)) + { + stream.Seek(0, SeekOrigin.Begin); + stream.CopyTo(fileStream); + } + } + } + string pathIcon = Path.Combine(pathToStoreIcons, $"{hostname}.ico"); ImagingHelper.ConvertToIcon(pathIconPng, pathIcon, 32); File.Delete(pathIconPng); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 35b6dc7..02a28e6 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.3.7")] -[assembly: AssemblyFileVersion("1.2.3.7")] +[assembly: AssemblyVersion("1.2.3.8")] +[assembly: AssemblyFileVersion("1.2.3.8")]