1 /* 2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_RESTOOL_RESOURCE_DUMP_H 17 #define OHOS_RESTOOL_RESOURCE_DUMP_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <map> 22 #include <memory> 23 #include <set> 24 #include <vector> 25 #include "config_parser.h" 26 #include "unzip.h" 27 #include "cJSON.h" 28 #include "cmd/dump_parser.h" 29 #include "resource_data.h" 30 #include "resource_item.h" 31 32 33 namespace OHOS { 34 namespace Global { 35 namespace Restool { 36 class ResourceDumper { 37 public: 38 virtual ~ResourceDumper() = default; 39 virtual uint32_t Dump(const DumpParserBase &parser); 40 protected: 41 virtual uint32_t DumpRes(std::string &out) const = 0; 42 void ReadHapInfo(const std::unique_ptr<char[]> &buffer, size_t len); 43 uint32_t LoadHap(); 44 uint32_t ReadFileFromZip(unzFile &zip, const char *fileName, std::unique_ptr<char[]> &buffer, size_t &len); 45 46 std::string inputPath_; 47 std::string bundleName_; 48 std::string moduleName_; 49 std::map<int64_t, std::vector<ResourceItem>> resInfos_; 50 }; 51 52 class ConfigDumper : public ResourceDumper { 53 public: 54 virtual ~ConfigDumper() = default; 55 uint32_t DumpRes(std::string &out) const override; 56 }; 57 58 59 class CommonDumper : public ResourceDumper { 60 public: 61 virtual ~CommonDumper() = default; 62 uint32_t DumpRes(std::string &out) const override; 63 64 private: 65 uint32_t AddValueToJson(const ResourceItem &item, cJSON *json) const; 66 uint32_t AddPairVauleToJson(const ResourceItem &item, cJSON *json) const; 67 uint32_t AddKeyParamsToJson(const std::vector<KeyParam> &keyParams, cJSON *json) const; 68 uint32_t AddResourceToJson(int64_t id, const std::vector<ResourceItem> &items, cJSON *json) const; 69 uint32_t AddItemCommonPropToJson(int32_t resId, const ResourceItem &item, cJSON* json) const; 70 }; 71 72 } // namespace Restool 73 } // namespace Global 74 } // namespace OHOS 75 76 #endif