GameDatabase: Use resource abstraction to read yaml

This commit is contained in:
Connor McLaughlin 2021-12-26 14:32:07 +10:00 committed by refractionpcsx2
parent 2c32c374fb
commit 1859ede325
3 changed files with 3 additions and 26 deletions

View File

@ -254,24 +254,14 @@ static void initDatabase()
});
try
{
auto filePath = Host::getResourceFilePath(GAMEDB_YAML_FILE_NAME);
if (!filePath.has_value())
std::optional<std::vector<u8>> buf(Host::ReadResourceFile(GAMEDB_YAML_FILE_NAME));
if (!buf.has_value())
{
Console.Error("[GameDB] Unable to open GameDB file, file does not exist.");
return;
}
auto dbStream = getFileStream(filePath.value());
dbStream.seekg(0, std::ios::end);
const size_t size = dbStream.tellg();
dbStream.seekg(0, std::ios::beg);
std::vector<char> buf(size);
dbStream.read(buf.data(), size);
dbStream.close();
const ryml::substr view = c4::basic_substring<char>(buf.data(), size);
const ryml::substr view = c4::basic_substring<char>(reinterpret_cast<char*>(buf->data()), buf->size());
ryml::Tree tree = ryml::parse(view);
ryml::NodeRef root = tree.rootref();

View File

@ -41,7 +41,4 @@ namespace Host
/// Reads a resource file file from the resources directory as a string.
std::optional<std::string> ReadResourceFileToString(const char* filename);
/// Returns the full filepath to a resource file, if it exists.
std::optional<std::string> getResourceFilePath(const char* filename);
} // namespace Host

View File

@ -67,13 +67,3 @@ std::optional<std::string> Host::ReadResourceFileToString(const char* filename)
return ret;
}
std::optional<std::string> Host::getResourceFilePath(const char* filename)
{
const std::string full_filename(Path::CombineStdString(EmuFolders::Resources, filename));
if (!FileSystem::FileExists(full_filename.c_str()))
{
Console.Error("Resource file does not exist '%s'", filename);
return std::nullopt;
}
return full_filename;
}