1 /* 2 * Copyright (c) 2021 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_PACK_H 17 #define OHOS_RESTOOL_RESOURCE_PACK_H 18 19 #include "cmd_parser.h" 20 #include "config_parser.h" 21 #include "resource_util.h" 22 #include "resource_item.h" 23 #include "resource_data.h" 24 25 namespace OHOS { 26 namespace Global { 27 namespace Restool { 28 class ResourcePack { 29 public: 30 explicit ResourcePack(const PackageParser &packageParser); 31 virtual ~ResourcePack() = default; 32 uint32_t Package(); 33 34 private: 35 uint32_t Init(); 36 uint32_t InitModule(); 37 void InitHeaderCreater(); 38 uint32_t InitOutput() const; 39 uint32_t GenerateHeader() const; 40 uint32_t InitConfigJson(); 41 uint32_t GenerateTextHeader(const std::string &headerPath) const; 42 uint32_t GenerateCplusHeader(const std::string &headerPath) const; 43 uint32_t GenerateJsHeader(const std::string &headerPath) const; 44 uint32_t CopyRawFile(const std::vector<std::string> &inputs) const; 45 uint32_t CopyRawFileImpl(const std::string &src, const std::string &dst) const; 46 uint32_t GenerateConfigJson(); 47 uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output); 48 uint32_t HandleFeature(); 49 uint32_t FindResourceItems(const std::map<int32_t, std::vector<ResourceItem>> &resInfoLocal, 50 std::vector<ResourceItem> &items, int32_t id) const; 51 uint32_t HandleLabel(std::vector<ResourceItem> &items, ConfigParser &config) const; 52 uint32_t HandleIcon(std::vector<ResourceItem> &items, ConfigParser &config) const; 53 void SaveResourceItem(const ResourceItem &resourceItem, int32_t nextId) const; 54 bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const; 55 PackageParser packageParser_; 56 std::string moduleName_; 57 using HeaderCreater = std::function<uint32_t(const std::string&)>; 58 std::map<std::string, HeaderCreater> headerCreaters_; 59 ConfigParser configJson_; 60 }; 61 } 62 } 63 } 64 #endif