未验证 提交 868dc047 编写于 作者: S Stanislav Baranov 提交者: GitHub

Support loading flutter assets from dynamic patch (#7308)

This replicates similar logic found in ApkAssetProvider that locates assets by their short name in a sudbirectory inside of an archive file, instead of only at the root of archive.
上级 1bd9d41f
...@@ -22,8 +22,8 @@ void UniqueUnzipperTraits::Free(void* file) { ...@@ -22,8 +22,8 @@ void UniqueUnzipperTraits::Free(void* file) {
unzClose(file); unzClose(file);
} }
ZipAssetStore::ZipAssetStore(std::string file_path) ZipAssetStore::ZipAssetStore(std::string file_path, std::string directory)
: file_path_(std::move(file_path)) { : file_path_(std::move(file_path)), directory_(std::move(directory)) {
BuildStatCache(); BuildStatCache();
} }
...@@ -43,8 +43,8 @@ std::unique_ptr<fml::Mapping> ZipAssetStore::GetAsMapping( ...@@ -43,8 +43,8 @@ std::unique_ptr<fml::Mapping> ZipAssetStore::GetAsMapping(
const std::string& asset_name) const { const std::string& asset_name) const {
TRACE_EVENT1("flutter", "ZipAssetStore::GetAsMapping", "name", TRACE_EVENT1("flutter", "ZipAssetStore::GetAsMapping", "name",
asset_name.c_str()); asset_name.c_str());
auto found = stat_cache_.find(asset_name);
auto found = stat_cache_.find(directory_ + "/" + asset_name);
if (found == stat_cache_.end()) { if (found == stat_cache_.end()) {
return nullptr; return nullptr;
} }
......
...@@ -23,7 +23,7 @@ using UniqueUnzipper = fml::UniqueObject<void*, UniqueUnzipperTraits>; ...@@ -23,7 +23,7 @@ using UniqueUnzipper = fml::UniqueObject<void*, UniqueUnzipperTraits>;
class ZipAssetStore final : public AssetResolver { class ZipAssetStore final : public AssetResolver {
public: public:
ZipAssetStore(std::string file_path); ZipAssetStore(std::string file_path, std::string directory);
~ZipAssetStore() override; ~ZipAssetStore() override;
...@@ -35,7 +35,9 @@ class ZipAssetStore final : public AssetResolver { ...@@ -35,7 +35,9 @@ class ZipAssetStore final : public AssetResolver {
: file_pos(p_file_pos), uncompressed_size(p_uncompressed_size) {} : file_pos(p_file_pos), uncompressed_size(p_uncompressed_size) {}
}; };
std::string file_path_; const std::string file_path_;
const std::string directory_;
mutable std::map<std::string, CacheEntry> stat_cache_; mutable std::map<std::string, CacheEntry> stat_cache_;
// |blink::AssetResolver| // |blink::AssetResolver|
......
...@@ -253,7 +253,7 @@ static void RunBundleAndSnapshotFromLibrary(JNIEnv* env, ...@@ -253,7 +253,7 @@ static void RunBundleAndSnapshotFromLibrary(JNIEnv* env,
const auto file_ext_index = bundlepath.rfind("."); const auto file_ext_index = bundlepath.rfind(".");
if (bundlepath.substr(file_ext_index) == ".zip") { if (bundlepath.substr(file_ext_index) == ".zip") {
asset_manager->PushBack( asset_manager->PushBack(
std::make_unique<blink::ZipAssetStore>(bundlepath)); std::make_unique<blink::ZipAssetStore>(bundlepath, "flutter_assets"));
} else { } else {
asset_manager->PushBack( asset_manager->PushBack(
std::make_unique<blink::DirectoryAssetBundle>(fml::OpenDirectory( std::make_unique<blink::DirectoryAssetBundle>(fml::OpenDirectory(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册