Skip to content

Commit dafaecb

Browse files
committed
MemoryCardFolder: Improve YAML error handling
1 parent c1f8e9f commit dafaecb

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

pcsx2/SIO/Memcard/MemoryCardFolder.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,32 +1788,26 @@ std::vector<FolderMemoryCard::EnumeratedFileEntry> FolderMemoryCard::GetOrderedF
17881788
std::string filePath(Path::Combine(dirPath, fd.FileName));
17891789
if (!(fd.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY))
17901790
{
1791-
std::optional<ryml::Tree> yaml = loadYamlFile(Path::Combine(dirPath, "_pcsx2_index").c_str());
1791+
const std::optional<ryml::Tree> yaml = loadYamlFile(Path::Combine(dirPath, "_pcsx2_index").c_str());
17921792

17931793
EnumeratedFileEntry entry{fd.FileName, fd.CreationTime, fd.ModificationTime, true};
17941794
int64_t newOrder = orderForLegacyFiles--;
17951795
if (yaml.has_value() && !yaml.value().empty())
17961796
{
1797-
ryml::NodeRef index = yaml.value().rootref();
1798-
for (const auto& n : index.children())
1797+
const ryml::ConstNodeRef index_node = yaml.value().crootref();
1798+
if (const ryml::ConstNodeRef child_node = index_node.find_child(ryml::to_csubstr(fd.FileName)); child_node.readable())
17991799
{
1800-
auto key = std::string(n.key().str, n.key().len);
1801-
}
1802-
if (index.has_child(ryml::to_csubstr(fd.FileName)))
1803-
{
1804-
const auto& node = index[ryml::to_csubstr(fd.FileName)];
1805-
if (node.has_child("timeCreated"))
1806-
{
1807-
node["timeCreated"] >> entry.m_timeCreated;
1808-
}
1809-
if (node.has_child("timeModified"))
1810-
{
1811-
node["timeModified"] >> entry.m_timeModified;
1812-
}
1813-
if (node.has_child("order"))
1814-
{
1815-
node["order"] >> newOrder;
1816-
}
1800+
const ryml::ConstNodeRef time_created = child_node.find_child("timeCreated");
1801+
if (time_created.readable() && time_created.has_val() && time_created.val().is_integer())
1802+
ryml::from_chars(time_created.val(), &entry.m_timeCreated);
1803+
1804+
const ryml::ConstNodeRef time_modified = child_node.find_child("timeModified");
1805+
if (time_modified.readable() && time_modified.has_val() && time_modified.val().is_integer())
1806+
ryml::from_chars(time_modified.val(), &entry.m_timeModified);
1807+
1808+
const ryml::ConstNodeRef order = child_node.find_child("order");
1809+
if (order.readable() && order.has_val() && order.val().is_integer())
1810+
ryml::from_chars(order.val(), &newOrder);
18171811
}
18181812
}
18191813

0 commit comments

Comments
 (0)