* Process a regular file, adding it to the archive if appropriate. * * This function is intended for use when creating a cached overlay package. * Only xml and .9.png files are processed and added to the package. * * If we're in "update" mode, and the file already exists in the archive, * delete the existing entry before adding the new one. */
| 558 | * delete the existing entry before adding the new one. |
| 559 | */ |
| 560 | bool processOverlayFile(Bundle* bundle, ZipFile* zip, |
| 561 | const sp<AaptGroup>& group, const sp<AaptFile>& file) |
| 562 | { |
| 563 | const bool hasData = file->hasData(); |
| 564 | |
| 565 | String8 storageName(group->getPath()); |
| 566 | storageName.convertToResPath(); |
| 567 | ZipEntry* entry; |
| 568 | bool fromGzip = false; |
| 569 | status_t result; |
| 570 | |
| 571 | if (strcasecmp(storageName.getPathExtension().string(), ".gz") == 0) { |
| 572 | fromGzip = true; |
| 573 | storageName = storageName.getBasePath(); |
| 574 | } |
| 575 | |
| 576 | if (bundle->getUpdate()) { |
| 577 | entry = zip->getEntryByName(storageName.string()); |
| 578 | if (entry != NULL) { |
| 579 | /* file already exists in archive; there can be only one */ |
| 580 | if (entry->getMarked()) { |
| 581 | fprintf(stderr, |
| 582 | "ERROR: '%s' exists twice (check for with & w/o '.gz'?)\n", |
| 583 | file->getPrintableSource().string()); |
| 584 | return false; |
| 585 | } |
| 586 | zip->remove(entry); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | if (hasData) { |
| 591 | const char* name = storageName.string(); |
| 592 | if (endsWith(name, ".9.png") || endsWith(name, ".xml") || endsWith(name, ".arsc")) { |
| 593 | if (endsWith(name, ".9.png")) { |
| 594 | preProcessImage(bundle, file); |
| 595 | } |
| 596 | result = zip->add(file->getData(), file->getSize(), storageName.string(), |
| 597 | file->getCompressionMethod(), &entry); |
| 598 | if (result == NO_ERROR) { |
| 599 | if (bundle->getVerbose()) { |
| 600 | printf(" '%s'%s", storageName.string(), fromGzip ? " (from .gz)" : ""); |
| 601 | if (entry->getCompressionMethod() == ZipEntry::kCompressStored) { |
| 602 | printf(" (not compressed)\n"); |
| 603 | } else { |
| 604 | printf(" (compressed %d%%)\n", calcPercent(entry->getUncompressedLen(), |
| 605 | entry->getCompressedLen())); |
| 606 | } |
| 607 | } |
| 608 | entry->setMarked(true); |
| 609 | } else { |
| 610 | if (result == ALREADY_EXISTS) { |
| 611 | fprintf(stderr, " Unable to add '%s': file already in archive (try '-u'?)\n", |
| 612 | file->getPrintableSource().string()); |
| 613 | } else { |
| 614 | fprintf(stderr, " Unable to add '%s': Zip add failed\n", |
| 615 | file->getPrintableSource().string()); |
| 616 | } |
| 617 | return false; |
no test coverage detected