mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-10-21 03:41:41 +00:00
d536cc8ae6
`MB` and `GB` can either be interpreted as having base-10 units, or base-2. `MiB` and `GiB` removes this discrepancy so that units of memory are always interpreted using base-2 units.
50 lines
No EOL
1.3 KiB
C#
50 lines
No EOL
1.3 KiB
C#
using Ryujinx.Ui.App.Common;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Ryujinx.Ava.Ui.Models.Generic
|
|
{
|
|
internal class FileSizeSortComparer : IComparer<ApplicationData>
|
|
{
|
|
public FileSizeSortComparer() { }
|
|
public FileSizeSortComparer(bool isAscending) { _order = isAscending ? 1 : -1; }
|
|
|
|
private int _order;
|
|
|
|
public int Compare(ApplicationData x, ApplicationData y)
|
|
{
|
|
string aValue = x.FileSize;
|
|
string bValue = y.FileSize;
|
|
|
|
if (aValue[^3..] == "GiB")
|
|
{
|
|
aValue = (float.Parse(aValue[0..^3]) * 1024).ToString();
|
|
}
|
|
else
|
|
{
|
|
aValue = aValue[0..^3];
|
|
}
|
|
|
|
if (bValue[^3..] == "GiB")
|
|
{
|
|
bValue = (float.Parse(bValue[0..^3]) * 1024).ToString();
|
|
}
|
|
else
|
|
{
|
|
bValue = bValue[0..^3];
|
|
}
|
|
|
|
if (float.Parse(aValue) > float.Parse(bValue))
|
|
{
|
|
return -1 * _order;
|
|
}
|
|
else if (float.Parse(bValue) > float.Parse(aValue))
|
|
{
|
|
return 1 * _order;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
} |