UI: Fixes GTK sorting regression of #4294

This commit is contained in:
Ac_K 2023-01-16 03:09:52 +01:00 committed by GitHub
parent 784cf9d594
commit 1faff14e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,65 +7,33 @@ namespace Ryujinx.Ui.Helper
{ {
public static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b) public static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b)
{ {
string aValue = model.GetValue(a, 5).ToString(); static string ReverseFormat(string time)
string bValue = model.GetValue(b, 5).ToString(); {
float aFloat; if (time == "Never")
float bFloat; {
return "00";
}
if (aValue.Length > 7 && aValue[^7..] == "minutes") var numbers = time.Split(new char[] { 'd', 'h', 'm' });
{
aValue = aValue.Replace("minutes", ""); time = time.Replace(" ", "").Replace("d", ".").Replace("h", ":").Replace("m", "");
aFloat = (float.Parse(aValue) * 60);
} if (numbers.Length == 2)
else if (aValue.Length > 5 && aValue[^5..] == "hours") {
{ return $"00.00:{time}";
aValue = aValue.Replace("hours", ""); }
aFloat = (float.Parse(aValue) * 3600); else if (numbers.Length == 3)
} {
else if (aValue.Length > 4 && aValue[^4..] == "days") return $"00.{time}";
{ }
aValue = aValue.Replace("days", "");
aFloat = (float.Parse(aValue) * 86400); return time;
}
else
{
aValue = aValue.Replace("seconds", "");
aFloat = float.Parse(aValue);
} }
if (bValue.Length > 7 && bValue[^7..] == "minutes") string aValue = ReverseFormat(model.GetValue(a, 5).ToString());
{ string bValue = ReverseFormat(model.GetValue(b, 5).ToString());
bValue = bValue.Replace("minutes", "");
bFloat = (float.Parse(bValue) * 60);
}
else if (bValue.Length > 5 && bValue[^5..] == "hours")
{
bValue = bValue.Replace("hours", "");
bFloat = (float.Parse(bValue) * 3600);
}
else if (bValue.Length > 4 && bValue[^4..] == "days")
{
bValue = bValue.Replace("days", "");
bFloat = (float.Parse(bValue) * 86400);
}
else
{
bValue = bValue[0..^8];
bFloat = float.Parse(bValue);
}
if (aFloat > bFloat) return TimeSpan.Compare(TimeSpan.Parse(aValue), TimeSpan.Parse(bValue));
{
return -1;
}
else if (bFloat > aFloat)
{
return 1;
}
else
{
return 0;
}
} }
public static int LastPlayedSort(ITreeModel model, TreeIter a, TreeIter b) public static int LastPlayedSort(ITreeModel model, TreeIter a, TreeIter b)