diff options
Diffstat (limited to 'src/Ryujinx.Ava/UI/Models')
| -rw-r--r-- | src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs | 13 | ||||
| -rw-r--r-- | src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs | 31 | ||||
| -rw-r--r-- | src/Ryujinx.Ava/UI/Models/SaveModel.cs | 23 |
3 files changed, 39 insertions, 28 deletions
diff --git a/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs b/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs index 8a434655..8340d39d 100644 --- a/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs +++ b/src/Ryujinx.Ava/UI/Models/Generic/LastPlayedSortComparer.cs @@ -13,20 +13,19 @@ namespace Ryujinx.Ava.UI.Models.Generic public int Compare(ApplicationData x, ApplicationData y) { - var aValue = x.LastPlayed; - var bValue = y.LastPlayed; + DateTime aValue = DateTime.UnixEpoch, bValue = DateTime.UnixEpoch; - if (!aValue.HasValue) + if (x?.LastPlayed != null) { - aValue = DateTime.UnixEpoch; + aValue = x.LastPlayed.Value; } - if (!bValue.HasValue) + if (y?.LastPlayed != null) { - bValue = DateTime.UnixEpoch; + bValue = y.LastPlayed.Value; } - return (IsAscending ? 1 : -1) * DateTime.Compare(bValue.Value, aValue.Value); + return (IsAscending ? 1 : -1) * DateTime.Compare(aValue, bValue); } } } diff --git a/src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs b/src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs new file mode 100644 index 00000000..d53ff566 --- /dev/null +++ b/src/Ryujinx.Ava/UI/Models/Generic/TimePlayedSortComparer.cs @@ -0,0 +1,31 @@ +using Ryujinx.Ui.App.Common; +using System; +using System.Collections.Generic; + +namespace Ryujinx.Ava.UI.Models.Generic +{ + internal class TimePlayedSortComparer : IComparer<ApplicationData> + { + public TimePlayedSortComparer() { } + public TimePlayedSortComparer(bool isAscending) { IsAscending = isAscending; } + + public bool IsAscending { get; } + + public int Compare(ApplicationData x, ApplicationData y) + { + TimeSpan aValue = TimeSpan.Zero, bValue = TimeSpan.Zero; + + if (x?.TimePlayed != null) + { + aValue = x.TimePlayed; + } + + if (y?.TimePlayed != null) + { + bValue = y.TimePlayed; + } + + return (IsAscending ? 1 : -1) * TimeSpan.Compare(aValue, bValue); + } + } +} diff --git a/src/Ryujinx.Ava/UI/Models/SaveModel.cs b/src/Ryujinx.Ava/UI/Models/SaveModel.cs index f15befbb..7b476932 100644 --- a/src/Ryujinx.Ava/UI/Models/SaveModel.cs +++ b/src/Ryujinx.Ava/UI/Models/SaveModel.cs @@ -4,7 +4,7 @@ using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Ava.UI.Windows; using Ryujinx.HLE.FileSystem; using Ryujinx.Ui.App.Common; -using System; +using Ryujinx.Ui.Common.Helper; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -38,26 +38,7 @@ namespace Ryujinx.Ava.UI.Models public bool SizeAvailable { get; set; } - public string SizeString => GetSizeString(); - - private string GetSizeString() - { - const int Scale = 1024; - string[] orders = { "GiB", "MiB", "KiB" }; - long max = (long)Math.Pow(Scale, orders.Length); - - foreach (string order in orders) - { - if (Size > max) - { - return $"{decimal.Divide(Size, max):##.##} {order}"; - } - - max /= Scale; - } - - return "0 KiB"; - } + public string SizeString => ValueFormatUtils.FormatFileSize(Size); public SaveModel(SaveDataInfo info) { |
