public string GetFormattedTotal() { if (_sizeLevel == SizeLevel.None) { _sizeLevel = SizeUtils.GetProperSizeLevel(DiskTotalSize - DiskFreeSize); } return($"Total: {SizeUtils.GetPrettySize(DiskTotalSize, _sizeLevel)}"); }
/// <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)}"); }
/// <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) });