From 41d1b4a3275e8427f6080996039b8f4fa6656e31 Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Mon, 14 Aug 2023 03:21:34 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=80=E5=90=AFpng?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E5=B0=BA=E5=AF=B8=E6=A0=A1=E9=AA=8C=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- include/cmd_list.h | 1 + include/cmd_parser.h | 4 ++++ include/resource_data.h | 1 + src/cmd_list.cpp | 13 +++++++++++++ src/cmd_parser.cpp | 13 +++++++++++++ src/resource_check.cpp | 4 ++-- src/resource_pack.cpp | 8 ++++++-- 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/cmd_list.h b/include/cmd_list.h index 2fbd116..ffd074a 100644 --- a/include/cmd_list.h +++ b/include/cmd_list.h @@ -36,6 +36,7 @@ private: 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, int c, HandleBack callback); + uint32_t GetBool(const Json::Value &node, int c, HandleBack callback); }; } } diff --git a/include/cmd_parser.h b/include/cmd_parser.h index 28069ac..ddab4ab 100644 --- a/include/cmd_parser.h +++ b/include/cmd_parser.h @@ -52,6 +52,7 @@ public: const std::string &GetDependEntry() const; const std::string &GetIdDefinedOutput() const; const std::string &GetIdDefinedInputPath() const; + bool GetIconCheck() const; private: void InitCommand(); @@ -77,6 +78,7 @@ private: uint32_t SetIdDefinedInputPath(const std::string& argValue); bool IsAscii(const std::string& argValue) const; bool IsLongOpt(char *argv[]) const; + uint32_t IconCheck(); static const struct option CMD_OPTS[]; static const std::string CMD_PARAMS; @@ -97,6 +99,7 @@ private: std::string dependEntry_; std::string idDefinedOutput_; std::string idDefinedInputPath_; + bool isIconCheck_ = false; }; template @@ -136,6 +139,7 @@ void CmdParser::ShowUseage() std::cout << " --defined-ids input id_defined.json path\n"; std::cout << " --dependEntry Build result directory of the specified entry module when the feature"; std::cout << " module resources are independently built in the FA model.\n"; + std::cout << " --icon-check Enable the PNG image verification function for icons and startwindows.\n"; } template diff --git a/include/resource_data.h b/include/resource_data.h index 916a81c..dc74235 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -114,6 +114,7 @@ enum Option { IDS = 1, DEFINED_IDS = 2, DEPENDENTRY = 3, + ICON_CHECK = 4, STARTID = 'e', FORCEWRITE = 'f', HELP = 'h', diff --git a/src/cmd_list.cpp b/src/cmd_list.cpp index 7afeb44..430bf8b 100644 --- a/src/cmd_list.cpp +++ b/src/cmd_list.cpp @@ -61,6 +61,7 @@ void CmdList::InitFileListCommand(Json::Value &root, HandleBack 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)); + fileListHandles_.push_back(bind(&CmdList::GetBool, this, root["iconCheck"], Option::ICON_CHECK, callback)); } uint32_t CmdList::GetString(const Json::Value &node, int c, HandleBack callback) @@ -113,6 +114,18 @@ uint32_t CmdList::GetModuleNames(const Json::Value &node, int c, HandleBack call } return RESTOOL_SUCCESS; } + +uint32_t CmdList::GetBool(const Json::Value &node, int c, HandleBack callback) +{ + if (node.type() != Json::booleanValue) { + return RESTOOL_SUCCESS; + } + + if (node.asBool() && callback(c, "") != RESTOOL_SUCCESS) { + return RESTOOL_ERROR; + } + return RESTOOL_SUCCESS; +} } } } diff --git a/src/cmd_parser.cpp b/src/cmd_parser.cpp index 42033a5..1f6d242 100644 --- a/src/cmd_parser.cpp +++ b/src/cmd_parser.cpp @@ -39,6 +39,7 @@ const struct option PackageParser::CMD_OPTS[] = { { "help", no_argument, nullptr, Option::HELP}, { "ids", required_argument, nullptr, Option::IDS}, { "defined-ids", required_argument, nullptr, Option::DEFINED_IDS}, + { "icon-check", no_argument, nullptr, Option::ICON_CHECK}, { 0, 0, 0, 0}, }; @@ -338,6 +339,17 @@ const string &PackageParser::GetIdDefinedInputPath() const return idDefinedInputPath_; } +uint32_t PackageParser::IconCheck() +{ + isIconCheck_ = true; + return RESTOOL_SUCCESS; +} + +bool PackageParser::GetIconCheck() const +{ + return isIconCheck_; +} + bool PackageParser::IsAscii(const string& argValue) const { #ifdef __WIN32 @@ -373,6 +385,7 @@ void PackageParser::InitCommand() handles_.emplace(Option::HELP, [this](const string &) -> uint32_t { return ShowHelp(); }); handles_.emplace(Option::IDS, bind(&PackageParser::SetIdDefinedOutput, this, _1)); handles_.emplace(Option::DEFINED_IDS, bind(&PackageParser::SetIdDefinedInputPath, this, _1)); + handles_.emplace(Option::ICON_CHECK, [this](const string &) -> uint32_t { return IconCheck(); }); } uint32_t PackageParser::HandleProcess(int c, const string& argValue) diff --git a/src/resource_check.cpp b/src/resource_check.cpp index 1ac39f8..2b1a878 100755 --- a/src/resource_check.cpp +++ b/src/resource_check.cpp @@ -74,7 +74,7 @@ void ResourceCheck::CheckNodeInResourceItem(const string &key, const ResourceIte return; } if (width != height) { - cout << "Warning: the png width and height not equal" << NEW_LINE_PATH << filePath << endl; + cerr << "Warning: the png width and height not equal" << NEW_LINE_PATH << filePath << endl; return; } auto result = g_keyNodeIndexs.find(key); @@ -85,7 +85,7 @@ void ResourceCheck::CheckNodeInResourceItem(const string &key, const ResourceIte if (normalSize != 0 && width > normalSize) { string warningMsg = "Warning: The width or height of the png file referenced by the " + key + \ " exceeds the limit (" + to_string(normalSize) + " pixels)" + NEW_LINE_PATH + filePath; - cout << warningMsg << endl; + cerr << warningMsg << endl; } } diff --git a/src/resource_pack.cpp b/src/resource_pack.cpp index e9de364..1c2b8a8 100644 --- a/src/resource_pack.cpp +++ b/src/resource_pack.cpp @@ -346,7 +346,9 @@ uint32_t ResourcePack::PackNormal() return RESTOOL_ERROR; } - CheckConfigJson(); + if (packageParser_.GetIconCheck()) { + CheckConfigJson(); + } ResourceTable resourceTable; if (!packageParser_.GetDependEntry().empty()) { @@ -565,7 +567,9 @@ uint32_t ResourcePack::PackCombine() return RESTOOL_ERROR; } - CheckConfigJsonForCombine(resourceAppend); + if (packageParser_.GetIconCheck()) { + CheckConfigJsonForCombine(resourceAppend); + } if (GenerateHeader() != RESTOOL_SUCCESS) { return RESTOOL_ERROR;