• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "append_compiler.h"
17 #include <iostream>
18 #include "restool_errors.h"
19 
20 namespace OHOS {
21 namespace Global {
22 namespace Restool {
23 using namespace std;
AppendCompiler(ResType type,const string & output)24 AppendCompiler::AppendCompiler(ResType type, const string &output) : IResourceCompiler(type, output)
25 {
26 }
27 
CompileSingleFile(const FileInfo & fileInfo)28 uint32_t AppendCompiler::CompileSingleFile(const FileInfo &fileInfo)
29 {
30     ResourceItem resourceItem(fileInfo.filename, fileInfo.keyParams, type_);
31     resourceItem.SetFilePath(fileInfo.filePath);
32     resourceItem.SetLimitKey(fileInfo.limitKey);
33 
34     string data = fileInfo.filePath;
35     if (!resourceItem.SetData(reinterpret_cast<const int8_t *>(data.c_str()), data.length())) {
36         std::string msg = "item data is null, resource name: " + resourceItem.GetName();
37         PrintError(GetError(ERR_CODE_UNDEFINED_ERROR).FormatCause(msg.c_str()).SetPosition(fileInfo.filePath));
38         return RESTOOL_ERROR;
39     }
40 
41     if (!MergeResourceItem(resourceItem)) {
42         return RESTOOL_ERROR;
43     }
44     return RESTOOL_SUCCESS;
45 }
46 }
47 }
48 }