2021-01-08 03:14:13 -05:00
|
|
|
|
using Gtk;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Ui.Helper
|
|
|
|
|
{
|
|
|
|
|
static class SortHelper
|
|
|
|
|
{
|
|
|
|
|
public static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b)
|
|
|
|
|
{
|
|
|
|
|
string aValue = model.GetValue(a, 5).ToString();
|
|
|
|
|
string bValue = model.GetValue(b, 5).ToString();
|
2022-12-05 20:40:06 -05:00
|
|
|
|
float aFloat;
|
|
|
|
|
float bFloat;
|
2021-01-08 03:14:13 -05:00
|
|
|
|
|
2022-12-05 20:40:06 -05:00
|
|
|
|
if (aValue.Length > 7 && aValue[^7..] == "minutes")
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
aValue = aValue.Replace("minutes", "");
|
|
|
|
|
aFloat = (float.Parse(aValue) * 60);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
2022-12-05 20:40:06 -05:00
|
|
|
|
else if (aValue.Length > 5 && aValue[^5..] == "hours")
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
aValue = aValue.Replace("hours", "");
|
|
|
|
|
aFloat = (float.Parse(aValue) * 3600);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
else if (aValue.Length > 4 && aValue[^4..] == "days")
|
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
aValue = aValue.Replace("days", "");
|
|
|
|
|
aFloat = (float.Parse(aValue) * 86400);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
aValue = aValue.Replace("seconds", "");
|
|
|
|
|
aFloat = float.Parse(aValue);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 20:40:06 -05:00
|
|
|
|
if (bValue.Length > 7 && bValue[^7..] == "minutes")
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
bValue = bValue.Replace("minutes", "");
|
|
|
|
|
bFloat = (float.Parse(bValue) * 60);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
2022-12-05 20:40:06 -05:00
|
|
|
|
else if (bValue.Length > 5 && bValue[^5..] == "hours")
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
bValue = bValue.Replace("hours", "");
|
|
|
|
|
bFloat = (float.Parse(bValue) * 3600);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
else if (bValue.Length > 4 && bValue[^4..] == "days")
|
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
bValue = bValue.Replace("days", "");
|
|
|
|
|
bFloat = (float.Parse(bValue) * 86400);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-12-05 20:40:06 -05:00
|
|
|
|
bValue = bValue[0..^8];
|
|
|
|
|
bFloat = float.Parse(bValue);
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 20:40:06 -05:00
|
|
|
|
if (aFloat > bFloat)
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2022-12-05 20:40:06 -05:00
|
|
|
|
else if (bFloat > aFloat)
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 17:27:42 -05:00
|
|
|
|
if (aValue[^3..] == "GiB")
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
2022-11-16 17:27:42 -05:00
|
|
|
|
aValue = (float.Parse(aValue[0..^3]) * 1024).ToString();
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-16 17:27:42 -05:00
|
|
|
|
aValue = aValue[0..^3];
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 17:27:42 -05:00
|
|
|
|
if (bValue[^3..] == "GiB")
|
2021-01-08 03:14:13 -05:00
|
|
|
|
{
|
2022-11-16 17:27:42 -05:00
|
|
|
|
bValue = (float.Parse(bValue[0..^3]) * 1024).ToString();
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-16 17:27:42 -05:00
|
|
|
|
bValue = bValue[0..^3];
|
2021-01-08 03:14:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (float.Parse(aValue) > float.Parse(bValue))
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
else if (float.Parse(bValue) > float.Parse(aValue))
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|