22 if (!std::filesystem::exists(path)) {
27 auto* ore =
new ORE{path};
28 auto packFile = std::unique_ptr<PackFile>(ore);
30 FileStream reader{ore->fullFilePath};
33 auto headerSize = reader.read<uint32_t>();
34 auto dirCount = reader.read<uint32_t>();
35 std::vector<std::pair<std::string, uint32_t>> dirInfos;
36 for (uint32_t i = 0; i < dirCount; i++) {
37 std::pair<std::string, uint32_t> dirInfo;
38 dirInfo.first = reader.read_string();
39 dirInfo.second = reader.read<uint32_t>();
40 dirInfos.push_back(dirInfo);
42 if (reader.tell_in() != headerSize) {
46 auto looseFileCount = reader.read<uint32_t>();
47 const auto addOreFiles = [&callback, ore, &reader](
const std::string& dirName, uint32_t dirOffset, uint32_t fileCount) {
48 for (uint32_t i = 0; i < fileCount; i++) {
51 auto entryPath = ore->cleanEntryPath(dirName + (dirName.empty() ?
"" :
"/") + reader.read_string());
53 entry.
offset = reader.read<uint32_t>() + dirOffset;
54 entry.
length = reader.read<uint32_t>();
56 ore->entries.emplace(entryPath, entry);
59 callback(entryPath, entry);
63 addOreFiles(
"", headerSize, looseFileCount);
65 for (
const auto& [dirName, dirOffset] : dirInfos) {
66 reader.seek_in(dirOffset);
67 if (reader.read<uint64_t>() != 8) {
70 addOreFiles(dirName, dirOffset +
sizeof(uint64_t), reader.read<uint32_t>());
This class represents the metadata that a file has inside a PackFile.
uint64_t offset
Offset, format-specific meaning - 0 if unused, or if the offset genuinely is 0.
uint64_t length
Length in bytes (in formats with compression, this is the uncompressed length)