!BREAKING: Changed ComputeSHA256Hash to FileInfo
This commit is contained in:
parent
c05c2fdd73
commit
f53ce5d067
2 changed files with 23 additions and 20 deletions
|
|
@ -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>
|
/// <summary>
|
||||||
/// Compute the SHA256-Hash for a given file
|
/// Compute the SHA256-Hash for a given file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ComputeSHA256Hash(string filePath)
|
public static string ComputeSHA256Hash(FileInfo filePath)
|
||||||
{
|
{
|
||||||
using SHA256 _SHA256 = SHA256.Create();
|
using SHA256 _SHA256 = SHA256.Create();
|
||||||
using FileStream fileStream = File.OpenRead(filePath);
|
using FileStream fileStream = filePath.OpenRead();
|
||||||
return BitConverter.ToString(_SHA256.ComputeHash(fileStream)).Replace("-", "").ToLowerInvariant();
|
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");
|
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static class StringExt
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shorten a string to the given length
|
/// Shorten a string to the given length
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -616,8 +626,9 @@ public static class StringExt
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string Truncate(this string value, int maxLength)
|
public static string Truncate(this string value, int maxLength)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value)) return value;
|
if (string.IsNullOrEmpty(value))
|
||||||
return value.Length <= maxLength ? value : value[ ..maxLength ];
|
return value;
|
||||||
|
return value.Length <= maxLength ? value : value[..maxLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -633,7 +644,7 @@ public static class StringExt
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value))
|
||||||
return 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
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute the SHA256-Hash for the given string
|
/// Changes the first letter to upper.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="str">The string to modify.</param>
|
||||||
/// <returns></returns>
|
/// <returns>The string with the first letter changed to upper.</returns>
|
||||||
public static string ComputeSHA256Hash(string str)
|
|
||||||
{
|
|
||||||
using SHA256 _SHA256 = SHA256.Create();
|
|
||||||
return BitConverter.ToString(_SHA256.ComputeHash(Encoding.ASCII.GetBytes(str))).Replace("-", "").ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string FirstLetterToUpper(this string str)
|
public static string FirstLetterToUpper(this string str)
|
||||||
{
|
{
|
||||||
return $"{str.First().ToString().ToUpper()}{str.Remove(0, 1)}";
|
return $"{str.First().ToString().ToUpper()}{str.Remove(0, 1)}";
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,7 @@ public class WindowsUtils
|
||||||
var processHandle = kernel32.OpenProcess(0x0400 | 0x0010, false, pid);
|
var processHandle = kernel32.OpenProcess(0x0400 | 0x0010, false, pid);
|
||||||
|
|
||||||
if (processHandle == IntPtr.Zero)
|
if (processHandle == IntPtr.Zero)
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
const int lengthSb = 4000;
|
const int lengthSb = 4000;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue