Replace WebClient with HttpClient

This commit is contained in:
teinarss
2021-02-21 16:56:55 +01:00
committed by Paul Chote
parent ed43071792
commit 7073279ab8
17 changed files with 604 additions and 562 deletions

View File

@@ -9,13 +9,12 @@
*/
#endregion
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Support;
namespace OpenRA
{
@@ -39,14 +38,16 @@ namespace OpenRA
var spriteSize = IconSize * density;
var sprite = sheetBuilder.Allocate(new Size(spriteSize, spriteSize), 1f / density);
Action<DownloadDataCompletedEventArgs> onComplete = i =>
Task.Run(async () =>
{
if (i.Error != null)
return;
try
{
var icon = new Png(new MemoryStream(i.Result));
var client = HttpClientFactory.Create();
var httpResponseMessage = await client.GetAsync(url);
var result = await httpResponseMessage.Content.ReadAsStreamAsync();
var icon = new Png(result);
if (icon.Width == spriteSize && icon.Height == spriteSize)
{
Game.RunAfterTick(() =>
@@ -57,9 +58,7 @@ namespace OpenRA
}
}
catch { }
};
new Download(url, _ => { }, onComplete);
});
return sprite;
}