diff --git a/MystatDesktopWpf/Languages/lang.en-US.xaml b/MystatDesktopWpf/Languages/lang.en-US.xaml index c38dc0f..08666ec 100644 --- a/MystatDesktopWpf/Languages/lang.en-US.xaml +++ b/MystatDesktopWpf/Languages/lang.en-US.xaml @@ -190,4 +190,10 @@ Windows settings Run on Windows startup + + + B + KB + MB + GB diff --git a/MystatDesktopWpf/Languages/lang.ru-RU.xaml b/MystatDesktopWpf/Languages/lang.ru-RU.xaml index 38fec0e..5a8ae99 100644 --- a/MystatDesktopWpf/Languages/lang.ru-RU.xaml +++ b/MystatDesktopWpf/Languages/lang.ru-RU.xaml @@ -189,4 +189,10 @@ Настройки Windows Запускать при старте Windows + + + Б + КБ + МБ + ГБ diff --git a/MystatDesktopWpf/Languages/lang.uk-UA.xaml b/MystatDesktopWpf/Languages/lang.uk-UA.xaml index f303c2f..4533510 100644 --- a/MystatDesktopWpf/Languages/lang.uk-UA.xaml +++ b/MystatDesktopWpf/Languages/lang.uk-UA.xaml @@ -189,4 +189,10 @@ Налаштування Windows Запускати під час старту Windows + + + Б + КБ + МБ + ГБ diff --git a/MystatDesktopWpf/Services/SizeFormatterService.cs b/MystatDesktopWpf/Services/SizeFormatterService.cs new file mode 100644 index 0000000..34badcc --- /dev/null +++ b/MystatDesktopWpf/Services/SizeFormatterService.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MystatDesktopWpf.Services +{ + internal static class SizeFormatterService + { + static string[] sizeLabelKeys = new string[] { "size-b", "size-kb", "size-mb", "size-gb" }; + + public static string Format(long sizeInBytes) + { + double cacheSize = sizeInBytes; + string label = sizeLabelKeys[0]; + + int i = 0; + while (cacheSize >= 1024) + { + cacheSize = Math.Round(cacheSize / 1024.0, 2, MidpointRounding.ToZero); + label = sizeLabelKeys[++i]; + } + + return $"{cacheSize} {App.Current.FindResource(label)}"; + } + } +} diff --git a/MystatDesktopWpf/UserControls/SettingsSections/CacheSettings.xaml.cs b/MystatDesktopWpf/UserControls/SettingsSections/CacheSettings.xaml.cs index 17b9bbd..b249f58 100644 --- a/MystatDesktopWpf/UserControls/SettingsSections/CacheSettings.xaml.cs +++ b/MystatDesktopWpf/UserControls/SettingsSections/CacheSettings.xaml.cs @@ -21,8 +21,6 @@ namespace MystatDesktopWpf.UserControls.SettingsSections /// public partial class CacheSettings : UserControl { - static string[] cacheSizeLabels = new string[] { "B", "KB", "MB", "GB" }; - public CacheSettings() { InitializeComponent(); @@ -52,19 +50,7 @@ public async void UpdateCacheSize() CacheSizeTextBlock.SetResourceReference(TextBlock.TextProperty, "m_Calculating"); long cacheSizeInBytes = await MystatAPICachingService.GetCacheSize(); - - - double cacheSize = cacheSizeInBytes; - string label = cacheSizeLabels[0]; - - int i = 0; - while (cacheSize >= 1024) - { - cacheSize = Math.Round(cacheSize / 1024.0, 2, MidpointRounding.ToZero); - label = cacheSizeLabels[++i]; - } - - CacheSizeTextBlock.Text = $"{cacheSize} {label}"; + CacheSizeTextBlock.Text = SizeFormatterService.Format(cacheSizeInBytes); } } }