1 /*
2 * Copyright (c) 2024 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 <iostream>
17 #include <ostream>
18 #include <string>
19
20 #include "hsp_packager.h"
21 #include "constants.h"
22 #include "packager.h"
23
24 namespace OHOS {
25 namespace AppPackingTool {
26 namespace {}
27
HspPackager(const std::map<std::string,std::string> & parameterMap,std::string & resultReceiver)28 HspPackager::HspPackager(const std::map<std::string, std::string> ¶meterMap, std::string &resultReceiver)
29 : Packager(parameterMap, resultReceiver)
30 {}
31
InitAllowedParam()32 int HspPackager::InitAllowedParam()
33 {
34 return ERR_OK;
35 }
PreProcess()36 int HspPackager::PreProcess()
37 {
38 return ERR_OK;
39 }
Process()40 int HspPackager::Process()
41 {
42 std::cout << "Hsp DoPackage" << std::endl;
43 std::string outPath = parameterMap_.at(Constants::PARAM_OUT_PATH);
44 zipFile zf = zipOpen64(outPath.c_str(), APPEND_STATUS_CREATE);
45 if (zf == nullptr) {
46 std::cout << "err zipOpen64 null" << std::endl;
47 return ERR_INVALID_VALUE;
48 }
49 zip_fileinfo fi = {};
50 std::map<std::string, std::string>::const_iterator it = parameterMap_.find(Constants::PARAM_JSON_PATH);
51 if (it != parameterMap_.end()) {
52 if (ParseJsonFile(moduleJson, it->second)) {
53 WriteStringToZip(zf, moduleJson.dump(), fs::path(Constants::MODULE_JSON), fi);
54 }
55 }
56 it = parameterMap_.find(Constants::PARAM_LIB_PATH);
57 if (it != parameterMap_.end()) {
58 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::LIB_PATH), fi);
59 }
60 it = parameterMap_.find(Constants::PARAM_RESOURCES_PATH);
61 if (it != parameterMap_.end()) {
62 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::RESOURCES_PATH), fi);
63 }
64 it = parameterMap_.find(Constants::PARAM_INDEX_PATH);
65 if (it != parameterMap_.end()) {
66 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::RESOURCES_INDEX), fi);
67 }
68 it = parameterMap_.find(Constants::PARAM_PACK_INFO_PATH);
69 if (it != parameterMap_.end()) {
70 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::PACK_INFO), fi);
71 }
72 it = parameterMap_.find(Constants::PARAM_ETS_PATH);
73 if (it != parameterMap_.end()) {
74 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::ETS_PATH), fi);
75 }
76 it = parameterMap_.find(Constants::PARAM_RPCID_PATH);
77 if (it != parameterMap_.end()) {
78 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::RPCID_SC), fi);
79 }
80 it = parameterMap_.find(Constants::PARAM_PKG_CONTEXT_PATH);
81 if (it != parameterMap_.end()) {
82 AddFileToZip(zf, fs::path(it->second), fs::path(Constants::PKG_CONTEXT_JSON), fi);
83 }
84 zipClose(zf, nullptr);
85 return ERR_OK;
86 }
PostProcess()87 int HspPackager::PostProcess()
88 {
89 return ERR_OK;
90 }
91
92 } // namespace AppPackingTool
93 } // namespace OHOS