FileSizeSortComparer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Ryujinx.Ui.App.Common;
  2. using System.Collections;
  3. namespace Ryujinx.Ava.Ui.Models
  4. {
  5. internal class FileSizeSortComparer : IComparer
  6. {
  7. public int Compare(object x, object y)
  8. {
  9. string aValue = (x as ApplicationData).TimePlayed;
  10. string bValue = (y as ApplicationData).TimePlayed;
  11. if (aValue[^2..] == "GB")
  12. {
  13. aValue = (float.Parse(aValue[0..^2]) * 1024).ToString();
  14. }
  15. else
  16. {
  17. aValue = aValue[0..^2];
  18. }
  19. if (bValue[^2..] == "GB")
  20. {
  21. bValue = (float.Parse(bValue[0..^2]) * 1024).ToString();
  22. }
  23. else
  24. {
  25. bValue = bValue[0..^2];
  26. }
  27. if (float.Parse(aValue) > float.Parse(bValue))
  28. {
  29. return -1;
  30. }
  31. else if (float.Parse(bValue) > float.Parse(aValue))
  32. {
  33. return 1;
  34. }
  35. else
  36. {
  37. return 0;
  38. }
  39. }
  40. }
  41. }