mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 17:24:42 -04:00
新增指定系统id_defined.json功能
Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
@@ -55,6 +55,7 @@ public:
|
||||
bool GetIconCheck() const;
|
||||
const TargetConfig &GetTargetConfigValues() const;
|
||||
bool IsTargetConfig() const;
|
||||
const std::vector<std::string> &GetSysIdDefinedPaths() const;
|
||||
|
||||
private:
|
||||
void InitCommand();
|
||||
@@ -78,6 +79,7 @@ private:
|
||||
uint32_t ShowHelp() const;
|
||||
uint32_t SetIdDefinedOutput(const std::string& argValue);
|
||||
uint32_t SetIdDefinedInputPath(const std::string& argValue);
|
||||
uint32_t AddSysIdDefined(const std::string& argValue);
|
||||
bool IsAscii(const std::string& argValue) const;
|
||||
bool IsLongOpt(char *argv[]) const;
|
||||
uint32_t IconCheck();
|
||||
@@ -105,6 +107,7 @@ private:
|
||||
bool isIconCheck_ = false;
|
||||
TargetConfig targetConfig_;
|
||||
bool isTtargetConfig_;
|
||||
std::vector<std::string> sysIdDefinedPaths_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
||||
@@ -40,13 +40,15 @@ private:
|
||||
uint32_t Init(const std::string &filePath, bool isSystem);
|
||||
using ParseFunction = std::function<bool(const cJSON *, ResourceId&)>;
|
||||
void InitParser();
|
||||
uint32_t IdDefinedToResourceIds(const cJSON *record, bool isSystem, const int64_t strtSysId = 0);
|
||||
uint32_t IdDefinedToResourceIds(const std::string &filePath, const cJSON *record,
|
||||
bool isSystem, const int64_t strtSysId = 0);
|
||||
bool ParseType(const cJSON *type, ResourceId &resourceId);
|
||||
bool ParseName(const cJSON *name, ResourceId &resourceId);
|
||||
bool ParseOrder(const cJSON *order, ResourceId &resourceId);
|
||||
bool ParseId(const cJSON *id, ResourceId &resourceId);
|
||||
bool PushResourceId(const ResourceId &resourceId, bool isSystem);
|
||||
bool PushResourceId(const std::string &filePath, const ResourceId &resourceId, bool isSystem);
|
||||
int64_t GetStartId() const;
|
||||
std::map<std::string, std::vector<std::pair<ResType, std::string>>> checkDefinedIds_;
|
||||
std::map<std::pair<ResType, std::string>, ResourceId> sysDefinedIds_;
|
||||
std::map<std::pair<ResType, std::string>, ResourceId> appDefinedIds_;
|
||||
std::map<int64_t, ResourceId> idDefineds_;
|
||||
|
||||
@@ -39,7 +39,7 @@ const static std::string NEW_LINE_PATH = "\nat ";
|
||||
const static std::string LONG_PATH_HEAD = "\\\\?\\";
|
||||
const static int32_t VERSION_MAX_LEN = 128;
|
||||
const static int32_t INT_TO_BYTES = sizeof(uint32_t);
|
||||
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.006" };
|
||||
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.007" };
|
||||
const static int32_t TAG_LEN = 4;
|
||||
|
||||
enum class KeyType {
|
||||
@@ -126,6 +126,7 @@ enum Option {
|
||||
DEPENDENTRY = 3,
|
||||
ICON_CHECK = 4,
|
||||
TARGET_CONFIG = 5,
|
||||
DEFINED_SYSIDS = 6,
|
||||
STARTID = 'e',
|
||||
FORCEWRITE = 'f',
|
||||
HELP = 'h',
|
||||
|
||||
@@ -42,6 +42,7 @@ const struct option PackageParser::CMD_OPTS[] = {
|
||||
{ "defined-ids", required_argument, nullptr, Option::DEFINED_IDS},
|
||||
{ "icon-check", no_argument, nullptr, Option::ICON_CHECK},
|
||||
{ "target-config", required_argument, nullptr, Option::TARGET_CONFIG},
|
||||
{ "defined-sysids", required_argument, nullptr, Option::DEFINED_SYSIDS},
|
||||
{ 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
@@ -110,6 +111,11 @@ const string &PackageParser::GetDependEntry() const
|
||||
return dependEntry_;
|
||||
}
|
||||
|
||||
const vector<std::string> &PackageParser::GetSysIdDefinedPaths() const
|
||||
{
|
||||
return sysIdDefinedPaths_;
|
||||
}
|
||||
|
||||
uint32_t PackageParser::AddInput(const string& argValue)
|
||||
{
|
||||
string inputPath = ResourceUtil::RealPath(argValue);
|
||||
@@ -131,6 +137,28 @@ uint32_t PackageParser::AddInput(const string& argValue)
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t PackageParser::AddSysIdDefined(const std::string& argValue)
|
||||
{
|
||||
string sysIdDefinedPath = ResourceUtil::RealPath(argValue);
|
||||
if (sysIdDefinedPath.empty()) {
|
||||
cerr << "Error: invalid system id_defined.json path: '" << argValue << "'" << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
auto ret = find_if(sysIdDefinedPaths_.begin(), sysIdDefinedPaths_.end(),
|
||||
[sysIdDefinedPath](auto iter) {return sysIdDefinedPath == iter;});
|
||||
if (ret != sysIdDefinedPaths_.end()) {
|
||||
cerr << "Error: repeat system id_defined.json path: '" << argValue << "'" << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (!IsAscii(sysIdDefinedPath)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
sysIdDefinedPaths_.push_back(sysIdDefinedPath);
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t PackageParser::AddPackageName(const string& argValue)
|
||||
{
|
||||
if (!packageName_.empty()) {
|
||||
@@ -419,6 +447,7 @@ void PackageParser::InitCommand()
|
||||
handles_.emplace(Option::DEFINED_IDS, bind(&PackageParser::SetIdDefinedInputPath, this, _1));
|
||||
handles_.emplace(Option::ICON_CHECK, [this](const string &) -> uint32_t { return IconCheck(); });
|
||||
handles_.emplace(Option::TARGET_CONFIG, bind(&PackageParser::ParseTargetConfig, this, _1));
|
||||
handles_.emplace(Option::DEFINED_SYSIDS, bind(&PackageParser::AddSysIdDefined, this, _1));
|
||||
}
|
||||
|
||||
uint32_t PackageParser::HandleProcess(int c, const string& argValue)
|
||||
|
||||
+28
-13
@@ -56,6 +56,7 @@ uint32_t IdDefinedParser::Init()
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
//SystemResource.hap only defined by base/element/id_defined.json
|
||||
if (isSys) {
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
@@ -66,6 +67,11 @@ uint32_t IdDefinedParser::Init()
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
for (const auto &sysIdDefinedPath : packageParser_.GetSysIdDefinedPaths()) {
|
||||
if (Init(sysIdDefinedPath, true) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
string sysIdDefinedPath = FileEntry::FilePath(packageParser_.GetRestoolPath())
|
||||
.GetParent().Append(ID_DEFINED_FILE).GetPath();
|
||||
if (Init(sysIdDefinedPath, true) != RESTOOL_SUCCESS) {
|
||||
@@ -109,7 +115,7 @@ uint32_t IdDefinedParser::Init(const string &filePath, bool isSystem)
|
||||
}
|
||||
}
|
||||
|
||||
if (IdDefinedToResourceIds(recordNode, isSystem, startSysId) != RESTOOL_SUCCESS) {
|
||||
if (IdDefinedToResourceIds(filePath, recordNode, isSystem, startSysId) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
@@ -124,7 +130,8 @@ void IdDefinedParser::InitParser()
|
||||
handles_.emplace("order", bind(&IdDefinedParser::ParseOrder, this, _1, _2));
|
||||
}
|
||||
|
||||
uint32_t IdDefinedParser::IdDefinedToResourceIds(const cJSON *record, bool isSystem, const int64_t startSysId)
|
||||
uint32_t IdDefinedParser::IdDefinedToResourceIds(const std::string &filePath, const cJSON *record,
|
||||
bool isSystem, const int64_t startSysId)
|
||||
{
|
||||
int64_t index = -1;
|
||||
for (cJSON *item = record->child; item; item = item->next) {
|
||||
@@ -143,14 +150,14 @@ uint32_t IdDefinedParser::IdDefinedToResourceIds(const cJSON *record, bool isSys
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
if (!PushResourceId(resourceId, isSystem)) {
|
||||
if (!PushResourceId(filePath, resourceId, isSystem)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
bool IdDefinedParser::PushResourceId(const ResourceId &resourceId, bool isSystem)
|
||||
bool IdDefinedParser::PushResourceId(const std::string &filePath, const ResourceId &resourceId, bool isSystem)
|
||||
{
|
||||
ResType resType = ResourceUtil::GetResTypeFromString(resourceId.type);
|
||||
auto ret = idDefineds_.emplace(resourceId.id, resourceId);
|
||||
@@ -158,18 +165,26 @@ bool IdDefinedParser::PushResourceId(const ResourceId &resourceId, bool isSystem
|
||||
cerr << "Error: '" << ret.first->second.name << "' and '" << resourceId.name << "' defind the same ID." << endl;
|
||||
return false;
|
||||
}
|
||||
if (isSystem) {
|
||||
auto ret1 = sysDefinedIds_.emplace(make_pair(resType, resourceId.name), resourceId);
|
||||
if (!ret1.second) {
|
||||
cerr << "Error: the same type of '" << resourceId.name << "' exists in the id_defined.json. " << endl;
|
||||
auto checkRet = checkDefinedIds_.find(filePath);
|
||||
if (checkRet != checkDefinedIds_.end()) {
|
||||
bool found = any_of(checkRet->second.begin(), checkRet->second.end(),
|
||||
[resType, resourceId](const auto &iterItem) {
|
||||
return (resType == iterItem.first) && (resourceId.name == iterItem.second);
|
||||
});
|
||||
if (found) {
|
||||
cerr << "Error: the same resource of '" << resourceId.name << "' exists in the " << filePath << endl;
|
||||
return false;
|
||||
}
|
||||
checkRet->second.push_back(make_pair(resType, resourceId.name));
|
||||
} else {
|
||||
auto ret2 = appDefinedIds_.emplace(make_pair(resType, resourceId.name), resourceId);
|
||||
if (!ret2.second) {
|
||||
cerr << "Error: the same type of '" << resourceId.name << "' exists in the id_defined.json. " << endl;
|
||||
return false;
|
||||
}
|
||||
std::vector<std::pair<ResType, std::string>> vects;
|
||||
vects.push_back(make_pair(resType, resourceId.name));
|
||||
checkDefinedIds_.emplace(filePath, vects);
|
||||
}
|
||||
if (isSystem) {
|
||||
sysDefinedIds_.emplace(make_pair(resType, resourceId.name), resourceId);
|
||||
} else {
|
||||
appDefinedIds_.emplace(make_pair(resType, resourceId.name), resourceId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ void ResConfigParser::InitFileListCommand(HandleBack callback)
|
||||
Option::MODULES, callback));
|
||||
fileListHandles_.emplace("iconCheck", bind(&ResConfigParser::GetBool, this, _1,
|
||||
Option::ICON_CHECK, callback));
|
||||
fileListHandles_.emplace("definedSysIds", bind(&ResConfigParser::GetString, this, _1,
|
||||
Option::DEFINED_SYSIDS, callback));
|
||||
}
|
||||
|
||||
uint32_t ResConfigParser::GetString(const cJSON *node, int c, HandleBack callback)
|
||||
|
||||
Reference in New Issue
Block a user