• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GenerateHeader() const;
41     uint32_t InitConfigJson();
42     uint32_t GenerateTextHeader(const std::string &headerPath) const;
43     uint32_t GenerateCplusHeader(const std::string &headerPath) const;
44     uint32_t GenerateJsHeader(const std::string &headerPath) const;
45     uint32_t CopyRawFile(const std::vector<std::string> &inputs) const;
46     uint32_t CopyRawFileImpl(const std::string &src, const std::string &dst) 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 HandleFeature();
54     uint32_t FindResourceItems(const std::map<int32_t, std::vector<ResourceItem>> &resInfoLocal,
55                                std::vector<ResourceItem> &items, int32_t id) const;
56     uint32_t HandleLabel(std::vector<ResourceItem> &items, ConfigParser &config) const;
57     uint32_t HandleIcon(std::vector<ResourceItem> &items, ConfigParser &config) const;
58     void SaveResourceItem(const ResourceItem &resourceItem, int32_t nextId) const;
59     void CheckConfigJson();
60     void CheckConfigJsonForCombine(ResourceAppend &resourceAppend);
61     bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const;
62     PackageParser packageParser_;
63     std::string moduleName_;
64     using HeaderCreater = std::function<uint32_t(const std::string&)>;
65     std::map<std::string, HeaderCreater> headerCreaters_;
66     ConfigParser configJson_;
67 };
68 }
69 }
70 }
71 #endif