Archived
1
Fork 0

Add exists() method to GameData

This commit is contained in:
Joshua Goins 2022-04-17 20:00:23 -04:00
parent e53e1a0e6c
commit 872bef51bb
2 changed files with 29 additions and 0 deletions

View file

@ -30,6 +30,8 @@ public:
[[nodiscard]] [[nodiscard]]
std::optional<MemoryBuffer> extractFile(std::string_view data_file_path); std::optional<MemoryBuffer> extractFile(std::string_view data_file_path);
bool exists(std::string_view data_file_path);
IndexFile<IndexHashTableEntry> getIndexListing(std::string_view folder); IndexFile<IndexHashTableEntry> getIndexListing(std::string_view folder);
void extractSkeleton(); void extractSkeleton();

View file

@ -347,6 +347,33 @@ std::optional<MemoryBuffer> GameData::extractFile(const std::string_view data_fi
} }
fmt::print("Failed to find file {}.\n", data_file_path); fmt::print("Failed to find file {}.\n", data_file_path);
return std::nullopt;
}
bool GameData::exists(std::string_view data_file_path) {
const uint64_t hash = calculateHash(data_file_path);
auto [repository, category] = calculateRepositoryCategory(data_file_path);
auto [index_filename, index2_filename] = repository.get_index_filenames(categoryToID[category]);
auto index_path = fmt::format("{data_directory}/{repository}/{filename}",
fmt::arg("data_directory", dataDirectory),
fmt::arg("repository", repository.name),
fmt::arg("filename", index_filename));
auto index2_path = fmt::format("{data_directory}/{repository}/{filename}",
fmt::arg("data_directory", dataDirectory),
fmt::arg("repository", repository.name),
fmt::arg("filename", index2_filename));
auto index_file = read_index_files(index_path, index2_path);
for(const auto entry : index_file.entries) {
if (entry.hash == hash) {
return true;
}
}
return false;
} }
std::optional<EXH> GameData::readExcelSheet(std::string_view name) { std::optional<EXH> GameData::readExcelSheet(std::string_view name) {