| 1173 | } |
| 1174 | |
| 1175 | bool GameDatabase::loadHashDatabase() |
| 1176 | { |
| 1177 | if (!s_hash_database.empty()) |
| 1178 | return true; |
| 1179 | |
| 1180 | Common::Timer load_timer; |
| 1181 | |
| 1182 | const std::string path(Path::Combine(EmuFolders::Resources, HASHDB_YAML_FILE_NAME)); |
| 1183 | const std::string name(HASHDB_YAML_FILE_NAME); |
| 1184 | |
| 1185 | std::optional<std::string> buffer = FileSystem::ReadFileToString(path.c_str()); |
| 1186 | if (!buffer.has_value()) |
| 1187 | { |
| 1188 | Console.Error("[HashDatabase] Unable to open hash database file, file does not exist."); |
| 1189 | return false; |
| 1190 | } |
| 1191 | |
| 1192 | ryml::csubstr yaml = ryml::to_csubstr(*buffer); |
| 1193 | |
| 1194 | Error error; |
| 1195 | std::optional<ryml::Tree> tree = ParseYAMLFromString(yaml, ryml::to_csubstr(name), &error); |
| 1196 | if (!tree.has_value()) |
| 1197 | { |
| 1198 | Console.ErrorFmt("[HashDatabase] Failed to parse hash database file {}:", path); |
| 1199 | Console.Error(error.GetDescription()); |
| 1200 | return false; |
| 1201 | } |
| 1202 | |
| 1203 | ryml::NodeRef root = tree->rootref(); |
| 1204 | |
| 1205 | bool okay = true; |
| 1206 | for (const ryml::NodeRef& n : root.children()) |
| 1207 | { |
| 1208 | if (!parseHashDatabaseEntry(n)) |
| 1209 | { |
| 1210 | okay = false; |
| 1211 | break; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | if (!okay) |
| 1216 | { |
| 1217 | s_track_hash_to_entry_map.clear(); |
| 1218 | s_hash_database.clear(); |
| 1219 | return false; |
| 1220 | } |
| 1221 | |
| 1222 | Console.WriteLn(Color_StrongGreen, "[HashDatabase] Loaded YAML in %.0f ms", load_timer.GetTimeMilliseconds()); |
| 1223 | return true; |
| 1224 | } |
| 1225 | |
| 1226 | void GameDatabase::unloadHashDatabase() |
| 1227 | { |
nothing calls this directly
no test coverage detected