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 "file_manager.h"
17 #include <algorithm>
18 #include <iostream>
19 #include "factory_resource_compiler.h"
20 #include "file_entry.h"
21 #include "key_parser.h"
22 #include "reference_parser.h"
23 #include "resource_directory.h"
24 #include "resource_util.h"
25 #include "restool_errors.h"
26 #include "resource_module.h"
27
28 namespace OHOS {
29 namespace Global {
30 namespace Restool {
31 using namespace std;
ScanModules(const vector<string> & inputs,const string & output)32 uint32_t FileManager::ScanModules(const vector<string> &inputs, const string &output)
33 {
34 for (auto input : inputs) {
35 map<ResType, vector<DirectoryInfo>> resTypeOfDirs;
36 if (ScanModule(input, output, resTypeOfDirs) != RESTOOL_SUCCESS) {
37 return RESTOOL_ERROR;
38 }
39 }
40 return ParseReference(output);
41 }
42
MergeResourceItem(const map<int32_t,vector<ResourceItem>> & resourceInfos)43 uint32_t FileManager::MergeResourceItem(const map<int32_t, vector<ResourceItem>> &resourceInfos)
44 {
45 return ResourceModule::MergeResourceItem(items_, resourceInfos);
46 }
47
48 // below private founction
ScanModule(const string & input,const string & output,map<ResType,vector<DirectoryInfo>> & resTypeOfDirs)49 uint32_t FileManager::ScanModule(const string &input, const string &output,
50 map<ResType, vector<DirectoryInfo>> &resTypeOfDirs)
51 {
52 ResourceModule resourceModule(input, output, moduleName_);
53 if (resourceModule.ScanResource() != RESTOOL_SUCCESS) {
54 return RESTOOL_ERROR;
55 }
56 resTypeOfDirs = resourceModule.GetScanDirectorys();
57 MergeResourceItem(resourceModule.GetOwner());
58 return RESTOOL_SUCCESS;
59 }
60
ParseReference(const string & output)61 uint32_t FileManager::ParseReference(const string &output)
62 {
63 ReferenceParser referenceParser;
64 if (referenceParser.ParseRefInResources(items_, output) != RESTOOL_SUCCESS) {
65 return RESTOOL_ERROR;
66 }
67 return RESTOOL_SUCCESS;
68 }
69 }
70 }
71 }
72