SortHelper.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Gtk;
  2. using System;
  3. namespace Ryujinx.Ui.Helper
  4. {
  5. static class SortHelper
  6. {
  7. public static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b)
  8. {
  9. string aValue = model.GetValue(a, 5).ToString();
  10. string bValue = model.GetValue(b, 5).ToString();
  11. if (aValue.Length > 4 && aValue[^4..] == "mins")
  12. {
  13. aValue = (float.Parse(aValue[0..^5]) * 60).ToString();
  14. }
  15. else if (aValue.Length > 3 && aValue[^3..] == "hrs")
  16. {
  17. aValue = (float.Parse(aValue[0..^4]) * 3600).ToString();
  18. }
  19. else if (aValue.Length > 4 && aValue[^4..] == "days")
  20. {
  21. aValue = (float.Parse(aValue[0..^5]) * 86400).ToString();
  22. }
  23. else
  24. {
  25. aValue = aValue[0..^1];
  26. }
  27. if (bValue.Length > 4 && bValue[^4..] == "mins")
  28. {
  29. bValue = (float.Parse(bValue[0..^5]) * 60).ToString();
  30. }
  31. else if (bValue.Length > 3 && bValue[^3..] == "hrs")
  32. {
  33. bValue = (float.Parse(bValue[0..^4]) * 3600).ToString();
  34. }
  35. else if (bValue.Length > 4 && bValue[^4..] == "days")
  36. {
  37. bValue = (float.Parse(bValue[0..^5]) * 86400).ToString();
  38. }
  39. else
  40. {
  41. bValue = bValue[0..^1];
  42. }
  43. if (float.Parse(aValue) > float.Parse(bValue))
  44. {
  45. return -1;
  46. }
  47. else if (float.Parse(bValue) > float.Parse(aValue))
  48. {
  49. return 1;
  50. }
  51. else
  52. {
  53. return 0;
  54. }
  55. }
  56. public static int LastPlayedSort(ITreeModel model, TreeIter a, TreeIter b)
  57. {
  58. string aValue = model.GetValue(a, 6).ToString();
  59. string bValue = model.GetValue(b, 6).ToString();
  60. if (aValue == "Never")
  61. {
  62. aValue = DateTime.UnixEpoch.ToString();
  63. }
  64. if (bValue == "Never")
  65. {
  66. bValue = DateTime.UnixEpoch.ToString();
  67. }
  68. return DateTime.Compare(DateTime.Parse(bValue), DateTime.Parse(aValue));
  69. }
  70. public static int FileSizeSort(ITreeModel model, TreeIter a, TreeIter b)
  71. {
  72. string aValue = model.GetValue(a, 8).ToString();
  73. string bValue = model.GetValue(b, 8).ToString();
  74. if (aValue[^2..] == "GB")
  75. {
  76. aValue = (float.Parse(aValue[0..^2]) * 1024).ToString();
  77. }
  78. else
  79. {
  80. aValue = aValue[0..^2];
  81. }
  82. if (bValue[^2..] == "GB")
  83. {
  84. bValue = (float.Parse(bValue[0..^2]) * 1024).ToString();
  85. }
  86. else
  87. {
  88. bValue = bValue[0..^2];
  89. }
  90. if (float.Parse(aValue) > float.Parse(bValue))
  91. {
  92. return -1;
  93. }
  94. else if (float.Parse(bValue) > float.Parse(aValue))
  95. {
  96. return 1;
  97. }
  98. else
  99. {
  100. return 0;
  101. }
  102. }
  103. }
  104. }