A helper function to parse the YAML file
| 26 | |
| 27 | // A helper function to parse the YAML file |
| 28 | static 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 |
| 57 | static void SaveYAMLToFile(const char* filename, const ryml::NodeRef& node) |
no test coverage detected