From 1859ede3254949ba033e58505cc94bce5355259d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 26 Dec 2021 14:32:07 +1000 Subject: [PATCH] GameDatabase: Use resource abstraction to read yaml --- pcsx2/GameDatabase.cpp | 16 +++------------- pcsx2/Host.h | 3 --- pcsx2/gui/AppHost.cpp | 10 ---------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/pcsx2/GameDatabase.cpp b/pcsx2/GameDatabase.cpp index d12783705e..6559bd451b 100644 --- a/pcsx2/GameDatabase.cpp +++ b/pcsx2/GameDatabase.cpp @@ -254,24 +254,14 @@ static void initDatabase() }); try { - auto filePath = Host::getResourceFilePath(GAMEDB_YAML_FILE_NAME); - if (!filePath.has_value()) + std::optional> 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 buf(size); - dbStream.read(buf.data(), size); - dbStream.close(); - - const ryml::substr view = c4::basic_substring(buf.data(), size); + const ryml::substr view = c4::basic_substring(reinterpret_cast(buf->data()), buf->size()); ryml::Tree tree = ryml::parse(view); ryml::NodeRef root = tree.rootref(); diff --git a/pcsx2/Host.h b/pcsx2/Host.h index 7a0b2d1820..b980ac2980 100644 --- a/pcsx2/Host.h +++ b/pcsx2/Host.h @@ -41,7 +41,4 @@ namespace Host /// Reads a resource file file from the resources directory as a string. std::optional ReadResourceFileToString(const char* filename); - - /// Returns the full filepath to a resource file, if it exists. - std::optional getResourceFilePath(const char* filename); } // namespace Host diff --git a/pcsx2/gui/AppHost.cpp b/pcsx2/gui/AppHost.cpp index efb82302c6..4b8fb3ff57 100644 --- a/pcsx2/gui/AppHost.cpp +++ b/pcsx2/gui/AppHost.cpp @@ -67,13 +67,3 @@ std::optional Host::ReadResourceFileToString(const char* filename) return ret; } -std::optional 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; -}