MCPcopy Create free account
hub / github.com/Illation/ETEngine / LoadFileList

Method LoadFileList

Engine/source/EtCore/FileSystem/Package/FilePackage.cpp:102–175  ·  view source on GitHub ↗

--------------------------------- FilePackage::LoadFileList Load all the relevant data about the files without actually loading their content

Source from the content-addressed store, hash-verified

100// Load all the relevant data about the files without actually loading their content
101//
102void FilePackage::LoadFileList()
103{
104 ET_ASSERT(m_File != nullptr);
105
106 // read the package header
107 //-------------------------
108 uint64 offset = 0u;
109 uint64 nextChunkSize = static_cast<uint64>(sizeof(PkgHeader));
110 std::vector<uint8> readBinData(std::move(m_File->ReadChunk(offset, nextChunkSize)));
111 offset += nextChunkSize;
112 PkgHeader const pkgHeader(*reinterpret_cast<PkgHeader const*>(readBinData.data()));
113
114 // read the central directory
115 //----------------------------
116
117 // read the entire data chunk for the central directory from the file
118 nextChunkSize = static_cast<uint64>(sizeof(PkgFileInfo)) * pkgHeader.numEntries;
119 readBinData = std::move(m_File->ReadChunk(offset, nextChunkSize));
120
121 // map into that read data
122 offset = 0u;
123 std::vector<PkgFileInfo> centralDirectory;
124 for (size_t infoIdx = 0u; infoIdx < pkgHeader.numEntries; ++infoIdx)
125 {
126 PkgFileInfo const* info = reinterpret_cast<PkgFileInfo const*>(readBinData.data() + static_cast<size_t>(offset));
127 offset += static_cast<uint64>(sizeof(PkgFileInfo));
128
129 centralDirectory.emplace_back(*info);
130 }
131
132 // read the files listed
133 //----------------------------
134 for (PkgFileInfo const& fileInfo : centralDirectory)
135 {
136 // start at the offset from the beginning of the package
137 offset = fileInfo.offset;
138 nextChunkSize = static_cast<uint64>(sizeof(PkgEntry));
139 readBinData = std::move(m_File->ReadChunk(offset, nextChunkSize));
140 offset += nextChunkSize;
141
142 PkgEntry const* entry = reinterpret_cast<PkgEntry const*>(readBinData.data());
143
144 // get and validate the fileId
145
146 ET_ASSERT(entry->fileId == fileInfo.fileId,
147 "File ID didn't match file info from central directory! Expected [%x] - found [%x]",
148 fileInfo.fileId, entry->fileId);
149
150 // Create our package file in the map and edit it after to avoid unnecessary file copying
151 auto emplaceIt = m_Entries.try_emplace(entry->fileId, PackageEntry());
152
153 if (!emplaceIt.second)
154 {
155 ET_ASSERT(false, "Entry list already contains a file with ID [%s] !", entry->fileId.ToStringDbg());
156 continue;
157 }
158
159 PackageEntry& pkgEntry = emplaceIt.first->second;

Callers

nothing calls this directly

Calls 3

ReadChunkMethod · 0.80
ToStringDbgMethod · 0.80
PackageEntryClass · 0.70

Tested by

no test coverage detected