LastPlayedSortComparer.cs 997 B

123456789101112131415161718192021222324252627282930313233
  1. using Ryujinx.Ava.Common.Locale;
  2. using Ryujinx.Ui.App.Common;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Ava.UI.Models.Generic
  6. {
  7. internal class LastPlayedSortComparer : IComparer<ApplicationData>
  8. {
  9. public LastPlayedSortComparer() { }
  10. public LastPlayedSortComparer(bool isAscending) { IsAscending = isAscending; }
  11. public bool IsAscending { get; }
  12. public int Compare(ApplicationData x, ApplicationData y)
  13. {
  14. string aValue = x.LastPlayed;
  15. string bValue = y.LastPlayed;
  16. if (aValue == LocaleManager.Instance[LocaleKeys.Never])
  17. {
  18. aValue = DateTime.UnixEpoch.ToString();
  19. }
  20. if (bValue == LocaleManager.Instance[LocaleKeys.Never])
  21. {
  22. bValue = DateTime.UnixEpoch.ToString();
  23. }
  24. return (IsAscending ? 1 : -1) * DateTime.Compare(DateTime.Parse(bValue), DateTime.Parse(aValue));
  25. }
  26. }
  27. }