potential mcdf fixes

This commit is contained in:
rootdarkarchon
2023-12-17 18:53:22 +01:00
committed by Loporrit
parent c843af1470
commit add2d2eda9
4 changed files with 62 additions and 24 deletions

View File

@@ -10,6 +10,32 @@ namespace MareSynchronos.Utils;
public static class VariousExtensions
{
public static string ToByteString(this int bytes, bool addSuffix = true)
{
string[] suffix = ["B", "KiB", "MiB", "GiB", "TiB"];
int i;
double dblSByte = bytes;
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
{
dblSByte = bytes / 1024.0;
}
return addSuffix ? $"{dblSByte:0.00} {suffix[i]}" : $"{dblSByte:0.00}";
}
public static string ToByteString(this long bytes, bool addSuffix = true)
{
string[] suffix = ["B", "KiB", "MiB", "GiB", "TiB"];
int i;
double dblSByte = bytes;
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
{
dblSByte = bytes / 1024.0;
}
return addSuffix ? $"{dblSByte:0.00} {suffix[i]}" : $"{dblSByte:0.00}";
}
public static void CancelDispose(this CancellationTokenSource? cts)
{
try