From 9e543703479b030ea33195768f5afcc62963c8a4 Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Fri, 4 Aug 2023 01:43:49 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4libxml2=E5=92=8Csqlites?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangyunzhong --- BUILD.gn | 19 +- CMakeLists.txt | 28 +- build/bounds_checking_function/BUILD.gn | 35 -- build/bounds_checking_function/CMakeLists.txt | 2 - build/jsoncpp/BUILD.gn | 28 -- build/jsoncpp/CMakeLists.txt | 3 - build/libxml2/CMakeLists.txt | 367 ----------------- build/sqlite3/BUILD.gn | 22 - build/sqlite3/CMakeLists.txt | 7 - bundle.json | 2 - include/cmd_parser.h | 17 +- include/file_manager.h | 9 +- include/i_resource_compiler.h | 13 +- include/increment_index.h | 48 --- include/increment_list.h | 58 --- include/increment_manager.h | 87 ---- include/module_combine.h | 40 -- include/preview_manager.h | 42 -- include/reference_parser.h | 1 - include/resource_data.h | 8 +- include/resource_module.h | 6 +- include/resource_module_inc.h | 38 -- include/resource_util.h | 7 - include/solid_xml.h | 117 ------ include/solid_xml_compiler.h | 38 -- include/sqlite_database.h | 50 --- include/xml_converter.h | 42 -- include/xml_key_node.h | 53 --- src/cmd_parser.cpp | 35 +- src/factory_resource_compiler.cpp | 3 - src/file_manager.cpp | 48 +-- src/generic_compiler.cpp | 26 +- src/i_resource_compiler.cpp | 90 ---- src/increment_index.cpp | 231 ----------- src/increment_list.cpp | 160 -------- src/increment_manager.cpp | 284 ------------- src/module_combine.cpp | 123 ------ src/preview_manager.cpp | 101 ----- src/reference_parser.cpp | 32 +- src/resource_module.cpp | 12 +- src/resource_module_inc.cpp | 86 ---- src/resource_pack.cpp | 33 +- src/resource_util.cpp | 12 +- src/solid_xml_compiler.cpp | 121 ------ src/sqlite_database.cpp | 201 --------- src/xml/key_manager.cpp | 58 --- src/xml/solid_xml.cpp | 386 ------------------ src/xml/xml_converter.cpp | 61 --- src/xml/xml_key_node.cpp | 116 ------ 49 files changed, 41 insertions(+), 3365 deletions(-) delete mode 100644 build/bounds_checking_function/BUILD.gn delete mode 100644 build/bounds_checking_function/CMakeLists.txt delete mode 100644 build/jsoncpp/BUILD.gn delete mode 100644 build/jsoncpp/CMakeLists.txt delete mode 100644 build/libxml2/CMakeLists.txt delete mode 100644 build/sqlite3/BUILD.gn delete mode 100644 build/sqlite3/CMakeLists.txt delete mode 100644 include/increment_index.h delete mode 100644 include/increment_list.h delete mode 100644 include/increment_manager.h delete mode 100644 include/module_combine.h delete mode 100644 include/preview_manager.h delete mode 100644 include/resource_module_inc.h delete mode 100644 include/solid_xml.h delete mode 100644 include/solid_xml_compiler.h delete mode 100644 include/sqlite_database.h delete mode 100644 include/xml_converter.h delete mode 100644 include/xml_key_node.h delete mode 100644 src/increment_index.cpp delete mode 100644 src/increment_list.cpp delete mode 100644 src/increment_manager.cpp delete mode 100644 src/module_combine.cpp delete mode 100644 src/preview_manager.cpp delete mode 100644 src/resource_module_inc.cpp delete mode 100644 src/solid_xml_compiler.cpp delete mode 100644 src/sqlite_database.cpp delete mode 100644 src/xml/key_manager.cpp delete mode 100644 src/xml/solid_xml.cpp delete mode 100644 src/xml/xml_converter.cpp delete mode 100644 src/xml/xml_key_node.cpp diff --git a/BUILD.gn b/BUILD.gn index fd4c2e5..44c75a8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -28,13 +28,8 @@ ohos_executable("restool") { "src/header.cpp", "src/i_resource_compiler.cpp", "src/id_worker.cpp", - "src/increment_index.cpp", - "src/increment_list.cpp", - "src/increment_manager.cpp", "src/json_compiler.cpp", "src/key_parser.cpp", - "src/module_combine.cpp", - "src/preview_manager.cpp", "src/reference_parser.cpp", "src/resource_append.cpp", "src/resource_check.cpp", @@ -42,33 +37,23 @@ ohos_executable("restool") { "src/resource_item.cpp", "src/resource_merge.cpp", "src/resource_module.cpp", - "src/resource_module_inc.cpp", "src/resource_pack.cpp", "src/resource_table.cpp", "src/resource_util.cpp", "src/restool.cpp", - "src/solid_xml_compiler.cpp", - "src/sqlite_database.cpp", "src/task_handle.cpp", - "src/xml/key_manager.cpp", - "src/xml/solid_xml.cpp", - "src/xml/xml_converter.cpp", - "src/xml/xml_key_node.cpp", ] include_dirs = [ "include", "//third_party/jsoncpp/include", - "//third_party/sqlite/include", "//third_party/bounds_checking_function/include", ] deps = [ - "build/bounds_checking_function:restool_bounds_checking_function", - "build/jsoncpp:restool_jsoncpp", - "build/sqlite3:restool_sqlite", + "//third_party/bounds_checking_function:libsec_static", + "//third_party/jsoncpp:jsoncpp_static", "//third_party/libpng:libpng_static", - "//third_party/libxml2:static_libxml2", ] cflags = [ "-std=c++17" ] diff --git a/CMakeLists.txt b/CMakeLists.txt index f32cef8..a1a1f31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,22 +16,28 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fstack-protector") endif() set(jsoncpp_dir ${CMAKE_SOURCE_DIR}/../../third_party/jsoncpp) +set(png_dir ${CMAKE_SOURCE_DIR}/../../third_party/libpng) +set(zlib_dir ${CMAKE_SOURCE_DIR}/../../third_party/zlib) set(bound_checking_function_dir ${CMAKE_SOURCE_DIR}/../../third_party/bounds_checking_function) -set(libxml2_dir ${CMAKE_SOURCE_DIR}/../../third_party/libxml2) -set(sqlite3_dir ${CMAKE_SOURCE_DIR}/../../third_party/sqlite) + include_directories(include) include_directories(${jsoncpp_dir}/include) +include_directories(${png_dir}/) include_directories(${bound_checking_function_dir}/include) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/build/libxml2/include) -include_directories(${sqlite3_dir}/include) aux_source_directory(src restool_source) -aux_source_directory(src/xml restool_source) + +aux_source_directory(${bound_checking_function_dir}/src lib_sec_source) +add_library(securec STATIC ${lib_sec_source}) + +aux_source_directory(${jsoncpp_dir}/src/lib_json json_source) +add_library(jsoncpp STATIC ${json_source}) + +aux_source_directory(${zlib_dir}/ zlib_source) +add_library(zlib STATIC ${zlib_source}) + +aux_source_directory(${png_dir}/ png_source) +add_library(png STATIC ${png_source}) add_executable(restool ${restool_source}) -target_link_libraries(restool myxml2 jsoncpp securec sqlite3) - -add_subdirectory(build/libxml2) -add_subdirectory(build/jsoncpp) -add_subdirectory(build/bounds_checking_function) -add_subdirectory(build/sqlite3) +target_link_libraries(restool jsoncpp securec zlib png) \ No newline at end of file diff --git a/build/bounds_checking_function/BUILD.gn b/build/bounds_checking_function/BUILD.gn deleted file mode 100644 index 34776ae..0000000 --- a/build/bounds_checking_function/BUILD.gn +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 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 -# -# 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. - -import("//build/ohos.gni") -import("//third_party/bounds_checking_function/libsec_src.gni") -ohos_static_library("restool_bounds_checking_function") { - sources = libsec_sources - - include_dirs = [ "//third_party/bounds_checking_function/include" ] - - cflags_cc = [ "-std=c++17" ] - cflags_c = [ - "-Wno-attributes", - "-Wno-inconsistent-dllimport", - "-D_INC_STRING_S", - "-D_INC_WCHAR_S", - "-D_SECIMP=//", - "-D_STDIO_S_DEFINED", - "-D_INC_STDIO_S", - "-D_INC_STDLIB_S", - "-D_INC_MEMORY_S", - ] - subsystem_name = "developtools" - part_name = "global_resource_tool" -} diff --git a/build/bounds_checking_function/CMakeLists.txt b/build/bounds_checking_function/CMakeLists.txt deleted file mode 100644 index f588c41..0000000 --- a/build/bounds_checking_function/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -aux_source_directory(${bound_checking_function_dir}/src lib_sec_source) -add_library(securec STATIC ${lib_sec_source}) \ No newline at end of file diff --git a/build/jsoncpp/BUILD.gn b/build/jsoncpp/BUILD.gn deleted file mode 100644 index f5c7d76..0000000 --- a/build/jsoncpp/BUILD.gn +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 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 -# -# 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. - -import("//build/ohos.gni") -ohos_static_library("restool_jsoncpp") { - sources = [ - "//third_party/jsoncpp/src/lib_json/json_reader.cpp", - "//third_party/jsoncpp/src/lib_json/json_value.cpp", - "//third_party/jsoncpp/src/lib_json/json_writer.cpp", - ] - - include_dirs = [ "//third_party/jsoncpp/include" ] - - cflags = [ "-std=c++17" ] - use_exceptions = true - subsystem_name = "developtools" - part_name = "global_resource_tool" -} diff --git a/build/jsoncpp/CMakeLists.txt b/build/jsoncpp/CMakeLists.txt deleted file mode 100644 index 3017644..0000000 --- a/build/jsoncpp/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -aux_source_directory(${jsoncpp_dir}/src/lib_json json_source) - -add_library(jsoncpp STATIC ${json_source}) \ No newline at end of file diff --git a/build/libxml2/CMakeLists.txt b/build/libxml2/CMakeLists.txt deleted file mode 100644 index 6f3b819..0000000 --- a/build/libxml2/CMakeLists.txt +++ /dev/null @@ -1,367 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(myxml2 LANGUAGES C) -#include(CheckCSourceCompiles) -#include(CheckIncludeFiles) -#include(CheckStructHasMember) -#include(CheckFunctionExists) -#include(CheckLibraryExists) -#include(CheckSymbolExists) - -include(CheckCSourceCompiles) -include(CheckFunctionExists) -include(CheckIncludeFiles) -include(CheckIncludeFile) -include(CheckLibraryExists) -include(CheckStructHasMember) -include(CheckSymbolExists) -include(CMakePackageConfigHelpers) -include(GNUInstallDirs) - -option(BUILD_SHARED_LIBS "Build shared libraries" OFF) -set(LIBXML2_WITH_AUTOMATA ON) -option(LIBXML2_WITH_C14N "Add the Canonicalization support" ON) -option(LIBXML2_WITH_CATALOG "Add the Catalog support" ON) -option(LIBXML2_WITH_DEBUG "Add the debugging module" ON) -option(LIBXML2_WITH_DOCB "Add Docbook SGML support" ON) -set(LIBXML2_WITH_EXPR ON) -option(LIBXML2_WITH_FTP "Add the FTP support" ON) -option(LIBXML2_WITH_HTML "Add the HTML support" ON) -option(LIBXML2_WITH_HTTP "Add the HTTP support" ON) -option(LIBXML2_WITH_ICONV "Add ICONV support" OFF) -option(LIBXML2_WITH_ICU "Add ICU support" OFF) -option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON) -option(LIBXML2_WITH_LEGACY "Add deprecated APIs for compatibility" ON) -option(LIBXML2_WITH_LZMA "Use liblzma" OFF) -option(LIBXML2_WITH_MEM_DEBUG "Add the memory debugging module" OFF) -option(LIBXML2_WITH_MODULES "Add the dynamic modules support" ON) -option(LIBXML2_WITH_OUTPUT "Add the serialization support" ON) -option(LIBXML2_WITH_PATTERN "Add the xmlPattern selection interface" ON) -option(LIBXML2_WITH_PROGRAMS "Build programs" ON) -option(LIBXML2_WITH_PUSH "Add the PUSH parser interfaces" ON) -option(LIBXML2_WITH_PYTHON "Build Python bindings" OFF) -option(LIBXML2_WITH_READER "Add the xmlReader parsing interface" ON) -option(LIBXML2_WITH_REGEXPS "Add Regular Expressions support" ON) -option(LIBXML2_WITH_RUN_DEBUG "Add the runtime debugging module" OFF) -option(LIBXML2_WITH_SAX1 "Add the older SAX1 interface" ON) -option(LIBXML2_WITH_SCHEMAS "Add Relax-NG and Schemas support" ON) -option(LIBXML2_WITH_SCHEMATRON "Add Schematron support" ON) -option(LIBXML2_WITH_THREADS "Add multithread support" ON) -option(LIBXML2_WITH_THREAD_ALLOC "Add per-thread memory" OFF) -option(LIBXML2_WITH_TREE "Add the DOM like tree manipulation APIs" ON) -set(LIBXML2_WITH_TRIO OFF) -set(LIBXML2_WITH_UNICODE ON) -option(LIBXML2_WITH_VALID "Add the DTD validation support" ON) -option(LIBXML2_WITH_WRITER "Add the xmlWriter saving interface" ON) -option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON) -option(LIBXML2_WITH_XPATH "Add the XPATH support" ON) -option(LIBXML2_WITH_XPTR "Add the XPointer support" ON) -option(LIBXML2_WITH_ZLIB "Use libz" OFF) - -set(LIBXML_MAJOR_VERSION 2) -set(LIBXML_MINOR_VERSION 9) -set(LIBXML_MICRO_VERSION 10) - -set(VERSION "${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}.${LIBXML_MICRO_VERSION}") -set(LIBXML_VERSION ${LIBXML_MAJOR_VERSION}0${LIBXML_MINOR_VERSION}0${LIBXML_MICRO_VERSION}) -set(LIBXML_VERSION_STRING "${LIBXML_VERSION}") -set(LIBXML_VERSION_EXTRA "") -set(LIBXML_VERSION_NUMBER ${LIBXML_VERSION}) - -foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_DOCB WITH_EXPR WITH_FTP WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_SAX1 WITH_LEGACY WITH_LZMA WITH_MEM_DEBUG WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_RUN_DEBUG WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_TREE WITH_TRIO WITH_UNICODE WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_ZLIB) - if (LIBXML2_${VARIABLE}) - set(${VARIABLE} 1) - else() - set(${VARIABLE} 0) - endif() -endforeach() - -check_c_source_compiles(" - void __attribute__((destructor)) - f(void) {} - int main(void) { return 0; } - " ATTRIBUTE_DESTRUCTOR) -check_c_source_compiles(" - #include - int main() { (void) gethostbyname((const char*) \"\"); return 0; } - " GETHOSTBYNAME_ARG_CAST_CONST) -if(NOT GETHOSTBYNAME_ARG_CAST_CONST) - set(GETHOSTBYNAME_ARG_CAST "(char *)") -else() - set(GETHOSTBYNAME_ARG_CAST "/**/") -endif() -CHECK_INCLUDE_FILE(arpa/inet.h HAVE_ARPA_INET_H) -check_include_files(arpa/nameser.h HAVE_ARPA_NAMESER_H) -check_struct_has_member("struct sockaddr_storage" ss_family "sys/socket.h;sys/types.h" HAVE_SS_FAMILY) -check_struct_has_member("struct sockaddr_storage" __ss_family "sys/socket.h;sys/types.h" HAVE_BROKEN_SS_FAMILY) -if(HAVE_BROKEN_SS_FAMILY) - set(ss_family __ss_family) -endif() -check_function_exists(class HAVE_CLASS) -check_include_files(ctype.h HAVE_CTYPE_H) -check_include_files(dirent.h HAVE_DIRENT_H) -check_include_files(dlfcn.h HAVE_DLFCN_H) -check_library_exists(dl dlopen "" HAVE_DLOPEN) -check_include_files(dl.h HAVE_DL_H) -check_include_files(errno.h HAVE_ERRNO_H) -check_include_files(fcntl.h HAVE_FCNTL_H) -check_function_exists(finite HAVE_FINITE) -check_include_files(float.h HAVE_FLOAT_H) -check_function_exists(fpclass HAVE_FPCLASS) -check_function_exists(fprintf HAVE_FPRINTF) -check_function_exists(fp_class HAVE_FP_CLASS) -check_function_exists(ftime HAVE_FTIME) -check_function_exists(getaddrinfo HAVE_GETADDRINFO) -check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) -check_include_files(inttypes.h HAVE_INTTYPES_H) -check_function_exists(isascii HAVE_ISASCII) -check_function_exists(isinf HAVE_ISINF) -check_function_exists(isnan HAVE_ISNAN) -check_function_exists(isnand HAVE_ISNAND) -check_library_exists(history append_history "" HAVE_LIBHISTORY) -check_library_exists(lzma lzma_code "" HAVE_LIBLZMA) -check_library_exists(pthread pthread_join "" HAVE_LIBPTHREAD) -check_library_exists(readline readline "" HAVE_LIBREADLINE) -check_library_exists(z gzread "" HAVE_LIBZ) -check_include_files(limits.h HAVE_LIMITS_H) -check_function_exists(localtime HAVE_LOCALTIME) -check_include_files(lzma.h HAVE_LZMA_H) -check_include_files(malloc.h HAVE_MALLOC_H) -check_include_files(math.h HAVE_MATH_H) -check_include_files(memory.h HAVE_MEMORY_H) -check_function_exists(mmap HAVE_MMAP) -check_function_exists(munmap HAVE_MUNMAP) -check_symbol_exists(DIR ndir.h HAVE_NDIR_H) -check_include_files(netdb.h HAVE_NETDB_H) -check_include_files(netinet/in.h HAVE_NETINET_IN_H) -check_include_files(poll.h HAVE_POLL_H) -check_function_exists(printf HAVE_PRINTF) -check_include_files(pthread.h HAVE_PTHREAD_H) -check_function_exists(putenv HAVE_PUTENV) -check_function_exists(rand HAVE_RAND) -check_function_exists(rand_r HAVE_RAND_R) -check_include_files(resolv.h HAVE_RESOLV_H) -check_library_exists(dld shl_load "" HAVE_SHLLOAD) -check_function_exists(signal HAVE_SIGNAL) -check_include_files(signal.h HAVE_SIGNAL_H) -check_function_exists(snprintf HAVE_SNPRINTF) -check_function_exists(sprintf HAVE_SPRINTF) -check_function_exists(srand HAVE_SRAND) -check_function_exists(sscanf HAVE_SSCANF) -check_function_exists(stat HAVE_STAT) -check_include_files(stdarg.h HAVE_STDARG_H) -check_include_files(stdint.h HAVE_STDINT_H) -check_include_files(stdlib.h HAVE_STDLIB_H) -check_function_exists(strftime HAVE_STRFTIME) -check_include_files(strings.h HAVE_STRINGS_H) -check_include_files(string.h HAVE_STRING_H) -check_symbol_exists(DIR sys/dir.h HAVE_SYS_DIR_H) -check_include_files(sys/mman.h HAVE_SYS_MMAN_H) -check_symbol_exists(DIR sys/ndir.h HAVE_SYS_NDIR_H) -check_include_files(sys/select.h HAVE_SYS_SELECT_H) -check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) -check_include_files(sys/stat.h HAVE_SYS_STAT_H) -check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H) -check_include_files(sys/time.h HAVE_SYS_TIME_H) -check_include_files(sys/types.h HAVE_SYS_TYPES_H) -check_function_exists(time HAVE_TIME) -check_include_files(time.h HAVE_TIME_H) -check_include_files(unistd.h HAVE_UNISTD_H) -check_function_exists(va_copy HAVE_VA_COPY) -check_function_exists(vfprintf HAVE_VFPRINTF) -check_function_exists(vsnprintf HAVE_VSNPRINTF) -check_function_exists(vsprintf HAVE_VSPRINTF) -check_function_exists(__va_copy HAVE___VA_COPY) -check_c_source_compiles(" - #include - #include - extern - #ifdef __cplusplus - \"C\" - #endif - #if defined(__STDC__) || defined(__cplusplus) - size_t iconv(iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft); - #else - size_t iconv(); - #endif - int main() { return 0; } -" ICONV_CONST_TEST) -if(NOT ICONV_CONST_TEST) - set(ICONV_CONST "const") -endif() -set(LT_OBJDIR ".libs/") -check_c_source_compiles(" - #include - #include - int main() { (void) send(1, (const char*) \"\", 1, 1); return 0; } -" SEND_ARG2_CAST_CONST) -if(NOT SEND_ARG2_CAST_CONST) - set(SEND_ARG2_CAST "(char *)") -else() - set(SEND_ARG2_CAST "/**/") -endif() -check_include_files("float.h;stdarg.h;stdlib.h;string.h" STDC_HEADERS) -check_c_source_compiles(" - #include - void a(va_list* ap) {}; - int main() { va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1; return 0; } -" VA_LIST_IS_ARRAY_TEST) -if(VA_LIST_IS_ARRAY_TEST) - set(VA_LIST_IS_ARRAY FALSE) -else() - set(VA_LIST_IS_ARRAY TRUE) -endif() -check_c_source_compiles(" - #include - #include - #include - int main() { (void) getsockopt(1, 1, 1, NULL, (socklen_t*) NULL); return 0; } -" XML_SOCKLEN_T_SOCKLEN_T) -if(XML_SOCKLEN_T_SOCKLEN_T) - set(XML_SOCKLEN_T socklen_t) -else() - check_c_source_compiles(" - #include - #include - #include - int main() { (void) getsockopt(1, 1, 1, NULL, (size_t*) NULL); return 0; } - " XML_SOCKLEN_T_SIZE_T) - if(XML_SOCKLEN_T_SIZE_T) - set(XML_SOCKLEN_T size_t) - else() - check_c_source_compiles(" - #include - #include - #include - int main() { (void) getsockopt (1, 1, 1, NULL, (int*) NULL); return 0; } - " XML_SOCKLEN_T_INT) - set(XML_SOCKLEN_T int) - endif() -endif() - - -file(COPY ${libxml2_dir} DESTINATION ./) -set(libxml2_original ${CMAKE_CURRENT_BINARY_DIR}/libxml2) -include_directories(${libxml2_original}/include) -set(third_party_libxml2 ${CMAKE_CURRENT_BINARY_DIR}/../../../../third_party/libxml2) -configure_file(${third_party_libxml2}/config.h.cmake.in ${third_party_libxml2}/include/config.h) -set(libxml2_original_header - ${libxml2_original}/include/libxml/c14n.h - ${libxml2_original}/include/libxml/catalog.h - ${libxml2_original}/include/libxml/chvalid.h - ${libxml2_original}/include/libxml/debugXML.h - ${libxml2_original}/include/libxml/dict.h - ${libxml2_original}/include/libxml/DOCBparser.h - ${libxml2_original}/include/libxml/encoding.h - ${libxml2_original}/include/libxml/entities.h - ${libxml2_original}/include/libxml/globals.h - ${libxml2_original}/include/libxml/hash.h - ${libxml2_original}/include/libxml/HTMLparser.h - ${libxml2_original}/include/libxml/HTMLtree.h - ${libxml2_original}/include/libxml/list.h - ${libxml2_original}/include/libxml/nanoftp.h - ${libxml2_original}/include/libxml/nanohttp.h - ${libxml2_original}/include/libxml/parser.h - ${libxml2_original}/include/libxml/parserInternals.h - ${libxml2_original}/include/libxml/pattern.h - ${libxml2_original}/include/libxml/relaxng.h - ${libxml2_original}/include/libxml/SAX.h - ${libxml2_original}/include/libxml/SAX2.h - ${libxml2_original}/include/libxml/schemasInternals.h - ${libxml2_original}/include/libxml/schematron.h - ${libxml2_original}/include/libxml/threads.h - ${libxml2_original}/include/libxml/tree.h - ${libxml2_original}/include/libxml/uri.h - ${libxml2_original}/include/libxml/valid.h - ${libxml2_original}/include/libxml/xinclude.h - ${libxml2_original}/include/libxml/xlink.h - ${libxml2_original}/include/libxml/xmlIO.h - ${libxml2_original}/include/libxml/xmlautomata.h - ${libxml2_original}/include/libxml/xmlerror.h - ${libxml2_original}/include/libxml/xmlexports.h - ${libxml2_original}/include/libxml/xmlmemory.h - ${libxml2_original}/include/libxml/xmlmodule.h - ${libxml2_original}/include/libxml/xmlreader.h - ${libxml2_original}/include/libxml/xmlregexp.h - ${libxml2_original}/include/libxml/xmlsave.h - ${libxml2_original}/include/libxml/xmlschemas.h - ${libxml2_original}/include/libxml/xmlschemastypes.h - ${libxml2_original}/include/libxml/xmlstring.h - ${libxml2_original}/include/libxml/xmlunicode.h - ${libxml2_original}/include/libxml/xmlwriter.h - ${libxml2_original}/include/libxml/xpath.h - ${libxml2_original}/include/libxml/xpathInternals.h - ${libxml2_original}/include/libxml/xpointer.h - ${libxml2_original}/include/wsockcompat.h -) - -set(libxml2_original_other_header - ${libxml2_original}/buf.h - ${libxml2_original}/elfgcchack.h - ${libxml2_original}/enc.h - ${libxml2_original}/libxml.h - ${libxml2_original}/save.h - ${libxml2_original}/timsort.h -) - -set(libxml2_original_source - ${libxml2_original}/buf.c - ${libxml2_original}/c14n.c - ${libxml2_original}/catalog.c - ${libxml2_original}/chvalid.c - ${libxml2_original}/debugXML.c - ${libxml2_original}/dict.c - ${libxml2_original}/encoding.c - ${libxml2_original}/entities.c - ${libxml2_original}/error.c - ${libxml2_original}/globals.c - ${libxml2_original}/hash.c - ${libxml2_original}/HTMLparser.c - ${libxml2_original}/HTMLtree.c - ${libxml2_original}/legacy.c - ${libxml2_original}/list.c - ${libxml2_original}/nanoftp.c - ${libxml2_original}/nanohttp.c - ${libxml2_original}/parser.c - ${libxml2_original}/parserInternals.c - ${libxml2_original}/pattern.c - ${libxml2_original}/relaxng.c - ${libxml2_original}/SAX.c - ${libxml2_original}/SAX2.c - ${libxml2_original}/schematron.c - ${libxml2_original}/threads.c - ${libxml2_original}/tree.c - ${libxml2_original}/uri.c - ${libxml2_original}/valid.c - ${libxml2_original}/xinclude.c - ${libxml2_original}/xlink.c - ${libxml2_original}/xmlIO.c - ${libxml2_original}/xmlmemory.c - ${libxml2_original}/xmlmodule.c - ${libxml2_original}/xmlreader.c - ${libxml2_original}/xmlregexp.c - ${libxml2_original}/xmlsave.c - ${libxml2_original}/xmlschemas.c - ${libxml2_original}/xmlschemastypes.c - ${libxml2_original}/xmlstring.c - ${libxml2_original}/xmlunicode.c - ${libxml2_original}/xmlwriter.c - ${libxml2_original}/xpath.c - ${libxml2_original}/xpointer.c - ${libxml2_original}/xzlib.c -) - -#set(CMAKE_THREAD_LIBS_INIT "-lpthread") -#message("pthread " ${CMAKE_THREAD_LIBS_INIT}) -find_package(Threads REQUIRED) -add_library(myxml2 STATIC ${libxml2_original_header} ${libxml2_original_other_header} ${libxml2_original_source}) -target_link_libraries(myxml2 PRIVATE Threads::Threads) - -if(WIN32) - target_link_libraries(myxml2 PRIVATE ws2_32) - set(WIN32_EXTRA_LIBADD "-lws2_32") -endif() -configure_file(${libxml2_original}/include/libxml/xmlversion.h.in ${libxml2_original}/include/libxml/xmlversion.h) - -file(COPY ${libxml2_original_header} DESTINATION ./include/libxml) -file(COPY ${libxml2_original}/include/libxml/xmlversion.h DESTINATION ./include/libxml) \ No newline at end of file diff --git a/build/sqlite3/BUILD.gn b/build/sqlite3/BUILD.gn deleted file mode 100644 index a04db9e..0000000 --- a/build/sqlite3/BUILD.gn +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 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 -# -# 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. - -import("//build/ohos.gni") -ohos_static_library("restool_sqlite") { - sources = [ "//third_party/sqlite/src/sqlite3.c" ] - - include_dirs = [ "//third_party/sqlite/include" ] - - subsystem_name = "developtools" - part_name = "global_resource_tool" -} diff --git a/build/sqlite3/CMakeLists.txt b/build/sqlite3/CMakeLists.txt deleted file mode 100644 index 4cffbf2..0000000 --- a/build/sqlite3/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(sqlite3_source - ${sqlite3_dir}/src/sqlite3.c -) - -add_library(sqlite3 STATIC ${sqlite3_source}) -add_definitions(-DSQLITE_OMIT_LOAD_EXTENSION) -target_link_libraries(sqlite3 pthread m) \ No newline at end of file diff --git a/bundle.json b/bundle.json index 3c7139f..f1f8727 100644 --- a/bundle.json +++ b/bundle.json @@ -21,9 +21,7 @@ "components": [], "third_party": [ "bounds_checking_function", - "libxml2", "jsoncpp", - "sqlite", "libpng" ] }, diff --git a/include/cmd_parser.h b/include/cmd_parser.h index 61d729a..28069ac 100644 --- a/include/cmd_parser.h +++ b/include/cmd_parser.h @@ -16,10 +16,10 @@ #ifndef OHOS_RESTOOL_CMD_PARSER_H #define OHOS_RESTOOL_CMD_PARSER_H -#include -#include -#include -#include +#include +#include +#include +#include #include "singleton.h" #include "resource_data.h" #include "restool_errors.h" @@ -46,10 +46,7 @@ public: const std::string &GetConfig() const; const std::string &GetRestoolPath() const; int32_t GetStartId() const; - const std::string &GetCachePath() const; bool IsFileList() const; - bool GetPreviewMode() const; - int32_t GetPriority() const; const std::vector &GetAppend() const; bool GetCombine() const; const std::string &GetDependEntry() const; @@ -68,13 +65,10 @@ private: uint32_t AddMoudleNames(const std::string& argValue); uint32_t AddConfig(const std::string& argValue); uint32_t AddStartId(const std::string& argValue); - uint32_t AddCachePath(const std::string& argValue); void AdaptResourcesDirForInput(); uint32_t CheckParam() const; uint32_t HandleProcess(int c, const std::string& argValue); uint32_t ParseFileList(const std::string& fileListPath); - uint32_t SetPreviewMode(); - uint32_t SetPriority(const std::string& argValue); uint32_t AddAppend(const std::string& argValue); uint32_t SetCombine(); uint32_t AddDependEntry(const std::string& argValue); @@ -97,10 +91,7 @@ private: std::string configPath_; std::string restoolPath_; int32_t startId_ = 0; - std::string cachePath_; bool isFileList_ = false; - bool previewMode_ = false; - int32_t priority_ = -1; std::vector append_; bool combine_ = false; std::string dependEntry_; diff --git a/include/file_manager.h b/include/file_manager.h index 58f330e..1857581 100644 --- a/include/file_manager.h +++ b/include/file_manager.h @@ -16,10 +16,9 @@ #ifndef OHOS_RESTOOL_FILE_MANAGER_H #define OHOS_RESTOOL_FILE_MANAGER_H -#include +#include #include "resource_data.h" #include "resource_item.h" -#include "increment_manager.h" #include "singleton.h" namespace OHOS { @@ -36,16 +35,12 @@ public: { moduleName_ = moduleName; }; - uint32_t ScanIncrement(const std::string &output); uint32_t MergeResourceItem(const std::map> &resourceInfos); private: uint32_t ScanModule(const std::string &input, const std::string &output, std::map> &resTypeOfDirs); - uint32_t ParseReference(const std::string &output, const std::vector &sxmlFolders); - bool NeedParseReferenceInSolidXml(ResType resType) const; - void FilterRefSolidXml(const std::string &output, std::vector &outputPaths, - const std::map> &resTypeOfDirs) const; + uint32_t ParseReference(const std::string &output); // id, resource items std::map> items_; diff --git a/include/i_resource_compiler.h b/include/i_resource_compiler.h index 07425f9..4735820 100644 --- a/include/i_resource_compiler.h +++ b/include/i_resource_compiler.h @@ -16,8 +16,7 @@ #ifndef OHOS_RESTOOL_RESOURCE_COMPILER_H #define OHOS_RESTOOL_RESOURCE_COMPILER_H -#include -#include "increment_manager.h" +#include #include "resource_data.h" #include "resource_item.h" @@ -32,24 +31,16 @@ public: const std::map> &GetResult() const; uint32_t Compile(const FileInfo &fileInfo); void SetModuleName(const std::string &moduleName); - void SetPreviewMode(bool enable) - { - previewMode_ = enable; - }; uint32_t CompileForAppend(const FileInfo &fileInfo); const std::map, std::vector> &GetResourceItems() const; protected: virtual uint32_t CompileSingleFile(const FileInfo &fileInfo); bool MergeResourceItem(const ResourceItem &resourceItem); - bool IsXmlFile(const FileInfo &fileInfo) const; - bool HasConvertedToSolidXml(const FileInfo &fileInfo) const; - bool NeedIfConvertToSolidXml() const; std::string GetOutputFolder(const DirectoryInfo &directoryInfo) const; ResType type_; std::string output_; std::string moduleName_; - bool previewMode_ = false; // id, resource items std::map> resourceInfos_; @@ -57,9 +48,7 @@ protected: std::map, std::vector> nameInfos_; private: - uint32_t ConvertToSolidXml(const std::map> &setsByDirectory); uint32_t PostCommit(); - void ListXmlFile(const std::vector &fileInfo, std::vector &xmlPaths) const; }; } } diff --git a/include/increment_index.h b/include/increment_index.h deleted file mode 100644 index dfa4a60..0000000 --- a/include/increment_index.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_INCREMENT_INDEX_H -#define OHOS_RESTOOL_INCREMENT_INDEX_H - -#include "resource_item.h" -#include "resource_util.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class IncrementIndex { -public: - IncrementIndex(const std::string &indexPath, const std::vector &folder); - virtual ~IncrementIndex() {}; - bool Save(const std::map> &items) const; - bool Load(std::map> &items) const; - void SetSkipPaths(const std::vector &skipPaths); - - static const std::string INDEX_FILE; -private: - bool LoadIndex(const Json::Value &indexInfo, std::map> &items) const; - bool ParseResourceItem(const Json::Value &item, const std::string &filePath, ResourceItem &resourceItem) const; - bool GetResourceItemProp(const Json::Value &item, const std::string &key, std::string &value) const; - bool PushResourceItem(const ResourceItem &resourceItem, int32_t id, - std::map> &items) const; - bool IsIgnore(const std::string &filePath) const; - const std::string &indexPath_; - const std::vector &folder_; - std::vector skipPaths_; -}; -} -} -} -#endif \ No newline at end of file diff --git a/include/increment_list.h b/include/increment_list.h deleted file mode 100644 index bfa90e7..0000000 --- a/include/increment_list.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_INCREMENT_LIST_H -#define OHOS_RESTOOL_INCREMENT_LIST_H - -#include -#include -#include "resource_data.h" -#include "resource_util.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class IncrementList { -public: - struct FileIncrement : FileInfo { - bool isDeleted; - std::string rootPath; - std::string relativePath; - }; - IncrementList(const std::string &listPath, const std::vector &folder); - virtual ~IncrementList() {}; - bool Parse(std::vector &fileList) const; - - static const std::string RESTOOL_LIST_FILE; -private: - bool GetFromPath(const std::string &filePath, FileIncrement &info) const; - int32_t GetPriority(const std::string &filePath) const; - bool ParseSegment(const std::string &filePath, std::vector &segments) const; - bool IteratorArray(const Json::Value &array, std::function callback) const; - bool ParseArray(const Json::Value &array, std::vector &fileList, bool isDeleted) const; - const std::string &listPath_; - const std::vector &folder_; - enum PathSegment { - SEG_RESOURCE = 0, - SEG_LIMIT_KEY = 1, - SEG_FILE_CLUSTER = 2, - SEG_FILE_NAME = 3, - SEG_MAX - }; -}; -} -} -} -#endif diff --git a/include/increment_manager.h b/include/increment_manager.h deleted file mode 100644 index b38d1f7..0000000 --- a/include/increment_manager.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_INCREMENT_MANAGER_H -#define OHOS_RESTOOL_INCREMENT_MANAGER_H - -#include -#include "resource_util.h" -#include "resource_item.h" -#include "singleton.h" - -#include "increment_list.h" -#include "increment_index.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class IncrementManager : public Singleton { -public: - struct FileIncrement : FileInfo { - std::string extension; - std::string relativePath; - std::string inputPath; - int32_t priority; - }; - - struct ModuleInfo { - std::string rootPath; - std::vector fileIncrements; - }; - - virtual ~IncrementManager(); - uint32_t Init(const std::string &cachePath, const std::vector &folder, - const std::string &outputPath, const std::string &moduleName); - const std::map> &GetResourceItems() const - { - return items_; - }; - const std::map> &GetScanDirs() const - { - return scanDirs_; - }; - bool FirstIncrement() const - { - return firstIncrement_; - }; - bool Enable() const - { - return enalbe_; - }; - - static const std::string ID_JSON_FILE; -private: - bool InitIdJson(); - bool InitList(std::vector &dels) const; - bool ScanModules(const std::vector &dels); - void FlushId(); - bool SaveIdJson() const; - bool LoadIdJson(); - void PushScanDir(const std::map> &scanDirs); - void DeleteRawFile(std::vector &dels) const; - bool ClearSolidXml() const; - std::string cachePath_; - std::vector folder_; - std::string outputPath_; - std::string moduleName_; - std::map> items_; - std::map> scanDirs_; - bool enalbe_ = false; - bool firstIncrement_ = true; -}; -} -} -} -#endif diff --git a/include/module_combine.h b/include/module_combine.h deleted file mode 100644 index 9da8df4..0000000 --- a/include/module_combine.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_FILE_COMBINE_H -#define OHOS_RESTOOL_FILE_COMBINE_H - -#include "resource_directory.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class ModuleCombine { -public: - ModuleCombine(const std::string &modulePath, const std::string &outputPath); - virtual ~ModuleCombine() {}; - bool Combine(); - -private: - bool CombineDirectory(const DirectoryInfo &directoryInfo); - bool CombineSolidXml(const std::string &src, const std::string &dst, - const std::map &sxmlPaths); - const std::string &modulePath_; - const std::string &outputPath_; -}; -} -} -} -#endif diff --git a/include/preview_manager.h b/include/preview_manager.h deleted file mode 100644 index 9cbe6ce..0000000 --- a/include/preview_manager.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_PREVIEW_MANAGER_H -#define OHOS_RESTOOL_PREVIEW_MANAGER_H - -#include -#include -#include "restool_errors.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class PreviewManager { -public: - PreviewManager() {}; - virtual ~PreviewManager(); - uint32_t ScanModules(const std::vector &modulePaths, const std::string &output); - void SetPriority(int32_t priority) - { - priority_ = priority; - }; -private: - bool ScanFile(const std::string &filePath, int32_t priority); - int32_t priority_ = -1; -}; -} -} -} -#endif \ No newline at end of file diff --git a/include/reference_parser.h b/include/reference_parser.h index bd95f54..98acda3 100644 --- a/include/reference_parser.h +++ b/include/reference_parser.h @@ -26,7 +26,6 @@ class ReferenceParser { public: ReferenceParser(); virtual ~ReferenceParser(); - uint32_t ParseRefInSolidXml(const std::vector &solidXmlFolders) const; uint32_t ParseRefInResources(std::map> &items, const std::string &output); uint32_t ParseRefInResourceItem(ResourceItem &resourceItem) const; uint32_t ParseRefInJsonFile(ResourceItem &resourceItem, const std::string &output, const bool isIncrement = false); diff --git a/include/resource_data.h b/include/resource_data.h index 0f8574c..916a81c 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -39,7 +39,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.004" }; +static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.005" }; const static int32_t TAG_LEN = 4; enum class KeyType { @@ -59,8 +59,6 @@ enum class KeyType { enum class ResType { ELEMENT = 0, - ANIMATION = 1, - LAYOUT = 3, RAW = 6, INTEGER = 8, STRING = 9, @@ -74,7 +72,6 @@ enum class ResType { FLOAT = 18, MEDIA = 19, PROF = 20, - GRAPHIC = 21, PATTERN = 22, INVALID_RES_TYPE = -1, }; @@ -197,8 +194,6 @@ const std::map g_contentClusterMap = { const std::map g_resTypeMap = { { static_cast(ResType::ELEMENT), ResType::ELEMENT}, - { static_cast(ResType::ANIMATION), ResType::ANIMATION}, - { static_cast(ResType::LAYOUT), ResType::LAYOUT}, { static_cast(ResType::RAW), ResType::RAW}, { static_cast(ResType::INTEGER), ResType::INTEGER}, { static_cast(ResType::STRING), ResType::STRING}, @@ -212,7 +207,6 @@ const std::map g_resTypeMap = { { static_cast(ResType::FLOAT), ResType::FLOAT}, { static_cast(ResType::MEDIA), ResType::MEDIA}, { static_cast(ResType::PROF), ResType::PROF}, - { static_cast(ResType::GRAPHIC), ResType::GRAPHIC}, { static_cast(ResType::PATTERN), ResType::PATTERN}, { static_cast(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE}, }; diff --git a/include/resource_module.h b/include/resource_module.h index ae01a1d..fcd0997 100644 --- a/include/resource_module.h +++ b/include/resource_module.h @@ -18,6 +18,7 @@ #include "resource_item.h" #include "resource_directory.h" +#include "resource_util.h" namespace OHOS { namespace Global { @@ -31,10 +32,6 @@ public: const std::map> &GetScanDirectorys() const; static uint32_t MergeResourceItem(std::map> &alls, const std::map> &other, bool tipError = false); - void SetPreviewMode(bool enable) - { - previewMode_ = enable; - }; protected: const std::string &modulePath_; @@ -42,7 +39,6 @@ protected: const std::string &moduleName_; std::map> owner_; std::map> scanDirs_; - bool previewMode_ = false; private: void Push(const std::map> &other); static const std::vector SCAN_SEQ; diff --git a/include/resource_module_inc.h b/include/resource_module_inc.h deleted file mode 100644 index ac9ba5d..0000000 --- a/include/resource_module_inc.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_RESOURCE_MODULE_INC_H -#define OHOS_RESTOOL_RESOURCE_MODULE_INC_H - -#include "increment_list.h" -#include "resource_module.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class ResourceModuleInc : public ResourceModule { -public: - ResourceModuleInc(const std::string &modulePath, const std::string &moduleOutput, - const std::string &moduleName, const std::vector &folder); - virtual ~ResourceModuleInc() {}; - uint32_t ScanResource(const std::vector &fileIncrements); - uint32_t SaveIndex() const; -private: - const std::vector &folder_; -}; -} -} -} -#endif diff --git a/include/resource_util.h b/include/resource_util.h index 7aa11de..63bbc11 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -139,13 +139,6 @@ public: */ static bool IsIgnoreFile(const std::string &filename, bool isFile); - /** - * @brief need convert to solid xml - * @param resType: ResType - * @return true if need, other false - */ - static bool NeedConverToSolidXml(ResType resType); - /** * @brief generate hash string * @param key: string diff --git a/include/solid_xml.h b/include/solid_xml.h deleted file mode 100644 index 4675f63..0000000 --- a/include/solid_xml.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_SOLID_XML_H -#define OHOS_RESTOOL_SOLID_XML_H - -#include -#include -#include -#include -#include "libxml/parser.h" -#include "xml_key_node.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class SolidXml { -public: - explicit SolidXml(const std::string &xmlPath, std::map> &keys); - virtual ~SolidXml(); - bool GenerateSolidXml(const std::string &filePath); - bool FlushNodeKeys(const std::string &filePath, - std::map> &newKeys); -private: - class Node { - public: - Node(): name_(-1), value_(-1), nameSpace_(-1) {}; - virtual ~Node() {}; - virtual void RawData(std::ofstream &out) const; - virtual bool LoadFrom(std::ifstream &in); - virtual bool FlushIndex(const std::map> &oldKeys, - std::map> &newKeys); - void SetName(int32_t index) - { - name_ = index; - }; - void SetValue(int32_t index) - { - value_ = index; - }; - void SetNameSpace(int32_t index) - { - nameSpace_ = index; - }; - protected: - int32_t name_; - int32_t value_; - int32_t nameSpace_; - }; - - class XmlNode : public Node { - public: - XmlNode() : child_(-1), brother_(-1) {}; - virtual ~XmlNode() {}; - void RawData(std::ofstream &out) const override; - bool LoadFrom(std::ifstream &in) override; - bool FlushIndex(const std::map> &oldKeys, - std::map> &newKeys) override; - void SetChild(int32_t index) - { - child_ = index; - }; - void SetBrother(int32_t index) - { - brother_ = index; - }; - void AddAttribute(int32_t index) - { - attributes_.push_back(index); - }; - private: - int32_t child_; - int32_t brother_; - std::vector attributes_; - }; - - void Compile(const xmlNodePtr nodePtr, std::shared_ptr &node); - void CompileAttr(const xmlAttrPtr attrPtr, std::shared_ptr &node); - void CompileNameSpace(const xmlNodePtr nodePtr, std::shared_ptr &node); - void AddNampeSpaceDef(int32_t nameSpace, int32_t href); - bool SaveToFile(const std::string &filePath) const; - void PretreatmentAttr(std::string &value) const; - bool LoadFromFile(const std::string &sxmlPath); - static bool ChangeToNewKey(const std::map> &oldKeys, - std::map> &newKeys, - XmlKeyNode::KeyType keyType, int32_t &keyId); - bool FlushXmlnsKey(std::map> &newKeys); - const std::string &xmlPath_; - std::map> &keys_; - std::vector> attributes_; - std::vector> nodes_; - std::vector nameSpaces_; - std::vector hrefs_; - - static const uint8_t SOLID_XML_MAGIC[]; - static const uint32_t SOLID_XML_MAGIC_LENGTH; - #define CHECK_IO(stream) \ - if (!stream) { \ - return false; \ - } -}; -} -} -} -#endif \ No newline at end of file diff --git a/include/solid_xml_compiler.h b/include/solid_xml_compiler.h deleted file mode 100644 index b2b9044..0000000 --- a/include/solid_xml_compiler.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_SOLID_XML_COMPILER_H -#define OHOS_RESTOOL_SOLID_XML_COMPILER_H - -#include "generic_compiler.h" -#include "libxml/parser.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class SolidXmlCompiler : public GenericCompiler { -public: - SolidXmlCompiler(ResType type, const std::string &output); - virtual ~SolidXmlCompiler(); -protected: - uint32_t CompileSingleFile(const FileInfo &fileInfo) override; -private: - bool ParseXml(const FileInfo &fileInfo); - bool ParseNodeId(const FileInfo &fileInfo, const xmlNodePtr &node, std::vector &ids); -}; -} -} -} -#endif \ No newline at end of file diff --git a/include/sqlite_database.h b/include/sqlite_database.h deleted file mode 100644 index 8ec06bb..0000000 --- a/include/sqlite_database.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_SQLITE_DATABASE_H -#define OHOS_RESTOOL_SQLITE_DATABASE_H - -#include -#include "resource_item.h" -#include "singleton.h" -#include "sqlite3.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class SqliteDatabase : public Singleton { -public: - void Init(const std::string &dbPath); - bool OpenDatabase(); - void CloseDatabase(); - bool Insert(const ResourceItem &resourceItem); - void SetPriority(int32_t priority) - { - priority_ = priority; - }; -private: - bool Query(const ResourceItem &resourceItem, int32_t &id); - bool FindMaxId(); - bool CreateTable(); - std::string GetValue(const ResourceItem &resourceItem) const; - std::string dbPath_; - sqlite3 *db_ = nullptr; - static int32_t id_; - int32_t priority_ = 0; -}; -} -} -} -#endif diff --git a/include/xml_converter.h b/include/xml_converter.h deleted file mode 100644 index 94bc8fb..0000000 --- a/include/xml_converter.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_XML_CONVERTER_H -#define OHOS_RESTOOL_XML_CONVERTER_H - -#include -#include -#include -#include "key_manager.h" - -namespace OHOS { -namespace Global { -namespace Restool { -class XmlConverter { -public: - XmlConverter(const std::vector &xmlPaths, const std::string &outputPath); - virtual ~XmlConverter(); - bool GenerateSolidXml(); - bool GenerateKey(); -private: - bool LoadKeys(const std::string &folderPath); - const std::vector &xmlPaths_; - const std::string &outputPath_; - KeyManager keyManager; -}; -} -} -} -#endif \ No newline at end of file diff --git a/include/xml_key_node.h b/include/xml_key_node.h deleted file mode 100644 index bc36d3c..0000000 --- a/include/xml_key_node.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#ifndef OHOS_RESTOOL_XML_KEY_NODE_H -#define OHOS_RESTOOL_XML_KEY_NODE_H - -#include -#include -#include -#include - -namespace OHOS { -namespace Global { -namespace Restool { -class XmlKeyNode { -public: - XmlKeyNode(); - virtual ~XmlKeyNode(); - int32_t PushKey(const std::string &name); - bool SaveToFile(const std::string &filePath) const; - bool LoadFromFile(const std::string &filePath); - using RefParser = std::function; - bool LoadFromFile(const std::string &filePath, RefParser parser); - bool GetKeyValue(int32_t keyId, std::string &value) const; - - enum class KeyType { - NODE = 0, - ATTRIBUTE, - CONSTANT, - CONTENT, - END - }; - static const std::map KEY_TO_FILE_NAME; -private: - int32_t keyId_; - std::map keyMap_; -}; -} -} -} -#endif \ No newline at end of file diff --git a/src/cmd_parser.cpp b/src/cmd_parser.cpp index 5915af7..42033a5 100644 --- a/src/cmd_parser.cpp +++ b/src/cmd_parser.cpp @@ -102,11 +102,6 @@ int32_t PackageParser::GetStartId() const return startId_; } -const string &PackageParser::GetCachePath() const -{ - return cachePath_; -} - const string &PackageParser::GetDependEntry() const { return dependEntry_; @@ -224,12 +219,6 @@ uint32_t PackageParser::AddStartId(const string& argValue) return RESTOOL_ERROR; } -uint32_t PackageParser::AddCachePath(const string& argValue) -{ - cachePath_ = argValue; - return RESTOOL_SUCCESS; -} - // -i input directory, add the resource directory void PackageParser::AdaptResourcesDirForInput() { @@ -252,7 +241,7 @@ uint32_t PackageParser::CheckParam() const return RESTOOL_ERROR; } - if (previewMode_ || !append_.empty()) { + if (!append_.empty()) { return RESTOOL_SUCCESS; } if (packageName_.empty()) { @@ -278,28 +267,6 @@ bool PackageParser::IsFileList() const return isFileList_; } -uint32_t PackageParser::SetPreviewMode() -{ - previewMode_ = true; - return RESTOOL_SUCCESS; -} - -bool PackageParser::GetPreviewMode() const -{ - return previewMode_; -} - -int32_t PackageParser::GetPriority() const -{ - return priority_; -} - -uint32_t PackageParser::SetPriority(const string& argValue) -{ - priority_ = atoi(argValue.c_str()); - return RESTOOL_SUCCESS; -} - uint32_t PackageParser::AddAppend(const string& argValue) { string appendPath = ResourceUtil::RealPath(argValue); diff --git a/src/factory_resource_compiler.cpp b/src/factory_resource_compiler.cpp index d5cfd6f..e4e8fc5 100644 --- a/src/factory_resource_compiler.cpp +++ b/src/factory_resource_compiler.cpp @@ -17,7 +17,6 @@ #include "append_compiler.h" #include "generic_compiler.h" #include "json_compiler.h" -#include "solid_xml_compiler.h" namespace OHOS { namespace Global { @@ -27,8 +26,6 @@ unique_ptr FactoryResourceCompiler::CreateCompiler(ResType ty { if (type == ResType::ELEMENT) { return make_unique(type, output); - } else if (type == ResType::LAYOUT || type == ResType::ANIMATION || type == ResType::GRAPHIC) { - return make_unique(type, output); } else { return make_unique(type, output); } diff --git a/src/file_manager.cpp b/src/file_manager.cpp index b81224f..dde0d14 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -14,8 +14,8 @@ */ #include "file_manager.h" -#include -#include +#include +#include #include "factory_resource_compiler.h" #include "file_entry.h" #include "key_parser.h" @@ -23,7 +23,6 @@ #include "resource_directory.h" #include "resource_util.h" #include "restool_errors.h" - #include "resource_module.h" namespace OHOS { @@ -32,24 +31,13 @@ namespace Restool { using namespace std; uint32_t FileManager::ScanModules(const vector &inputs, const string &output) { - vector sxmlFolders; for (auto input : inputs) { map> resTypeOfDirs; if (ScanModule(input, output, resTypeOfDirs) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } - FilterRefSolidXml(output, sxmlFolders, resTypeOfDirs); } - return ParseReference(output, sxmlFolders); -} - -uint32_t FileManager::ScanIncrement(const string &output) -{ - auto &incrementManager = IncrementManager::GetInstance(); - items_ = incrementManager.GetResourceItems(); - vector sxmlFolders; - FilterRefSolidXml(output, sxmlFolders, incrementManager.GetScanDirs()); - return ParseReference(output, sxmlFolders); + return ParseReference(output); } uint32_t FileManager::MergeResourceItem(const map> &resourceInfos) @@ -70,40 +58,14 @@ uint32_t FileManager::ScanModule(const string &input, const string &output, return RESTOOL_SUCCESS; } -uint32_t FileManager::ParseReference(const string &output, const vector &sxmlFolders) +uint32_t FileManager::ParseReference(const string &output) { ReferenceParser referenceParser; - if (referenceParser.ParseRefInSolidXml(sxmlFolders) != RESTOOL_SUCCESS || - referenceParser.ParseRefInResources(items_, output) != RESTOOL_SUCCESS) { + if (referenceParser.ParseRefInResources(items_, output) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } return RESTOOL_SUCCESS; } - -bool FileManager::NeedParseReferenceInSolidXml(ResType resType) const -{ - if (resType == ResType::LAYOUT || resType == ResType::ANIMATION || resType == ResType::GRAPHIC) { - return true; - } - return false; -} - -void FileManager::FilterRefSolidXml(const string &output, vector &outputPaths, - const map> &resTypeOfDirs) const -{ - for (const auto &iter : resTypeOfDirs) { - if (!NeedParseReferenceInSolidXml(iter.first)) { - continue; - } - for (const auto &resourceDir : iter.second) { - string outputPath = FileEntry::FilePath(output).Append(RESOURCES_DIR).Append(resourceDir.limitKey) - .Append(resourceDir.fileCluster).GetPath(); - if (find(outputPaths.begin(), outputPaths.end(), outputPath) == outputPaths.end()) { - outputPaths.push_back(outputPath); - } - } - } -} } } } diff --git a/src/generic_compiler.cpp b/src/generic_compiler.cpp index 3e55c93..cfb6904 100644 --- a/src/generic_compiler.cpp +++ b/src/generic_compiler.cpp @@ -14,7 +14,7 @@ */ #include "generic_compiler.h" -#include +#include #include "file_entry.h" #include "resource_util.h" #include "restool_errors.h" @@ -54,9 +54,6 @@ bool GenericCompiler::PostFile(const FileInfo &fileInfo) resourceItem.SetLimitKey(fileInfo.limitKey); string data = fileInfo.filename; - if (IsConvertToSolidXml(fileInfo)) { - data = FileEntry::FilePath(data).ReplaceExtension(".sxml").GetPath(); - } data = moduleName_ + SEPARATOR + RESOURCES_DIR + SEPARATOR + \ fileInfo.limitKey + SEPARATOR + fileInfo.fileCluster + SEPARATOR + data; if (!resourceItem.SetData(reinterpret_cast(data.c_str()), data.length())) { @@ -75,38 +72,17 @@ string GenericCompiler::GetOutputFilePath(const FileInfo &fileInfo) const bool GenericCompiler::IsIgnore(const FileInfo &fileInfo) const { - if (IsConvertToSolidXml(fileInfo)) { - if (HasConvertedToSolidXml(fileInfo)) { - return true; - } - return false; - } return ResourceUtil::FileExist(GetOutputFilePath(fileInfo)); } bool GenericCompiler::CopyFile(const FileInfo &fileInfo) const { - if (previewMode_) { - return true; - } - if (IsConvertToSolidXml(fileInfo)) { - return true; - } - string outputFolder = GetOutputFolder(fileInfo); if (!ResourceUtil::CreateDirs(outputFolder)) { return false; } return ResourceUtil::CopyFleInner(fileInfo.filePath, GetOutputFilePath(fileInfo)); } - -bool GenericCompiler::IsConvertToSolidXml(const FileInfo &fileInfo) const -{ - if (NeedIfConvertToSolidXml() && IsXmlFile(fileInfo)) { - return true; - } - return false; -} } } } \ No newline at end of file diff --git a/src/i_resource_compiler.cpp b/src/i_resource_compiler.cpp index 414d7a3..a3e2c03 100644 --- a/src/i_resource_compiler.cpp +++ b/src/i_resource_compiler.cpp @@ -20,8 +20,6 @@ #include "id_worker.h" #include "resource_util.h" #include "restool_errors.h" -#include "sqlite_database.h" -#include "xml_converter.h" namespace OHOS { namespace Global { @@ -72,13 +70,6 @@ uint32_t IResourceCompiler::Compile(const vector &directoryInfos) return RESTOOL_ERROR; } } - - if (previewMode_) { - return RESTOOL_SUCCESS; - } - if (NeedIfConvertToSolidXml() && ConvertToSolidXml(setsByDirectory) != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } return PostCommit(); } @@ -92,20 +83,6 @@ uint32_t IResourceCompiler::Compile(const FileInfo &fileInfo) if (CompileSingleFile(fileInfo) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } - - if (previewMode_) { - return RESTOOL_SUCCESS; - } - map> setsByDirectory; - if (NeedIfConvertToSolidXml()) { - string outputFolder = FileEntry::FilePath(output_).Append(RESOURCES_DIR) - .Append(fileInfo.limitKey).Append(fileInfo.fileCluster).GetPath(); - setsByDirectory[outputFolder].push_back(fileInfo); - } - - if (ConvertToSolidXml(setsByDirectory) != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } return PostCommit(); } @@ -124,33 +101,6 @@ void IResourceCompiler::SetModuleName(const string &moduleName) moduleName_ = moduleName; } -uint32_t IResourceCompiler::ConvertToSolidXml(const map> &setsByDirectory) -{ - for (const auto &iter : setsByDirectory) { - vector xmlPaths; - ListXmlFile(iter.second, xmlPaths); - if (xmlPaths.empty()) { - continue; - } - - string xmlOutPath = iter.first; - if (!ResourceUtil::CreateDirs(xmlOutPath)) { - return RESTOOL_ERROR; - } - - sort(xmlPaths.begin(), xmlPaths.end()); - XmlConverter xmlConverter(xmlPaths, xmlOutPath); - if (!xmlConverter.GenerateSolidXml()) { - return RESTOOL_ERROR; - } - - if (!xmlConverter.GenerateKey()) { - return RESTOOL_ERROR; - } - } - return RESTOOL_SUCCESS; -} - uint32_t IResourceCompiler::CompileSingleFile(const FileInfo &fileInfo) { return RESTOOL_SUCCESS; @@ -173,9 +123,6 @@ uint32_t IResourceCompiler::PostCommit() bool IResourceCompiler::MergeResourceItem(const ResourceItem &resourceItem) { - if (previewMode_) { - return SqliteDatabase::GetInstance().Insert(resourceItem); - } string idName = ResourceUtil::GetIdName(resourceItem.GetName(), resourceItem.GetResType()); if (!IdWorker::GetInstance().IsValidName(idName)) { cerr << "Error: invalid idName '" << idName << "'."<< NEW_LINE_PATH << resourceItem.GetFilePath() << endl; @@ -200,43 +147,6 @@ bool IResourceCompiler::MergeResourceItem(const ResourceItem &resourceItem) return true; } -void IResourceCompiler::ListXmlFile(const vector &fileInfos, vector &xmlPaths) const -{ - for (const auto &fileInfo : fileInfos) { - if (!IsXmlFile(fileInfo)) { - continue; - } - - if (HasConvertedToSolidXml(fileInfo)) { - continue; - } - xmlPaths.push_back(fileInfo.filePath); - } -} - -bool IResourceCompiler::IsXmlFile(const FileInfo &fileInfo) const -{ - if (FileEntry::FilePath(fileInfo.filePath).GetExtension() != ".xml") { - return false; - } - return true; -} - -bool IResourceCompiler::HasConvertedToSolidXml(const FileInfo &fileInfo) const -{ - string solidXmlPath = FileEntry::FilePath(output_).Append(RESOURCES_DIR).Append(fileInfo.limitKey) - .Append(fileInfo.fileCluster).Append(fileInfo.filename).ReplaceExtension(".sxml").GetPath(); - if (ResourceUtil::FileExist(solidXmlPath)) { - return true; - } - return false; -} - -bool IResourceCompiler::NeedIfConvertToSolidXml() const -{ - return ResourceUtil::NeedConverToSolidXml(type_); -} - string IResourceCompiler::GetOutputFolder(const DirectoryInfo &directoryInfo) const { string outputFolder = FileEntry::FilePath(output_).Append(RESOURCES_DIR) diff --git a/src/increment_index.cpp b/src/increment_index.cpp deleted file mode 100644 index 34c73b2..0000000 --- a/src/increment_index.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "increment_index.h" -#include -#include -#include "key_parser.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -const string IncrementIndex::INDEX_FILE = "index.json"; -IncrementIndex::IncrementIndex(const string &indexPath, const vector &folder) - : indexPath_(indexPath), folder_(folder) -{ -} - -bool IncrementIndex::Save(const map> &items) const -{ - Json::Value root; - root["header"] = Json::Value(Json::ValueType::objectValue); - root["header"]["folder"] = Json::Value(Json::ValueType::arrayValue); - for (const auto &folder : folder_) { - root["header"]["folder"].append(folder); - } - - root["index"] = Json::Value(Json::ValueType::objectValue); - for (const auto &item : items) { - string id = to_string(item.first); - root["index"][id] = Json::Value(Json::ValueType::objectValue); - for (const auto &resourceItem : item.second) { - root["index"][id][resourceItem.GetFilePath()] = Json::Value(Json::ValueType::objectValue); - auto &record = root["index"][id][resourceItem.GetFilePath()]; - string data(reinterpret_cast(resourceItem.GetData()), resourceItem.GetDataLength()); - record["data"] = data; - record["name"] = resourceItem.GetName(); - record["limitkey"] = resourceItem.GetLimitKey(); - record["type"] = ResourceUtil::ResTypeToString(resourceItem.GetResType()); - } - } - - if (!ResourceUtil::SaveToJsonFile(indexPath_, root)) { - return false; - } - return true; -} - -bool IncrementIndex::Load(map> &items) const -{ - Json::Value indexJson; - if (!ResourceUtil::OpenJsonFile(indexPath_, indexJson)) { - return false; - } - - auto headerInfo = indexJson["header"]; - if (headerInfo.empty() || !headerInfo.isObject()) { - cerr << "Error: header info." << NEW_LINE_PATH << indexPath_ << endl; - return true; - } - auto folderInfo = headerInfo["folder"]; - if (folderInfo.empty() || !folderInfo.isArray()) { - cerr << "Error: folder info." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - if (folder_.size() != folderInfo.size()) { - cerr << "Error: add/delete dependency, don't support increment compile." << endl; - return false; - } - - for (size_t i = 0; i < folder_.size(); i++) { - if (folder_[i] != folderInfo[static_cast(i)].asString()) { - cerr << "Error: dependency change, don't support increment compile." << endl; - return true; - } - } - - if (!LoadIndex(indexJson["index"], items)) { - return false; - } - return true; -} - -void IncrementIndex::SetSkipPaths(const vector &skipPaths) -{ - skipPaths_ = skipPaths; -} - -// below private -bool IncrementIndex::LoadIndex(const Json::Value &indexInfo, map> &items) const -{ - if (indexInfo.empty() || !indexInfo.isObject()) { - cerr << "Error: index info." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - - for (const auto &idMember : indexInfo.getMemberNames()) { - int32_t id = strtol(idMember.c_str(), nullptr, 10); - if (id < 0) { - cerr << "Error: '" << idMember << "' not integer string." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - if (items.count(id) != 0) { - cerr << "Error: '" << idMember << "' duplicated." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - if (!indexInfo[idMember].isObject()) { - cerr << "Error: '" << idMember << "' not object." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - for (const auto &pathMember : indexInfo[idMember].getMemberNames()) { - if (IsIgnore(pathMember)) { - continue; - } - auto item = indexInfo[idMember][pathMember]; - if (!item.isObject()) { - cerr << "Error: [" << idMember << "][" << pathMember<<"] not object."; - cerr << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - ResourceItem resourceItem; - if (!ParseResourceItem(item, pathMember, resourceItem)) { - cerr << "Error: [" << idMember << "][" << pathMember<<"]." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - if (!PushResourceItem(resourceItem, id, items)) { - return false; - } - } - } - return true; -} - -bool IncrementIndex::ParseResourceItem(const Json::Value &item, const string &filePath, - ResourceItem &resourceItem) const -{ - string name; - string type; - string limitKey; - string data; - if (!GetResourceItemProp(item, "name", name) || !GetResourceItemProp(item, "type", type) || - !GetResourceItemProp(item, "limitkey", limitKey) || !GetResourceItemProp(item, "data", data)) { - cerr << "Error: 'name' 'type' 'limitkey' 'data' invalid." << endl; - return false; - } - ResType resType = ResourceUtil::GetResTypeFromString(type); - if (resType == ResType::INVALID_RES_TYPE) { - cerr << "Error: invaid ResType '" << type << "'." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - vector keyParams; - if (!KeyParser::Parse(limitKey, keyParams)) { - return false; - } - ResourceItem temp(name, keyParams, resType); - if (resType != ResType::ID && !temp.SetData(reinterpret_cast(data.c_str()), data.length())) { - cerr << "Error: resource set data fail." << endl; - return false; - } - temp.SetFilePath(filePath); - temp.SetLimitKey(limitKey); - resourceItem = temp; - return true; -} - -bool IncrementIndex::GetResourceItemProp(const Json::Value &item, const string &key, string &value) const -{ - if (item[key].empty() || !item[key].isString()) { - return false; - } - value = item[key].asString(); - return true; -} - -bool IncrementIndex::PushResourceItem(const ResourceItem &resourceItem, int32_t id, - map> &items) const -{ - if (items.find(id) == items.end()) { - items[id].push_back(resourceItem); - return true; - } - - const auto &first = items[id].begin(); - if (resourceItem.GetName() != first->GetName()) { - cerr << "Error: '" << resourceItem.GetName() << "', expect '" << first->GetName() << "'."; - cerr << NEW_LINE_PATH << indexPath_ <GetResType()) { - cerr << "Error: '" << ResourceUtil::ResTypeToString(resourceItem.GetResType()); - cerr << "', expect '" << ResourceUtil::ResTypeToString(first->GetResType()) << "'."; - cerr << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - auto result = find_if(items[id].begin(), items[id].end(), [&resourceItem](const auto &iter) { - return resourceItem.GetLimitKey() == iter.GetLimitKey(); - }); - if (result != items[id].end()) { - cerr << "Error: '" << resourceItem.GetLimitKey() << "' conflict." << NEW_LINE_PATH << indexPath_ << endl; - return false; - } - items[id].push_back(resourceItem); - return true; -} - -bool IncrementIndex::IsIgnore(const string &filePath) const -{ - if (skipPaths_.empty()) { - return false; - } - - if (find(skipPaths_.begin(), skipPaths_.end(), filePath) != skipPaths_.end()) { - return true; - } - return false; -} -} -} -} \ No newline at end of file diff --git a/src/increment_list.cpp b/src/increment_list.cpp deleted file mode 100644 index 1b24416..0000000 --- a/src/increment_list.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "increment_list.h" -#include -#include -#include "file_entry.h" -#include "key_parser.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -const string IncrementList::RESTOOL_LIST_FILE = "restool_list.json"; -IncrementList::IncrementList(const string &listPath, const vector &folder) - : listPath_(listPath), folder_(folder) -{ -} - -bool IncrementList::Parse(std::vector &fileList) const -{ - Json::Value listJson; - if (!ResourceUtil::OpenJsonFile(listPath_, listJson)) { - return false; - } - - if (ParseArray(listJson["del"], fileList, true) && - ParseArray(listJson["fix"], fileList, false)) { - return true; - } - return false; -} - -// below private -bool IncrementList::GetFromPath(const string &filePath, FileIncrement &info) const -{ - int32_t priority = GetPriority(filePath); - if (priority < 0) { - cerr << "Error: '" << RESTOOL_LIST_FILE << "' invalid." << NEW_LINE_PATH << filePath << endl; - return false; - } - info.rootPath = folder_[priority]; - string rootPath = FileEntry::FilePath(info.rootPath).Append("").GetPath(); - info.relativePath = filePath.substr(rootPath.length()); - vector segments; - if (!ParseSegment(info.relativePath, segments)) { - return false; - } - - info.dirPath = FileEntry::FilePath(filePath).GetParent().GetPath(); - info.filePath = filePath; - info.limitKey = segments[SEG_LIMIT_KEY]; - if (info.limitKey == RAW_FILE_DIR) { - info.dirType = ResType::INVALID_RES_TYPE; - return true; - } - if (!KeyParser::Parse(info.limitKey, info.keyParams)) { - cerr << "Error: '" << info.limitKey << "' invalid limit key." << NEW_LINE_PATH << filePath << endl; - return false; - } - - info.fileCluster = segments[SEG_FILE_CLUSTER]; - info.dirType = ResourceUtil::GetResTypeByDir(info.fileCluster); - if (info.dirType == ResType::INVALID_RES_TYPE) { - cerr << "Error: '" << info.fileCluster << "' invalid ResType." << NEW_LINE_PATH << filePath << endl; - return false; - } - info.filename = segments[SEG_FILE_NAME]; - return true; -} - -int32_t IncrementList::GetPriority(const string &filePath) const -{ - auto result = find_if(folder_.begin(), folder_.end(), [&filePath](auto &iter) { - string rootPath = FileEntry::FilePath(iter).Append("").GetPath(); - if (filePath.length() <= rootPath.length()) { - return false; - } - if (filePath.compare(0, rootPath.length(), rootPath.c_str()) == 0) { - return true; - } - return true; - }); - if (result == folder_.end()) { - return -1; - } - return (result - folder_.begin()); -} - -bool IncrementList::ParseSegment(const string &filePath, vector &segments) const -{ - vector segs = FileEntry::FilePath(filePath).GetSegments(); - copy(segs.begin(), segs.end(), back_inserter(segments)); - - if (segments.size() >= (SEG_RESOURCE + 1) && segments[SEG_RESOURCE] != RESOURCES_DIR) { - cerr << "Error: don't contain '" << RESOURCES_DIR << "'." << NEW_LINE_PATH << filePath << endl; - return false; - } - - if (segments.size() >= (SEG_LIMIT_KEY + 1) && segments[SEG_LIMIT_KEY] == RAW_FILE_DIR) { - return true; - } - - if (segments.size() != SEG_MAX) { - cerr << "Error: segments != " << SEG_MAX << NEW_LINE_PATH << filePath << endl; - return false; - } - return true; -} - -bool IncrementList::IteratorArray(const Json::Value &array, function callback) const -{ - if (array.empty()) { - return true; - } - - if (!array.isArray()) { - cerr << "Error: "<< RESTOOL_LIST_FILE << ",not array." << endl; - return false; - } - - for (Json::ArrayIndex i = 0; i < array.size(); i++) { - if (!array[i].isString()) { - cerr << "Error: " << RESTOOL_LIST_FILE << ",not string." << endl; - return false; - } - if (callback && !callback(array[i].asString())) { - return false; - } - } - return true; -} - -bool IncrementList::ParseArray(const Json::Value &array, vector &fileList, bool isDeleted) const -{ - return IteratorArray(array, [this, &fileList, &isDeleted](const string &filePath) { - FileIncrement info; - info.isDeleted = isDeleted; - if (!GetFromPath(filePath, info)) { - return false; - } - fileList.push_back(info); - return true; - }); -} -} -} -} \ No newline at end of file diff --git a/src/increment_manager.cpp b/src/increment_manager.cpp deleted file mode 100644 index d28466b..0000000 --- a/src/increment_manager.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "increment_manager.h" -#include -#include -#include "file_entry.h" -#include "id_worker.h" -#include "key_parser.h" -#include "module_combine.h" -#include "resource_module_inc.h" -#include "restool_errors.h" -#include "xml_key_node.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -const string IncrementManager::ID_JSON_FILE = "ids.json"; -IncrementManager::~IncrementManager() -{ -} - -uint32_t IncrementManager::Init(const string &cachePath, const vector &folder, - const string &outputPath, const string &moduleName) -{ - cachePath_ = cachePath; - folder_ = folder; - outputPath_ = outputPath; - moduleName_ = moduleName; - - if (!InitIdJson()) { - return RESTOOL_ERROR; - } - - if (!ClearSolidXml()) { - return RESTOOL_ERROR; - } - - vector dels; - if (!InitList(dels)) { - return RESTOOL_ERROR; - } - - DeleteRawFile(dels); - if (!ScanModules(dels)) { - return RESTOOL_ERROR; - } - enalbe_= true; - return RESTOOL_SUCCESS; -} - -// below private -bool IncrementManager::InitIdJson() -{ - string idJsonPath = FileEntry::FilePath(cachePath_).Append(ID_JSON_FILE).GetPath(); - if (!ResourceUtil::FileExist(idJsonPath)) { - return true; - } - if (!LoadIdJson()) { - return false; - } - firstIncrement_ = false; - return true; -} - -bool IncrementManager::ScanModules(const vector &dels) -{ - vector moduleInfos; - for (const auto &folder : folder_) { - ModuleInfo moduleInfo; - moduleInfo.rootPath = folder; - for_each(dels.begin(), dels.end(), [&moduleInfo](const auto &iter) { - if (moduleInfo.rootPath != iter.rootPath) { - return; - } - moduleInfo.fileIncrements.push_back(iter); - }); - moduleInfos.push_back(moduleInfo); - } - - for (auto &iter : moduleInfos) { - string pathHash = ResourceUtil::GenerateHash(iter.rootPath); - string moduleCachePath = FileEntry::FilePath(cachePath_).Append(pathHash).GetPath(); - ResourceModuleInc resourceModuleInc(iter.rootPath, moduleCachePath, moduleName_, folder_); - if (FirstIncrement()) { - if (resourceModuleInc.ResourceModule::ScanResource() != RESTOOL_SUCCESS) { - return false; - } - } else { - if (resourceModuleInc.ScanResource(iter.fileIncrements) != RESTOOL_SUCCESS) { - return false; - } - } - - PushScanDir(resourceModuleInc.GetScanDirectorys()); - if (ResourceModule::MergeResourceItem(items_, resourceModuleInc.GetOwner()) != RESTOOL_SUCCESS) { - return false; - } - if (resourceModuleInc.SaveIndex() != RESTOOL_SUCCESS) { - return false; - } - - ModuleCombine moduleCombine(moduleCachePath, outputPath_); - if (!moduleCombine.Combine()) { - return false; - } - } - FlushId(); - SaveIdJson(); - return true; -} - -bool IncrementManager::InitList(vector &dels) const -{ - string listPath = FileEntry::FilePath(cachePath_).Append(IncrementList::RESTOOL_LIST_FILE).GetPath(); - if (!ResourceUtil::FileExist(listPath)) { - return true; - } - - IncrementList incrementList(listPath, folder_); - if (!incrementList.Parse(dels)) { - return false; - } - return true; -} - -void IncrementManager::FlushId() -{ - for_each(items_.begin(), items_.end(), [](const auto &iter) { - auto &idWorker = IdWorker::GetInstance(); - ResType resType = iter.second.begin()->GetResType(); - string name = ResourceUtil::GetIdName(iter.second.begin()->GetName(), resType); - idWorker.GenerateId(resType, name); - }); -} - -bool IncrementManager::SaveIdJson() const -{ - Json::Value root; - for (const auto &iter : items_) { - Json::Value node; - ResType resType = iter.second.begin()->GetResType(); - node["name"] = ResourceUtil::GetIdName(iter.second.begin()->GetName(), resType); - node["type"] = ResourceUtil::ResTypeToString(resType); - root[to_string(iter.first)] = node; - } - - string idJsonPath = FileEntry::FilePath(cachePath_).Append(ID_JSON_FILE).GetPath(); - if (!ResourceUtil::SaveToJsonFile(idJsonPath, root)) { - return false; - } - return true; -} - -bool IncrementManager::LoadIdJson() -{ - Json::Value root; - string idJsonPath = FileEntry::FilePath(cachePath_).Append(ID_JSON_FILE).GetPath(); - if (!ResourceUtil::OpenJsonFile(idJsonPath, root)) { - return false; - } - - if (!root.isObject()) { - cerr << "Error: invalid, not object." << NEW_LINE_PATH << idJsonPath << endl; - return false; - } - - auto &idWorker = IdWorker::GetInstance(); - for (const auto &member : root.getMemberNames()) { - int32_t id = strtol(member.c_str(), nullptr, 10); - if (id < 0) { - cerr << "Error: invalid '" << member << "'." << NEW_LINE_PATH << idJsonPath << endl; - return false; - } - - const auto &node = root[member]; - if (!node.isObject()) { - cerr << "Error: '" << member << "' not object." << NEW_LINE_PATH << idJsonPath << endl; - return false; - } - if (!node["name"].isString()) { - cerr << "Error: '" << member << "' name not string." << NEW_LINE_PATH << idJsonPath << endl; - return false; - } - string name = node["name"].asString(); - - if (!node["type"].isString()) { - cerr << "Error: '" << member << "' type not string." << NEW_LINE_PATH << idJsonPath << endl; - return false; - } - ResType resType = ResourceUtil::GetResTypeFromString(node["type"].asString()); - if (resType == ResType::INVALID_RES_TYPE) { - cerr << "Error: '" << member << "' '" << node["type"] << "' invalid."; - cerr << NEW_LINE_PATH << idJsonPath << endl; - return false; - } - if (!idWorker.PushCache(resType, name, id)) { - return false; - } - } - return true; -} - -void IncrementManager::PushScanDir(const map> &scanDirs) -{ - for (const auto &iter : scanDirs) { - for (const auto &directoryInfo : iter.second) { - scanDirs_[iter.first].push_back(directoryInfo); - } - } -} - -void IncrementManager::DeleteRawFile(vector &dels) const -{ - for (auto it = dels.begin(); it != dels.end();) { - if (it->dirType != ResType::INVALID_RES_TYPE) { - it++; - continue; - } - string rawFilePath = FileEntry::FilePath(outputPath_).Append(it->relativePath).GetPath(); - if (remove(rawFilePath.c_str()) != 0) { - cout << "Warning: remove fail '" << rawFilePath << "'" << endl; - } - it = dels.erase(it); - } -} - -bool IncrementManager::ClearSolidXml() const -{ - string resourceDir = FileEntry::FilePath(outputPath_).Append(RESOURCES_DIR).GetPath(); - if (!ResourceUtil::FileExist(resourceDir)) { - return true; - } - - ResourceDirectory resourceDirectory; - if (!resourceDirectory.ScanResources(resourceDir, [](const DirectoryInfo &info) { - if (!ResourceUtil::NeedConverToSolidXml(info.dirType)) { - return true; - } - - FileEntry f(info.dirPath); - if (!f.Init()) { - return false; - } - - for (const auto &entry : f.GetChilds()) { - if (!entry->IsFile()) { - cerr << "Error: '" << entry->GetFilePath().GetPath() << "' is directroy." << endl; - return false; - } - - string extension = entry->GetFilePath().GetExtension(); - if (extension != ".sxml" && extension != ".key" && extension != ".json") { - continue; - } - - if (remove(entry->GetFilePath().GetPath().c_str()) != 0) { - cerr << "Error: remove failed '" << entry->GetFilePath().GetPath(); - cerr << "', reason: " << strerror(errno) << endl; - return false; - } - } - return true; - })) { - return false; - } - return true; -} -} -} -} diff --git a/src/module_combine.cpp b/src/module_combine.cpp deleted file mode 100644 index a579e4c..0000000 --- a/src/module_combine.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "module_combine.h" -#include -#include -#include "file_entry.h" -#include "key_manager.h" -#include "resource_util.h" -#include "solid_xml.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -ModuleCombine::ModuleCombine(const string &modulePath, const string &outputPath) - : modulePath_(modulePath), outputPath_(outputPath) -{ -} - -bool ModuleCombine::Combine() -{ - string resourceDir = FileEntry::FilePath(modulePath_).Append(RESOURCES_DIR).GetPath(); - ResourceDirectory resourceDirectory; - if (!resourceDirectory.ScanResources(resourceDir, [this](const DirectoryInfo &info) -> bool { - return CombineDirectory(info); - })) { - return false; - } - return true; -} - -// below private -bool ModuleCombine::CombineDirectory(const DirectoryInfo &directoryInfo) -{ - string outputFolder = FileEntry::FilePath(outputPath_).Append(RESOURCES_DIR) - .Append(directoryInfo.limitKey).Append(directoryInfo.fileCluster).GetPath(); - if (!ResourceUtil::CreateDirs(outputFolder)) { - return false; - } - - map sxmlPaths; - FileEntry f(directoryInfo.dirPath); - if (!f.Init()) { - return false; - } - for (const auto &entry : f.GetChilds()) { - string src = entry->GetFilePath().GetPath(); - if (!entry->IsFile()) { - cerr << "Error: " << src << " is directory." << endl; - return false; - } - - string filename = entry->GetFilePath().GetFilename(); - string dst = FileEntry::FilePath(outputFolder).Append(filename).GetPath(); - if (ResourceUtil::FileExist(dst)) { - continue; - } - - if (entry->GetFilePath().GetExtension() == ".sxml") { - sxmlPaths.emplace(src, dst); - continue; - } - - auto result = find_if (XmlKeyNode::KEY_TO_FILE_NAME.begin(), XmlKeyNode::KEY_TO_FILE_NAME.end(), - [&filename](const auto &iter) { - return filename == iter.second; - }); - if (result != XmlKeyNode::KEY_TO_FILE_NAME.end()) { - continue; - } - - if (!ResourceUtil::CopyFleInner(src, dst)) { - return true; - } - } - return CombineSolidXml(directoryInfo.dirPath, outputFolder, sxmlPaths); -} - -bool ModuleCombine::CombineSolidXml(const string &src, const string &dst, const map &sxmlPaths) -{ - if (sxmlPaths.empty()) { - return true; - } - - KeyManager oldKeyManager; - if (!oldKeyManager.LoadKey(src)) { - return false; - } - - KeyManager newKeyManager; - if (!newKeyManager.LoadKey(dst)) { - return false; - } - - for (const auto &sxmlPath : sxmlPaths) { - SolidXml solidXml(sxmlPath.first, oldKeyManager.GetKeys()); - if (!solidXml.FlushNodeKeys(sxmlPath.second, newKeyManager.GetKeys())) { - return false; - } - } - - if (!newKeyManager.SaveKey(dst)) { - cerr << "Error: GenerateToOther " << modulePath_ << " fail." << endl; - return false; - } - return true; -} -} -} -} diff --git a/src/preview_manager.cpp b/src/preview_manager.cpp deleted file mode 100644 index 2eef2ca..0000000 --- a/src/preview_manager.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 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 - * - * 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. - */ - -#include "preview_manager.h" -#include -#include "factory_resource_compiler.h" -#include "file_entry.h" -#include "key_parser.h" -#include "resource_module.h" -#include "resource_util.h" -#include "sqlite_database.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -PreviewManager::~PreviewManager() -{ - SqliteDatabase &database = SqliteDatabase::GetInstance(); - database.CloseDatabase(); -} - -uint32_t PreviewManager::ScanModules(const vector &modulePaths, const string &output) -{ - SqliteDatabase &database = SqliteDatabase::GetInstance(); - string dbPath = FileEntry::FilePath(output).Append("resources.db").GetPath(); - database.Init(dbPath); - if (!database.OpenDatabase()) { - return RESTOOL_ERROR; - } - - int32_t priority = 0; - if (priority_ >= 0) { - priority = priority_; - } - - for (const auto &iter : modulePaths) { - if (FileEntry::IsDirectory(iter)) { - ResourceModule resourceMoudle(iter, output, ""); - resourceMoudle.SetPreviewMode(true); - database.SetPriority(priority); - if (resourceMoudle.ScanResource() != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } - } else if (!ScanFile(iter, priority)) { - return RESTOOL_ERROR; - } - if (priority_ >= 0) { - continue; - } - priority++; - } - return RESTOOL_SUCCESS; -} - -bool PreviewManager::ScanFile(const string &filePath, int32_t priority) -{ - if (!ResourceUtil::FileExist(filePath)) { - cerr << "Error: " << filePath << " non't exist." << endl; - return false; - } - FileInfo fileInfo; - fileInfo.filePath = filePath; - fileInfo.filename = FileEntry::FilePath(filePath).GetFilename(); - fileInfo.dirPath = FileEntry::FilePath(filePath).GetParent().GetPath(); - fileInfo.fileCluster = FileEntry::FilePath(fileInfo.dirPath).GetFilename(); - fileInfo.limitKey = FileEntry::FilePath(fileInfo.dirPath).GetParent().GetFilename(); - - fileInfo.dirType = ResourceUtil::GetResTypeByDir(fileInfo.fileCluster); - if (fileInfo.dirType == ResType::INVALID_RES_TYPE) { - return false; - } - - if (!KeyParser::Parse(fileInfo.limitKey, fileInfo.keyParams)) { - return false; - } - - unique_ptr resourceCompiler = - FactoryResourceCompiler::CreateCompiler(fileInfo.dirType, ""); - resourceCompiler->SetPreviewMode(true); - resourceCompiler->SetModuleName(""); - if (resourceCompiler->Compile(fileInfo) != RESTOOL_SUCCESS) { - return false; - } - return true; -} -} -} -} diff --git a/src/reference_parser.cpp b/src/reference_parser.cpp index ae4bf56..6194099 100644 --- a/src/reference_parser.cpp +++ b/src/reference_parser.cpp @@ -14,11 +14,10 @@ */ #include "reference_parser.h" -#include -#include +#include +#include #include "file_entry.h" #include "restool_errors.h" -#include "xml_key_node.h" namespace OHOS { namespace Global { @@ -33,10 +32,8 @@ const map ReferenceParser::ID_REFS = { { "^\\$profile:", ResType::PROF }, { "^\\$integer:", ResType::INTEGER }, { "^\\$string:", ResType::STRING }, - { "^\\$layout:", ResType::LAYOUT }, { "^\\$pattern:", ResType::PATTERN }, { "^\\$plural:", ResType::PLURAL }, - { "^\\$graphic:", ResType::GRAPHIC }, { "^\\$theme:", ResType::THEME } }; @@ -49,10 +46,8 @@ const map ReferenceParser::ID_OHOS_REFS = { { "^\\$ohos:profile:", ResType::PROF }, { "^\\$ohos:integer:", ResType::INTEGER }, { "^\\$ohos:string:", ResType::STRING }, - { "^\\$ohos:layout:", ResType::LAYOUT }, { "^\\$ohos:pattern:", ResType::PATTERN }, { "^\\$ohos:plural:", ResType::PLURAL }, - { "^\\$ohos:graphic:", ResType::GRAPHIC }, { "^\\$ohos:theme:", ResType::THEME } }; @@ -64,29 +59,6 @@ ReferenceParser::~ReferenceParser() { } -uint32_t ReferenceParser::ParseRefInSolidXml(const vector &solidXmlFolders) const -{ - for (const auto &solidXmlFolder : solidXmlFolders) { - string filePath = FileEntry::FilePath(solidXmlFolder) - .Append(XmlKeyNode::KEY_TO_FILE_NAME.at(XmlKeyNode::KeyType::CONSTANT)).GetPath(); - if (!ResourceUtil::FileExist(filePath)) { - continue; - } - - XmlKeyNode xmlKeyNode; - if (!xmlKeyNode.LoadFromFile(filePath, [this](auto &key) -> bool { - return ParseRefString(key); - })) { - return RESTOOL_ERROR; - } - - if (!xmlKeyNode.SaveToFile(filePath)) { - return RESTOOL_ERROR; - } - } - return RESTOOL_SUCCESS; -} - uint32_t ReferenceParser::ParseRefInResources(map> &items, const string &output) { for (auto &iter : items) { diff --git a/src/resource_module.cpp b/src/resource_module.cpp index 57cc968..b808f30 100644 --- a/src/resource_module.cpp +++ b/src/resource_module.cpp @@ -14,8 +14,8 @@ */ #include "resource_module.h" -#include -#include +#include +#include #include "factory_resource_compiler.h" #include "restool_errors.h" @@ -27,9 +27,6 @@ const vector ResourceModule::SCAN_SEQ = { ResType::ELEMENT, ResType::MEDIA, ResType::PROF, - ResType::ANIMATION, - ResType::GRAPHIC, - ResType::LAYOUT, }; ResourceModule::ResourceModule(const string &modulePath, const string &moduleOutput, const string &moduleName) : modulePath_(modulePath), moduleOutput_(moduleOutput), moduleName_(moduleName) @@ -59,7 +56,6 @@ uint32_t ResourceModule::ScanResource() unique_ptr resourceCompiler = FactoryResourceCompiler::CreateCompiler(type, moduleOutput_); resourceCompiler->SetModuleName(moduleName_); - resourceCompiler->SetPreviewMode(previewMode_); if (resourceCompiler->Compile(item->second) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } @@ -111,10 +107,6 @@ uint32_t ResourceModule::MergeResourceItem(map> &a // below private void ResourceModule::Push(const map> &other) { - if (previewMode_) { - return; - } - for (const auto &iter : other) { owner_.emplace(iter.first, iter.second); } diff --git a/src/resource_module_inc.cpp b/src/resource_module_inc.cpp deleted file mode 100644 index 6b4f508..0000000 --- a/src/resource_module_inc.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "resource_module_inc.h" -#include -#include "factory_resource_compiler.h" -#include "file_entry.h" -#include "increment_index.h" -#include "restool_errors.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -ResourceModuleInc::ResourceModuleInc(const string &modulePath, const string &moduleOutput, - const string &moduleName, const vector &folder) - : ResourceModule(modulePath, moduleOutput, moduleName), folder_(folder) -{ -} - -uint32_t ResourceModuleInc::ScanResource(const vector &fileIncrements) -{ - vector skips; - for (const auto &fileIncrement : fileIncrements) { - skips.push_back(fileIncrement.filePath); - if (fileIncrement.dirType == ResType::ELEMENT) { - continue; - } - string filePathDel = FileEntry::FilePath(moduleOutput_).Append(RESOURCES_DIR) - .Append(fileIncrement.limitKey).Append(fileIncrement.fileCluster).Append(fileIncrement.filename).GetPath(); - if (ResourceUtil::NeedConverToSolidXml(fileIncrement.dirType) && - FileEntry::FilePath(filePathDel).GetExtension() == ".xml") { - filePathDel = FileEntry::FilePath(filePathDel).ReplaceExtension(".sxml").GetPath(); - } - if (remove(filePathDel.c_str()) != 0) { - cerr << "Error: remove failed '" << filePathDel << "', reason: " << strerror(errno) << endl; - return RESTOOL_ERROR; - } - } - - string indexPath = FileEntry::FilePath(moduleOutput_).Append(IncrementIndex::INDEX_FILE).GetPath(); - IncrementIndex moduleIndex(indexPath, folder_); - moduleIndex.SetSkipPaths(skips); - if (!moduleIndex.Load(owner_)) { - return RESTOOL_ERROR; - } - - for (const auto &fileIncrement : fileIncrements) { - unique_ptr resourceCompiler = - FactoryResourceCompiler::CreateCompiler(fileIncrement.dirType, moduleOutput_); - resourceCompiler->SetModuleName(moduleName_); - if (resourceCompiler->Compile(fileIncrement) != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } - - if (MergeResourceItem(owner_, resourceCompiler->GetResult(), true) != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } - } - return RESTOOL_SUCCESS; -} - -uint32_t ResourceModuleInc::SaveIndex() const -{ - string indexPath = FileEntry::FilePath(moduleOutput_).Append(IncrementIndex::INDEX_FILE).GetPath(); - IncrementIndex moduleIndex(indexPath, folder_); - if (!moduleIndex.Save(owner_)) { - return RESTOOL_ERROR; - } - return RESTOOL_SUCCESS; -} -} -} -} \ No newline at end of file diff --git a/src/resource_pack.cpp b/src/resource_pack.cpp index d457bc3..e9de364 100644 --- a/src/resource_pack.cpp +++ b/src/resource_pack.cpp @@ -19,11 +19,9 @@ #include "file_entry.h" #include "file_manager.h" #include "header.h" -#include "increment_manager.h" #include "resource_merge.h" #include "resource_table.h" #include "resource_check.h" -#include "preview_manager.h" namespace OHOS { namespace Global { @@ -35,10 +33,6 @@ ResourcePack::ResourcePack(const PackageParser &packageParser):packageParser_(pa uint32_t ResourcePack::Package() { - if (packageParser_.GetPreviewMode()) { - return PackPreview(); - } - if (!packageParser_.GetAppend().empty()) { return PackAppend(); } @@ -118,12 +112,6 @@ void ResourcePack::InitHeaderCreater() uint32_t ResourcePack::InitOutput() const { - string cachePath = packageParser_.GetCachePath(); - string indexPath = FileEntry::FilePath(cachePath).Append(IncrementManager::ID_JSON_FILE).GetPath(); - if (!cachePath.empty() && ResourceUtil::FileExist(indexPath)) { - return RESTOOL_SUCCESS; - } - bool forceWrite = packageParser_.GetForceWrite(); bool combine = packageParser_.GetCombine(); string output = packageParser_.GetOutput(); @@ -325,19 +313,7 @@ uint32_t ResourcePack::ScanResources(const vector &inputs, const string { auto &fileManager = FileManager::GetInstance(); fileManager.SetModuleName(moduleName_); - string cachePath = packageParser_.GetCachePath(); - if (cachePath.empty()) { - if (fileManager.ScanModules(inputs, output) != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } - return RESTOOL_SUCCESS; - } - - auto &incrementManager = IncrementManager::GetInstance(); - if (incrementManager.Init(cachePath, inputs, output, moduleName_) != RESTOOL_SUCCESS) { - return RESTOOL_ERROR; - } - if (fileManager.ScanIncrement(output) != RESTOOL_SUCCESS) { + if (fileManager.ScanModules(inputs, output) != RESTOOL_SUCCESS) { return RESTOOL_ERROR; } return RESTOOL_SUCCESS; @@ -565,13 +541,6 @@ void ResourcePack::SaveResourceItem(const ResourceItem &resourceItem, int32_t ne fileManager.MergeResourceItem(resInfo); } -uint32_t ResourcePack::PackPreview() -{ - PreviewManager preview; - preview.SetPriority(packageParser_.GetPriority()); - return preview.ScanModules(packageParser_.GetInputs(), packageParser_.GetOutput()); -} - uint32_t ResourcePack::PackAppend() { ResourceAppend resourceAppend(packageParser_); diff --git a/src/resource_util.cpp b/src/resource_util.cpp index efce845..5b8eb4d 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -137,8 +137,7 @@ string ResourceUtil::ResTypeToString(ResType type) string ResourceUtil::GetIdName(const string &name, ResType type) { - if (type != ResType::MEDIA && type != ResType::LAYOUT && type != ResType::PROF && - type != ResType::ANIMATION && type != ResType::GRAPHIC) { + if (type != ResType::MEDIA && type != ResType::PROF) { return name; } @@ -245,15 +244,6 @@ bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile) return false; } -bool ResourceUtil::NeedConverToSolidXml(ResType resType) -{ - if (resType == ResType::LAYOUT || resType == ResType::ANIMATION || - resType == ResType::GRAPHIC) { - return true; - } - return false; -} - string ResourceUtil::GenerateHash(const string &key) { hash hash_function; diff --git a/src/solid_xml_compiler.cpp b/src/solid_xml_compiler.cpp deleted file mode 100644 index fa4d893..0000000 --- a/src/solid_xml_compiler.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "solid_xml_compiler.h" -#include -#include -#include "resource_util.h" -#include "restool_errors.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -SolidXmlCompiler::SolidXmlCompiler(ResType type, const string &output) - : GenericCompiler(type, output) -{ -} - -SolidXmlCompiler::~SolidXmlCompiler() -{ -} - -uint32_t SolidXmlCompiler::CompileSingleFile(const FileInfo &fileInfo) -{ - if (!IsXmlFile(fileInfo)) { - cerr << "Error: '" << fileInfo.filePath << "' should be xml file." << endl; - return RESTOOL_ERROR; - } - - if (HasConvertedToSolidXml(fileInfo)) { - return RESTOOL_SUCCESS; - } - - if (!PostFile(fileInfo)) { - return RESTOOL_ERROR; - } - - if (!ParseXml(fileInfo)) { - return RESTOOL_ERROR; - } - return RESTOOL_SUCCESS; -} - -bool SolidXmlCompiler::ParseXml(const FileInfo &fileInfo) -{ - xmlKeepBlanksDefault(0); - xmlDocPtr doc = xmlParseFile(fileInfo.filePath.c_str()); - if (doc == nullptr) { - return false; - } - - vector ids; - bool result = ParseNodeId(fileInfo, xmlDocGetRootElement(doc), ids); - xmlFreeDoc(doc); - if (!result) { - return false; - } - - for (const auto &id : ids) { - ResourceItem resourceItem(id, fileInfo.keyParams, ResType::ID); - resourceItem.SetFilePath(fileInfo.filePath); - resourceItem.SetLimitKey(fileInfo.limitKey); - if (!MergeResourceItem(resourceItem)) { - return false; - } - } - return true; -} - -bool SolidXmlCompiler::ParseNodeId(const FileInfo &fileInfo, const xmlNodePtr &node, vector &ids) -{ - if (node == nullptr) { - return true; - } - - if (node->type == XML_COMMENT_NODE) { - return ParseNodeId(fileInfo, node->next, ids); - } - - string idValue; - xmlChar * xmlValue = xmlGetProp(node, BAD_CAST "id"); - if (xmlValue != nullptr) { - idValue = string(reinterpret_cast(xmlValue)); - xmlFree(xmlValue); - } - - regex ref("^\\$\\+id:"); - smatch result; - if (regex_search(idValue, result, ref)) { - string name = idValue.substr(result[0].str().size()); - if (find(ids.begin(), ids.end(), name) != ids.end()) { - cerr << "Error: '" << idValue << "' duplicated in " << fileInfo.filePath << endl; - return false; - } - ids.push_back(name); - } - - if (!ParseNodeId(fileInfo, node->children, ids)) { - return false; - } - - if (!ParseNodeId(fileInfo, node->next, ids)) { - return false; - } - return true; -} -} -} -} diff --git a/src/sqlite_database.cpp b/src/sqlite_database.cpp deleted file mode 100644 index bbd16dc..0000000 --- a/src/sqlite_database.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 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 - * - * 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. - */ - -#include "sqlite_database.h" -#include - -#include "resource_util.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -int32_t SqliteDatabase::id_ = 0; -void SqliteDatabase::Init(const string &dbPath) -{ - dbPath_ = dbPath; -} - -bool SqliteDatabase::OpenDatabase() -{ - int result = sqlite3_open(dbPath_.c_str(), &db_); - if (result) { - cerr << "Can't open database: " << sqlite3_errmsg(db_) << endl; - return false; - } - - if (!CreateTable()) { - return false; - } - - if (!FindMaxId()) { - return false; - } - return true; -} - -void SqliteDatabase::CloseDatabase() -{ - if (db_ == nullptr) { - return; - } - sqlite3_close(db_); - db_ = nullptr; -} - -bool SqliteDatabase::Insert(const ResourceItem &resourceItem) -{ - if (resourceItem.GetResType() == ResType::ID) { - return true; - } - - int32_t id = -1; - if (!Query(resourceItem, id)) { - return false; - } - - if (id >= 0) { - return true; - } - - string data = GetValue(resourceItem); - string sql = "insert into resource_index values(" + to_string(id_) + ",'" + resourceItem.GetName() + "','" + \ - data + "'," + \ - to_string((int32_t)resourceItem.GetResType()) + ",'" + resourceItem.GetFilePath() + \ - "','" + resourceItem.GetLimitKey() + "'," + to_string(priority_) + ")"; - auto callback = [](void *owner, int argc, char **argv, char **azColName) -> int { - return 0; - }; - - char *zErrMsg = 0; - int result = sqlite3_exec(db_, sql.c_str(), callback, nullptr, &zErrMsg); - if (result) { - cerr << "insert sql error: " << zErrMsg << endl; - sqlite3_free(zErrMsg); - return false; - } - id_++; - return true; -} - -bool SqliteDatabase::Query(const ResourceItem &resourceItem, int32_t &id) -{ - string sql = "select id from resource_index where name='" + resourceItem.GetName() + \ - "' and type='" + to_string((int32_t)resourceItem.GetResType()) + \ - "' and limitkey='" + resourceItem.GetLimitKey() + \ - "' and priority=" + to_string(priority_); - auto callback = [](void *id, int argc, char **argv, char **azColName) -> int { - if (argc > 0 && id) { - (*static_cast(id)) = atoi(argv[0]); - } - return 0; - }; - - id = -1; - char *zErrMsg = 0; - int result = sqlite3_exec(db_, sql.c_str(), callback, &id, &zErrMsg); - if (result) { - cerr << "query sql error: " << zErrMsg << endl; - sqlite3_free(zErrMsg); - return false; - } - - if (id < 0) { - return true; - } - - sql = "update resource_index set value='" + GetValue(resourceItem) + \ - "', path='" + resourceItem.GetFilePath() + \ - "' where id = " + to_string(id); - result = sqlite3_exec(db_, sql.c_str(), callback, nullptr, &zErrMsg); - if (result) { - cerr << "query sql error: " << zErrMsg << endl; - sqlite3_free(zErrMsg); - return false; - } - return true; -} - -bool SqliteDatabase::FindMaxId() -{ - string sql = "select max(id) from resource_index"; - auto callback = [](void *owner, int argc, char **argv, char **azColName) -> int { - if (argc > 0 && argv[0]) { - id_ = atoi(argv[0]) + 1; - } - return 0; - }; - - char *zErrMsg = 0; - int result = sqlite3_exec(db_, sql.c_str(), callback, nullptr, &zErrMsg); - if (result) { - cerr << "find max id sql error: " << zErrMsg << endl; - sqlite3_free(zErrMsg); - return false; - } - return true; -} - -bool SqliteDatabase::CreateTable() -{ - string sql = "select * from sqlite_master where name = 'resource_index'"; - auto callback = [](void *find, int argc, char **argv, char **azColName) -> int { - if (argc > 0 && find) { - (*static_cast(find)) = true; - } - return 0; - }; - - bool find = false; - char *zErrMsg = 0; - int result = sqlite3_exec(db_, sql.c_str(), callback, &find, &zErrMsg); - if (result) { - cerr << "search table error: " << zErrMsg << endl; - sqlite3_free(zErrMsg); - return false; - } - - if (find) { - return true; - } - - sql = "create table resource_index(id int, name, value image, type int, path, limitkey, priority int)"; - result = sqlite3_exec(db_, sql.c_str(), callback, nullptr, &zErrMsg); - if (result) { - cerr << "create table error: " << zErrMsg << endl; - sqlite3_free(zErrMsg); - return false; - } - return true; -} - -string SqliteDatabase::GetValue(const ResourceItem &resourceItem) const -{ - string data(reinterpret_cast(resourceItem.GetData()), resourceItem.GetDataLength()); - if (resourceItem.GetResType() == ResType::STRARRAY || resourceItem.GetResType() == ResType::INTARRAY || - resourceItem.GetResType() == ResType::THEME || resourceItem.GetResType() == ResType::PATTERN || - resourceItem.GetResType() == ResType::PLURAL) { - vector contents = ResourceUtil::DecomposeStrings(data); - Json::Value array(Json::arrayValue); - for (const auto &iter : contents) { - array.append(iter); - } - data = array.toStyledString(); - } - return data; -} -} -} -} diff --git a/src/xml/key_manager.cpp b/src/xml/key_manager.cpp deleted file mode 100644 index 8536357..0000000 --- a/src/xml/key_manager.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "key_manager.h" -#include "file_entry.h" -#include "resource_util.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -KeyManager::KeyManager() -{ - keys_.emplace(XmlKeyNode::KeyType::NODE, make_shared()); - keys_.emplace(XmlKeyNode::KeyType::ATTRIBUTE, make_shared()); - keys_.emplace(XmlKeyNode::KeyType::CONSTANT, make_shared()); - keys_.emplace(XmlKeyNode::KeyType::CONTENT, make_shared()); -} - -bool KeyManager::LoadKey(const string &keysPath) -{ - for (auto &key : keys_) { - string keyPath = FileEntry::FilePath(keysPath).Append(XmlKeyNode::KEY_TO_FILE_NAME.at(key.first)).GetPath(); - if (!ResourceUtil::FileExist(keyPath)) { - continue; - } - if (!key.second->LoadFromFile(keyPath)) { - return false; - } - } - return true; -} - -bool KeyManager::SaveKey(const string &keysPath) -{ - for (const auto &iter : keys_) { - string keyPath = FileEntry::FilePath(keysPath).Append(XmlKeyNode::KEY_TO_FILE_NAME.at(iter.first)).GetPath(); - if (!iter.second->SaveToFile(keyPath)) { - return false; - } - } - return true; -} -} -} -} \ No newline at end of file diff --git a/src/xml/solid_xml.cpp b/src/xml/solid_xml.cpp deleted file mode 100644 index afd72ff..0000000 --- a/src/xml/solid_xml.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "solid_xml.h" -#include -#include -#include "securec.h" -#include "resource_util.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -const uint8_t SolidXml::SOLID_XML_MAGIC[] = "SolidXml"; -const uint32_t SolidXml::SOLID_XML_MAGIC_LENGTH = - (sizeof(SolidXml::SOLID_XML_MAGIC) / sizeof(uint32_t) + 1) * sizeof(uint32_t); - -SolidXml::SolidXml(const string &xmlPath, map> &keys) - : xmlPath_(xmlPath), keys_(keys) -{ -} - -SolidXml::~SolidXml() -{ -} - -bool SolidXml::GenerateSolidXml(const string &filePath) -{ - xmlKeepBlanksDefault(0); - xmlDocPtr doc = xmlParseFile(xmlPath_.c_str()); - if (doc == nullptr) { - return false; - } - - xmlNodePtr rootNode = xmlDocGetRootElement(doc); - if (rootNode == nullptr) { - xmlFreeDoc(doc); - return false; - } - auto root = make_shared(); - nodes_.push_back(root); - Compile(rootNode, root); - xmlFreeDoc(doc); - return SaveToFile(filePath); -} - -bool SolidXml::FlushNodeKeys(const string &filePath, map> &newKeys) -{ - if (!LoadFromFile(xmlPath_)) { - cerr << "Error: load " << xmlPath_ << " fail." << endl; - return false; - } - - bool firstNode = true; - for (auto &node : nodes_) { - if (!node->FlushIndex(keys_, newKeys)) { - cerr << "Error: flush node key fail, '" << xmlPath_ << "'" << endl; - return false; - } - if (firstNode && !FlushXmlnsKey(newKeys)) { - return false; - } - firstNode = false; - } - - for (auto &attr : attributes_) { - if (!attr->FlushIndex(keys_, newKeys)) { - cerr << "Error: flush attibutes key fail, '" << xmlPath_ << "'" << endl; - return false; - } - } - return SaveToFile(filePath); -} - -// below private -void SolidXml::Compile(const xmlNodePtr nodePtr, shared_ptr &node) -{ - if (nodePtr->type == XML_COMMENT_NODE) { - if (nodePtr->next) { - Compile(nodePtr->next, node); - } - return; - } - - string name(reinterpret_cast(nodePtr->name)); - node->SetName(keys_[XmlKeyNode::KeyType::NODE]->PushKey(name)); - CompileNameSpace(nodePtr, node); - CompileAttr(nodePtr->properties, node); - - if (nodePtr->children) { - if (nodePtr->children->type == XML_TEXT_NODE) { - string content(reinterpret_cast(nodePtr->children->content)); - node->SetValue(keys_[XmlKeyNode::KeyType::CONTENT]->PushKey(content)); - } else { - auto child = make_shared(); - nodes_.push_back(child); - node->SetChild(nodes_.size() - 1); - Compile(nodePtr->children, child); - } - } - - if (nodePtr->next) { - auto brother = make_shared(); - nodes_.push_back(brother); - node->SetBrother(nodes_.size() - 1); - Compile(nodePtr->next, brother); - } -} - -void SolidXml::CompileAttr(const xmlAttrPtr attrPtr, shared_ptr &node) -{ - if (attrPtr == nullptr) { - return; - } - - xmlChar *xmlValue = xmlNodeListGetString(attrPtr->doc, attrPtr->children, 1); - string value(reinterpret_cast(xmlValue)); - PretreatmentAttr(value); - xmlFree(xmlValue); - string name(reinterpret_cast(attrPtr->name)); - auto attr = make_shared(); - attributes_.push_back(attr); - attr->SetName(keys_[XmlKeyNode::KeyType::ATTRIBUTE]->PushKey(name)); - attr->SetValue(keys_[XmlKeyNode::KeyType::CONSTANT]->PushKey(value)); - if (attrPtr->ns != nullptr && attrPtr->ns->prefix != nullptr) { - string nameSpace(reinterpret_cast(attrPtr->ns->prefix)); - attr->SetNameSpace(keys_[XmlKeyNode::KeyType::NODE]->PushKey(nameSpace)); - } - node->AddAttribute(attributes_.size() - 1); - CompileAttr(attrPtr->next, node); -} - -void SolidXml::CompileNameSpace(const xmlNodePtr nodePtr, shared_ptr &node) -{ - if (nodePtr->ns && nodePtr->ns->prefix) { - string nameSpace(reinterpret_cast(nodePtr->ns->prefix)); - node->SetNameSpace(keys_[XmlKeyNode::KeyType::NODE]->PushKey(nameSpace)); - } - - auto nsDef = nodePtr->nsDef; - while (nsDef) { - string nameSpace; - string href; - if (nsDef->prefix) { - nameSpace = string(reinterpret_cast(nsDef->prefix)); - } - if (nsDef->href) { - href = string(reinterpret_cast(nsDef->href)); - } - int32_t nameSpaceIndex = keys_[XmlKeyNode::KeyType::NODE]->PushKey(nameSpace); - int32_t herfIndex = keys_[XmlKeyNode::KeyType::NODE]->PushKey(href); - AddNampeSpaceDef(nameSpaceIndex, herfIndex); - nsDef = nsDef->next; - } -} - -void SolidXml::Node::RawData(ofstream &out) const -{ - out.write(reinterpret_cast(&nameSpace_), sizeof(int32_t)); - out.write(reinterpret_cast(&name_), sizeof(int32_t)); - out.write(reinterpret_cast(&value_), sizeof(int32_t)); -} - -void SolidXml::XmlNode::RawData(ofstream &out) const -{ - SolidXml::Node::RawData(out); - out.write(reinterpret_cast(&child_), sizeof(int32_t)); - out.write(reinterpret_cast(&brother_), sizeof(int32_t)); - int32_t attrStart = attributes_.size(); - int32_t attrCount = attributes_.size(); - if (!attributes_.empty()) { - attrStart = attributes_.at(0); - } - out.write(reinterpret_cast(&attrStart), sizeof(int32_t)); - out.write(reinterpret_cast(&attrCount), sizeof(int32_t)); -} - -bool SolidXml::Node::LoadFrom(ifstream &in) -{ - CHECK_IO(in.read(reinterpret_cast(&nameSpace_), sizeof(int32_t))) - CHECK_IO(in.read(reinterpret_cast(&name_), sizeof(int32_t))); - CHECK_IO(in.read(reinterpret_cast(&value_), sizeof(int32_t))); - return true; -} - -bool SolidXml::XmlNode::LoadFrom(ifstream &in) -{ - if (!SolidXml::Node::LoadFrom(in)) { - return false; - } - CHECK_IO(in.read(reinterpret_cast(&child_), sizeof(int32_t))); - CHECK_IO(in.read(reinterpret_cast(&brother_), sizeof(int32_t))); - int32_t attrStart = 0; - int32_t attrCount = 0; - CHECK_IO(in.read(reinterpret_cast(&attrStart), sizeof(int32_t))); - CHECK_IO(in.read(reinterpret_cast(&attrCount), sizeof(int32_t))); - for (int32_t i = attrStart; i < attrStart + attrCount; i++) { - attributes_.push_back(i); - } - return true; -} - -bool SolidXml::Node::FlushIndex(const map> &oldKeys, - map> &newKeys) -{ - if (!ChangeToNewKey(oldKeys, newKeys, XmlKeyNode::KeyType::NODE, nameSpace_) || - !ChangeToNewKey(oldKeys, newKeys, XmlKeyNode::KeyType::ATTRIBUTE, name_) || - !ChangeToNewKey(oldKeys, newKeys, XmlKeyNode::KeyType::CONSTANT, value_)) { - return false; - } - return true; -} - -bool SolidXml::XmlNode::FlushIndex(const map> &oldKeys, - map> &newKeys) -{ - if (!ChangeToNewKey(oldKeys, newKeys, XmlKeyNode::KeyType::NODE, nameSpace_) || - !ChangeToNewKey(oldKeys, newKeys, XmlKeyNode::KeyType::NODE, name_) || - !ChangeToNewKey(oldKeys, newKeys, XmlKeyNode::KeyType::CONTENT, value_)) { - return false; - } - return true; -} - -void SolidXml::AddNampeSpaceDef(int32_t nameSpace, int32_t href) -{ - nameSpaces_.push_back(nameSpace); - hrefs_.push_back(href); -} - -bool SolidXml::SaveToFile(const std::string &filePath) const -{ - ofstream out(filePath, ofstream::out | ofstream::binary); - if (!out.is_open()) { - cerr << "Error: open failed '" << filePath << "', reason: " << strerror(errno) << endl; - return false; - } - - // write solid xml header - uint8_t magic[SOLID_XML_MAGIC_LENGTH] = {0}; - if (memcpy_s(magic, SOLID_XML_MAGIC_LENGTH, SOLID_XML_MAGIC, sizeof(SOLID_XML_MAGIC)) != EOK) { - cerr << "Error: SolidXml::SaveToFile memcpy_s fail." << endl; - return false; - } - uint32_t version = 1; - uint32_t numOfNodes = nodes_.size(); - uint32_t numOfAttributes = attributes_.size(); - uint32_t numOfNameSpaces = nameSpaces_.size(); - out.write(reinterpret_cast(magic), SOLID_XML_MAGIC_LENGTH); - out.write(reinterpret_cast(&version), sizeof(uint32_t)); - out.write(reinterpret_cast(&numOfNodes), sizeof(uint32_t)); - out.write(reinterpret_cast(&numOfAttributes), sizeof(uint32_t)); - out.write(reinterpret_cast(&numOfNameSpaces), sizeof(uint32_t)); - - // write node - for (const auto &node : nodes_) { - node->RawData(out); - } - - // write attribute - for (const auto &attribute : attributes_) { - attribute->RawData(out); - } - - // write namespace - for (const auto &nameSpace : nameSpaces_) { - out.write(reinterpret_cast(&nameSpace), sizeof(int32_t)); - } - - // write href - for (const auto &href : hrefs_) { - out.write(reinterpret_cast(&href), sizeof(int32_t)); - } - return true; -} - -void SolidXml::PretreatmentAttr(string &value) const -{ - regex ref("^\\$\\+id:"); - smatch result; - if (!regex_search(value, result, ref)) { - return; - } - value.replace(0, result[0].str().length(), "$id:"); -} - -bool SolidXml::LoadFromFile(const string &sxmlPath) -{ - ifstream in(sxmlPath, ifstream::in | ifstream::binary); - if (!in.is_open()) { - cerr << "Error: open failed '" << sxmlPath << "', reason: " << strerror(errno) << endl; - return false; - } - - char header[SOLID_XML_MAGIC_LENGTH]; - CHECK_IO(in.read(header, SOLID_XML_MAGIC_LENGTH)); - - uint32_t version = 0; - CHECK_IO(in.read(reinterpret_cast(&version), sizeof(uint32_t))); - - uint32_t numOfNodes = 0; - CHECK_IO(in.read(reinterpret_cast(&numOfNodes), sizeof(uint32_t))); - - uint32_t numOfAttributes = 0; - CHECK_IO(in.read(reinterpret_cast(&numOfAttributes), sizeof(uint32_t))); - - uint32_t numOfNameSpaces = 0; - CHECK_IO(in.read(reinterpret_cast(&numOfNameSpaces), sizeof(uint32_t))); - - for (uint32_t i = 0; i < numOfNodes; i++) { - auto xmlNode = make_shared(); - if (!xmlNode->LoadFrom(in)) { - return false; - } - nodes_.push_back(xmlNode); - } - - for (uint32_t i = 0; i < numOfAttributes; i++) { - auto attr = make_shared(); - if (!attr->LoadFrom(in)) { - return false; - } - attributes_.push_back(attr); - } - - for (uint32_t i = 0; i < numOfNameSpaces; i++) { - int32_t nameSpace = -1; - CHECK_IO(in.read(reinterpret_cast(&nameSpace), sizeof(int32_t))); - nameSpaces_.push_back(nameSpace); - } - - for (uint32_t i = 0; i < numOfNameSpaces; i++) { - int32_t href = -1; - CHECK_IO(in.read(reinterpret_cast(&href), sizeof(int32_t))); - hrefs_.push_back(href); - } - return true; -} - -bool SolidXml::ChangeToNewKey(const map> &oldKeys, - map> &newKeys, - XmlKeyNode::KeyType keyType, int32_t &keyId) -{ - if (keyId <= 0) { - return true; - } - - string value; - if (!oldKeys.at(keyType)->GetKeyValue(keyId, value)) { - return false; - } - - keyId = newKeys[keyType]->PushKey(value); - return true; -} - -bool SolidXml::FlushXmlnsKey(map> &newKeys) -{ - if (nameSpaces_.size() != hrefs_.size()) { - return false; - } - - for (uint32_t i = 0; i < nameSpaces_.size(); i++) { - if (!ChangeToNewKey(keys_, newKeys, XmlKeyNode::KeyType::NODE, nameSpaces_[i]) || - !ChangeToNewKey(keys_, newKeys, XmlKeyNode::KeyType::NODE, hrefs_[i])) { - cerr << "Error: flush namespace key fail, '" << xmlPath_ << "'" << endl; - return false; - } - } - return true; -} -} -} -} diff --git a/src/xml/xml_converter.cpp b/src/xml/xml_converter.cpp deleted file mode 100644 index 4307a25..0000000 --- a/src/xml/xml_converter.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "xml_converter.h" -#include "file_entry.h" -#include "resource_util.h" -#include "solid_xml.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -XmlConverter::XmlConverter(const vector &xmlPaths, const string &outputPath) - : xmlPaths_(xmlPaths), outputPath_(outputPath) -{ -} - -XmlConverter::~XmlConverter() -{ -} - -bool XmlConverter::GenerateSolidXml() -{ - if (!LoadKeys(outputPath_)) { - return false; - } - for (const auto &xmlPath : xmlPaths_) { - SolidXml solidXml(xmlPath, keyManager.GetKeys()); - string filename = FileEntry::FilePath(xmlPath).GetFilename(); - string filePath = FileEntry::FilePath(outputPath_).Append(filename).ReplaceExtension(".sxml").GetPath(); - if (!solidXml.GenerateSolidXml(filePath)) { - return false; - } - } - return true; -} - -bool XmlConverter::GenerateKey() -{ - return keyManager.SaveKey(outputPath_); -} - -bool XmlConverter::LoadKeys(const std::string &folderPath) -{ - return keyManager.LoadKey(folderPath); -} -} -} -} diff --git a/src/xml/xml_key_node.cpp b/src/xml/xml_key_node.cpp deleted file mode 100644 index c9cceed..0000000 --- a/src/xml/xml_key_node.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2021 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 - * - * 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. - */ - -#include "xml_key_node.h" -#include -#include -#include -#include -#include "resource_util.h" - -namespace OHOS { -namespace Global { -namespace Restool { -using namespace std; -const map XmlKeyNode::KEY_TO_FILE_NAME = { - {KeyType::NODE, "nodes.key" }, - {KeyType::ATTRIBUTE, "attributes.key" }, - {KeyType::CONSTANT, "constants.key" }, - {KeyType::CONTENT, "contents.key" } -}; -XmlKeyNode::XmlKeyNode() : keyId_(0) -{ - PushKey(""); -} - -XmlKeyNode::~XmlKeyNode() -{ -} - -int32_t XmlKeyNode::PushKey(const string &name) -{ - auto result = keyMap_.emplace(name, keyId_); - if (result.second) { - return keyId_++; - } - return result.first->second; -} - -bool XmlKeyNode::SaveToFile(const string &filePath) const -{ - ofstream out(filePath, ofstream::out | ofstream::binary); - if (!out.is_open()) { - cerr << "Error: open failed '" << filePath << "', reason: " << strerror(errno) << endl; - return false; - } - - vector> sets(keyMap_.begin(), keyMap_.end()); - sort(sets.begin(), sets.end(), [](const auto &a, const auto &b) { - return a.second < b.second; - }); - - char null = 0; - for (const auto &iter : sets) { - out.write(reinterpret_cast(iter.first.c_str()), iter.first.length()); - out.write(&null, sizeof(char)); - } - return true; -} - -bool XmlKeyNode::LoadFromFile(const string &filePath) -{ - return LoadFromFile(filePath, nullptr); -} - -bool XmlKeyNode::LoadFromFile(const std::string &filePath, RefParser parser) -{ - ifstream in(filePath, ifstream::in | ifstream::binary); - if (!in.is_open()) { - cerr << "Error: open failed '" << filePath << "', reason: " << strerror(errno) << endl; - return false; - } - - string inputLine; - getline(in, inputLine); - if (inputLine.empty()) { - return true; - } - - string::size_type offset = 0; - while (offset < inputLine.length()) { - string item(inputLine.c_str() + offset); - offset = offset + item.length() + sizeof(char); - if (parser && !parser(item)) { - return false; - } - PushKey(item); - } - return true; -} - -bool XmlKeyNode::GetKeyValue(int32_t keyId, std::string &value) const -{ - auto result = find_if(keyMap_.begin(), keyMap_.end(), [&keyId](const auto &iter) { - return keyId == iter.second; - }); - if (result == keyMap_.end()) { - return false; - } - value = result->first; - return true; -} -} -} -} \ No newline at end of file