From f53ce5d06758bb0f3563af95b2b8d5f08ffd29c1 Mon Sep 17 00:00:00 2001
From: Mira <56395159+TheXorog@users.noreply.github.com>
Date: Mon, 24 Apr 2023 14:48:58 +0200
Subject: [PATCH] !BREAKING: Changed ComputeSHA256Hash to FileInfo
---
UniversalExtensions.cs | 41 +++++++++++++++++++++-----------------
WindowsAPI/WindowsUtils.cs | 2 --
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/UniversalExtensions.cs b/UniversalExtensions.cs
index 8af4d8f..383a158 100644
--- a/UniversalExtensions.cs
+++ b/UniversalExtensions.cs
@@ -381,15 +381,28 @@ public static class UniversalExtensions
+ ///
+ /// Compute the SHA256-Hash for the given string
+ ///
+ ///
+ ///
+ public static string ComputeSHA256Hash(string str)
+ {
+ using SHA256 _SHA256 = SHA256.Create();
+ return BitConverter.ToString(_SHA256.ComputeHash(Encoding.ASCII.GetBytes(str))).Replace("-", "").ToLowerInvariant();
+ }
+
+
+
///
/// Compute the SHA256-Hash for a given file
///
///
///
- 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();
}
@@ -401,7 +414,7 @@ public static class UniversalExtensions
///
///
public static TimeSpan GetTimespanUntil(this DateTime until) =>
- (until.ToUniversalTime() - DateTime.UtcNow);
+ (until.ToUniversalTime() - DateTime.UtcNow);
@@ -604,10 +617,7 @@ public static class UniversalExtensions
{
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
}
-}
-public static class StringExt
-{
///
/// Shorten a string to the given length
///
@@ -616,8 +626,9 @@ public static class StringExt
///
public static string Truncate(this string value, int maxLength)
{
- if (string.IsNullOrEmpty(value)) return value;
- return value.Length <= maxLength ? value : value[ ..maxLength ];
+ if (string.IsNullOrEmpty(value))
+ return value;
+ return value.Length <= maxLength ? value : value[..maxLength];
}
@@ -633,7 +644,7 @@ public static class StringExt
if (string.IsNullOrEmpty(value))
return value;
- return value.Length <= maxLength ? value : $"{value[ ..(maxLength - 2) ]}..";
+ return value.Length <= maxLength ? value : $"{value[..(maxLength - 2)]}..";
}
@@ -655,16 +666,10 @@ public static class StringExt
///
- /// Compute the SHA256-Hash for the given string
+ /// Changes the first letter to upper.
///
- ///
- ///
- public static string ComputeSHA256Hash(string str)
- {
- using SHA256 _SHA256 = SHA256.Create();
- return BitConverter.ToString(_SHA256.ComputeHash(Encoding.ASCII.GetBytes(str))).Replace("-", "").ToLowerInvariant();
- }
-
+ /// The string to modify.
+ /// The string with the first letter changed to upper.
public static string FirstLetterToUpper(this string str)
{
return $"{str.First().ToString().ToUpper()}{str.Remove(0, 1)}";
diff --git a/WindowsAPI/WindowsUtils.cs b/WindowsAPI/WindowsUtils.cs
index e53eedc..2ee0e51 100644
--- a/WindowsAPI/WindowsUtils.cs
+++ b/WindowsAPI/WindowsUtils.cs
@@ -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;