MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / loadYamlFile

Function loadYamlFile

pcsx2/SIO/Memcard/MemoryCardFolder.cpp:28–54  ·  view source on GitHub ↗

A helper function to parse the YAML file

Source from the content-addressed store, hash-verified

26
27// A helper function to parse the YAML file
28static std::optional<ryml::Tree> loadYamlFile(const char* filePath)
29{
30 const std::optional<std::string> buffer = FileSystem::ReadFileToString(filePath);
31 if (!buffer.has_value())
32 return std::nullopt;
33
34 const ryml::csubstr yaml(ryml::to_csubstr(buffer.value()));
35 const std::string file_name(Path::GetFileName(filePath));
36
37 Error error;
38 std::optional<ryml::Tree> tree = ParseYAMLFromString(yaml, ryml::to_csubstr(file_name), &error);
39 if (!tree.has_value())
40 {
41 Console.ErrorFmt("[MemoryCard] Failed to parse folder memory card file '{}':", filePath);
42 Console.Error(error.GetDescription());
43 return std::nullopt;
44 }
45
46 // Repair damaged memory card entries - file names were saved to the YAML file with trailing \0's
47 // due to a possible rapidyaml bug: https://github.com/biojppm/rapidyaml/issues/531
48 for (ryml::NodeRef node : tree->rootref().children())
49 {
50 node.set_key(node.key().trimr('\0'));
51 }
52
53 return tree;
54}
55
56/// A helper function to write a YAML file
57static void SaveYAMLToFile(const char* filename, const ryml::NodeRef& node)

Callers 4

FlushFileEntriesMethod · 0.85
GetOrderedFilesMethod · 0.85
DeleteFromIndexMethod · 0.85
WriteIndexMethod · 0.85

Calls 6

ParseYAMLFromStringFunction · 0.85
GetDescriptionMethod · 0.80
keyMethod · 0.80
valueMethod · 0.45
ErrorFmtMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected