mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
asm & csm: add file size to WorldSaveRestoreWindow
This commit is contained in:
parent
957c18faf4
commit
0c18b60501
8 changed files with 90 additions and 5 deletions
39
src/ServerManager.Common/Converters/FileSizeConverter.cs
Normal file
39
src/ServerManager.Common/Converters/FileSizeConverter.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace ServerManagerTool.Common.Converters
|
||||
{
|
||||
public class FileSizeConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
private const decimal DIVISOR = 1024M;
|
||||
|
||||
// Load all suffixes in an array
|
||||
private static readonly string[] suffixes = { "Bytes", "KB", "MB", "GB", "TB", "PB" };
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var counter = 0;
|
||||
var number = System.Convert.ToDecimal(value);
|
||||
|
||||
while (number / DIVISOR >= 1)
|
||||
{
|
||||
number /= DIVISOR;
|
||||
counter++;
|
||||
}
|
||||
|
||||
return string.Format("{0:n2} {1}", number, suffixes[counter]);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new InvalidOperationException("FileSizeConverter can only be used OneWay.");
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue