| 47 | //------------------------------------------------------------------- |
| 48 | |
| 49 | bool |
| 50 | IsBundleFile(std::string const& location) |
| 51 | { |
| 52 | if (location.empty()) |
| 53 | { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | // We require a zip file with at least one top-level directory |
| 58 | // containing a manifest.json file for a file to be a valid bundle. |
| 59 | try |
| 60 | { |
| 61 | // If this location is a bundle, a top level directory will |
| 62 | // contain a manifest.json file at its root. There is no need |
| 63 | // to recursively search nested directories. |
| 64 | namespace cppms = cppmicroservices; |
| 65 | using cppmicroservices::any_map; |
| 66 | using cppmicroservices::AnyMap; |
| 67 | BundleResourceContainer resContainer(location, AnyMap(any_map::UNORDERED_MAP_CASEINSENSITIVE_KEYS)); |
| 68 | auto topLevelDirs = resContainer.GetTopLevelDirs(); |
| 69 | return std::any_of(topLevelDirs.begin(), |
| 70 | topLevelDirs.end(), |
| 71 | [&resContainer](std::string const& dir) -> bool |
| 72 | { |
| 73 | std::vector<std::string> names; |
| 74 | std::vector<uint32_t> indices; |
| 75 | |
| 76 | resContainer.GetChildren(dir + "/", true, names, indices); |
| 77 | return std::any_of(names.begin(), |
| 78 | names.end(), |
| 79 | [](const std::string& resourceName) -> bool |
| 80 | { return (resourceName == std::string("manifest.json")); }); |
| 81 | }); |
| 82 | } |
| 83 | catch (...) |
| 84 | { |
| 85 | return false; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | bool |
| 90 | OnlyContainsManifest(std::shared_ptr<BundleResourceContainer> const& resContainer) |
no test coverage detected