2021-01-08 08:14:13 +00:00
|
|
|
|
using Gtk;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Ui.Helper
|
|
|
|
|
{
|
|
|
|
|
static class SortHelper
|
|
|
|
|
{
|
|
|
|
|
public static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b)
|
|
|
|
|
{
|
2023-01-16 02:09:52 +00:00
|
|
|
|
static string ReverseFormat(string time)
|
2021-01-08 08:14:13 +00:00
|
|
|
|
{
|
2023-01-16 02:09:52 +00:00
|
|
|
|
if (time == "Never")
|
|
|
|
|
{
|
|
|
|
|
return "00";
|
|
|
|
|
}
|
2021-01-08 08:14:13 +00:00
|
|
|
|
|
2023-01-16 02:09:52 +00:00
|
|
|
|
var numbers = time.Split(new char[] { 'd', 'h', 'm' });
|
2021-01-08 08:14:13 +00:00
|
|
|
|
|
2023-01-16 02:09:52 +00:00
|
|
|
|
time = time.Replace(" ", "").Replace("d", ".").Replace("h", ":").Replace("m", "");
|
|
|
|
|
|
|
|
|
|
if (numbers.Length == 2)
|
|
|
|
|
{
|
|
|
|
|
return $"00.00:{time}";
|
|
|
|
|
}
|
|
|
|
|
else if (numbers.Length == 3)
|
|
|
|
|
{
|
|
|
|
|
return $"00.{time}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return time;
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|
2023-01-16 02:09:52 +00:00
|
|
|
|
|
|
|
|
|
string aValue = ReverseFormat(model.GetValue(a, 5).ToString());
|
|
|
|
|
string bValue = ReverseFormat(model.GetValue(b, 5).ToString());
|
|
|
|
|
|
|
|
|
|
return TimeSpan.Compare(TimeSpan.Parse(aValue), TimeSpan.Parse(bValue));
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int LastPlayedSort(ITreeModel model, TreeIter a, TreeIter b)
|
|
|
|
|
{
|
|
|
|
|
string aValue = model.GetValue(a, 6).ToString();
|
|
|
|
|
string bValue = model.GetValue(b, 6).ToString();
|
|
|
|
|
|
|
|
|
|
if (aValue == "Never")
|
|
|
|
|
{
|
|
|
|
|
aValue = DateTime.UnixEpoch.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bValue == "Never")
|
|
|
|
|
{
|
|
|
|
|
bValue = DateTime.UnixEpoch.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DateTime.Compare(DateTime.Parse(bValue), DateTime.Parse(aValue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int FileSizeSort(ITreeModel model, TreeIter a, TreeIter b)
|
|
|
|
|
{
|
|
|
|
|
string aValue = model.GetValue(a, 8).ToString();
|
|
|
|
|
string bValue = model.GetValue(b, 8).ToString();
|
|
|
|
|
|
2022-11-16 22:27:42 +00:00
|
|
|
|
if (aValue[^3..] == "GiB")
|
2021-01-08 08:14:13 +00:00
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
|
aValue = (float.Parse(aValue[0..^3]) * 1024).ToString();
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
|
aValue = aValue[0..^3];
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 22:27:42 +00:00
|
|
|
|
if (bValue[^3..] == "GiB")
|
2021-01-08 08:14:13 +00:00
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
|
bValue = (float.Parse(bValue[0..^3]) * 1024).ToString();
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-16 22:27:42 +00:00
|
|
|
|
bValue = bValue[0..^3];
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (float.Parse(aValue) > float.Parse(bValue))
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else if (float.Parse(bValue) > float.Parse(aValue))
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-16 02:09:52 +00:00
|
|
|
|
}
|