diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index 614f49cc13..ba9f6bac7c 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -1369,6 +1369,14 @@ std::vector FolderMemoryCard::GetOrderedF int64_t orderForDirectories = 1; int64_t orderForLegacyFiles = -1; + const auto getOptionalNodeAttribute = []( const YAML::Node& node, const char* attribName, auto def ) { + auto result = std::move(def); + if ( node.IsDefined() ) { + result = node[attribName].as( def ); + } + return result; + }; + wxString fileName; bool hasNext = dir.GetFirst( &fileName ); while ( hasNext ) { @@ -1386,9 +1394,9 @@ std::vector FolderMemoryCard::GetOrderedF const YAML::Node& node = index[ fileNameUTF8.data() ]; // orderForLegacyFiles will decrement even if it ends up being unused, but that's fine - auto key = std::make_pair( true, node["order"].as( orderForLegacyFiles-- ) ); - EnumeratedFileEntry entry { fileName, node["timeCreated"].as( creationTime.GetTicks() ), - node["timeModified"].as( modificationTime.GetTicks() ), true }; + auto key = std::make_pair( true, getOptionalNodeAttribute( node, "order", orderForLegacyFiles-- ) ); + EnumeratedFileEntry entry { fileName, getOptionalNodeAttribute( node, "timeCreated", creationTime.GetTicks() ), + getOptionalNodeAttribute( node, "timeModified", modificationTime.GetTicks() ), true }; sortContainer.try_emplace( std::move(key), std::move(entry) ); } else { @@ -1403,8 +1411,8 @@ std::vector FolderMemoryCard::GetOrderedF // orderForDirectories will increment even if it ends up being unused, but that's fine auto key = std::make_pair( false, orderForDirectories++ ); - EnumeratedFileEntry entry { fileName, node["timeCreated"].as( creationTime.GetTicks() ), - node["timeModified"].as( modificationTime.GetTicks() ), false }; + EnumeratedFileEntry entry { fileName, getOptionalNodeAttribute( node, "timeCreated", creationTime.GetTicks() ), + getOptionalNodeAttribute( node, "timeModified", modificationTime.GetTicks() ), false }; sortContainer.try_emplace( std::move(key), std::move(entry) ); }