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

Function LoadArchiveFromFile

engine/resource/src/resource_archive.cpp:78–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76 }
77
78 Result LoadArchiveFromFile(const char* index_file_path, const char* data_file_path, HArchiveIndexContainer* archive)
79 {
80 FILE* f_index = fopen(index_file_path, "rb");
81 if (!f_index)
82 {
83 return RESULT_IO_ERROR;
84 }
85
86 FILE* f_data = 0;
87 ArchiveIndexContainer* aic = new ArchiveIndexContainer;
88 aic->m_IsMemMapped = false;
89
90 ArchiveIndex* ai = new ArchiveIndex;
91 aic->m_ArchiveIndex = ai;
92
93 aic->m_ArchiveFileIndex = new ArchiveFileIndex;
94 dmStrlCpy(aic->m_ArchiveFileIndex->m_Path, index_file_path, DMPATH_MAX_PATH);
95
96 if (fread(ai, 1, sizeof(ArchiveIndex), f_index) != sizeof(ArchiveIndex))
97 {
98 CleanupResources(f_index, f_data, aic);
99 return RESULT_IO_ERROR;
100 }
101
102 if(dmEndian::ToNetwork(ai->m_Version) != VERSION)
103 {
104 dmLogError("Archive version differs. Expected %d, but it was %d", VERSION, dmEndian::ToNetwork(ai->m_Version));
105 CleanupResources(f_index, f_data, aic);
106 return RESULT_VERSION_MISMATCH;
107 }
108
109 uint32_t entry_count = dmEndian::ToNetwork(ai->m_EntryDataCount);
110 uint32_t entry_offset = dmEndian::ToNetwork(ai->m_EntryDataOffset);
111 uint32_t hash_offset = dmEndian::ToNetwork(ai->m_HashOffset);
112
113 fseek(f_index, hash_offset, SEEK_SET);
114 aic->m_ArchiveFileIndex->m_Hashes = new uint8_t[entry_count * dmResourceArchive::MAX_HASH];
115
116 uint32_t hash_total_size = entry_count * dmResourceArchive::MAX_HASH;
117 if (fread(aic->m_ArchiveFileIndex->m_Hashes, 1, hash_total_size, f_index) != hash_total_size)
118 {
119 CleanupResources(f_index, f_data, aic);
120 return RESULT_IO_ERROR;
121 }
122
123 fseek(f_index, entry_offset, SEEK_SET);
124 aic->m_ArchiveFileIndex->m_Entries = new EntryData[entry_count];
125 uint32_t entries_total_size = entry_count * sizeof(EntryData);
126 if (fread(aic->m_ArchiveFileIndex->m_Entries, 1, entries_total_size, f_index) != entries_total_size)
127 {
128 CleanupResources(f_index, f_data, aic);
129 return RESULT_IO_ERROR;
130 }
131
132 // Mark that this archive was loaded from file, and not memory-mapped
133 ai->m_Userdata = FILE_LOADED_INDICATOR;
134
135 f_data = fopen(data_file_path, "rb");

Callers 2

MountArchiveInternalFunction · 0.85
TESTFunction · 0.85

Calls 3

dmStrlCpyFunction · 0.85
CleanupResourcesFunction · 0.85
ToNetworkFunction · 0.85

Tested by 1

TESTFunction · 0.68