MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / insertEntry

Method insertEntry

Engine/source/core/util/zip/zipArchive.cpp:142–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140//-----------------------------------------------------------------------------
141
142void ZipArchive::insertEntry(ZipEntry *ze)
143{
144 char path[1024];
145 dStrncpy(path, ze->mCD.mFilename.c_str(), sizeof(path));
146 path[sizeof(path) - 1] = 0;
147
148 for(S32 i = 0;i < dStrlen(path);++i)
149 {
150 if(path[i] == '\\')
151 path[i] = '/';
152 }
153
154 ZipEntry *root = mRoot;
155
156 char *ptr = path, *slash = NULL;
157 do
158 {
159 slash = dStrchr(ptr, '/');
160 if(slash)
161 {
162 // Add the directory
163 *slash = 0;
164
165 // try to get root, create if not found
166 ZipEntry *newEntry = NULL;
167 if (!root->mChildren.tryGetValue(ptr, newEntry))
168 {
169 newEntry = new ZipEntry;
170 newEntry->mParent = root;
171 newEntry->mName = String(ptr);
172 newEntry->mIsDirectory = true;
173 newEntry->mCD.setFilename(path);
174
175 root->mChildren[ptr] = newEntry;
176 }
177
178 root = newEntry;
179
180 *slash = '/';
181 ptr = slash + 1;
182 }
183 else
184 {
185 // Add the file.
186 if(*ptr)
187 {
188 ze->mIsDirectory = false;
189 ze->mName = ptr;
190 ze->mParent = root;
191 root->mChildren[ptr] = ze;
192 mEntries.push_back(ze);
193 }
194 else
195 {
196 // [tom, 2/6/2007] If ptr is empty, this was a directory entry. Since
197 // we created a new entry for it above, we need to delete the old
198 // pointer otherwise it will leak as it won't have got inserted.
199

Callers

nothing calls this directly

Calls 8

dStrncpyFunction · 0.85
tryGetValueMethod · 0.80
dStrlenFunction · 0.50
dStrchrFunction · 0.50
StringClass · 0.50
c_strMethod · 0.45
setFilenameMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected