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