From d3bc838477f835da8de9f1ff4c313bfd0ea54d5d Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 23 Jan 2025 12:58:23 +0100 Subject: [PATCH] Refactored to use the long extension --- .../Tools/FileInfoExtensions.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/MindWork AI Studio/Tools/FileInfoExtensions.cs b/app/MindWork AI Studio/Tools/FileInfoExtensions.cs index 8d3d81d..c300262 100644 --- a/app/MindWork AI Studio/Tools/FileInfoExtensions.cs +++ b/app/MindWork AI Studio/Tools/FileInfoExtensions.cs @@ -2,20 +2,16 @@ namespace AIStudio.Tools; public static class FileInfoExtensions { + /// + /// Returns the file size in human-readable format. + /// + /// The file info object. + /// The file size in human-readable format. public static string FileSize(this FileInfo fileInfo) { if (!fileInfo.Exists) return "N/A"; - var size = fileInfo.Length; - string[] sizes = { "B", "kB", "MB", "GB", "TB" }; - var order = 0; - while (size >= 1024 && order < sizes.Length - 1) - { - order++; - size /= 1024; - } - - return $"{size:0.##} {sizes[order]}"; + return fileInfo.Length.FileSize(); } } \ No newline at end of file