From ce7c99c3de4853758bd37d46b3e582b27681797a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 14 Apr 2022 08:22:10 -0400 Subject: [PATCH] Add method to get index file directly --- include/gamedata.h | 13 ++++++++----- src/gamedata.cpp | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/gamedata.h b/include/gamedata.h index 28458d7..ec5df7e 100644 --- a/include/gamedata.h +++ b/include/gamedata.h @@ -5,6 +5,7 @@ #include #include "exhparser.h" #include "exlparser.h" +#include "indexparser.h" /* * This handles reading/extracting the raw data from game data packs, such as dat0, index and index2 files. @@ -26,12 +27,19 @@ public: */ void extractFile(std::string_view dataFilePath, std::string_view outPath); + IndexFile getIndexListing(std::string_view folder); + void extractSkeleton(); std::optional readExcelSheet(std::string_view name); std::vector getAllSheetNames(); + /* + * Calculates a uint64 hash from a given game path. + */ + uint64_t calculateHash(std::string_view path); + private: /* * This returns a proper SQEX-style filename for index, index2, and dat files. @@ -44,11 +52,6 @@ private: */ std::tuple calculateRepositoryCategory(std::string_view path); - /* - * Calculates a uint64 hash from a given game path. - */ - uint64_t calculateHash(std::string_view path); - std::string dataDirectory; EXL rootEXL; diff --git a/src/gamedata.cpp b/src/gamedata.cpp index 7980fd5..079b3e9 100644 --- a/src/gamedata.cpp +++ b/src/gamedata.cpp @@ -436,11 +436,14 @@ std::optional GameData::readExcelSheet(std::string_view name) { std::string exhFilename = "exd/" + newFilename + ".exh"; - extractFile(exhFilename, newFilename + ".exh"); + std::string outPath = newFilename + ".exh"; + std::replace(outPath.begin(), outPath.end(), '/', '_'); + + extractFile(exhFilename, outPath); fmt::print("Done extracting files, now parsing...\n"); - return readEXH(newFilename + ".exh"); + return readEXH(outPath); } } @@ -498,3 +501,11 @@ void GameData::extractSkeleton() { fclose(newFile); fclose(file); } + +IndexFile GameData::getIndexListing(std::string_view folder) { + auto [repository, category] = calculateRepositoryCategory(fmt::format("{}/{}", folder, "a")); + + auto indexFilename = calculateFilename(categoryToID[category], getExpansionID(repository), 0, "win32", "index"); + + return readIndexFile(dataDirectory + "/" + repository + "/" + indexFilename); +}