| 2316 | } |
| 2317 | |
| 2318 | ssize_t |
| 2319 | AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename) |
| 2320 | { |
| 2321 | int count = 0; |
| 2322 | SortedVector<AaptGroupEntry> entries; |
| 2323 | |
| 2324 | ZipFile* zip = new ZipFile; |
| 2325 | status_t err = zip->open(filename, ZipFile::kOpenReadOnly); |
| 2326 | if (err != NO_ERROR) { |
| 2327 | fprintf(stderr, "error opening zip file %s\n", filename); |
| 2328 | count = err; |
| 2329 | delete zip; |
| 2330 | return -1; |
| 2331 | } |
| 2332 | |
| 2333 | const int N = zip->getNumEntries(); |
| 2334 | for (int i=0; i<N; i++) { |
| 2335 | ZipEntry* entry = zip->getEntryByIndex(i); |
| 2336 | if (entry->getDeleted()) { |
| 2337 | continue; |
| 2338 | } |
| 2339 | |
| 2340 | if (bundle->getInternalZipPath()) { |
| 2341 | bool prefixed = (strncmp(entry->getFileName(), bundle->getInternalZipPath(), strlen(bundle->getInternalZipPath())) == 0); |
| 2342 | if (!prefixed) { |
| 2343 | continue; |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | String8 entryName(entry->getFileName()); //ex: /res/drawable/foo.png |
| 2348 | String8 entryLeaf = entryName.getPathLeaf(); //ex: foo.png |
| 2349 | String8 entryDirFull = entryName.getPathDir(); //ex: res/drawable |
| 2350 | String8 entryDir = entryDirFull.getPathLeaf(); //ex: drawable |
| 2351 | |
| 2352 | //Do not process directories |
| 2353 | if (entryLeaf.size() == 0) { |
| 2354 | continue; |
| 2355 | } |
| 2356 | |
| 2357 | AaptGroupEntry group; |
| 2358 | String8 resType; |
| 2359 | bool b = group.initFromDirName(entryDir, &resType); |
| 2360 | if (!b) { |
| 2361 | fprintf(stderr, "invalid resource directory name: %s\n", entryDir.string()); |
| 2362 | err = -1; |
| 2363 | continue; |
| 2364 | } |
| 2365 | |
| 2366 | //This will do a cached lookup as well |
| 2367 | sp<AaptDir> dir = makeDir(resType); //Does lookup as well on mdirs |
| 2368 | sp<AaptFile> file = new AaptFile(entryName, group, resType, String8(filename)); |
| 2369 | file->setCompressionMethod(entry->getCompressionMethod()); |
| 2370 | |
| 2371 | // need to inflate nine patch images for processing |
| 2372 | if (endsWith(entryLeaf.string(), ".png")) { |
| 2373 | size_t len = entry->getUncompressedLen(); |
| 2374 | void* data = zip->uncompress(entry); |
| 2375 | void* buf = file->editData(len); |
no test coverage detected