Skip to content

Commit

Permalink
GameDatabase: Use resource abstraction to read yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed Dec 28, 2021
1 parent 2c32c37 commit 1859ede
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
16 changes: 3 additions & 13 deletions pcsx2/GameDatabase.cpp
Expand Up @@ -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();

Expand Down
3 changes: 0 additions & 3 deletions pcsx2/Host.h
Expand Up @@ -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
10 changes: 0 additions & 10 deletions pcsx2/gui/AppHost.cpp
Expand Up @@ -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;
}

0 comments on commit 1859ede

Please sign in to comment.