mirror of
https://gitee.com/openharmony/global_resource_management
synced 2024-11-23 07:59:51 +00:00
修改资源id解析流程
Signed-off-by: gaochao <gaochao69@huawei.com>
This commit is contained in:
parent
f4c4c8066c
commit
3da39a5b98
@ -33,7 +33,7 @@ void ReportInitResourceManagerFail(const std::string& bundleName, const std::str
|
||||
}
|
||||
}
|
||||
|
||||
void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const std::string& errMsg)
|
||||
void ReportGetResourceByIdFail(uint32_t resId, const std::string& result, const std::string& errMsg)
|
||||
{
|
||||
int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::GLOBAL_RESMGR, "GET_RES_BY_ID_FAILED",
|
||||
HiSysEventNameSpace::EventType::BEHAVIOR,
|
||||
@ -42,7 +42,7 @@ void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const s
|
||||
"ERROR_MSG", errMsg);
|
||||
if (ret != 0) {
|
||||
RESMGR_HILOGE(RESMGR_TAG,
|
||||
"HiSysEventWrite failed! ret %{public}d, resId %{public}d, result %{public}s, errMsg %{public}s.",
|
||||
"HiSysEventWrite failed! ret %{public}d, resId %{public}u, result %{public}s, errMsg %{public}s.",
|
||||
ret, resId, result.c_str(), errMsg.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace Global {
|
||||
namespace Resource {
|
||||
void ReportInitResourceManagerFail(const std::string& bundleName, const std::string& errMsg);
|
||||
|
||||
void ReportGetResourceByIdFail(int32_t resId, const std::string& result, const std::string& errMsg);
|
||||
void ReportGetResourceByIdFail(uint32_t resId, const std::string& result, const std::string& errMsg);
|
||||
|
||||
void ReportGetResourceByNameFail(const std::string& resName, const std::string& result, const std::string& errMsg);
|
||||
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
* @param id when return true, set id. as sample : 16777225
|
||||
* @return true: value is ref
|
||||
*/
|
||||
static bool IsRef(const std::string &value, ResType &resType, int &id);
|
||||
static bool IsRef(const std::string &value, ResType &resType, uint32_t &id);
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
|
@ -224,7 +224,7 @@ bool IdItem::HaveParent() const
|
||||
return (values_.size() % 2 == 1); // Taking the remainder of 2 to determine the existence of a parent node
|
||||
}
|
||||
|
||||
bool IdItem::IsRef(const std::string &value, ResType &resType, int &id)
|
||||
bool IdItem::IsRef(const std::string &value, ResType &resType, uint32_t &id)
|
||||
{
|
||||
const char *it = value.c_str();
|
||||
const char *st = it;
|
||||
@ -240,11 +240,11 @@ bool IdItem::IsRef(const std::string &value, ResType &resType, int &id)
|
||||
typeStr.assign(it + 1, index - 1);
|
||||
idStr.assign(it + index + 1, value.size() - index);
|
||||
|
||||
int idd = atoi(idStr.c_str());
|
||||
if (idd <= 0) {
|
||||
unsigned long tmpId;
|
||||
if (!Utils::convertToUnsignedLong(idStr, tmpId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t idd = static_cast<uint32_t>(tmpId);
|
||||
for (auto iit = resTypeStrList.begin(); iit != resTypeStrList.end(); ++iit) {
|
||||
auto tValue = iit->second;
|
||||
auto type = iit->first;
|
||||
|
@ -427,7 +427,7 @@ RState ResourceManagerImpl::GetPluralString(const std::shared_ptr<HapResource::V
|
||||
|
||||
RState ResourceManagerImpl::ResolveReference(const std::string value, std::string &outValue)
|
||||
{
|
||||
int id;
|
||||
uint32_t id;
|
||||
ResType resType;
|
||||
bool isRef = true;
|
||||
int count = 0;
|
||||
@ -517,7 +517,7 @@ RState ResourceManagerImpl::ResolveParentReference(const std::shared_ptr<IdItem>
|
||||
}
|
||||
if (haveParent) {
|
||||
// get parent
|
||||
int id;
|
||||
uint32_t id;
|
||||
ResType resType;
|
||||
bool isRef = IdItem::IsRef(currItem->values_[0], resType, id);
|
||||
if (!isRef) {
|
||||
@ -797,7 +797,7 @@ RState ResourceManagerImpl::GetInteger(const std::shared_ptr<IdItem> idItem, int
|
||||
RState ResourceManagerImpl::ProcessReference(const std::string value,
|
||||
std::vector<std::shared_ptr<IdItem>> &idItems)
|
||||
{
|
||||
int id;
|
||||
uint32_t id;
|
||||
ResType resType;
|
||||
bool isRef = true;
|
||||
int count = 0;
|
||||
|
@ -66,7 +66,7 @@ void ResDescTest::TearDown()
|
||||
HWTEST_F(ResDescTest, ResDescFuncTest001, TestSize.Level1)
|
||||
{
|
||||
std::string str;
|
||||
int id;
|
||||
uint32_t id;
|
||||
ResType resType;
|
||||
str.assign("abc");
|
||||
EXPECT_TRUE(!IdItem::IsRef(str, resType, id));
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
std::string moduleName;
|
||||
|
||||
/** the resource id in hap */
|
||||
int32_t id;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
enum class NapiValueType {
|
||||
|
@ -26,7 +26,7 @@ struct ResMgrDataContext {
|
||||
napi_async_work work_;
|
||||
|
||||
std::string bundleName_;
|
||||
int32_t resId_;
|
||||
uint32_t resId_;
|
||||
int32_t param_;
|
||||
|
||||
std::string path_;
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
|
||||
static std::string GetResNameOrPath(napi_env env, size_t argc, napi_value *argv);
|
||||
|
||||
static int GetResId(napi_env env, size_t argc, napi_value *argv);
|
||||
static uint32_t GetResId(napi_env env, size_t argc, napi_value *argv);
|
||||
|
||||
static void NapiThrow(napi_env env, int32_t errCode);
|
||||
|
||||
@ -66,7 +66,7 @@ public:
|
||||
napi_value &value);
|
||||
|
||||
static bool GetHapResourceManager(const ResMgrDataContext* dataContext,
|
||||
std::shared_ptr<ResourceManager> &resMgr, int32_t &resId);
|
||||
std::shared_ptr<ResourceManager> &resMgr, uint32_t &resId);
|
||||
|
||||
static RState GetIncludeSystem(napi_env env, napi_value value, bool &includeSystem);
|
||||
|
||||
|
@ -406,7 +406,7 @@ napi_value ResourceManagerNapiAsyncImpl::ProcessNoParam(napi_env env, napi_callb
|
||||
auto getStringFunc = [](napi_env env, void* data) {
|
||||
ResMgrDataContext *dataContext = static_cast<ResMgrDataContext*>(data);
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId);
|
||||
if (!ret) {
|
||||
@ -466,7 +466,7 @@ napi_value ResourceManagerNapiAsyncImpl::GetStringByName(napi_env env, napi_call
|
||||
auto getStringArrayFunc = [](napi_env env, void* data) {
|
||||
ResMgrDataContext *dataContext = static_cast<ResMgrDataContext*>(data);
|
||||
RState state;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
if (dataContext->resId_ != 0 || dataContext->resource_ != nullptr) {
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId);
|
||||
@ -521,7 +521,7 @@ napi_value ResourceManagerNapiAsyncImpl::GetStringArrayByName(napi_env env, napi
|
||||
auto getMediaFunc = [](napi_env env, void *data) {
|
||||
ResMgrDataContext *dataContext = static_cast<ResMgrDataContext*>(data);
|
||||
std::string path;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId);
|
||||
if (!ret) {
|
||||
@ -565,7 +565,7 @@ auto getMediaBase64Func = [](napi_env env, void *data) {
|
||||
std::string path;
|
||||
RState state;
|
||||
if (dataContext->resId_ != 0 || dataContext->resource_ != nullptr) {
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId);
|
||||
if (!ret) {
|
||||
@ -629,7 +629,7 @@ auto getPluralCapFunc = [](napi_env env, void *data) {
|
||||
ResMgrDataContext *dataContext = static_cast<ResMgrDataContext*>(data);
|
||||
RState state;
|
||||
if (dataContext->resId_ != 0 || dataContext->resource_ != nullptr) {
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId);
|
||||
if (!ret) {
|
||||
@ -813,7 +813,7 @@ napi_value ResourceManagerNapiAsyncImpl::GetRawFileList(napi_env env, napi_callb
|
||||
auto getColorFunc = [](napi_env env, void* data) {
|
||||
ResMgrDataContext *dataContext = static_cast<ResMgrDataContext*>(data);
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
|
||||
if (!ResourceManagerNapiUtils::GetHapResourceManager(dataContext, resMgr, resId)) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to GetHapResourceManager in getColorFunc");
|
||||
|
@ -309,7 +309,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessStrResource(napi_env env, napi_callb
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetStringSync");
|
||||
@ -357,7 +357,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessSymbolResource(napi_env env, napi_ca
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetSymbol");
|
||||
@ -399,7 +399,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessColorResource(napi_env env, napi_cal
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in ProcessColorResource");
|
||||
@ -442,7 +442,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessNumResource(napi_env env, napi_callb
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to ResourceManagerNapiUtils::GetHapResourceManager in GetNumber");
|
||||
@ -484,7 +484,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessBoolResource(napi_env env, napi_call
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret2) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetBoolean");
|
||||
@ -525,7 +525,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcesstMediaContentBase64Resource(napi_env
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret2) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetMediaContentBase64Sync");
|
||||
@ -570,7 +570,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessMediaContentResource(napi_env env, n
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret2) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetMediaContentSync");
|
||||
@ -616,7 +616,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessPluralStringValueResource(napi_env e
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret2) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetPluralStringValueSync");
|
||||
@ -669,7 +669,7 @@ int32_t ResourceManagerNapiSyncImpl::ProcessStringArrayValueResource(napi_env en
|
||||
std::unique_ptr<ResMgrDataContext> &dataContext)
|
||||
{
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
bool ret2 = ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId);
|
||||
if (!ret2) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resMgr in GetStringArrayValueSync");
|
||||
@ -729,7 +729,7 @@ napi_value ResourceManagerNapiSyncImpl::GetDrawableDescriptor(napi_env env, napi
|
||||
}
|
||||
|
||||
std::shared_ptr<ResourceManager> resMgr = nullptr;
|
||||
int32_t resId = 0;
|
||||
uint32_t resId = 0;
|
||||
if (!ResourceManagerNapiUtils::GetHapResourceManager(dataContext.get(), resMgr, resId)) {
|
||||
dataContext->SetErrorMsg("Failed to get GetHapResourceManager in GetDrawableDescriptor", true);
|
||||
return nullptr;
|
||||
|
@ -110,7 +110,7 @@ std::string ResourceManagerNapiUtils::GetResNameOrPath(napi_env env, size_t argc
|
||||
return buf.data();
|
||||
}
|
||||
|
||||
int ResourceManagerNapiUtils::GetResId(napi_env env, size_t argc, napi_value *argv)
|
||||
uint32_t ResourceManagerNapiUtils::GetResId(napi_env env, size_t argc, napi_value *argv)
|
||||
{
|
||||
if (argc == 0 || argv == nullptr) {
|
||||
return 0;
|
||||
@ -126,14 +126,14 @@ int ResourceManagerNapiUtils::GetResId(napi_env env, size_t argc, napi_value *ar
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Invalid param, not number");
|
||||
return 0;
|
||||
}
|
||||
int resId = 0;
|
||||
status = napi_get_value_int32(env, argv[ARRAY_SUBCRIPTOR_ZERO], &resId);
|
||||
int64_t resId = 0;
|
||||
status = napi_get_value_int64(env, argv[ARRAY_SUBCRIPTOR_ZERO], &resId);
|
||||
if (status != napi_ok) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get id number");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return resId;
|
||||
return static_cast<uint32_t>(resId);
|
||||
}
|
||||
|
||||
std::string ResourceManagerNapiUtils::FindErrMsg(int32_t errCode)
|
||||
@ -358,13 +358,13 @@ bool ResourceManagerNapiUtils::GetResourceObjectId(napi_env env,
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resource id number");
|
||||
return false;
|
||||
}
|
||||
int32_t resId = 0;
|
||||
status = napi_get_value_int32(env, id, &resId);
|
||||
int64_t resId = 0;
|
||||
status = napi_get_value_int64(env, id, &resId);
|
||||
if (status != napi_ok) {
|
||||
RESMGR_HILOGE(RESMGR_JS_TAG, "Failed to get resource id value");
|
||||
return false;
|
||||
}
|
||||
resourcePtr->id = resId;
|
||||
resourcePtr->id = static_cast<uint32_t>(resId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -392,7 +392,7 @@ int32_t ResourceManagerNapiUtils::GetResourceObject(napi_env env,
|
||||
}
|
||||
|
||||
bool ResourceManagerNapiUtils::GetHapResourceManager(const ResMgrDataContext* dataContext,
|
||||
std::shared_ptr<ResourceManager> &resMgr, int32_t &resId)
|
||||
std::shared_ptr<ResourceManager> &resMgr, uint32_t &resId)
|
||||
{
|
||||
std::shared_ptr<ResourceManager::Resource> resource = dataContext->resource_;
|
||||
// In fa module, resource is null.
|
||||
|
Loading…
Reference in New Issue
Block a user