!BREAKING: Changed ComputeSHA256Hash to FileInfo

This commit is contained in:
Mira 2023-04-24 14:48:58 +02:00
parent c05c2fdd73
commit f53ce5d067
Signed by untrusted user who does not match committer: Xorog
GPG key ID: 983798ED9C3E7C36
2 changed files with 23 additions and 20 deletions

View file

@ -381,15 +381,28 @@ public static class UniversalExtensions
/// <summary>
/// Compute the SHA256-Hash for the given string
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string ComputeSHA256Hash(string str)
{
using SHA256 _SHA256 = SHA256.Create();
return BitConverter.ToString(_SHA256.ComputeHash(Encoding.ASCII.GetBytes(str))).Replace("-", "").ToLowerInvariant();
}
/// <summary>
/// Compute the SHA256-Hash for a given file
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string ComputeSHA256Hash(string filePath)
public static string ComputeSHA256Hash(FileInfo filePath)
{
using SHA256 _SHA256 = SHA256.Create();
using FileStream fileStream = File.OpenRead(filePath);
using FileStream fileStream = filePath.OpenRead();
return BitConverter.ToString(_SHA256.ComputeHash(fileStream)).Replace("-", "").ToLowerInvariant();
}
@ -604,10 +617,7 @@ public static class UniversalExtensions
{
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
}
}
public static class StringExt
{
/// <summary>
/// Shorten a string to the given length
/// </summary>
@ -616,7 +626,8 @@ public static class StringExt
/// <returns></returns>
public static string Truncate(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
if (string.IsNullOrEmpty(value))
return value;
return value.Length <= maxLength ? value : value[..maxLength];
}
@ -655,16 +666,10 @@ public static class StringExt
/// <summary>
/// Compute the SHA256-Hash for the given string
/// Changes the first letter to upper.
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string ComputeSHA256Hash(string str)
{
using SHA256 _SHA256 = SHA256.Create();
return BitConverter.ToString(_SHA256.ComputeHash(Encoding.ASCII.GetBytes(str))).Replace("-", "").ToLowerInvariant();
}
/// <param name="str">The string to modify.</param>
/// <returns>The string with the first letter changed to upper.</returns>
public static string FirstLetterToUpper(this string str)
{
return $"{str.First().ToString().ToUpper()}{str.Remove(0, 1)}";

View file

@ -10,9 +10,7 @@ public class WindowsUtils
var processHandle = kernel32.OpenProcess(0x0400 | 0x0010, false, pid);
if (processHandle == IntPtr.Zero)
{
return null;
}
const int lengthSb = 4000;