9bab8ee8f9
Introduced new services and view models for performance monitoring and system tweaks, including corresponding views. Added converters and updated main application files to integrate these features. Refactored service configuration and improved application structure to support new functionality.
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace ThreadPilot.Converters
|
|
{
|
|
/// <summary>
|
|
/// Converts byte values to human-readable string format
|
|
/// </summary>
|
|
public class BytesToStringConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is long bytes)
|
|
{
|
|
return FormatBytes(bytes);
|
|
}
|
|
|
|
if (value is int intBytes)
|
|
{
|
|
return FormatBytes(intBytes);
|
|
}
|
|
|
|
return "0 B";
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static string FormatBytes(long bytes)
|
|
{
|
|
string[] suffixes = { "B", "KB", "MB", "GB", "TB" };
|
|
int counter = 0;
|
|
decimal number = bytes;
|
|
|
|
while (Math.Round(number / 1024) >= 1)
|
|
{
|
|
number /= 1024;
|
|
counter++;
|
|
}
|
|
|
|
return $"{number:n1} {suffixes[counter]}";
|
|
}
|
|
}
|
|
}
|