mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-08 15:56:23 +02:00
Improve code structure
- Add separate API project - Add notification system
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user