diff --git a/ArcaneLibs/FileUtils.cs b/ArcaneLibs/FileUtils.cs new file mode 100644 index 0000000..c2d7b62 --- /dev/null +++ b/ArcaneLibs/FileUtils.cs @@ -0,0 +1,18 @@ +using System.Reflection; +using System.Security.Cryptography; + +namespace ArcaneLibs; + +public static class FileUtils { + public static async Task GetFileSha384Async(string path) { + using var sha384 = SHA384.Create(); + await using var stream = File.OpenRead(path); + return Convert.ToBase64String(await sha384.ComputeHashAsync(stream)); + } + + public static string GetBinDir() { + var assembly = Assembly.GetEntryAssembly(); + var uri = new Uri(assembly!.Location); + return Path.GetDirectoryName(uri.LocalPath)!; + } +} \ No newline at end of file diff --git a/ArcaneLibs/Util.cs b/ArcaneLibs/Util.cs index 02b6fd4..9e15fee 100644 --- a/ArcaneLibs/Util.cs +++ b/ArcaneLibs/Util.cs @@ -160,7 +160,7 @@ public static async IAsyncEnumerable GetCommandOutputInDirAsync(string p } public static string BytesToString(long byteCount, int maxnums = 2) { - string[] suf = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "EiB" }; //Longs run out around EB + string[] suf = ["B", "kiB", "MiB", "GiB", "TiB", "PiB", "EiB"]; //Longs run out around EB if (byteCount == 0) return "0 " + suf[0]; var bytes = Math.Abs(byteCount); @@ -170,7 +170,7 @@ public static string BytesToString(long byteCount, int maxnums = 2) { } public static string SI_BytesToString(long byteCount, int maxnums = 2) { - string[] suf = { "B", "kB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB + string[] suf = ["B", "kB", "MB", "GB", "TB", "PB", "EB"]; //Longs run out around EB if (byteCount == 0) return "0 " + suf[0]; var bytes = Math.Abs(byteCount);