2023-12-04 13:17:13 +00:00
|
|
|
using System;
|
2023-05-12 00:56:37 +01:00
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
|
|
namespace Ryujinx.Ui.App.Common
|
2021-01-08 08:14:13 +00:00
|
|
|
{
|
|
|
|
public class ApplicationMetadata
|
|
|
|
{
|
2022-12-02 13:16:43 +00:00
|
|
|
public string Title { get; set; }
|
2023-06-29 01:39:22 +01:00
|
|
|
public bool Favorite { get; set; }
|
Overhaul of string formatting/parsing/sorting logic for TimeSpans, DateTimes, and file sizes (#4956)
* Fixed formatting/parsing issues with ApplicationData properties TimePlayed, LastPlayed, and FileSize
Replaced double-based TimePlayed property with TimeSpan?-based one in ApplicationData and ApplicationMetadata
Added a migration for TimePlayed, just like in #4861
Consolidated ApplicationData's FileSize* properties into one FileSize property
Added a formatting/parsing helper class ValueFormatUtils for TimeSpans, DateTimes, and file sizes
Added new value converters for TimeSpans and file sizes for the Avalonia UI
Added TimePlayedSortComparer
Fixed sort order in LastPlayedSortComparer
Fixed sort order for ApplicationData fields TimePlayed, LastPlayed, and FileSize
Fixed crashes caused by SortHelper
Replaced SystemInfo.ToMiBString with ToGiBString backed by ValueFormatUtils
Replaced SaveModel.GetSizeString() with ValueFormatUtils
* Additional ApplicationLibrary changes that got lost in the last commit
* Removed unneeded usings
* Removed converters as they are no longer needed
* Updated comment on FormatDateTime
* Removed base10 parameter from ValueFormatUtils
FormatFileSize now always returns base 2 values with base 10 units
Made ParseFileSize capable of parsing both base 2 and base 10 units
* Removed nullable attribute from TimePlayed property
Centralized TimePlayed update code into ApplicationMetadata
* Changed UpdateTimePlayed() to use TimeSpan logic
* Removed JsonIgnore attributes from ApplicationData
* Implemented requested format changes
* Fixed mistakes in method documentation comments
* Made it so the Last Played value "Never" is localized in the Avalonia UI
* Implemented suggestions
* Remove unused import
* Did a comment refinement pass in ValueFormatUtils.cs
* Reordered ValueFormatUtils methods and sorted them into #regions
* Integrated functionality from #5056
Also removed Logger print from last_played migration code
* Implemented suggestions
* Moved ValueFormatUtils and SystemInfo to namespace Ryujinx.Ui.Common
* common: Respect proper value format convention and use base10 by default
This could be discuss again in another issue/PR, for now revert to the previous behavior.
Signed-off-by: Mary Guillemard <mary@mary.zone>
---------
Signed-off-by: Mary Guillemard <mary@mary.zone>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Mary Guillemard <mary@mary.zone>
2023-11-06 21:47:44 +00:00
|
|
|
|
|
|
|
[JsonPropertyName("timespan_played")]
|
|
|
|
public TimeSpan TimePlayed { get; set; } = TimeSpan.Zero;
|
2023-05-12 00:56:37 +01:00
|
|
|
|
|
|
|
[JsonPropertyName("last_played_utc")]
|
|
|
|
public DateTime? LastPlayed { get; set; } = null;
|
|
|
|
|
Overhaul of string formatting/parsing/sorting logic for TimeSpans, DateTimes, and file sizes (#4956)
* Fixed formatting/parsing issues with ApplicationData properties TimePlayed, LastPlayed, and FileSize
Replaced double-based TimePlayed property with TimeSpan?-based one in ApplicationData and ApplicationMetadata
Added a migration for TimePlayed, just like in #4861
Consolidated ApplicationData's FileSize* properties into one FileSize property
Added a formatting/parsing helper class ValueFormatUtils for TimeSpans, DateTimes, and file sizes
Added new value converters for TimeSpans and file sizes for the Avalonia UI
Added TimePlayedSortComparer
Fixed sort order in LastPlayedSortComparer
Fixed sort order for ApplicationData fields TimePlayed, LastPlayed, and FileSize
Fixed crashes caused by SortHelper
Replaced SystemInfo.ToMiBString with ToGiBString backed by ValueFormatUtils
Replaced SaveModel.GetSizeString() with ValueFormatUtils
* Additional ApplicationLibrary changes that got lost in the last commit
* Removed unneeded usings
* Removed converters as they are no longer needed
* Updated comment on FormatDateTime
* Removed base10 parameter from ValueFormatUtils
FormatFileSize now always returns base 2 values with base 10 units
Made ParseFileSize capable of parsing both base 2 and base 10 units
* Removed nullable attribute from TimePlayed property
Centralized TimePlayed update code into ApplicationMetadata
* Changed UpdateTimePlayed() to use TimeSpan logic
* Removed JsonIgnore attributes from ApplicationData
* Implemented requested format changes
* Fixed mistakes in method documentation comments
* Made it so the Last Played value "Never" is localized in the Avalonia UI
* Implemented suggestions
* Remove unused import
* Did a comment refinement pass in ValueFormatUtils.cs
* Reordered ValueFormatUtils methods and sorted them into #regions
* Integrated functionality from #5056
Also removed Logger print from last_played migration code
* Implemented suggestions
* Moved ValueFormatUtils and SystemInfo to namespace Ryujinx.Ui.Common
* common: Respect proper value format convention and use base10 by default
This could be discuss again in another issue/PR, for now revert to the previous behavior.
Signed-off-by: Mary Guillemard <mary@mary.zone>
---------
Signed-off-by: Mary Guillemard <mary@mary.zone>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Mary Guillemard <mary@mary.zone>
2023-11-06 21:47:44 +00:00
|
|
|
[JsonPropertyName("time_played")]
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
|
|
|
public double TimePlayedOld { get; set; }
|
|
|
|
|
2023-05-12 00:56:37 +01:00
|
|
|
[JsonPropertyName("last_played")]
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
|
|
|
public string LastPlayedOld { get; set; }
|
Overhaul of string formatting/parsing/sorting logic for TimeSpans, DateTimes, and file sizes (#4956)
* Fixed formatting/parsing issues with ApplicationData properties TimePlayed, LastPlayed, and FileSize
Replaced double-based TimePlayed property with TimeSpan?-based one in ApplicationData and ApplicationMetadata
Added a migration for TimePlayed, just like in #4861
Consolidated ApplicationData's FileSize* properties into one FileSize property
Added a formatting/parsing helper class ValueFormatUtils for TimeSpans, DateTimes, and file sizes
Added new value converters for TimeSpans and file sizes for the Avalonia UI
Added TimePlayedSortComparer
Fixed sort order in LastPlayedSortComparer
Fixed sort order for ApplicationData fields TimePlayed, LastPlayed, and FileSize
Fixed crashes caused by SortHelper
Replaced SystemInfo.ToMiBString with ToGiBString backed by ValueFormatUtils
Replaced SaveModel.GetSizeString() with ValueFormatUtils
* Additional ApplicationLibrary changes that got lost in the last commit
* Removed unneeded usings
* Removed converters as they are no longer needed
* Updated comment on FormatDateTime
* Removed base10 parameter from ValueFormatUtils
FormatFileSize now always returns base 2 values with base 10 units
Made ParseFileSize capable of parsing both base 2 and base 10 units
* Removed nullable attribute from TimePlayed property
Centralized TimePlayed update code into ApplicationMetadata
* Changed UpdateTimePlayed() to use TimeSpan logic
* Removed JsonIgnore attributes from ApplicationData
* Implemented requested format changes
* Fixed mistakes in method documentation comments
* Made it so the Last Played value "Never" is localized in the Avalonia UI
* Implemented suggestions
* Remove unused import
* Did a comment refinement pass in ValueFormatUtils.cs
* Reordered ValueFormatUtils methods and sorted them into #regions
* Integrated functionality from #5056
Also removed Logger print from last_played migration code
* Implemented suggestions
* Moved ValueFormatUtils and SystemInfo to namespace Ryujinx.Ui.Common
* common: Respect proper value format convention and use base10 by default
This could be discuss again in another issue/PR, for now revert to the previous behavior.
Signed-off-by: Mary Guillemard <mary@mary.zone>
---------
Signed-off-by: Mary Guillemard <mary@mary.zone>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Mary Guillemard <mary@mary.zone>
2023-11-06 21:47:44 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates <see cref="LastPlayed"/>. Call this before launching a game.
|
|
|
|
/// </summary>
|
|
|
|
public void UpdatePreGame()
|
|
|
|
{
|
|
|
|
LastPlayed = DateTime.UtcNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates <see cref="LastPlayed"/> and <see cref="TimePlayed"/>. Call this after a game ends.
|
|
|
|
/// </summary>
|
|
|
|
public void UpdatePostGame()
|
|
|
|
{
|
|
|
|
DateTime? prevLastPlayed = LastPlayed;
|
|
|
|
UpdatePreGame();
|
|
|
|
|
|
|
|
if (!prevLastPlayed.HasValue)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeSpan diff = DateTime.UtcNow - prevLastPlayed.Value;
|
|
|
|
double newTotalSeconds = TimePlayed.Add(diff).TotalSeconds;
|
|
|
|
TimePlayed = TimeSpan.FromSeconds(Math.Round(newTotalSeconds, MidpointRounding.AwayFromZero));
|
|
|
|
}
|
2021-01-08 08:14:13 +00:00
|
|
|
}
|
2023-06-29 01:39:22 +01:00
|
|
|
}
|