• 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 #include "resource_merge.h"
17 #include "cmd_parser.h"
18 #include "file_entry.h"
19 
20 namespace OHOS {
21 namespace Global {
22 namespace Restool {
23 using namespace std;
24 const vector<ConfigParser::ModuleType> ResourceMerge::ORDERS = {
25     ConfigParser::ModuleType::NONE,
26     ConfigParser::ModuleType::ENTRY,
27     ConfigParser::ModuleType::FEATURE,
28     ConfigParser::ModuleType::HAR
29 };
30 
ResourceMerge()31 ResourceMerge::ResourceMerge()
32 {
33 }
34 
~ResourceMerge()35 ResourceMerge::~ResourceMerge()
36 {
37 }
38 
Init()39 uint32_t ResourceMerge::Init()
40 {
41     auto &cmdParser = CmdParser<PackageParser>::GetInstance().GetCmdParser();
42     const vector<string> &inputs = cmdParser.GetInputs();
43     if (cmdParser.IsFileList()) {
44         inputsOrder_ = inputs;
45         return RESTOOL_SUCCESS;
46     }
47 
48     map<ConfigParser::ModuleType, vector<string>> inputTypes;
49     for (auto it = inputs.crbegin(); it != inputs.crend(); it++) {
50         string filePath = FileEntry::FilePath(*it).Append(ConfigParser::GetConfigName()).GetPath();
51         string resourceDir = FileEntry::FilePath(*it).Append(RESOURCES_DIR).GetPath();
52         ConfigParser::ModuleType moduleType = ConfigParser::ModuleType::NONE;
53         if (!ResourceUtil::FileExist(filePath)) {
54             inputTypes[moduleType].push_back(resourceDir);
55             continue;
56         }
57         ConfigParser configParser(filePath);
58         if (configParser.Init() != RESTOOL_SUCCESS) {
59             return RESTOOL_ERROR;
60         }
61         moduleType = configParser.GetModuleType();
62         inputTypes[moduleType].push_back(resourceDir);
63     }
64 
65     for (const auto &type : ORDERS) {
66         if (inputTypes.find(type) == inputTypes.end()) {
67             continue;
68         }
69         inputsOrder_.insert(inputsOrder_.end(), inputTypes[type].begin(), inputTypes[type].end());
70     }
71     return RESTOOL_SUCCESS;
72 }
73 
GetInputs() const74 const vector<string> &ResourceMerge::GetInputs() const
75 {
76     return inputsOrder_;
77 }
78 }
79 }
80 }