5#include "flutter/assets/directory_asset_bundle.h"
10#include "flutter/fml/eintr_wrapper.h"
11#include "flutter/fml/file.h"
12#include "flutter/fml/mapping.h"
13#include "flutter/fml/trace_event.h"
19 bool is_valid_after_asset_manager_change)
20 : descriptor_(
std::move(descriptor)) {
24 is_valid_after_asset_manager_change_ = is_valid_after_asset_manager_change;
31bool DirectoryAssetBundle::IsValid()
const {
36bool DirectoryAssetBundle::IsValidAfterAssetManagerChange()
const {
37 return is_valid_after_asset_manager_change_;
42 return AssetResolver::AssetResolverType::kDirectoryAssetBundle;
46std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
47 const std::string& asset_name)
const {
49 FML_DLOG(WARNING) <<
"Asset bundle was not valid.";
53 auto mapping = std::make_unique<fml::FileMapping>(
fml::OpenFile(
56 if (!mapping->IsValid()) {
63std::vector<std::unique_ptr<fml::Mapping>> DirectoryAssetBundle::GetAsMappings(
64 const std::string& asset_pattern,
65 const std::optional<std::string>& subdir)
const {
66 std::vector<std::unique_ptr<fml::Mapping>> mappings;
68 FML_DLOG(WARNING) <<
"Asset bundle was not valid.";
74 const std::string& filename) {
75 TRACE_EVENT0(
"flutter",
"DirectoryAssetBundle::GetAsMappings FileVisitor");
77 if (std::regex_match(filename, asset_regex)) {
87 auto mapping = std::make_unique<fml::FileMapping>(fd);
89 if (mapping && mapping->IsValid()) {
90 mappings.push_back(std::move(mapping));
103 FML_LOG(
ERROR) <<
"Subdirectory path " << subdir.value()
104 <<
" is not a directory";
113bool DirectoryAssetBundle::operator==(
const AssetResolver& other)
const {
114 auto other_bundle = other.as_directory_asset_bundle();
118 return is_valid_after_asset_manager_change_ ==
119 other_bundle->is_valid_after_asset_manager_change_ &&
120 descriptor_.
get() == other_bundle->descriptor_.get();
AssetResolverType
Identifies the type of AssetResolver an instance is.
DirectoryAssetBundle(fml::UniqueFD descriptor, bool is_valid_after_asset_manager_change)
~DirectoryAssetBundle() override
#define FML_DLOG(severity)
#define FML_LOG(severity)
fml::UniqueFD OpenFileReadOnly(const fml::UniqueFD &base_directory, const char *path)
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
bool VisitFilesRecursively(const fml::UniqueFD &directory, const FileVisitor &visitor)
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
bool IsDirectory(const fml::UniqueFD &directory)
#define TRACE_EVENT0(category_group, name)