| 256 | } |
| 257 | |
| 258 | ZipArchive::ZipEntry *ZipArchive::findZipEntry(const char *filename) |
| 259 | { |
| 260 | char path[1024]; |
| 261 | dStrncpy(path, filename, sizeof(path)); |
| 262 | path[sizeof(path) - 1] = 0; |
| 263 | |
| 264 | for(S32 i = 0;i < dStrlen(path);++i) |
| 265 | { |
| 266 | if(path[i] == '\\') |
| 267 | path[i] = '/'; |
| 268 | } |
| 269 | |
| 270 | ZipEntry *root = mRoot; |
| 271 | |
| 272 | char *ptr = path, *slash = NULL; |
| 273 | do |
| 274 | { |
| 275 | slash = dStrchr(ptr, '/'); |
| 276 | if(slash) |
| 277 | { |
| 278 | // Find the directory |
| 279 | *slash = 0; |
| 280 | |
| 281 | // check child dict for new root |
| 282 | ZipEntry *newRoot = NULL; |
| 283 | if (!root->mChildren.tryGetValue(ptr, newRoot)) |
| 284 | return NULL; |
| 285 | |
| 286 | root = newRoot; |
| 287 | |
| 288 | ptr = slash + 1; |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | // Find the file |
| 293 | ZipEntry* entry = NULL; |
| 294 | if (root->mChildren.tryGetValue(ptr, entry)) |
| 295 | return entry; |
| 296 | } |
| 297 | } while(slash); |
| 298 | |
| 299 | return NULL; |
| 300 | } |
| 301 | |
| 302 | //----------------------------------------------------------------------------- |
| 303 |
no test coverage detected