From 0dd120ad36194a05e8caaed35ef777f6ca70c030 Mon Sep 17 00:00:00 2001 From: chencheng31 Date: Sat, 26 Mar 2022 15:04:06 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chencheng31 --- include/cmd_parser.h | 4 ++-- include/file_manager.h | 4 ++-- include/reference_parser.h | 2 +- include/resource_util.h | 2 +- src/file_manager.cpp | 6 +++--- src/reference_parser.cpp | 4 ++-- src/resource_util.cpp | 2 +- src/restool.cpp | 4 ++++ src/xml/solid_xml.cpp | 7 ++++++- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/cmd_parser.h b/include/cmd_parser.h index 98e7510..1bbabcf 100644 --- a/include/cmd_parser.h +++ b/include/cmd_parser.h @@ -35,7 +35,7 @@ public: class PackageParser : public ICmdParser { public: PackageParser() {}; - ~PackageParser() = default; + virtual ~PackageParser() = default; uint32_t Parse(int argc, char *argv[]) override; const std::vector &GetInputs() const; const std::string &GetPackageName() const; @@ -104,7 +104,7 @@ template void CmdParser::ShowUseage() { std::cout << "This is an OHOS Packaging Tool.\n"; - std::cout << "Useage:\n"; + std::cout << "Usage:\n"; std::cout << TOOL_NAME << " [arguments] Package the OHOS resources.\n"; std::cout << "[arguments]:\n"; std::cout << " -i input resource path, can add more.\n"; diff --git a/include/file_manager.h b/include/file_manager.h index c19802e..747cad3 100644 --- a/include/file_manager.h +++ b/include/file_manager.h @@ -28,7 +28,7 @@ namespace Restool { class FileManager : public Singleton { public: uint32_t ScanModules(const std::vector &inputs, const std::string &output); - const std::map> &GetResources() const { return alls_; }; + const std::map> &GetResources() const { return items_; }; void SetModuleName(const std::string &moduleName) { moduleName_ = moduleName; }; uint32_t ScanIncrement(const std::string &output); @@ -42,7 +42,7 @@ private: const std::map> &resTypeOfDirs) const; // id, resource items - std::map> alls_; + std::map> items_; std::string moduleName_; }; } diff --git a/include/reference_parser.h b/include/reference_parser.h index 60e9e8f..b1c3b1e 100644 --- a/include/reference_parser.h +++ b/include/reference_parser.h @@ -27,7 +27,7 @@ public: ReferenceParser(); virtual ~ReferenceParser(); uint32_t ParseRefInSolidXml(const std::vector &solidXmlFolders) const; - uint32_t ParseRefInElement(std::map> &alls) const; + uint32_t ParseRefInElement(std::map> &items) const; uint32_t ParseRefInString(std::string &value, bool &update) const; uint32_t ParseRefInProfile(const std::string &output) const; uint32_t ParseRefInJson(const std::string &filePath) const; diff --git a/include/resource_util.h b/include/resource_util.h index f61e752..bbc9a24 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -116,7 +116,7 @@ public: static bool CopyFleInner(const std::string &src, const std::string &dst); /** - * @brief create directorys + * @brief create directories * @param filePath: directory path * @return true if success, other false */ diff --git a/src/file_manager.cpp b/src/file_manager.cpp index 5a14b0a..5f1795d 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -46,7 +46,7 @@ uint32_t FileManager::ScanModules(const vector &inputs, const string &ou uint32_t FileManager::ScanIncrement(const string &output) { auto &incrementManager = IncrementManager::GetInstance(); - alls_ = incrementManager.GetResourceItems(); + items_ = incrementManager.GetResourceItems(); vector sxmlFolders; FilterRefSolidXml(output, sxmlFolders, incrementManager.GetScanDirs()); return ParseReference(output, sxmlFolders); @@ -67,14 +67,14 @@ uint32_t FileManager::ScanModule(const string &input, const string &output, uint32_t FileManager::MergeResourceItem(const map> &resourceInfos) { - return ResourceModule::MergeResourceItem(alls_, resourceInfos); + return ResourceModule::MergeResourceItem(items_, resourceInfos); } uint32_t FileManager::ParseReference(const string &output, const vector &sxmlFolders) { ReferenceParser referenceParser; if (referenceParser.ParseRefInSolidXml(sxmlFolders) != RESTOOL_SUCCESS || - referenceParser.ParseRefInElement(alls_) != RESTOOL_SUCCESS || + referenceParser.ParseRefInElement(items_) != RESTOOL_SUCCESS || referenceParser.ParseRefInProfile(output) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } diff --git a/src/reference_parser.cpp b/src/reference_parser.cpp index 7467382..c799eec 100644 --- a/src/reference_parser.cpp +++ b/src/reference_parser.cpp @@ -87,9 +87,9 @@ uint32_t ReferenceParser::ParseRefInSolidXml(const vector &solidXmlFolde return RESTOOL_SUCCESS; } -uint32_t ReferenceParser::ParseRefInElement(map> &alls) const +uint32_t ReferenceParser::ParseRefInElement(map> &items) const { - for (auto &iter : alls) { + for (auto &iter : items) { for (auto &resourceItem : iter.second) { if (IsNotElement(resourceItem.GetResType())) { break; diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 3fcc3fc..deb0815 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -75,7 +75,7 @@ bool ResourceUtil::OpenJsonFile(const string &path, Json::Value &root) { ifstream ifs(path, ios::binary); if (!ifs) { - cerr << "Error: open json faild '" << path << "'" << endl; + cerr << "Error: open json failed '" << path << "'" << endl; return false; } diff --git a/src/restool.cpp b/src/restool.cpp index 135ed98..85e780d 100644 --- a/src/restool.cpp +++ b/src/restool.cpp @@ -33,6 +33,10 @@ uint32_t PackCmdHandle(PackageParser &packageParser) int main(int argc, char *argv[]) { + if (argv == nullptr) { + cerr << "Error: argv null" << endl; + return RESTOOL_ERROR; + } auto &parser = CmdParser::GetInstance(); if (parser.Parse(argc, argv) != RESTOOL_SUCCESS) { parser.ShowUseage(); diff --git a/src/xml/solid_xml.cpp b/src/xml/solid_xml.cpp index c1fbee7..bd7f9f6 100644 --- a/src/xml/solid_xml.cpp +++ b/src/xml/solid_xml.cpp @@ -43,9 +43,14 @@ bool SolidXml::GenerateSolidXml(const string &filePath) return false; } + xmlNodePtr rootNode = xmlDocGetRootElement(doc); + if (rootNode == nullptr) { + xmlFreeDoc(doc); + return false; + } auto root = make_shared(); nodes_.push_back(root); - Compile(xmlDocGetRootElement(doc), root); + Compile(rootNode, root); xmlFreeDoc(doc); return SaveToFile(filePath); } From be4ae32b08628f1dde607de97423db9eb48d49ae Mon Sep 17 00:00:00 2001 From: chencheng31 Date: Sat, 26 Mar 2022 16:23:42 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9LICENSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chencheng31 --- LICENSE | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/LICENSE b/LICENSE index 261eeb9..4947287 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -173,29 +174,4 @@ incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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 - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + END OF TERMS AND CONDITIONS \ No newline at end of file From 471fc07eae68d730792909cb4454d3f1c077daed Mon Sep 17 00:00:00 2001 From: chencheng31 Date: Tue, 19 Apr 2022 14:34:56 +0800 Subject: [PATCH 3/6] =?UTF-8?q?1,=20=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=97=A5=E5=BF=97=202=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E5=BC=95=E7=94=A8=E7=B3=BB=E7=BB=9F=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=203=EF=BC=8C=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=ADstartWindowIcon,startWindowBackground,resourc?= =?UTF-8?q?e,extra=20=E6=A0=87=E7=AD=BE=E8=B5=84=E6=BA=90=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E6=9B=BF=E6=8D=A2=E6=88=90=E8=B5=84=E6=BA=90ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chencheng31 --- include/resource_data.h | 2 +- src/config_parser.cpp | 6 +++++- src/file_entry.cpp | 3 +-- src/i_resource_compiler.cpp | 1 - src/json_compiler.cpp | 14 +++++++------- src/resource_util.cpp | 1 + 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/resource_data.h b/include/resource_data.h index 7487426..92c3fee 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -32,7 +32,7 @@ const static std::string ID_DEFINED_FILE = "id_defined.json"; const static std::string RESOURCE_INDEX_FILE = "resources.index"; const static std::string SEPARATOR = "/"; const static int32_t VERSION_MAX_LEN = 128; -static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 2.007" }; +static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 2.008" }; const static int32_t TAG_LEN = 4; enum class KeyType { diff --git a/src/config_parser.cpp b/src/config_parser.cpp index b5a825c..5879e98 100644 --- a/src/config_parser.cpp +++ b/src/config_parser.cpp @@ -34,7 +34,11 @@ const map ConfigParser::JSON_STRING_IDS = { { "label", "^\\$string:" }, { "description", "^\\$string:" }, { "theme", "^\\$theme:" }, - { "reason", "^\\$string:" } + { "reason", "^\\$string:" }, + { "startWindowIcon", "^\\$media:" }, + { "startWindowBackground", "^\\$color:"}, + { "resource", "^\\$[a-z]+:" }, + { "extra", "^\\$[a-z]+:" } }; const map ConfigParser::JSON_ARRAY_IDS = { diff --git a/src/file_entry.cpp b/src/file_entry.cpp index e51c3e1..e74ae67 100644 --- a/src/file_entry.cpp +++ b/src/file_entry.cpp @@ -65,7 +65,6 @@ const vector> FileEntry::GetChilds() const filePath = filePath_.GetPath() + SEPARATE + filename; unique_ptr f = make_unique(filePath); - cout << filePath << endl; f->Init(); children.push_back(move(f)); } @@ -223,7 +222,7 @@ bool FileEntry::CreateDirsInner(const string &path, string::size_type offset) string::size_type pos = path.find_first_of(SEPARATE.front(), offset); if (pos == string::npos) { #if _WIN32 - return mkdir(path.c_str()); + return mkdir(path.c_str()) == 0; #else return mkdir(path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0; #endif diff --git a/src/i_resource_compiler.cpp b/src/i_resource_compiler.cpp index 0b3e53d..b3c598c 100644 --- a/src/i_resource_compiler.cpp +++ b/src/i_resource_compiler.cpp @@ -68,7 +68,6 @@ uint32_t IResourceCompiler::Compile(const vector &directoryInfos) return a.filePath < b.filePath; }); for (const auto &fileInfo : fileInfos) { - cout << "compile " << fileInfo.filePath << endl; if (CompileSingleFile(fileInfo) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } diff --git a/src/json_compiler.cpp b/src/json_compiler.cpp index 023893b..9015f22 100644 --- a/src/json_compiler.cpp +++ b/src/json_compiler.cpp @@ -169,7 +169,7 @@ bool JsonCompiler::HandleBoolean(const Json::Value &objectNode, ResourceItem &re { Json::Value valueNode = objectNode[TAG_VALUE]; if (valueNode.isString()) { - regex ref("^\\$boolean:.*"); + regex ref("^\\$(ohos:)?boolean:.*"); if (!regex_match(valueNode.asString(), ref)) { cerr << "Error: '" << valueNode.asString() << "' only refer '$boolean:xxx',"; cerr << resourceItem.GetFilePath() << endl; @@ -290,17 +290,17 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso } const map REFS = { - { ResType::STRING, "$string:" }, - { ResType::STRARRAY, "$string:" }, - { ResType::COLOR, "$color:" }, - { ResType::FLOAT, "$float:" } + { ResType::STRING, "\\$(ohos:)?string:" }, + { ResType::STRARRAY, "\\$(ohos:)?string:" }, + { ResType::COLOR, "\\$(ohos:)?color:" }, + { ResType::FLOAT, "\\$(ohos:)?float:" } }; string value = valueNode.asString(); ResType type = resourceItem.GetResType(); regex ref("^\\$.+:"); smatch result; - if (regex_search(value, result, ref) && result[0] != REFS.at(type)) { + if (regex_search(value, result, ref) && !regex_match(result[0].str(), regex(REFS.at(type)))) { cerr << "Error: '" << value << "' only refer '"<< REFS.at(type) << "xxx',"; cerr << resourceItem.GetFilePath() << endl; return false; @@ -311,7 +311,7 @@ bool JsonCompiler::CheckJsonStringValue(const Json::Value &valueNode, const Reso bool JsonCompiler::CheckJsonIntegerValue(const Json::Value &valueNode, const ResourceItem &resourceItem) const { if (valueNode.isString()) { - regex ref("^\\$integer:.*"); + regex ref("^\\$(ohos:)?integer:.*"); if (!regex_match(valueNode.asString(), ref)) { cerr << "Error: '" << valueNode.asString() << "' only refer '$integer:xxx',"; cerr << resourceItem.GetFilePath() << endl; diff --git a/src/resource_util.cpp b/src/resource_util.cpp index deb0815..f47c1db 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -236,6 +236,7 @@ bool ResourceUtil::CreateDirs(const string &filePath) if (!FileEntry::CreateDirs(filePath)) { cerr << "Error: create dir fail '" << filePath << "'" << endl; + return false; } return true; } From 89f75a66cfba3f580b08e233df211d52e4f2e681 Mon Sep 17 00:00:00 2001 From: chencheng31 Date: Thu, 21 Apr 2022 11:46:45 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=94=AF=E6=8C=81mac=20os=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=BC=96=E8=AF=91libxml2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chencheng31 --- build/libxml2/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/libxml2/BUILD.gn b/build/libxml2/BUILD.gn index 90e4139..0e76d16 100644 --- a/build/libxml2/BUILD.gn +++ b/build/libxml2/BUILD.gn @@ -19,8 +19,8 @@ config("restool_libxml2_config") { include_dirs += [ "//developtools/global_resource_tool/build/libxml2/win32/include" ] defines = [ "LIBXML_STATIC" ] - } else { - include_dirs += [ "${LIBXML_PATH}/config" ] + } else if (is_mac) { + defines = [ "LIBXML_THREAD_ENABLED" ] } include_dirs += [ "${LIBXML_PATH}/include" ] From 7364e8ca4867f172ba97c2c4f0a75acd9c2b8c15 Mon Sep 17 00:00:00 2001 From: chencheng31 Date: Thu, 21 Apr 2022 14:58:45 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=A4=9A=E7=BA=A7=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=8C=85=E5=90=AB=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chencheng31 --- src/file_entry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_entry.cpp b/src/file_entry.cpp index e74ae67..78aa8cc 100644 --- a/src/file_entry.cpp +++ b/src/file_entry.cpp @@ -228,7 +228,7 @@ bool FileEntry::CreateDirsInner(const string &path, string::size_type offset) #endif } - string subPath = path.substr(0, pos); + string subPath = path.substr(0, pos + 1); if (!Exist(subPath)) { #if _WIN32 if (mkdir(subPath.c_str()) != 0) { From 2603ce3652998412b193b283926ea9be551dc551 Mon Sep 17 00:00:00 2001 From: chencheng31 Date: Mon, 9 May 2022 14:12:30 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8C=89=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=90=8D=E8=87=AA=E5=8A=A8=E5=88=86=E9=85=8D=E8=B5=84?= =?UTF-8?q?=E6=BA=90ID=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chencheng31 --- src/resource_pack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resource_pack.cpp b/src/resource_pack.cpp index 77bc355..6cf0cbf 100644 --- a/src/resource_pack.cpp +++ b/src/resource_pack.cpp @@ -123,7 +123,7 @@ uint32_t ResourcePack::InitModule() } int32_t startId = ((it - moduleNames.begin()) + 1) * 0x01000000; - if (startId == 0x07000000) { + if (startId >= 0x07000000) { startId = startId + 0x01000000; } return idWorker.Init(hapType, startId);