2022-11-01 18:21:26 +00:00
|
|
|
#include "PackIndex.h"
|
2022-11-03 03:30:35 +00:00
|
|
|
#include "BinaryIO.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2022-11-01 18:21:26 +00:00
|
|
|
|
|
|
|
PackIndex::PackIndex(const std::filesystem::path& filePath) {
|
|
|
|
m_FileStream = std::ifstream(filePath / "versions" / "primary.pki", std::ios::in | std::ios::binary);
|
|
|
|
|
|
|
|
BinaryIO::BinaryRead<uint32_t>(m_FileStream, m_Version);
|
|
|
|
BinaryIO::BinaryRead<uint32_t>(m_FileStream, m_PackPathCount);
|
2023-12-23 17:24:16 +00:00
|
|
|
|
|
|
|
m_PackPaths.resize(m_PackPathCount);
|
|
|
|
for (auto& item : m_PackPaths) {
|
|
|
|
BinaryIO::ReadString<uint32_t>(m_FileStream, item, BinaryIO::ReadType::String);
|
2022-11-01 18:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BinaryIO::BinaryRead<uint32_t>(m_FileStream, m_PackFileIndexCount);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_PackFileIndexCount; i++) {
|
|
|
|
PackFileIndex packFileIndex;
|
|
|
|
BinaryIO::BinaryRead<PackFileIndex>(m_FileStream, packFileIndex);
|
|
|
|
|
|
|
|
m_PackFileIndices.push_back(packFileIndex);
|
|
|
|
}
|
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Loaded pack catalog with %i pack files and %i files", m_PackPaths.size(), m_PackFileIndices.size());
|
2022-11-01 18:21:26 +00:00
|
|
|
|
2022-11-03 03:30:35 +00:00
|
|
|
for (auto& item : m_PackPaths) {
|
|
|
|
std::replace(item.begin(), item.end(), '\\', '/');
|
|
|
|
|
2022-11-01 18:21:26 +00:00
|
|
|
auto* pack = new Pack(filePath / item);
|
|
|
|
|
|
|
|
m_Packs.push_back(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_FileStream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
PackIndex::~PackIndex() {
|
|
|
|
for (const auto* item : m_Packs) {
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|