mirror of
https://github.com/openharmony/global_resmgr_standard.git
synced 2026-07-19 19:33:32 -04:00
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -22,10 +22,10 @@ namespace Global {
|
||||
namespace Resource {
|
||||
class AutoMutex {
|
||||
public:
|
||||
inline AutoMutex(Lock &lock) : lock_(lock)
|
||||
explicit inline AutoMutex(Lock &lock) : lock_(lock)
|
||||
{ lock_.lock(); }
|
||||
|
||||
inline AutoMutex(Lock *lock) : lock_(*lock)
|
||||
explicit inline AutoMutex(Lock *lock) : lock_(*lock)
|
||||
{ lock_.lock(); }
|
||||
|
||||
inline ~AutoMutex()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -29,7 +29,7 @@ namespace Global {
|
||||
namespace Resource {
|
||||
class HapManager {
|
||||
public:
|
||||
HapManager(ResConfigImpl *resConfig);
|
||||
explicit HapManager(ResConfigImpl *resConfig);
|
||||
|
||||
~HapManager();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
static DeviceType GetDeviceType(uint32_t value);
|
||||
|
||||
static ColorMode GetColorMode(uint32_t value);
|
||||
|
||||
private:
|
||||
static const char *RES_FILE_NAME;
|
||||
};
|
||||
|
||||
@@ -373,7 +373,7 @@ bool HapManager::AddResourcePath(const char *path)
|
||||
if (pResource == nullptr) {
|
||||
return false;
|
||||
}
|
||||
this->hapResources_.push_back((HapResource *)pResource);
|
||||
this->hapResources_.push_back(const_cast<HapResource *>(pResource));
|
||||
this->loadedHapPaths_[sPath] = std::vector<std::string>();
|
||||
return true;
|
||||
}
|
||||
@@ -392,7 +392,7 @@ RState HapManager::ReloadAll()
|
||||
}
|
||||
return HAP_INIT_FAILED;
|
||||
}
|
||||
newResources.push_back((HapResource *)pResource);
|
||||
newResources.push_back(const_cast<HapResource *>(pResource));
|
||||
std::vector<std::string> &overlayPaths = iter->second;
|
||||
if (overlayPaths.size() == 0) {
|
||||
continue;
|
||||
|
||||
@@ -142,7 +142,7 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI
|
||||
return nullptr;
|
||||
}
|
||||
inFile.seekg(0, std::ios::beg);
|
||||
inFile.read((char *)buf, bufLen);
|
||||
inFile.read(static_cast<char *>(buf), bufLen);
|
||||
inFile.close();
|
||||
|
||||
HILOG_DEBUG("extract success, bufLen:%d", bufLen);
|
||||
@@ -153,7 +153,7 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI
|
||||
free(buf);
|
||||
return nullptr;
|
||||
}
|
||||
int32_t out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, defaultConfig);
|
||||
int32_t out = HapParser::ParseResHex(static_cast<char *>(buf), bufLen, *resDesc, defaultConfig);
|
||||
if (out != OK) {
|
||||
delete (resDesc);
|
||||
free(buf);
|
||||
|
||||
@@ -74,7 +74,7 @@ RState ResConfigImpl::SetLocaleInfo(const char *language,
|
||||
UErrorCode errCode = U_ZERO_ERROR;
|
||||
Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage())
|
||||
.setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode);
|
||||
|
||||
|
||||
if (!U_SUCCESS(errCode)) {
|
||||
state = NOT_ENOUGH_MEM;
|
||||
delete resLocale;
|
||||
@@ -180,7 +180,7 @@ bool ResConfigImpl::CopyLocale(ResConfig &other)
|
||||
}
|
||||
UErrorCode errCode = U_ZERO_ERROR;
|
||||
Locale tempLocale = icu::LocaleBuilder().setLocale(*other.GetLocaleInfo()).build(errCode);
|
||||
|
||||
|
||||
if (!U_SUCCESS(errCode)) {
|
||||
delete temp;
|
||||
return false;
|
||||
@@ -218,6 +218,9 @@ bool ResConfigImpl::Copy(ResConfig &other)
|
||||
|
||||
bool ResConfigImpl::Match(const ResConfigImpl *other) const
|
||||
{
|
||||
if (other == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (LocaleMatcher::Match(this->resLocale_, other->GetResLocale()) == false) {
|
||||
return false;
|
||||
}
|
||||
@@ -252,7 +255,7 @@ bool ResConfigImpl::Match(const ResConfigImpl *other) const
|
||||
bool ResConfigImpl::IsMoreSuitable(const ResConfigImpl *other,
|
||||
const ResConfigImpl *request) const
|
||||
{
|
||||
if (request != nullptr) {
|
||||
if (request != nullptr && other != nullptr) {
|
||||
int8_t result =
|
||||
LocaleMatcher::IsMoreSuitable(this->GetResLocale(), other->GetResLocale(),
|
||||
request->GetResLocale());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -378,7 +378,7 @@ Locale *BuildFromString(const char *str, char sep, RState &rState)
|
||||
UErrorCode errCode = U_ZERO_ERROR;
|
||||
Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage())
|
||||
.setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode);
|
||||
|
||||
|
||||
if (!U_SUCCESS(errCode)) {
|
||||
delete resLocale;
|
||||
rState = ERROR;
|
||||
|
||||
@@ -240,7 +240,7 @@ RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, c
|
||||
RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifierDir *vuqd,
|
||||
int quantity, std::string &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
// not found or type invalid
|
||||
if (vuqd == nullptr) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
@@ -644,6 +644,9 @@ RState ResourceManagerImpl::GetRawFile(const HapResource::ValueUnderQualifierDir
|
||||
std::string &outValue)
|
||||
{
|
||||
// not found or type invalid
|
||||
if (vuqd == nullptr) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
const IdItem *idItem = vuqd->GetIdItem();
|
||||
if (idItem == nullptr || idItem->resType_ != resType) {
|
||||
return NOT_FOUND;
|
||||
|
||||
@@ -73,7 +73,7 @@ int32_t HapParser::ReadFileFromZip(const char *zipFile, const char *fileName, vo
|
||||
return UNKNOWN_ERROR;
|
||||
} // obtained the necessary details about file inside zip
|
||||
|
||||
*buffer = (void *)malloc(fileInfo.uncompressed_size); // setup buffer
|
||||
*buffer = static_cast<void *>(malloc(fileInfo.uncompressed_size)); // setup buffer
|
||||
bufLen = fileInfo.uncompressed_size;
|
||||
if ((*buffer) == nullptr) {
|
||||
unzClose(uf);
|
||||
@@ -144,7 +144,7 @@ int32_t HapParser::ReadIndexFromFile(const char *zipFile, void **buffer,
|
||||
}
|
||||
|
||||
// parse config.json
|
||||
std::string mName = GetModuleName((char *)tmpBuf);
|
||||
std::string mName = GetModuleName(static_cast<char *>(tmpBuf));
|
||||
if (mName.size() == 0) {
|
||||
errInfo = "parse moduleName from config.json error";
|
||||
free(tmpBuf);
|
||||
@@ -174,7 +174,7 @@ int32_t ParseString(const char *buffer, uint32_t &offset, std::string &id, bool
|
||||
return SYS_ERROR;
|
||||
}
|
||||
offset += 2;
|
||||
std::string tmp = std::string((char *)buffer + offset, includeTemi ? (strLen - 1) : strLen);
|
||||
std::string tmp = std::string(const_cast<char *>(buffer) + offset, includeTemi ? (strLen - 1) : strLen);
|
||||
offset += includeTemi ? strLen : (strLen + 1);
|
||||
id = tmp;
|
||||
return OK;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -25,6 +25,9 @@ namespace Global {
|
||||
namespace Resource {
|
||||
bool Utils::IsAlphaString(const char *s, int32_t len)
|
||||
{
|
||||
if (s == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int32_t i;
|
||||
for (i = 0; i < len; i++) {
|
||||
char c = *(s + i);
|
||||
@@ -37,6 +40,9 @@ bool Utils::IsAlphaString(const char *s, int32_t len)
|
||||
|
||||
bool Utils::IsNumericString(const char *s, int32_t len)
|
||||
{
|
||||
if (s == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int32_t i;
|
||||
for (i = 0; i < len; i++) {
|
||||
char c = *(s + i);
|
||||
@@ -60,6 +66,9 @@ bool Utils::IsNumericString(const char *s, int32_t len)
|
||||
*/
|
||||
void Utils::DecodeScript(uint32_t encodeScript, char *outValue)
|
||||
{
|
||||
if (outValue == nullptr) {
|
||||
return;
|
||||
}
|
||||
outValue[0] = (encodeScript & 0xFF000000) >> 24;
|
||||
outValue[1] = (encodeScript & 0x00FF0000) >> 16;
|
||||
outValue[2] = (encodeScript & 0x0000FF00) >> 8;
|
||||
@@ -268,6 +277,9 @@ static uint32_t ParseHex(char c, RState &state)
|
||||
*/
|
||||
RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue)
|
||||
{
|
||||
if (s == nullptr) {
|
||||
return INVALID_FORMAT;
|
||||
}
|
||||
uint32_t color = 0;
|
||||
RState parseState = SUCCESS;
|
||||
size_t len = strlen(s);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
||||
@@ -41,6 +41,9 @@ using namespace OHOS::AppExecFwk;
|
||||
|
||||
static void ExecuteGetResMgr(napi_env env, void* data)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
ResMgrAsyncContext *asyncContext = static_cast<ResMgrAsyncContext*>(data);
|
||||
|
||||
asyncContext->createValueFunc_ = [](napi_env env, ResMgrAsyncContext &context) -> napi_value {
|
||||
|
||||
Reference in New Issue
Block a user