• 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 "config_parser.h"
20 #include "resource_append.h"
21 #include "resource_data.h"
22 #include "resource_item.h"
23 #include "resource_merge.h"
24 #include "resource_util.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     virtual uint32_t Pack();
35 
36 protected:
37     uint32_t InitResourcePack();
38     uint32_t PackResources(const ResourceMerge &resourceMerge);
39     virtual uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
40     PackageParser packageParser_;
41     std::string moduleName_;
42     ConfigParser configJson_;
43 
44 private:
45     uint32_t InitModule();
46     void InitHeaderCreater();
47     uint32_t InitOutput() const;
48     uint32_t InitCompression();
49     uint32_t GenerateHeader() const;
50     uint32_t InitConfigJson();
51     uint32_t GenerateTextHeader(const std::string &headerPath) const;
52     uint32_t GenerateCplusHeader(const std::string &headerPath) const;
53     uint32_t GenerateJsHeader(const std::string &headerPath) const;
54     uint32_t GenerateConfigJson();
55     uint32_t PackPreview();
56     uint32_t PackAppend();
57     uint32_t PackCombine();
58     uint32_t HandleFeature();
59     uint32_t FindResourceItems(const std::map<int64_t, std::vector<ResourceItem>> &resInfoLocal,
60                                std::vector<ResourceItem> &items, int64_t id) const;
61     uint32_t HandleLabel(std::vector<ResourceItem> &items, ConfigParser &config) const;
62     uint32_t HandleIcon(std::vector<ResourceItem> &items, ConfigParser &config) const;
63     void SaveResourceItem(const ResourceItem &resourceItem, int64_t nextId) const;
64     void CheckConfigJson();
65     void CheckConfigJsonForCombine(ResourceAppend &resourceAppend);
66     bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const;
67     void ShowPackSuccess();
68 
69     using HeaderCreater = std::function<uint32_t(const std::string&)>;
70     std::map<std::string, HeaderCreater> headerCreaters_;
71     PackType packType_ = PackType::NORMAL;
72 };
73 }
74 }
75 }
76 #endif