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

Method initDatabase

pcsx2/GameDatabase.cpp:1018–1062  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1016}
1017
1018void GameDatabase::initDatabase()
1019{
1020 const std::string path(Path::Combine(EmuFolders::Resources, GAMEDB_YAML_FILE_NAME));
1021 const std::string name(GAMEDB_YAML_FILE_NAME);
1022
1023 const std::optional<std::string> buffer = FileSystem::ReadFileToString(path.c_str());
1024 if (!buffer.has_value())
1025 {
1026 Console.Error("GameDB: Unable to open GameDB file, file does not exist.");
1027 return;
1028 }
1029
1030 const ryml::csubstr yaml = ryml::to_csubstr(*buffer);
1031
1032 Error error;
1033 std::optional<ryml::Tree> tree = ParseYAMLFromString(yaml, ryml::to_csubstr(name), &error);
1034 if (!tree.has_value())
1035 {
1036 Console.ErrorFmt("GameDB: Failed to parse game database file {}:", path);
1037 Console.Error(error.GetDescription());
1038 return;
1039 }
1040
1041 ryml::NodeRef root = tree->rootref();
1042
1043 for (const ryml::NodeRef& n : root.children())
1044 {
1045 auto serial = StringUtil::toLower(std::string(n.key().str, n.key().len));
1046
1047 // Serials and CRCs must be inserted as lower-case, as that is how they are retrieved
1048 // this is because the application may pass a lowercase CRC or serial along
1049 //
1050 // However, YAML's keys are as expected case-sensitive, so we have to explicitly do our own duplicate checking
1051 if (s_game_db.count(serial) == 1)
1052 {
1053 Console.ErrorFmt("GameDB: Duplicate serial '{}' found in GameDB. Skipping, Serials are case-insensitive!", serial);
1054 continue;
1055 }
1056
1057 if (n.is_map())
1058 {
1059 parseAndInsert(serial, n);
1060 }
1061 }
1062}
1063
1064void GameDatabase::ensureLoaded()
1065{

Callers

nothing calls this directly

Calls 10

CombineFunction · 0.85
ParseYAMLFromStringFunction · 0.85
toLowerFunction · 0.85
GetDescriptionMethod · 0.80
keyMethod · 0.80
stringClass · 0.50
c_strMethod · 0.45
ErrorMethod · 0.45
ErrorFmtMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected