MCPcopy Create free account
hub / github.com/defold/defold / ReadEntry

Function ReadEntry

engine/resource/src/resource_archive.cpp:299–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297 }
298
299 Result ReadEntry(HArchiveIndexContainer archive, const EntryData* entry, void* buffer)
300 {
301 // We always assume it's in Host format, since it may arrive from memory mapped data
302 const uint32_t flags = dmEndian::ToNetwork(entry->m_Flags);
303 const uint32_t size = dmEndian::ToNetwork(entry->m_ResourceSize);
304 const uint32_t resource_offset = dmEndian::ToNetwork(entry->m_ResourceDataOffset);
305 uint32_t compressed_size = dmEndian::ToNetwork(entry->m_ResourceCompressedSize);
306
307 bool encrypted = (flags & dmResourceArchive::ENTRY_FLAG_ENCRYPTED);
308 bool compressed = (flags & dmResourceArchive::ENTRY_FLAG_COMPRESSED);
309
310 const ArchiveFileIndex* afi = archive->m_ArchiveFileIndex;
311 bool resource_memmapped = afi->m_IsMemMapped;
312
313 uint8_t* temp_data = 0;
314 uint8_t* source_data = 0;
315 uint32_t source_data_size = 0;
316
317 if (!resource_memmapped)
318 {
319 // we need to read from the file on disc
320 FILE* resource_file = afi->m_FileResourceData;
321 fseek(resource_file, resource_offset, SEEK_SET);
322
323 Result result = dmResourceArchive::RESULT_OK;
324 // Note, we don't need to check if it's encrypted here, as it's guaranteed to
325 // have the same size after decryption
326 // So, we only need a temp buffer if the file is compressed
327 if (!compressed)
328 {
329 // we can read directly to the output buffer
330 if (fread(buffer, 1, size, resource_file) != size)
331 {
332 result = dmResourceArchive::RESULT_IO_ERROR;
333 }
334 source_data = (uint8_t*)buffer;
335 source_data_size = (uint32_t)size;
336 }
337 else
338 {
339 // We need a temp buffer to read to, since we can't decompress to the same buffer
340 temp_data = new uint8_t[compressed_size];
341 if (fread(temp_data, 1, compressed_size, resource_file) != compressed_size)
342 {
343 result = RESULT_IO_ERROR;
344 }
345 source_data = temp_data;
346 source_data_size = compressed_size;
347 }
348
349 if (result != dmResourceArchive::RESULT_OK)
350 {
351 delete[] temp_data;
352 return result;
353 }
354 }
355 else
356 {

Callers 2

ReadFileFunction · 0.85
TESTFunction · 0.85

Calls 3

ToNetworkFunction · 0.85
DecryptBufferFunction · 0.85
DecompressBufferFunction · 0.85

Tested by 1

TESTFunction · 0.68