MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / AddResourcesFromArchive

Method AddResourcesFromArchive

tools/rc/ResourceCompiler.cpp:616–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614}
615
616void
617ZipArchive::AddResourcesFromArchive(std::string const& archiveFileName)
618{
619 mz_zip_archive currZipArchive;
620 mz_uint currZipIndex = 0;
621 memset(&currZipArchive, 0, sizeof(mz_zip_archive));
622 std::clog << "Merging zip file " << archiveFileName << " ... " << std::endl;
623 if (!mz_zip_reader_init_file(&currZipArchive, archiveFileName.c_str(), 0))
624 {
625 throw std::runtime_error("Could not initialize zip archive " + archiveFileName);
626 }
627 char archiveName[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
628 mz_uint numZipIndices = mz_zip_reader_get_num_files(&currZipArchive);
629 for (currZipIndex = 0; currZipIndex < numZipIndices; ++currZipIndex)
630 {
631 mz_uint numBytes = mz_zip_reader_get_filename(&currZipArchive, currZipIndex, archiveName, sizeof archiveName);
632 std::clog << "\tmerging: " << archiveName << " (from " << archiveFileName << ") " << std::endl;
633 try
634 {
635 if (numBytes > 1)
636 {
637 // Issue 161.2: change to use mz_zip_read_is_file_a_directory() instead of checking
638 // for the format of the string.
639 if (MZ_FALSE == mz_zip_reader_is_file_a_directory(&currZipArchive, currZipIndex))
640 {
641 if (!archivedNames.insert(archiveName).second)
642 {
643 throw std::runtime_error("Found duplicate file with name " + std::string(archiveName));
644 }
645
646 std::string archiveEntry(archiveName);
647 if (archiveEntry.find_first_of("/", 0) == archiveEntry.find_last_of("/")
648 && std::string::npos != archiveEntry.find("/manifest.json"))
649 {
650 validateManifestInArchive(&currZipArchive, archiveFileName, archiveEntry);
651 }
652
653 if (!mz_zip_writer_add_from_zip_reader(writeArchive.get(), &currZipArchive, currZipIndex))
654 {
655 throw std::runtime_error("Failed to append file " + std::string(archiveName) + " from archive "
656 + archiveFileName);
657 }
658 }
659 else
660 {
661 AddDirectory(std::string(archiveName));
662 }
663 }
664 }
665 catch (std::exception const&)
666 {
667 mz_zip_reader_end(&currZipArchive);
668 throw;
669 }
670 }
671 std::clog << "Finished merging files from " << archiveFileName << std::endl;
672 mz_zip_reader_end(&currZipArchive);
673}

Callers 1

mainFunction · 0.80

Calls 4

getMethod · 0.80
insertMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected