mirror of
https://gitee.com/openharmony/global_resource_management
synced 2024-11-24 00:20:19 +00:00
commit
65b39f2121
@ -78,6 +78,8 @@ public:
|
||||
*/
|
||||
bool AddResource(const char *path, const uint32_t &selectedTypes);
|
||||
|
||||
bool AddPatchResource(const char *path, const char *patchPath);
|
||||
|
||||
/**
|
||||
* Add resource path to overlay paths
|
||||
* @param path the resource path
|
||||
@ -395,6 +397,8 @@ private:
|
||||
|
||||
bool AddResourcePath(const char *path, const uint32_t &selectedTypes = SELECT_ALL);
|
||||
|
||||
bool AddPatchResourcePath(const char *path, const char *patchPath);
|
||||
|
||||
// when resConfig_ updated we must call ReloadAll()
|
||||
RState ReloadAll();
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <unzip.h>
|
||||
#include <set>
|
||||
#include "res_desc.h"
|
||||
#include "res_config_impl.h"
|
||||
#include "resource_manager.h"
|
||||
@ -90,23 +91,25 @@ public:
|
||||
/**
|
||||
* Get the raw file data from hap
|
||||
* @param hapPath the hap path
|
||||
* @param patchPath the hqf path
|
||||
* @param rawFileName the rawFile path
|
||||
* @param len the rawFile path
|
||||
* @param outValue the rawFile path
|
||||
* @return the rawFile path
|
||||
*/
|
||||
static RState ReadRawFileFromHap(const std::string &hapPath, const std::string &rawFileName,
|
||||
size_t &len, std::unique_ptr<uint8_t[]> &outValue);
|
||||
static RState ReadRawFileFromHap(const std::string &hapPath, const std::string &patchPath,
|
||||
const std::string &rawFileName, size_t &len, std::unique_ptr<uint8_t[]> &outValue);
|
||||
|
||||
/**
|
||||
* Get the raw file descriptor
|
||||
* @param hapPath the hap path
|
||||
* @param patchPath the hqf path
|
||||
* @param rawFileName the rawFile path
|
||||
* @param descriptor the rawFile path
|
||||
* @return the rawFile path
|
||||
*/
|
||||
static RState ReadRawFileDescriptor(const char *hapPath, const std::string &rawFileName,
|
||||
ResourceManager::RawFileDescriptor &descriptor);
|
||||
static RState ReadRawFileDescriptor(const char *hapPath, const char *patchPath,
|
||||
const std::string &rawFileName, ResourceManager::RawFileDescriptor &descriptor);
|
||||
|
||||
/**
|
||||
* Get the raw file list
|
||||
@ -116,7 +119,7 @@ public:
|
||||
* @return SUCCESS if resource exist, else not found
|
||||
*/
|
||||
static RState GetRawFileList(const std::string &hapPath, const std::string &rawDirPath,
|
||||
std::vector<std::string>& fileList);
|
||||
std::set<std::string>& fileList);
|
||||
|
||||
/**
|
||||
* Get the raw file list in UnCompressed
|
||||
|
@ -133,6 +133,40 @@ public:
|
||||
return isOverlay_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hqf resource path.
|
||||
*/
|
||||
inline std::string GetPatchPath() const
|
||||
{
|
||||
return patchPath_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hqf flag of HapResource.
|
||||
*
|
||||
* @return true if isPatch_ is true, false otherwise
|
||||
*/
|
||||
inline bool IsPatch() const
|
||||
{
|
||||
return isPatch_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hqf resource path.
|
||||
*/
|
||||
inline void SetPatchPath(const std::string& patchPath)
|
||||
{
|
||||
patchPath_ = patchPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hqf flag of HapResource.
|
||||
*/
|
||||
inline void IsPatch(bool isPatch)
|
||||
{
|
||||
isPatch_ = isPatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource information
|
||||
*/
|
||||
@ -340,8 +374,14 @@ private:
|
||||
// judge the hap resource is overlay or not.
|
||||
bool isOverlay_;
|
||||
|
||||
//judge the theme SystemRes is enabled or not.
|
||||
// judge the theme SystemRes is enabled or not.
|
||||
bool isThemeSystemResEnable_;
|
||||
|
||||
// hqf resource path.
|
||||
std::string patchPath_;
|
||||
|
||||
// judge the hqf is enabled or not.
|
||||
bool isPatch_ = false;
|
||||
};
|
||||
} // namespace Resource
|
||||
} // namespace Global
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
*/
|
||||
virtual bool AddResource(const char *path, const uint32_t &selectedTypes = SELECT_ALL);
|
||||
|
||||
virtual bool AddPatchResource(const char *path, const char *patchPath);
|
||||
|
||||
/**
|
||||
* Add resource path to overlay paths
|
||||
* @param path the resource path
|
||||
|
@ -372,6 +372,12 @@ bool HapManager::AddResource(const char *path, const uint32_t &selectedTypes)
|
||||
return this->AddResourcePath(path, selectedTypes);
|
||||
}
|
||||
|
||||
bool HapManager::AddPatchResource(const char *path, const char *patchPath)
|
||||
{
|
||||
AutoMutex mutex(this->lock_);
|
||||
return this->AddPatchResourcePath(path, patchPath);
|
||||
}
|
||||
|
||||
bool HapManager::AddResource(const std::string &path, const std::vector<std::string> &overlayPaths)
|
||||
{
|
||||
AutoMutex mutex(this->lock_);
|
||||
@ -495,6 +501,25 @@ bool HapManager::AddResourcePath(const char *path, const uint32_t &selectedTypes
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HapManager::AddPatchResourcePath(const char *path, const char *patchPath)
|
||||
{
|
||||
std::string sPath(path);
|
||||
auto it = loadedHapPaths_.find(sPath);
|
||||
if (it == loadedHapPaths_.end()) {
|
||||
RESMGR_HILOGW(RESMGR_TAG, "AddPatchResourcePath hapPath not load, hapPath = %{public}s", sPath.c_str());
|
||||
return false;
|
||||
}
|
||||
std::string sPatchPath(patchPath);
|
||||
for (auto iter = hapResources_.begin(); iter != hapResources_.end(); iter++) {
|
||||
if ((*iter)->GetIndexPath() == sPath) {
|
||||
(*iter)->SetPatchPath(sPatchPath);
|
||||
(*iter)->IsPatch(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RState HapManager::ReloadAll()
|
||||
{
|
||||
if (hapResources_.size() == 0) {
|
||||
@ -746,9 +771,13 @@ RState HapManager::FindRawFileFromHap(const std::string &rawFileName, size_t &le
|
||||
if ((*iter)->IsSystemResource() || (*iter)->IsOverlayResource()) {
|
||||
continue;
|
||||
}
|
||||
const std::string tempPath = (*iter)->GetIndexPath();
|
||||
std::string tempPath = (*iter)->GetIndexPath();
|
||||
std::string tempPatchPath = "";
|
||||
if ((*iter)->IsPatch()) {
|
||||
tempPatchPath = (*iter)->GetPatchPath();
|
||||
}
|
||||
if (Utils::ContainsTail(tempPath, Utils::tailSet)) { // if file path is compressed
|
||||
RState state = HapParser::ReadRawFileFromHap(tempPath, rawFileName, len, outValue);
|
||||
RState state = HapParser::ReadRawFileFromHap(tempPath, tempPatchPath, rawFileName, len, outValue);
|
||||
if (state != SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
@ -790,9 +819,13 @@ RState HapManager::GetRawFd(const std::string &rawFileName, ResourceManager::Raw
|
||||
if ((*iter)->IsSystemResource() || (*iter)->IsOverlayResource()) {
|
||||
continue;
|
||||
}
|
||||
const std::string tempPath = (*iter)->GetIndexPath();
|
||||
std::string tempPath = (*iter)->GetIndexPath();
|
||||
std::string tempPatchPath = "";
|
||||
if ((*iter)->IsPatch()) {
|
||||
tempPatchPath = (*iter)->GetPatchPath();
|
||||
}
|
||||
if (Utils::ContainsTail(tempPath, Utils::tailSet)) { // if file path is compressed
|
||||
state = HapParser::ReadRawFileDescriptor(tempPath.c_str(), rawFileName, descriptor);
|
||||
state = HapParser::ReadRawFileDescriptor(tempPath.c_str(), tempPatchPath.c_str(), rawFileName, descriptor);
|
||||
} else { // if file path is uncompressed
|
||||
state = HapManager::FindRawFileDescriptor(rawFileName, descriptor);
|
||||
}
|
||||
@ -808,7 +841,22 @@ RState HapManager::GetRawFileList(const std::string &rawDirPath, std::vector<std
|
||||
{
|
||||
std::string hapOrIndexPath;
|
||||
if (HapManager::GetValidHapPath(hapOrIndexPath) == OK) {
|
||||
return HapParser::GetRawFileList(hapOrIndexPath, rawDirPath, fileList);
|
||||
std::string temPatchPath;
|
||||
for (auto iter = hapResources_.begin(); iter != hapResources_.end(); iter++) {
|
||||
if ((*iter)->IsSystemResource() || (*iter)->IsOverlayResource()) {
|
||||
continue;
|
||||
}
|
||||
if ((*iter)->GetIndexPath() == hapOrIndexPath && (*iter)->IsPatch()) {
|
||||
temPatchPath = (*iter)->GetPatchPath();
|
||||
}
|
||||
}
|
||||
std::set<std::string> fileSet;
|
||||
RState hapState = HapParser::GetRawFileList(hapOrIndexPath, rawDirPath, fileSet);
|
||||
RState hqfState = HapParser::GetRawFileList(temPatchPath, rawDirPath, fileSet);
|
||||
for (auto it = fileSet.begin(); it != fileSet.end(); it++) {
|
||||
fileList.emplace_back(*it);
|
||||
}
|
||||
return (hapState != SUCCESS && hqfState != SUCCESS) ? ERROR_CODE_RES_PATH_INVALID : SUCCESS;
|
||||
}
|
||||
if (HapManager::GetValidIndexPath(hapOrIndexPath) == OK) {
|
||||
return HapParser::GetRawFileListUnCompressed(hapOrIndexPath, rawDirPath, fileList);
|
||||
|
@ -1092,6 +1092,11 @@ bool ResourceManagerImpl::AddResource(const char *path, const uint32_t &selected
|
||||
return this->hapManager_->AddResource(path, selectedTypes);
|
||||
}
|
||||
|
||||
bool ResourceManagerImpl::AddPatchResource(const char *path, const char *patchPath)
|
||||
{
|
||||
return this->hapManager_->AddPatchResource(path, patchPath);
|
||||
}
|
||||
|
||||
bool ResourceManagerImpl::AddResource(const std::string &path, const std::vector<std::string> &overlayPaths)
|
||||
{
|
||||
return this->hapManager_->AddResource(path, overlayPaths);
|
||||
|
@ -276,40 +276,56 @@ std::string HapParser::GetRawFilePath(std::shared_ptr<AbilityBase::Extractor> &e
|
||||
}
|
||||
#endif
|
||||
|
||||
RState HapParser::ReadRawFileFromHap(const std::string &hapPath, const std::string &rawFileName, size_t &len,
|
||||
std::unique_ptr<uint8_t[]> &outValue)
|
||||
RState HapParser::ReadRawFileFromHap(const std::string &hapPath, const std::string &patchPath,
|
||||
const std::string &rawFileName, size_t &len, std::unique_ptr<uint8_t[]> &outValue)
|
||||
{
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
bool isNewExtractor = false;
|
||||
auto extractor = AbilityBase::ExtractorUtil::GetExtractor(hapPath, isNewExtractor);
|
||||
std::string tempPath = patchPath.empty() ? hapPath : patchPath;
|
||||
auto extractor = AbilityBase::ExtractorUtil::GetExtractor(tempPath, isNewExtractor);
|
||||
if (extractor == nullptr) {
|
||||
RESMGR_HILOGE(RESMGR_TAG, "failed to get extractor hapPath, %{public}s", hapPath.c_str());
|
||||
RESMGR_HILOGE(RESMGR_TAG, "failed to get extractor hapPath, %{public}s", tempPath.c_str());
|
||||
return NOT_FOUND;
|
||||
}
|
||||
std::string rawfilePath = HapParser::GetRawFilePath(extractor, rawFileName);
|
||||
if (!extractor->HasEntry(rawfilePath)) {
|
||||
if (!extractor->HasEntry(rawfilePath) && patchPath.empty()) {
|
||||
RESMGR_HILOGD(RESMGR_TAG,
|
||||
"the rawfile file %{public}s is not exist in %{public}s", rawfilePath.c_str(), hapPath.c_str());
|
||||
"the rawfile file %{public}s is not exist in %{public}s", rawfilePath.c_str(), tempPath.c_str());
|
||||
return ERROR_CODE_RES_PATH_INVALID;
|
||||
}
|
||||
if (!extractor->HasEntry(rawfilePath) && !patchPath.empty()) {
|
||||
extractor = AbilityBase::ExtractorUtil::GetExtractor(hapPath, isNewExtractor);
|
||||
if (extractor == nullptr) {
|
||||
RESMGR_HILOGE(RESMGR_TAG, "failed to get extractor hapPath, %{public}s", tempPath.c_str());
|
||||
return NOT_FOUND;
|
||||
}
|
||||
rawfilePath = HapParser::GetRawFilePath(extractor, rawFileName);
|
||||
if (!extractor->HasEntry(rawfilePath)) {
|
||||
RESMGR_HILOGD(RESMGR_TAG,
|
||||
"the rawfile file %{public}s is not exist in %{public}s", rawfilePath.c_str(), tempPath.c_str());
|
||||
return ERROR_CODE_RES_PATH_INVALID;
|
||||
}
|
||||
}
|
||||
bool ret = extractor->ExtractToBufByName(rawfilePath, outValue, len);
|
||||
if (!ret) {
|
||||
RESMGR_HILOGE(RESMGR_TAG, "failed to get rawfile data rawfilePath, %{public}s, hapPath, %{public}s",
|
||||
rawfilePath.c_str(), hapPath.c_str());
|
||||
rawfilePath.c_str(), tempPath.c_str());
|
||||
return NOT_FOUND;
|
||||
}
|
||||
#endif
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState HapParser::ReadRawFileDescriptor(const char *hapPath, const std::string &rawFileName,
|
||||
RState HapParser::ReadRawFileDescriptor(const char *hapPath, const char *patchPath, const std::string &rawFileName,
|
||||
ResourceManager::RawFileDescriptor &descriptor)
|
||||
{
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
char outPath[PATH_MAX + 1] = {0};
|
||||
Utils::CanonicalizePath(hapPath, outPath, PATH_MAX);
|
||||
std::string sPatchPath(patchPath);
|
||||
const char *tempPath = sPatchPath.empty() ? hapPath : patchPath;
|
||||
Utils::CanonicalizePath(tempPath, outPath, PATH_MAX);
|
||||
bool isNewExtractor = false;
|
||||
auto extractor = AbilityBase::ExtractorUtil::GetExtractor(outPath, isNewExtractor);
|
||||
if (extractor == nullptr) {
|
||||
@ -317,11 +333,25 @@ RState HapParser::ReadRawFileDescriptor(const char *hapPath, const std::string &
|
||||
return NOT_FOUND;
|
||||
}
|
||||
std::string rawfilePath = HapParser::GetRawFilePath(extractor, rawFileName);
|
||||
if (!extractor->HasEntry(rawfilePath)) {
|
||||
if (!extractor->HasEntry(rawfilePath) && sPatchPath.empty()) {
|
||||
RESMGR_HILOGD(RESMGR_TAG,
|
||||
"the rawfile file %{public}s is not exist in %{public}s", rawfilePath.c_str(), hapPath);
|
||||
"the rawfile file %{public}s is not exist in %{public}s", rawfilePath.c_str(), outPath);
|
||||
return ERROR_CODE_RES_PATH_INVALID;
|
||||
}
|
||||
if (!extractor->HasEntry(rawfilePath) && !sPatchPath.empty()) {
|
||||
Utils::CanonicalizePath(hapPath, outPath, PATH_MAX);
|
||||
extractor = AbilityBase::ExtractorUtil::GetExtractor(outPath, isNewExtractor);
|
||||
if (extractor == nullptr) {
|
||||
RESMGR_HILOGE(RESMGR_TAG, "failed to get extractor hapPath, %{public}s", outPath);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
rawfilePath = HapParser::GetRawFilePath(extractor, rawFileName);
|
||||
if (!extractor->HasEntry(rawfilePath)) {
|
||||
RESMGR_HILOGD(RESMGR_TAG,
|
||||
"the rawfile file %{public}s is not exist in %{public}s", rawfilePath.c_str(), outPath);
|
||||
return ERROR_CODE_RES_PATH_INVALID;
|
||||
}
|
||||
}
|
||||
AbilityBase::FileInfo fileInfo;
|
||||
bool ret = extractor->GetFileInfo(rawfilePath, fileInfo);
|
||||
if (!ret) {
|
||||
@ -341,7 +371,7 @@ RState HapParser::ReadRawFileDescriptor(const char *hapPath, const std::string &
|
||||
}
|
||||
|
||||
RState HapParser::GetRawFileList(const std::string &hapPath, const std::string &rawDirPath,
|
||||
std::vector<std::string>& fileList)
|
||||
std::set<std::string>& fileSet)
|
||||
{
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
@ -352,7 +382,6 @@ RState HapParser::GetRawFileList(const std::string &hapPath, const std::string &
|
||||
"failed to get extractor from ability in GetRawFileList hapPath, %{public}s", hapPath.c_str());
|
||||
return NOT_FOUND;
|
||||
}
|
||||
std::set<std::string> fileSet;
|
||||
std::string rawfilePath = HapParser::GetRawFilePath(extractor, rawDirPath);
|
||||
if (!extractor->IsDirExist(rawfilePath)) {
|
||||
RESMGR_HILOGD(RESMGR_TAG,
|
||||
@ -364,9 +393,6 @@ RState HapParser::GetRawFileList(const std::string &hapPath, const std::string &
|
||||
RESMGR_HILOGE(RESMGR_TAG, "failed to get fileSet from ability rawfilePath, %{public}s", rawfilePath.c_str());
|
||||
return ERROR_CODE_RES_PATH_INVALID;
|
||||
}
|
||||
for (auto it = fileSet.begin(); it != fileSet.end(); it++) {
|
||||
fileList.emplace_back(*it);
|
||||
}
|
||||
#endif
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -236,6 +236,8 @@ public:
|
||||
|
||||
virtual RState GetFormatPluralStringByName(std::string &outValue, const char *name, int quantity,
|
||||
std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams) = 0;
|
||||
|
||||
virtual bool AddPatchResource(const char *path, const char *patchPath) = 0;
|
||||
};
|
||||
|
||||
EXPORT_FUNC ResourceManager *CreateResourceManager();
|
||||
@ -270,6 +272,7 @@ EXPORT_FUNC ResourceManager *GetSystemResourceManagerNoSandBox();
|
||||
EXPORT_FUNC std::shared_ptr<ResourceManager> CreateResourceManager(const std::string &bundleName,
|
||||
const std::string &moduleName, const std::string &hapPath, const std::vector<std::string> &overlayPath,
|
||||
ResConfig &resConfig, int32_t appType = 0, int32_t userId = 0);
|
||||
|
||||
} // namespace Resource
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user