Improve code structure

- Add separate API project
- Add notification system
This commit is contained in:
Stone_Red
2022-02-24 22:56:45 +01:00
parent 6ffdc720a4
commit cf7f952012
28 changed files with 590 additions and 488 deletions
@@ -0,0 +1,29 @@
using System.Security.Cryptography;
namespace HyperbolicDownloaderApi.FileProcessing;
internal static class FileValidator
{
public static async Task<string> CalculateHashAsync(string filePath)
{
using SHA512 sha = SHA512.Create();
using FileStream? stream = File.OpenRead(filePath);
byte[]? hash = await sha.ComputeHashAsync(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
public static string CalculateHash(string filePath)
{
return CalculateHashAsync(filePath).GetAwaiter().GetResult();
}
public static async Task<bool> ValidateHashAsync(string filePath, string hash)
{
return await CalculateHashAsync(filePath) == hash;
}
public static bool ValidateHash(string filePath, string hash)
{
return CalculateHash(filePath) == hash;
}
}