123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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<T>(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<T>(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);
- }
- }
- }
- }
|