Converted items that could be in a using statement

This commit is contained in:
ZestyTS 2022-06-30 10:58:17 -07:00
parent b2d82c670e
commit 3372052131

View file

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Threading.Tasks;
namespace UWUVCI_AIO_WPF.Classes
{
@ -63,26 +64,22 @@ namespace UWUVCI_AIO_WPF.Classes
public static bool DoesToolsFolderExist()
{
if (Directory.Exists(FolderName))
{
return true;
}
return false;
return Directory.Exists(FolderName);
}
public static bool IsToolRight(string name)
public static async Task<bool> IsToolRight(string name)
{
bool ret = false;
WebClient client = new WebClient();
client.DownloadFile(backupulr + name + ".md5", name + ".md5");
StreamReader sr = new StreamReader(name + ".md5");
var md5 = sr.ReadLine();
if(CalculateMD5(name) == md5)
using (var client = new WebClient())
{
ret = true;
await client.DownloadFile(backupulr + name + ".md5", name + ".md5");
using (var sr = new StreamReader(name + ".md5"))
{
var md5 = sr.ReadLine();
ret = CalculateMD5(name) == md5;
}
File.Delete(name + ".md5");
}
sr.Close();
File.Delete(name + ".md5");
return ret;
}
static string CalculateMD5(string filename)
@ -92,7 +89,6 @@ namespace UWUVCI_AIO_WPF.Classes
using (var stream = File.OpenRead(filename))
{
string ret = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower();
stream.Close();
return ret;
}
}