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