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;
37 return is_valid_after_asset_manager_change_;
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()) {
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.";
72 std::regex asset_regex(asset_pattern);
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";
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.
virtual const DirectoryAssetBundle * as_directory_asset_bundle() const
DirectoryAssetBundle(fml::UniqueFD descriptor, bool is_valid_after_asset_manager_change)
std::vector< std::unique_ptr< fml::Mapping > > GetAsMappings(const std::string &asset_pattern, const std::optional< std::string > &subdir) const override
Same as GetAsMapping() but returns mappings for all files who's name matches a given pattern....
std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const override
~DirectoryAssetBundle() override
bool operator==(const AssetResolver &other) const override
bool IsValidAfterAssetManagerChange() const override
Certain asset resolvers are still valid after the asset manager is replaced before a hot reload,...
AssetResolver::AssetResolverType GetType() const override
Gets the type of AssetResolver this is. Types are defined in AssetResolverType.
bool IsValid() const 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)