Changed LastPlayed field from string to nullable DateTime (#4861)
* Changed LastPlayed field from string to nullable DateTime Added ApplicationData.LastPlayedString property Added NullableDateTimeConverter for the DateTime->string conversion in Avalonia * Added migration from string-based last_played to DateTime-based last_played_utc * Updated comment style * Added MarkupExtension to NullableDateTimeConverter and changed its usage Cleaned up leftover usings * Missed one comment
This commit is contained in:
parent
5cbdfbc7a4
commit
531da8a1c0
9 changed files with 113 additions and 43 deletions
|
@ -414,21 +414,28 @@ namespace Ryujinx.Ui.App.Common
|
|||
ApplicationMetadata appMetadata = LoadAndSaveMetaData(titleId, appMetadata =>
|
||||
{
|
||||
appMetadata.Title = titleName;
|
||||
});
|
||||
|
||||
if (appMetadata.LastPlayed != "Never")
|
||||
{
|
||||
if (!DateTime.TryParse(appMetadata.LastPlayed, out _))
|
||||
if (appMetadata.LastPlayedOld == default || appMetadata.LastPlayed.HasValue)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Application, $"Last played datetime \"{appMetadata.LastPlayed}\" is invalid for current system culture, skipping (did current culture change?)");
|
||||
// Don't do the migration if last_played doesn't exist or last_played_utc already has a value.
|
||||
return;
|
||||
}
|
||||
|
||||
appMetadata.LastPlayed = "Never";
|
||||
// Migrate from string-based last_played to DateTime-based last_played_utc.
|
||||
if (DateTime.TryParse(appMetadata.LastPlayedOld, out DateTime lastPlayedOldParsed))
|
||||
{
|
||||
Logger.Info?.Print(LogClass.Application, $"last_played found: \"{appMetadata.LastPlayedOld}\", migrating to last_played_utc");
|
||||
appMetadata.LastPlayed = lastPlayedOldParsed;
|
||||
|
||||
// Migration successful: deleting last_played from the metadata file.
|
||||
appMetadata.LastPlayedOld = default;
|
||||
}
|
||||
else
|
||||
{
|
||||
appMetadata.LastPlayed = appMetadata.LastPlayed[..^3];
|
||||
// Migration failed: emitting warning but leaving the unparsable value in the metadata file so the user can fix it.
|
||||
Logger.Warning?.Print(LogClass.Application, $"Last played string \"{appMetadata.LastPlayedOld}\" is invalid for current system culture, skipping (did current culture change?)");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ApplicationData data = new()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue