Пример #1
0
 public string GetFormattedTotal()
 {
     if (_sizeLevel == SizeLevel.None)
     {
         _sizeLevel = SizeUtils.GetProperSizeLevel(DiskTotalSize - DiskFreeSize);
     }
     return($"Total: {SizeUtils.GetPrettySize(DiskTotalSize, _sizeLevel)}");
 }
Пример #2
0
        /// <summary>
        /// 获取格式化大小
        /// </summary>
        /// <param name="size">文件/文件夹大小</param>
        /// <param name="sizeLevel">大小级别</param>
        /// <returns></returns>
        public static string GetPrettySize(ulong size, SizeLevel sizeLevel)
        {
            var tempSize = (double)size;
            var rate     = (int)sizeLevel;

            while (rate != 0)
            {
                tempSize /= Rate;
                rate--;
            }

            return($"{tempSize:0.##} {PrettySizeLevel(sizeLevel)}");
        }
Пример #3
0
 /// <summary>
 /// 翻译文件进制英文
 /// </summary>
 /// <param name="sizeLevel"></param>
 /// <returns></returns>
 private static string PrettySizeLevel(SizeLevel sizeLevel)
 {
     CheckSizeLevel(sizeLevel);
     return(sizeLevel switch {
         SizeLevel.Byte => "B",
         SizeLevel.Kilobyte => "KB",
         SizeLevel.Megabyte => "MB",
         SizeLevel.Gigabyte => "GB",
         SizeLevel.Terabyte => "TB",
         SizeLevel.Petabyte => "PB",
         SizeLevel.Exabyte => "EB",
         SizeLevel.None => "",
         _ => throw new ArgumentOutOfRangeException(nameof(sizeLevel), sizeLevel, null)
     });