mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 18:47:21 +00:00
Improved the dialogs for local data sources and the Batch Processing assistant (#1096)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
149395c1a0
commit
f7e6ceb915
45 files changed
+2514
-361
No files matched your search
@@ -6,6 +6,8 @@ public static class LongExtensions
|
||||
{
|
||||
private static readonly string[] COUNT_SUFFIXES = ["k", "M", "B", "T"];
|
||||
|
||||
private static readonly string[] SIZE_UNITS = ["B", "kB", "MB", "GB", "TB"];
|
||||
|
||||
/// <summary>
|
||||
/// Formats a count so that large numbers stay readable: 1456 becomes 1.46k, 4512900 becomes 4.51M.
|
||||
/// </summary>
|
||||
@@ -42,20 +44,31 @@ public static class LongExtensions
|
||||
public static string CompactCount(this int count) => ((long)count).CompactCount();
|
||||
|
||||
/// <summary>
|
||||
/// Formats the file size in a human-readable format.
|
||||
/// Formats the file size in a human-readable format, e.g., 1.9 MB.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Like CompactCount, the decimal separator follows the culture of the active language plugin.
|
||||
/// </remarks>
|
||||
/// <param name="sizeBytes">The size in bytes.</param>
|
||||
/// <returns>The formatted file size.</returns>
|
||||
public static string FileSize(this long sizeBytes)
|
||||
public static string FileSize(this long sizeBytes) => sizeBytes.FileSize(I18N.I.Culture);
|
||||
|
||||
/// <summary>
|
||||
/// Formats the file size in a human-readable format, with the decimal separator of the given culture.
|
||||
/// </summary>
|
||||
/// <param name="sizeBytes">The size in bytes.</param>
|
||||
/// <param name="culture">The culture whose decimal separator to use.</param>
|
||||
/// <returns>The formatted file size.</returns>
|
||||
internal static string FileSize(this long sizeBytes, IFormatProvider culture)
|
||||
{
|
||||
string[] sizes = { "B", "kB", "MB", "GB", "TB" };
|
||||
var order = 0;
|
||||
while (sizeBytes >= 1024 && order < sizes.Length - 1)
|
||||
double size = sizeBytes;
|
||||
while (size >= 1024 && order < SIZE_UNITS.Length - 1)
|
||||
{
|
||||
order++;
|
||||
sizeBytes /= 1024;
|
||||
size /= 1024;
|
||||
}
|
||||
|
||||
return $"{sizeBytes:0.##} {sizes[order]}";
|
||||
return $"{size.ToString("0.##", culture)} {SIZE_UNITS[order]}";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user