mirror of
https://gitee.com/openharmony/global_resource_management
synced 2024-10-06 21:43:49 +00:00
commit
1d002e0e6c
@ -56,7 +56,7 @@ public:
|
||||
* @param resConfig the device resConfig
|
||||
* @return true if this themeConfig match the device resConfig, else false
|
||||
*/
|
||||
static bool Match(const ThemeConfig *themeConfig, const ResConfigImpl &resConfig);
|
||||
static bool Match(const std::shared_ptr<ThemeConfig> &themeConfig, const ResConfigImpl &resConfig);
|
||||
|
||||
/**
|
||||
* Whether this themeConfig best match the device resConfig
|
||||
@ -65,9 +65,9 @@ public:
|
||||
* @param resConfig the device resConfig
|
||||
* @return true if this themeConfig best match the device resConfig, else false
|
||||
*/
|
||||
bool BestMatch(const ThemeConfig *themeConfig, const ResConfigImpl &resConfig) const;
|
||||
bool BestMatch(const std::shared_ptr<ThemeConfig> &themeConfig, const ResConfigImpl &resConfig) const;
|
||||
private:
|
||||
bool IsMoreMatchThan(const ThemeConfig *themeConfig) const;
|
||||
bool IsMoreMatchThan(const std::shared_ptr<ThemeConfig> &themeConfig) const;
|
||||
|
||||
Direction themeDirection_;
|
||||
ColorMode themeColorMode_;
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
* @param rootDirs the theme skins dirs
|
||||
*/
|
||||
void LoadThemeSkinResource(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::vector<std::string> &rootDirs);
|
||||
const std::vector<std::string> &rootDirs, const std::string &themeFlag);
|
||||
|
||||
/**
|
||||
* Load the icons dir resource int theme pack.
|
||||
@ -61,7 +61,7 @@ public:
|
||||
* @param rootDirs the theme icons dirs
|
||||
*/
|
||||
void LoadThemeIconsResource(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::vector<std::string> &rootDirs);
|
||||
const std::vector<std::string> &rootDirs, const std::string &themeFlag);
|
||||
|
||||
/**
|
||||
* Get the theme resource related to bundlename, modulename, resType, resName and resConfig.
|
||||
@ -97,17 +97,24 @@ public:
|
||||
|
||||
private:
|
||||
ThemePackManager();
|
||||
std::vector<ThemeResource *> skinResource_;
|
||||
std::vector<ThemeResource *> iconResource_;
|
||||
std::vector<const ThemeResource::ThemeValue *> GetThemeResourceList(
|
||||
std::string themeFlag;
|
||||
void ClearSkinResource(const std::string &themeFlag);
|
||||
void ClearIconResource(const std::string &themeFlag);
|
||||
std::vector<std::shared_ptr<ThemeResource> > skinResource_;
|
||||
std::vector<std::shared_ptr<ThemeResource>> iconResource_;
|
||||
std::vector<std::shared_ptr<ThemeResource::ThemeValue> > GetThemeResourceList(
|
||||
const std::pair<std::string, std::string> &bundInfo, const ResType &resType, const std::string &resName) const;
|
||||
|
||||
const ThemeResource::ThemeQualifierValue *GetThemeQualifierValue(
|
||||
const std::shared_ptr<ThemeResource::ThemeQualifierValue> GetThemeQualifierValue(
|
||||
const std::pair<std::string, std::string> &bundInfo, const ResType &resType,
|
||||
const std::string &resName, const ResConfigImpl &resConfig);
|
||||
|
||||
const ThemeResource::ThemeQualifierValue *GetBestMatchThemeResource(
|
||||
const std::vector<const ThemeResource::ThemeValue *> candidates, const ResConfigImpl &resConfig);
|
||||
const std::shared_ptr<ThemeResource::ThemeQualifierValue> GetBestMatchThemeResource(
|
||||
const std::vector<std::shared_ptr<ThemeResource::ThemeValue> > &candidates,
|
||||
const ResConfigImpl &resConfig);
|
||||
|
||||
Lock lockSkin_;
|
||||
Lock lockIcon_;
|
||||
};
|
||||
} // namespace Resource
|
||||
} // namespace Global
|
||||
|
@ -59,8 +59,8 @@ class ThemeResource {
|
||||
public:
|
||||
ThemeResource(std::string path);
|
||||
~ThemeResource();
|
||||
static const ThemeResource* LoadThemeResource(const std::string& rootDir);
|
||||
static const ThemeResource* LoadThemeIconResource(const std::string& rootDir);
|
||||
static const std::shared_ptr<ThemeResource> LoadThemeResource(const std::string& rootDir);
|
||||
static const std::shared_ptr<ThemeResource> LoadThemeIconResource(const std::string& rootDir);
|
||||
class ThemeQualifierValue {
|
||||
public:
|
||||
inline const std::string GetResValue() const
|
||||
@ -68,7 +68,7 @@ public:
|
||||
return resValue_;
|
||||
}
|
||||
|
||||
inline const ThemeConfig *GetThemeConfig() const
|
||||
inline const std::shared_ptr<ThemeConfig> GetThemeConfig() const
|
||||
{
|
||||
return themeConfig_;
|
||||
}
|
||||
@ -77,28 +77,29 @@ public:
|
||||
{
|
||||
return themeKey_;
|
||||
}
|
||||
ThemeQualifierValue(const ThemeKey themeKey, ThemeConfig *themeConfig, const std::string &value);
|
||||
ThemeQualifierValue(const ThemeKey themeKey, std::shared_ptr<ThemeConfig> themeConfig,
|
||||
const std::string &value);
|
||||
~ThemeQualifierValue();
|
||||
private:
|
||||
ThemeKey themeKey_;
|
||||
ThemeConfig* themeConfig_;
|
||||
std::shared_ptr<ThemeConfig> themeConfig_;
|
||||
std::string resValue_;
|
||||
};
|
||||
|
||||
class ThemeValue {
|
||||
public:
|
||||
inline void AddThemeLimitPath(ThemeQualifierValue *themeQualifer)
|
||||
inline void AddThemeLimitPath(std::shared_ptr<ThemeQualifierValue> themeQualifer)
|
||||
{
|
||||
limitPaths_.push_back(themeQualifer);
|
||||
}
|
||||
|
||||
inline const std::vector<ThemeQualifierValue *> &GetThemeLimitPathsConst() const
|
||||
inline const std::vector<std::shared_ptr<ThemeQualifierValue> > &GetThemeLimitPathsConst() const
|
||||
{
|
||||
return limitPaths_;
|
||||
}
|
||||
~ThemeValue();
|
||||
private:
|
||||
std::vector<ThemeQualifierValue *> limitPaths_;
|
||||
std::vector<std::shared_ptr<ThemeQualifierValue> > limitPaths_;
|
||||
};
|
||||
/**
|
||||
* Get the theme value related bundlename, modulename, resType and resource name.
|
||||
@ -108,9 +109,10 @@ public:
|
||||
* @param name the resource name
|
||||
* @return the theme value vector
|
||||
*/
|
||||
std::vector<const ThemeResource::ThemeValue *> GetThemeValues(const std::pair<std::string, std::string> &bundInfo,
|
||||
std::vector<std::shared_ptr<ThemeResource::ThemeValue> > GetThemeValues(
|
||||
const std::pair<std::string, std::string> &bundInfo,
|
||||
const ResType &resType, const std::string &name);
|
||||
|
||||
|
||||
/**
|
||||
* Get the theme icon related bundlename, modulename and resource name.
|
||||
*
|
||||
@ -119,7 +121,7 @@ public:
|
||||
* @return the icon path
|
||||
*/
|
||||
const std::string GetThemeAppIcon(const std::pair<std::string, std::string> &bundleInfo, const std::string &name);
|
||||
|
||||
|
||||
/**
|
||||
* Get the theme value related bundlename, modulename, resType and resource name.
|
||||
*
|
||||
@ -129,14 +131,20 @@ public:
|
||||
* @return the theme value vector
|
||||
*/
|
||||
std::string GetThemeResBundleName(const std::string &themePath);
|
||||
|
||||
inline std::string GetThemePath()
|
||||
{
|
||||
return themePath_;
|
||||
}
|
||||
|
||||
std::string themePath_;
|
||||
private:
|
||||
std::vector<std::tuple<ResType, std::string, ThemeValue *> > themeValueVec_;
|
||||
std::vector<std::tuple<ResType, std::string, std::shared_ptr<ThemeValue>> > themeValueVec_;
|
||||
std::vector<std::pair<ThemeKey, std::string> > iconValues_;
|
||||
void ParseJson(const std::string &bundleName, const std::string &moduleName, const std::string &jsonPath);
|
||||
void ParseIcon(const std::string &bundleName, const std::string &moduleName, const std::string &iconPath);
|
||||
void InitThemeRes(std::pair<std::string, std::string> bundleInfo, cJSON *root,
|
||||
ThemeConfig *themeConfig, const std::string &resTypeStr);
|
||||
std::shared_ptr<ThemeConfig> themeConfig, const std::string &resTypeStr);
|
||||
static ThemeResource *themeRes;
|
||||
};
|
||||
} // namespace Resource
|
||||
|
@ -933,6 +933,7 @@ bool ResourceManagerImpl::RemoveAppOverlay(const std::string &path)
|
||||
|
||||
RState ResourceManagerImpl::UpdateResConfig(ResConfig &resConfig)
|
||||
{
|
||||
ThemePackManager::GetThemePackManager()->LoadThemeRes(bundleInfo.first, bundleInfo.second, themeMask);
|
||||
#if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__)
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@ void ThemeConfig::SetThemeColorMode(ColorMode colorMode)
|
||||
this->themeColorMode_ = colorMode;
|
||||
}
|
||||
|
||||
bool ThemeConfig::Match(const ThemeConfig *themeConfig, const ResConfigImpl &resConfig)
|
||||
bool ThemeConfig::Match(const std::shared_ptr<ThemeConfig> &themeConfig, const ResConfigImpl &resConfig)
|
||||
{
|
||||
ColorMode colorMode = resConfig.GetColorMode();
|
||||
Direction direction = resConfig.GetDirection();
|
||||
@ -51,7 +51,7 @@ bool ThemeConfig::Match(const ThemeConfig *themeConfig, const ResConfigImpl &res
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThemeConfig::BestMatch(const ThemeConfig *themeConfig, const ResConfigImpl &resConfig) const
|
||||
bool ThemeConfig::BestMatch(const std::shared_ptr<ThemeConfig> &themeConfig, const ResConfigImpl &resConfig) const
|
||||
{
|
||||
ColorMode colorMode = resConfig.GetColorMode();
|
||||
Direction direction = resConfig.GetDirection();
|
||||
@ -67,7 +67,7 @@ bool ThemeConfig::BestMatch(const ThemeConfig *themeConfig, const ResConfigImpl
|
||||
return this->IsMoreMatchThan(themeConfig);
|
||||
}
|
||||
|
||||
bool ThemeConfig::IsMoreMatchThan(const ThemeConfig *themeConfig) const
|
||||
bool ThemeConfig::IsMoreMatchThan(const std::shared_ptr<ThemeConfig> &themeConfig) const
|
||||
{
|
||||
if (this->themeDirection_ != themeConfig->themeDirection_) {
|
||||
return this->themeDirection_ != DIRECTION_NOT_SET;
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
#include "theme_pack_manager.h"
|
||||
|
||||
#include "auto_mutex.h"
|
||||
#include <dirent.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -30,24 +31,20 @@ static std::once_flag themeMgrFlag;
|
||||
const std::string sysResIdPreFix = "125";
|
||||
const std::string themeFlagA = "data/themes/a/app/flag";
|
||||
const std::string themeFlagB = "data/themes/b/app/flag";
|
||||
const std::string themeSkinA = "/data/themes/a/app/skin";
|
||||
const std::string themeSkinB = "/data/themes/b/app/skin";
|
||||
const std::string themeIconsA = "/data/themes/a/app/icons";
|
||||
const std::string themeIconsB = "/data/themes/b/app/icons";
|
||||
const std::string flagA = "a";
|
||||
const std::string flagB = "b";
|
||||
const int ENABLE_THEME_POS = 13;
|
||||
ThemePackManager::ThemePackManager()
|
||||
{}
|
||||
|
||||
ThemePackManager::~ThemePackManager()
|
||||
{
|
||||
for (size_t i = 0; i < skinResource_.size(); i++) {
|
||||
if (skinResource_[i] != nullptr) {
|
||||
delete skinResource_[i];
|
||||
skinResource_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < iconResource_.size(); i++) {
|
||||
if (iconResource_[i] != nullptr) {
|
||||
delete iconResource_[i];
|
||||
iconResource_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
skinResource_.clear();
|
||||
iconResource_.clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<ThemePackManager> ThemePackManager::GetThemePackManager()
|
||||
@ -85,8 +82,20 @@ std::vector<std::string> GetRootDir(const std::string &strCurrentDir, std::strin
|
||||
return vDir;
|
||||
}
|
||||
|
||||
void ThemePackManager::ClearSkinResource(const std::string &themeFlag)
|
||||
{
|
||||
AutoMutex mutex(this->lockSkin_);
|
||||
for (auto it = skinResource_.begin(); it != skinResource_.end();) {
|
||||
if ((*it)->GetThemePath().substr(ENABLE_THEME_POS, 1) != themeFlag) { // 1 means get the enable theme
|
||||
it = skinResource_.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThemePackManager::LoadThemeSkinResource(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::vector<std::string> &rootDirs)
|
||||
const std::vector<std::string> &rootDirs, const std::string &themeFlag)
|
||||
{
|
||||
if (rootDirs.empty()) {
|
||||
return;
|
||||
@ -101,39 +110,40 @@ void ThemePackManager::LoadThemeSkinResource(const std::string &bundleName, cons
|
||||
if (tempBundleName != bundleName && tempBundleName != "systemRes") {
|
||||
continue;
|
||||
}
|
||||
const ThemeResource *pThemeResource = ThemeResource::LoadThemeResource(dir);
|
||||
auto pThemeResource = ThemeResource::LoadThemeResource(dir);
|
||||
if (pThemeResource != nullptr) {
|
||||
this->skinResource_.emplace_back(const_cast<ThemeResource *>(pThemeResource));
|
||||
this->skinResource_.emplace_back(pThemeResource);
|
||||
}
|
||||
}
|
||||
ClearSkinResource(themeFlag);
|
||||
}
|
||||
|
||||
void ThemePackManager::LoadThemeRes(const std::string &bundleName, const std::string &moduleName,
|
||||
std::string& themeMask)
|
||||
{
|
||||
const std::string themeSkinA = "/data/themes/a/app/skin";
|
||||
const std::string themeSkinB = "/data/themes/b/app/skin";
|
||||
const std::string themeIconsA = "/data/themes/a/app/icons";
|
||||
const std::string themeIconsB = "/data/themes/b/app/icons";
|
||||
std::vector<std::string> rootDirs;
|
||||
std::vector<std::string> iconDirs;
|
||||
if (Utils::IsFileExist(themeFlagA)) {
|
||||
if (Utils::IsFileExist(themeFlagA) && themeFlag != flagA) {
|
||||
themeFlag = flagA;
|
||||
rootDirs = GetRootDir(themeSkinA, themeMask);
|
||||
iconDirs = GetRootDir(themeIconsA, themeMask);
|
||||
} else if (Utils::IsFileExist(themeFlagB)) {
|
||||
} else if (Utils::IsFileExist(themeFlagB) && themeFlag != flagB) {
|
||||
themeFlag = flagB;
|
||||
rootDirs = GetRootDir(themeSkinB, themeMask);
|
||||
iconDirs = GetRootDir(themeIconsB, themeMask);
|
||||
} else {
|
||||
themeFlag = "";
|
||||
return;
|
||||
}
|
||||
LoadThemeSkinResource(bundleName, moduleName, rootDirs);
|
||||
LoadThemeIconsResource(bundleName, moduleName, iconDirs);
|
||||
LoadThemeSkinResource(bundleName, moduleName, rootDirs, themeFlag);
|
||||
LoadThemeIconsResource(bundleName, moduleName, iconDirs, themeFlag);
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string ThemePackManager::FindThemeResource(const std::pair<std::string, std::string> &bundleInfo,
|
||||
std::vector<const IdItem *> idItems, const ResConfigImpl &resConfig)
|
||||
{
|
||||
AutoMutex mutex(this->lockSkin_);
|
||||
std::string result;
|
||||
for (size_t i = 0; i < idItems.size(); i++) {
|
||||
std::string resName = idItems[i]->GetItemResName();
|
||||
@ -163,12 +173,12 @@ const std::string ThemePackManager::GetThemeResource(const std::pair<std::string
|
||||
return themeQualifierValue->GetResValue();
|
||||
}
|
||||
|
||||
std::vector<const ThemeResource::ThemeValue *> ThemePackManager::GetThemeResourceList(
|
||||
std::vector<std::shared_ptr<ThemeResource::ThemeValue> > ThemePackManager::GetThemeResourceList(
|
||||
const std::pair<std::string, std::string> &bundInfo, const ResType &resType, const std::string &resName) const
|
||||
{
|
||||
std::vector<const ThemeResource::ThemeValue *> result;
|
||||
std::vector<std::shared_ptr<ThemeResource::ThemeValue> > result;
|
||||
for (size_t i = 0; i < skinResource_.size(); ++i) {
|
||||
ThemeResource *pThemeResource = skinResource_[i];
|
||||
auto pThemeResource = skinResource_[i];
|
||||
if (pThemeResource == nullptr) {
|
||||
HILOG_ERROR("pThemeResource == nullptr");
|
||||
return result;
|
||||
@ -182,7 +192,7 @@ std::vector<const ThemeResource::ThemeValue *> ThemePackManager::GetThemeResourc
|
||||
return result;
|
||||
}
|
||||
|
||||
const ThemeResource::ThemeQualifierValue *ThemePackManager::GetThemeQualifierValue(
|
||||
const std::shared_ptr<ThemeResource::ThemeQualifierValue> ThemePackManager::GetThemeQualifierValue(
|
||||
const std::pair<std::string, std::string> &bundInfo, const ResType &resType,
|
||||
const std::string &resName, const ResConfigImpl &resConfig)
|
||||
{
|
||||
@ -193,17 +203,18 @@ const ThemeResource::ThemeQualifierValue *ThemePackManager::GetThemeQualifierVal
|
||||
return GetBestMatchThemeResource(candidates, resConfig);
|
||||
}
|
||||
|
||||
const ThemeResource::ThemeQualifierValue* ThemePackManager::GetBestMatchThemeResource(
|
||||
const std::vector<const ThemeResource::ThemeValue *> candidates, const ResConfigImpl &resConfig)
|
||||
const std::shared_ptr<ThemeResource::ThemeQualifierValue> ThemePackManager::GetBestMatchThemeResource(
|
||||
const std::vector<std::shared_ptr<ThemeResource::ThemeValue> > &candidates, const ResConfigImpl &resConfig)
|
||||
{
|
||||
const ThemeResource::ThemeQualifierValue *result = nullptr;
|
||||
const ThemeConfig *bestThemeConfig = nullptr;
|
||||
std::shared_ptr<ThemeResource::ThemeQualifierValue> result = nullptr;
|
||||
std::shared_ptr<ThemeConfig> bestThemeConfig = nullptr;
|
||||
for (auto iter = candidates.rbegin(); iter != candidates.rend(); iter++) {
|
||||
const std::vector<ThemeResource::ThemeQualifierValue *> ThemePaths = (*iter)->GetThemeLimitPathsConst();
|
||||
const std::vector<std::shared_ptr<ThemeResource::ThemeQualifierValue> > ThemePaths =
|
||||
(*iter)->GetThemeLimitPathsConst();
|
||||
size_t len = ThemePaths.size();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
ThemeResource::ThemeQualifierValue *path = ThemePaths[i];
|
||||
const ThemeConfig *themeConfig = path->GetThemeConfig();
|
||||
std::shared_ptr<ThemeResource::ThemeQualifierValue> path = ThemePaths[i];
|
||||
auto themeConfig = path->GetThemeConfig();
|
||||
if (!ThemeConfig::Match(themeConfig, resConfig)) {
|
||||
continue;
|
||||
}
|
||||
@ -221,8 +232,20 @@ const ThemeResource::ThemeQualifierValue* ThemePackManager::GetBestMatchThemeRes
|
||||
return result;
|
||||
}
|
||||
|
||||
void ThemePackManager::ClearIconResource(const std::string &themeFlag)
|
||||
{
|
||||
AutoMutex mutex(this->lockIcon_);
|
||||
for (auto it = iconResource_.begin(); it != iconResource_.end();) {
|
||||
if ((*it)->GetThemePath().substr(ENABLE_THEME_POS, 1) != themeFlag) { // 1 means get the enable theme
|
||||
it = iconResource_.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThemePackManager::LoadThemeIconsResource(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::vector<std::string> &rootDirs)
|
||||
const std::vector<std::string> &rootDirs, const std::string &themeFlag)
|
||||
{
|
||||
if (rootDirs.empty()) {
|
||||
return;
|
||||
@ -237,19 +260,21 @@ void ThemePackManager::LoadThemeIconsResource(const std::string &bundleName, con
|
||||
if (tempBundleName != bundleName) {
|
||||
continue;
|
||||
}
|
||||
const ThemeResource *pThemeResource = ThemeResource::LoadThemeIconResource(dir);
|
||||
auto pThemeResource = ThemeResource::LoadThemeIconResource(dir);
|
||||
if (pThemeResource != nullptr) {
|
||||
this->iconResource_.emplace_back(const_cast<ThemeResource *>(pThemeResource));
|
||||
this->iconResource_.emplace_back(pThemeResource);
|
||||
}
|
||||
}
|
||||
ClearIconResource(themeFlag);
|
||||
}
|
||||
|
||||
const std::string ThemePackManager::FindThemeIconResource(const std::pair<std::string, std::string> &bundleInfo,
|
||||
const std::string &iconName)
|
||||
{
|
||||
AutoMutex mutex(this->lockIcon_);
|
||||
std::string result;
|
||||
for (size_t i = 0; i < iconResource_.size(); i++) {
|
||||
ThemeResource *pThemeResource = iconResource_[i];
|
||||
auto pThemeResource = iconResource_[i];
|
||||
if (pThemeResource == nullptr) {
|
||||
return std::string("");
|
||||
}
|
||||
|
@ -32,34 +32,21 @@ ThemeResource::ThemeResource(std::string path) : themePath_(path)
|
||||
|
||||
ThemeResource::~ThemeResource()
|
||||
{
|
||||
for (auto themeValue : themeValueVec_) {
|
||||
if (std::get<THIRED_ELEMENT>(themeValue) != nullptr) {
|
||||
delete std::get<THIRED_ELEMENT>(themeValue);
|
||||
std::get<THIRED_ELEMENT>(themeValue) = nullptr;
|
||||
}
|
||||
}
|
||||
themeValueVec_.clear();
|
||||
iconValues_.clear();
|
||||
}
|
||||
|
||||
ThemeResource::ThemeQualifierValue::~ThemeQualifierValue()
|
||||
{
|
||||
if (themeConfig_ != nullptr) {
|
||||
delete themeConfig_;
|
||||
themeConfig_ = nullptr;
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
ThemeResource::ThemeValue::~ThemeValue()
|
||||
{
|
||||
for (size_t i = 0; i < limitPaths_.size(); ++i) {
|
||||
if (limitPaths_[i] != nullptr) {
|
||||
delete limitPaths_[i];
|
||||
limitPaths_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
limitPaths_.clear();
|
||||
}
|
||||
|
||||
ThemeResource::ThemeQualifierValue::ThemeQualifierValue(const ThemeKey themeKey, ThemeConfig *themeConfig,
|
||||
const std::string &value) : themeKey_(themeKey), themeConfig_(themeConfig), resValue_(value)
|
||||
ThemeResource::ThemeQualifierValue::ThemeQualifierValue(const ThemeKey themeKey,
|
||||
std::shared_ptr<ThemeConfig> themeConfig, const std::string &value) : themeKey_(themeKey),
|
||||
themeConfig_(themeConfig), resValue_(value)
|
||||
{}
|
||||
|
||||
std::unordered_map<std::string, ResType> themeResTypeMap {
|
||||
@ -81,9 +68,9 @@ std::string GetResKey(const std::string &jsonPath)
|
||||
return res;
|
||||
}
|
||||
|
||||
ThemeConfig *GetThemeConfig(const std::string &iconPath)
|
||||
std::shared_ptr<ThemeConfig> GetThemeConfig(const std::string &iconPath)
|
||||
{
|
||||
ThemeConfig *themeConfig = new ThemeConfig();
|
||||
auto themeConfig = std::make_shared<ThemeConfig>();
|
||||
std::string resKey = GetResKey(iconPath);
|
||||
if (resKey == "dark") {
|
||||
themeConfig->SetThemeColorMode(ColorMode::DARK);
|
||||
@ -109,7 +96,7 @@ ResType GetResType(const std::string &resTypeStr)
|
||||
}
|
||||
|
||||
void ThemeResource::InitThemeRes(std::pair<std::string, std::string> bundleInfo, cJSON *root,
|
||||
ThemeConfig *themeConfig, const std::string &resTypeStr)
|
||||
std::shared_ptr<ThemeConfig> themeConfig, const std::string &resTypeStr)
|
||||
{
|
||||
if (root == nullptr) {
|
||||
HILOG_WARN("The json file has not resType = %{public}s", resTypeStr.c_str());
|
||||
@ -130,13 +117,13 @@ void ThemeResource::InitThemeRes(std::pair<std::string, std::string> bundleInfo,
|
||||
HILOG_WARN("The resource value is not exist in childValue");
|
||||
return;
|
||||
}
|
||||
ThemeValue *themeValue = new (std::nothrow) ThemeResource::ThemeValue();
|
||||
auto themeValue = std::shared_ptr<ThemeValue>();
|
||||
if (themeValue == nullptr) {
|
||||
HILOG_ERROR("New themeValue fialed in InitThemeRes");
|
||||
return;
|
||||
}
|
||||
ThemeKey themeKey = ThemeKey(bundleInfo.first, bundleInfo.second, resType, name->valuestring);
|
||||
ThemeQualifierValue *themeQualifierValue = new ThemeQualifierValue(themeKey, themeConfig,
|
||||
auto themeQualifierValue = std::make_shared<ThemeQualifierValue>(themeKey, themeConfig,
|
||||
value->valuestring);
|
||||
if (themeQualifierValue == nullptr) {
|
||||
HILOG_ERROR("New themeQualifierValue fialed in InitThemeRes");
|
||||
@ -165,7 +152,7 @@ void ThemeResource::ParseJson(const std::string &bundleName, const std::string &
|
||||
char *jsonData = (char *)malloc(len + 1);
|
||||
std::fread(jsonData, len, 1, pf);
|
||||
jsonData[len] = '\0';
|
||||
ThemeConfig *themeConfig = GetThemeConfig(jsonPath);
|
||||
auto themeConfig = GetThemeConfig(jsonPath);
|
||||
cJSON *jsonValue = cJSON_Parse(jsonData);
|
||||
std::pair<std::string, std::string> bundleInfo(bundleName, moduleName);
|
||||
cJSON *floatRoot = cJSON_GetObjectItem(jsonValue, "float");
|
||||
@ -186,7 +173,7 @@ void ThemeResource::ParseJson(const std::string &bundleName, const std::string &
|
||||
void ThemeResource::ParseIcon(const std::string &bundleName, const std::string &moduleName,
|
||||
const std::string &iconPath)
|
||||
{
|
||||
ThemeConfig *themeConfig = GetThemeConfig(iconPath);
|
||||
auto themeConfig = GetThemeConfig(iconPath);
|
||||
auto pos1 = iconPath.rfind('.');
|
||||
auto pos2 = iconPath.rfind('/');
|
||||
if (pos1 == std::string::npos || pos2 == std::string::npos) {
|
||||
@ -194,13 +181,13 @@ void ThemeResource::ParseIcon(const std::string &bundleName, const std::string &
|
||||
return;
|
||||
}
|
||||
std::string iconName = iconPath.substr(pos2 + 1, pos1 - pos2 - 1);
|
||||
ThemeValue *themeValue = new (std::nothrow) ThemeResource::ThemeValue();
|
||||
auto themeValue = std::make_shared<ThemeValue>();
|
||||
if (themeValue == nullptr) {
|
||||
HILOG_ERROR("new themeValue failed in ParseIcon");
|
||||
return;
|
||||
}
|
||||
ThemeKey themeKey = ThemeKey(bundleName, moduleName, ResType::MEDIA, iconName);
|
||||
ThemeQualifierValue *themeQualifierValue = new ThemeQualifierValue(themeKey, themeConfig, iconPath);
|
||||
auto themeQualifierValue = std::make_shared<ThemeQualifierValue>(themeKey, themeConfig, iconPath);
|
||||
if (themeQualifierValue == nullptr) {
|
||||
HILOG_ERROR("new themeQualifierValue failed in ParseIcon");
|
||||
return;
|
||||
@ -210,10 +197,10 @@ void ThemeResource::ParseIcon(const std::string &bundleName, const std::string &
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<const ThemeResource::ThemeValue *> ThemeResource::GetThemeValues(
|
||||
std::vector<std::shared_ptr<ThemeResource::ThemeValue> > ThemeResource::GetThemeValues(
|
||||
const std::pair<std::string, std::string> &bundInfo, const ResType &resType, const std::string &name)
|
||||
{
|
||||
std::vector<const ThemeResource::ThemeValue *> result;
|
||||
std::vector<std::shared_ptr<ThemeResource::ThemeValue> > result;
|
||||
if (themeValueVec_.empty()) {
|
||||
return result;
|
||||
}
|
||||
@ -278,9 +265,13 @@ std::tuple<std::string, std::string> GetBundleInfo(const std::string& rootDir, c
|
||||
return bundleInfoTuple;
|
||||
}
|
||||
|
||||
const ThemeResource* ThemeResource::LoadThemeResource(const std::string& rootDir)
|
||||
const std::shared_ptr<ThemeResource> ThemeResource::LoadThemeResource(const std::string& rootDir)
|
||||
{
|
||||
ThemeResource *themeResource = new (std::nothrow) ThemeResource(rootDir);
|
||||
if (rootDir.empty()) {
|
||||
HILOG_ERROR("Invalid rootDir in LoadThemeResource = %{public}s", rootDir.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
auto themeResource = std::make_shared<ThemeResource>(rootDir);
|
||||
if (themeResource == nullptr) {
|
||||
HILOG_ERROR("New themeResource failed in LoadThemeResource");
|
||||
return nullptr;
|
||||
@ -314,15 +305,28 @@ std::string ThemeResource::GetThemeResBundleName(const std::string &themePath)
|
||||
return bundleName;
|
||||
}
|
||||
|
||||
const ThemeResource* ThemeResource::LoadThemeIconResource(const std::string& iconPath)
|
||||
std::string GetIconsBundleName(const std::string& iconPath)
|
||||
{
|
||||
if (iconPath.empty()) {
|
||||
return std::string("");
|
||||
}
|
||||
auto pos = iconPath.rfind('/');
|
||||
if (pos == std::string::npos) {
|
||||
HILOG_ERROR("invalid iconPath = %{public}s in GetIconsBundleName", iconPath.c_str());
|
||||
return std::string("");
|
||||
}
|
||||
return iconPath.substr(pos + 1);
|
||||
}
|
||||
|
||||
const std::shared_ptr<ThemeResource> ThemeResource::LoadThemeIconResource(const std::string& iconPath)
|
||||
{
|
||||
if (iconPath.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
ThemeResource *themeResource = new (std::nothrow) ThemeResource(iconPath);
|
||||
auto themeResource = std::make_shared<ThemeResource>(iconPath);
|
||||
std::string bundleName = GetIconsBundleName(iconPath);
|
||||
std::vector<std::string> resPaths = GetFiles(iconPath);
|
||||
for (auto path : resPaths) {
|
||||
auto bundleInfo = GetBundleInfo(iconPath, path);
|
||||
auto pos1 = path.rfind('.');
|
||||
auto pos2 = path.rfind('/');
|
||||
if (pos1 == std::string::npos || pos2 == std::string::npos) {
|
||||
@ -330,8 +334,7 @@ const ThemeResource* ThemeResource::LoadThemeIconResource(const std::string& ico
|
||||
continue;
|
||||
}
|
||||
std::string iconName = path.substr(pos2 + 1, pos1 - pos2 - 1);
|
||||
ThemeKey themeKey = ThemeKey(std::get<FIRST_ELEMENT>(bundleInfo),
|
||||
std::get<SECOND_ELEMENT>(bundleInfo), ResType::MEDIA, iconName);
|
||||
ThemeKey themeKey = ThemeKey(bundleName, "", ResType::MEDIA, iconName);
|
||||
themeRes->iconValues_.emplace_back(std::make_pair(themeKey, path));
|
||||
}
|
||||
return themeResource;
|
||||
@ -344,9 +347,6 @@ const std::string ThemeResource::GetThemeAppIcon(const std::pair<std::string, st
|
||||
if (iconValues_[i].first.bundleName != bundleInfo.first) {
|
||||
continue;
|
||||
}
|
||||
if (!iconValues_[i].first.moduleName.empty() && iconValues_[i].first.moduleName != bundleInfo.second) {
|
||||
continue;
|
||||
}
|
||||
if (iconName == iconValues_[i].first.resName) {
|
||||
return iconValues_[i].second;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user