id_defined.json功能支持文件命令解析

Signed-off-by: fangyunzhong <fangyunzhong2@huawei.com>
This commit is contained in:
fangyunzhong
2023-05-20 08:11:16 +00:00
committed by fyz1019
parent e6e5e1f6a8
commit 31cee7a962
3 changed files with 34 additions and 23 deletions
+4 -1
View File
@@ -30,9 +30,12 @@ public:
using HandleBack = std::function<uint32_t(int c, const std::string &argValue)>;
uint32_t Init(const std::string &filePath, HandleBack callback);
private:
void InitFileListCommand(Json::Value &root, HandleBack callback);
using HandleFileListValue = std::function<uint32_t()>;
std::vector<HandleFileListValue> fileListHandles_;
uint32_t GetString(const Json::Value &node, int c, HandleBack callback);
uint32_t GetArray(const Json::Value &node, int c, HandleBack callback);
uint32_t GetModuleNames(const Json::Value &node, HandleBack callback);
uint32_t GetModuleNames(const Json::Value &node, int c, HandleBack callback);
};
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ const static std::string LONG_PATH_HEAD = "\\\\?\\";
const static std::string ID_DEFINED_INDENTATION = " ";
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 4.002" };
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.003" };
const static int32_t TAG_LEN = 4;
enum class KeyType {
+29 -21
View File
@@ -20,7 +20,7 @@ namespace OHOS {
namespace Global {
namespace Restool {
using namespace std;
uint32_t CmdList::Init(const string &filePath, function<uint32_t(int c, const string &argValue)> callback)
uint32_t CmdList::Init(const string &filePath, HandleBack callback)
{
Json::Value root;
if (!ResourceUtil::OpenJsonFile(filePath, root)) {
@@ -31,23 +31,12 @@ uint32_t CmdList::Init(const string &filePath, function<uint32_t(int c, const st
return RESTOOL_SUCCESS;
}
if (GetString(root["configPath"], Option::JSON, callback) != RESTOOL_SUCCESS ||
GetString(root["packageName"], Option::PACKAGENAME, callback) != RESTOOL_SUCCESS ||
GetString(root["output"], Option::OUTPUTPATH, callback) != RESTOOL_SUCCESS ||
GetString(root["startId"], Option::STARTID, callback) != RESTOOL_SUCCESS ||
GetString(root["entryCompiledResource"], Option::DEPENDENTRY, callback) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
InitFileListCommand(root, callback);
if (GetModuleNames(root["moduleNames"], callback) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
if (GetArray(root["ResourceTable"], Option::RESHEADER, callback) != RESTOOL_SUCCESS ||
GetString(root["applicationResource"], Option::INPUTPATH, callback) != RESTOOL_SUCCESS ||
GetArray(root["moduleResources"], Option::INPUTPATH, callback) != RESTOOL_SUCCESS ||
GetArray(root["dependencies"], Option::INPUTPATH, callback) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
for (auto iter : fileListHandles_) {
if (iter() != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
}
callback(Option::FORCEWRITE, "");
@@ -55,6 +44,25 @@ uint32_t CmdList::Init(const string &filePath, function<uint32_t(int c, const st
}
// below private
void CmdList::InitFileListCommand(Json::Value &root, HandleBack callback)
{
using namespace placeholders;
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["configPath"], Option::JSON, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["packageName"], Option::PACKAGENAME, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["output"], Option::OUTPUTPATH, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["startId"], Option::STARTID, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["entryCompiledResource"],
Option::DEPENDENTRY, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["ids"], Option::IDS, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["definedIds"], Option::DEFINED_IDS, callback));
fileListHandles_.push_back(bind(&CmdList::GetString, this, root["applicationResource"],
Option::INPUTPATH, callback));
fileListHandles_.push_back(bind(&CmdList::GetArray, this, root["ResourceTable"], Option::RESHEADER, callback));
fileListHandles_.push_back(bind(&CmdList::GetArray, this, root["moduleResources"], Option::INPUTPATH, callback));
fileListHandles_.push_back(bind(&CmdList::GetArray, this, root["dependencies"], Option::INPUTPATH, callback));
fileListHandles_.push_back(bind(&CmdList::GetModuleNames, this, root["moduleNames"], Option::MODULES, callback));
}
uint32_t CmdList::GetString(const Json::Value &node, int c, HandleBack callback)
{
if (!node.isString()) {
@@ -84,13 +92,13 @@ uint32_t CmdList::GetArray(const Json::Value &node, int c, HandleBack callback)
return RESTOOL_SUCCESS;
}
uint32_t CmdList::GetModuleNames(const Json::Value &node, HandleBack callback)
uint32_t CmdList::GetModuleNames(const Json::Value &node, int c, HandleBack callback)
{
string moduleNames;
if (node.isString()) {
return GetString(node, Option::MODULES, callback);
return GetString(node, c, callback);
}
if (GetArray(node, Option::MODULES, [&moduleNames](int c, const string &argValue) {
if (GetArray(node, c, [&moduleNames](int c, const string &argValue) {
if (!moduleNames.empty()) {
moduleNames.append(",");
}
@@ -100,7 +108,7 @@ uint32_t CmdList::GetModuleNames(const Json::Value &node, HandleBack callback)
return RESTOOL_ERROR;
}
if (!moduleNames.empty() && callback(Option::MODULES, moduleNames) != RESTOOL_SUCCESS) {
if (!moduleNames.empty() && callback(c, moduleNames) != RESTOOL_SUCCESS) {
return RESTOOL_ERROR;
}
return RESTOOL_SUCCESS;