• 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::SHARED,
29     ConfigParser::ModuleType::HAR
30 };
31 
ResourceMerge()32 ResourceMerge::ResourceMerge()
33 {
34 }
35 
~ResourceMerge()36 ResourceMerge::~ResourceMerge()
37 {
38 }
39 
Init()40 uint32_t ResourceMerge::Init()
41 {
42     auto &cmdParser = CmdParser<PackageParser>::GetInstance().GetCmdParser();
43     const vector<string> &inputs = cmdParser.GetInputs();
44     if (cmdParser.IsFileList()) {
45         inputsOrder_ = inputs;
46         return RESTOOL_SUCCESS;
47     }
48 
49     map<ConfigParser::ModuleType, vector<string>> inputTypes;
50     for (auto it = inputs.crbegin(); it != inputs.crend(); it++) {
51         string filePath = FileEntry::FilePath(*it).Append(ConfigParser::GetConfigName()).GetPath();
52         string resourceDir = FileEntry::FilePath(*it).Append(RESOURCES_DIR).GetPath();
53         ConfigParser::ModuleType moduleType = ConfigParser::ModuleType::NONE;
54         if (!ResourceUtil::FileExist(filePath)) {
55             inputTypes[moduleType].push_back(resourceDir);
56             continue;
57         }
58         ConfigParser configParser(filePath);
59         if (configParser.Init() != RESTOOL_SUCCESS) {
60             return RESTOOL_ERROR;
61         }
62         moduleType = configParser.GetModuleType();
63         inputTypes[moduleType].push_back(resourceDir);
64     }
65 
66     for (const auto &type : ORDERS) {
67         if (inputTypes.find(type) == inputTypes.end()) {
68             continue;
69         }
70         inputsOrder_.insert(inputsOrder_.end(), inputTypes[type].begin(), inputTypes[type].end());
71     }
72     return RESTOOL_SUCCESS;
73 }
74 
GetInputs() const75 const vector<string> &ResourceMerge::GetInputs() const
76 {
77     return inputsOrder_;
78 }
79 }
80 }
81 }