Fixed naming issue plus made code more efficient

This commit is contained in:
ZestyTS 2022-08-26 16:40:20 -07:00
parent 1c4b7a9722
commit 2f7f2a3b99

View file

@ -64,44 +64,28 @@ namespace UWUVCI_AIO_WPF.Classes
public static async Task<bool> IsToolRightAsync(string name) public static async Task<bool> IsToolRightAsync(string name)
{ {
bool ret = false; string md5Name = name + ".md5";
string md5Name = FolderName + "\\" + name + ".md5"; string md5Path = FolderName + "\\" + md5Name;
using (var httpClient = new HttpClient()) using (var httpClient = new HttpClient())
{ {
using (var response = await httpClient.GetStreamAsync(backupulr + md5Name)) using var response = await httpClient.GetStreamAsync(backupulr + md5Name);
using (var fs = new FileStream(md5Name, FileMode.Create)) using var fs = new FileStream(md5Path, FileMode.Create);
await response.CopyToAsync(fs); await response.CopyToAsync(fs);
}
var md5 = "";
using (var sr = new StreamReader(md5Path))
md5 = await sr.ReadToEndAsync();
using var sr = new StreamReader(md5Name); return CalculateMD5(md5Path) == md5;
var md5 = await sr.ReadLineAsync();
if (CalculateMD5(name) == md5)
ret = true;
}
//Dumb solution but whatever, hopefully this deletes the md5file
try
{
File.Delete(md5Name);
}
catch { }
try
{
File.Delete(new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).DirectoryName + "\\bin\\Tools\\" + md5Name);
}
catch { }
try
{
File.Delete(new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location).DirectoryName + "\\bin\\bases\\" + md5Name);
}
catch { }
return ret;
} }
static string CalculateMD5(string filename) static string CalculateMD5(string filename)
{ {
var ret = "";
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(); ret = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower();
return ret; return ret;
} }