mirror of
https://github.com/stuff-by-3-random-dudes/UWUVCI-AIO-WPF
synced 2024-11-22 02:53:04 +00:00
Swapped to httpClient for async calls
This commit is contained in:
parent
c9a379bf83
commit
eba3c07aad
2 changed files with 46 additions and 37 deletions
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -67,18 +68,19 @@ namespace UWUVCI_AIO_WPF.Classes
|
|||
{
|
||||
bool ret = false;
|
||||
string md5Name = FolderName + "\\" + name + ".md5";
|
||||
using (WebClient client = new WebClient())
|
||||
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
await client.DownloadFileTaskAsync(backupulr + md5Name, md5Name);
|
||||
using (StreamReader sr = new StreamReader(md5Name))
|
||||
{
|
||||
var md5 = sr.ReadLine();
|
||||
if (CalculateMD5(name) == md5)
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
using (var response = await httpClient.GetStreamAsync(backupulr + md5Name))
|
||||
using (var fs = new FileStream(md5Name, FileMode.Create))
|
||||
await response.CopyToAsync(fs);
|
||||
|
||||
using var sr = new StreamReader(md5Name);
|
||||
var md5 = await sr.ReadLineAsync();
|
||||
if (CalculateMD5(name) == md5)
|
||||
ret = true;
|
||||
}
|
||||
|
||||
//Dumb solution but whatever, hopefully this deletes the md5file
|
||||
try
|
||||
{
|
||||
|
@ -99,14 +101,11 @@ namespace UWUVCI_AIO_WPF.Classes
|
|||
}
|
||||
static string CalculateMD5(string filename)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
using (var stream = File.OpenRead(filename))
|
||||
{
|
||||
string ret = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
using var md5 = MD5.Create();
|
||||
using var stream = File.OpenRead(filename);
|
||||
string ret = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower();
|
||||
|
||||
return ret;
|
||||
}
|
||||
public static List<MissingTool> CheckForMissingTools()
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ using System.Timers;
|
|||
using NAudio.Utils;
|
||||
using System.Security.Cryptography;
|
||||
using System.Drawing;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace UWUVCI_AIO_WPF
|
||||
{
|
||||
|
@ -1641,8 +1642,10 @@ namespace UWUVCI_AIO_WPF
|
|||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "bases", name);
|
||||
try
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
await client.DownloadFileTaskAsync(getDownloadLink(name, false), filePath);
|
||||
using var httpClient = new HttpClient();
|
||||
using var response = await httpClient.GetStreamAsync(getDownloadLink(name, false));
|
||||
using var fs = new FileStream(filePath, FileMode.Create);
|
||||
await response.CopyToAsync(fs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -1665,13 +1668,13 @@ namespace UWUVCI_AIO_WPF
|
|||
do
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
await client.DownloadFileTaskAsync(getDownloadLink(name, true), filePath);
|
||||
}
|
||||
|
||||
using var httpClient = new HttpClient();
|
||||
using var response = await httpClient.GetStreamAsync(getDownloadLink(name, true));
|
||||
using var fs = new FileStream(filePath, FileMode.Create);
|
||||
await response.CopyToAsync(fs);
|
||||
|
||||
} while (!Task.Run(() => ToolCheck.IsToolRightAsync(name)).GetAwaiter().GetResult());
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -2920,16 +2923,16 @@ namespace UWUVCI_AIO_WPF
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
using (await client.OpenReadTaskAsync("http://google.com/generate_204"))
|
||||
using (var client = new HttpClient())
|
||||
using (await client.GetAsync("http://google.com/generate_204"))
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
var googleBlocked = false;
|
||||
|
||||
using (var client = new WebClient())
|
||||
using (await client.OpenReadTaskAsync("https://raw.githubusercontent.com"))
|
||||
using (var client = new HttpClient())
|
||||
using (await client.GetAsync("https://raw.githubusercontent.com"))
|
||||
googleBlocked = true;
|
||||
|
||||
Custom_Message cm;
|
||||
|
@ -2954,16 +2957,16 @@ namespace UWUVCI_AIO_WPF
|
|||
{
|
||||
try
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
using (await client.OpenReadTaskAsync("http://google.com/generate_204"))
|
||||
using (var client = new HttpClient())
|
||||
using (await client.GetAsync("http://google.com/generate_204"))
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
using (await client.OpenReadTaskAsync("http://raw.githubusercontent.com"))
|
||||
using (var client = new HttpClient())
|
||||
using (await client.GetAsync("http://raw.githubusercontent.com"))
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
|
@ -3031,16 +3034,23 @@ namespace UWUVCI_AIO_WPF
|
|||
cm.ShowDialog();
|
||||
if (addi)
|
||||
{
|
||||
var client = new WebClient();
|
||||
var client = new HttpClient();
|
||||
if (ini)
|
||||
{
|
||||
client.DownloadFile(inip, Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", "game.ini"));
|
||||
using var response = await client.GetStreamAsync(inip);
|
||||
using var fs = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", "game.ini"), FileMode.Create);
|
||||
await response.CopyToAsync(fs);
|
||||
|
||||
(Thing as N64Config).ini.Text = Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", "game.ini");
|
||||
GameConfiguration.N64Stuff.INIPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", "game.ini");
|
||||
}
|
||||
if (btsnd)
|
||||
{
|
||||
client.DownloadFile(btsndp, Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", $"bootSound.{exten}"));
|
||||
|
||||
using var response = await client.GetStreamAsync(inip);
|
||||
using var fs = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", $"bootSound.{exten}"), FileMode.Create);
|
||||
await response.CopyToAsync(fs);
|
||||
|
||||
BootSound = Path.Combine(Directory.GetCurrentDirectory(), "bin", "repo", $"bootSound.{exten}");
|
||||
switch (console)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue