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

Method AddResourceFile

tools/rc/ResourceCompiler.cpp:518–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516}
517
518void
519ZipArchive::AddResourceFile(std::string const& resFileName, bool isManifest)
520{
521 std::string archiveName = resFileName;
522
523 bool pathToResIsAbsolute = false;
524#ifndef __MINGW32__
525 // Issue 161.3: check to see if resFileName is relative or not, and exit early if it is not.
526 std::filesystem::path pathToResFile { resFileName };
527 pathToResIsAbsolute = pathToResFile.is_absolute();
528#else
529 pathToResIsAbsolute = !PathIsRelativeA(resFileName.c_str());
530#endif
531
532 if (pathToResIsAbsolute)
533 {
534 throw std::runtime_error("Relatvie path to resource file required. " + resFileName + " is absolute");
535 }
536
537 // This check exists solely to maintain a deprecated way of adding manifest.json
538 // through the --res-add option.
539 if (isManifest || resFileName == std::string("manifest.json"))
540 {
541 rapidjson::Document root;
542 parseAndValidateJsonFromFile(resFileName, root);
543 }
544
545 // if it is a manifest file, we ignore the parent directory path because the
546 // manifest file is always placed at the root of the bundle name directory
547 if (isManifest && resFileName.find_last_of(PATH_SEPARATOR) != std::string::npos)
548 {
549 archiveName = resFileName.substr(resFileName.find_last_of(PATH_SEPARATOR) + 1);
550 }
551
552 std::string archiveEntry = bundleName + "/" + archiveName;
553 CheckAndAddToArchivedNames(archiveEntry);
554
555 if (!mz_zip_writer_add_file(writeArchive.get(),
556 archiveEntry.c_str(),
557 resFileName.c_str(),
558 NULL,
559 0,
560 compressionLevel))
561 {
562 throw std::runtime_error("Error writing file to archive");
563 }
564 // add a directory entries for the file path
565 size_t lastPathSeparatorPos = archiveEntry.find("/", 0);
566 while (lastPathSeparatorPos != std::string::npos)
567 {
568 AddDirectory(archiveEntry.substr(0, lastPathSeparatorPos + 1));
569 lastPathSeparatorPos = archiveEntry.find("/", lastPathSeparatorPos + 1);
570 }
571}
572
573void
574ZipArchive::AddDirectory(std::string const& dirName)

Callers 1

mainFunction · 0.80

Calls 3

getMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected