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 #include "resource_append.h" 25 26 namespace OHOS { 27 namespace Global { 28 namespace Restool { 29 class ResourcePack { 30 public: 31 explicit ResourcePack(const PackageParser &packageParser); 32 virtual ~ResourcePack() = default; 33 uint32_t Package(); 34 35 private: 36 uint32_t Init(); 37 uint32_t InitModule(); 38 void InitHeaderCreater(); 39 uint32_t InitOutput() const; 40 uint32_t InitCompression(); 41 uint32_t GenerateHeader() const; 42 uint32_t InitConfigJson(); 43 uint32_t GenerateTextHeader(const std::string &headerPath) const; 44 uint32_t GenerateCplusHeader(const std::string &headerPath) const; 45 uint32_t GenerateJsHeader(const std::string &headerPath) const; 46 uint32_t CopyRawFileOrResFile(const std::string &filePath, const std::string &fileType); 47 uint32_t CopyRawFileOrResFile(const std::vector<std::string> &inputs); 48 uint32_t CopyRawFileOrResFileImpl(const std::string &src, const std::string &dst); 49 uint32_t GenerateConfigJson(); 50 uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output); 51 uint32_t PackNormal(); 52 uint32_t PackPreview(); 53 uint32_t PackAppend(); 54 uint32_t PackCombine(); 55 uint32_t HandleFeature(); 56 uint32_t FindResourceItems(const std::map<int64_t, std::vector<ResourceItem>> &resInfoLocal, 57 std::vector<ResourceItem> &items, int64_t id) const; 58 uint32_t HandleLabel(std::vector<ResourceItem> &items, ConfigParser &config) const; 59 uint32_t HandleIcon(std::vector<ResourceItem> &items, ConfigParser &config) const; 60 void SaveResourceItem(const ResourceItem &resourceItem, int64_t nextId) const; 61 void CheckConfigJson(); 62 void CheckConfigJsonForCombine(ResourceAppend &resourceAppend); 63 bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const; 64 PackageParser packageParser_; 65 std::string moduleName_; 66 using HeaderCreater = std::function<uint32_t(const std::string&)>; 67 std::map<std::string, HeaderCreater> headerCreaters_; 68 ConfigParser configJson_; 69 }; 70 } 71 } 72 } 73 #endif