using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace VeloeMinecraftLauncher.MinecraftLauncher { internal static class Downloader { public static T DownloadAndDeserializeJsonData(string url) where T : new() { using (var webClient = new HttpClient()) { var jsonData = string.Empty; try { jsonData = webClient.GetStringAsync(url).Result; } catch (Exception) { } return string.IsNullOrEmpty(jsonData) ? new T() : JsonSerializer.Deserialize(jsonData); } } public static void DownloadFile(string url, string path, string filename) { using (var webClient = new WebClient()) { if (!Directory.Exists(path)) Directory.CreateDirectory(path); webClient.DownloadFileAsync(new System.Uri(url), path + "\\" + filename); } } } }