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 "bundle_parser.h" 17 18 #include <sstream> 19 20 #include "app_log_wrapper.h" 21 #include "bundle_constants.h" 22 #include "bundle_extractor.h" 23 #include "bundle_profile.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 Parse(const std::string & pathName,InnerBundleInfo & innerBundleInfo) const28ErrCode BundleParser::Parse(const std::string &pathName, InnerBundleInfo &innerBundleInfo) const 29 { 30 APP_LOGI("parse from %{public}s", pathName.c_str()); 31 BundleExtractor bundleExtractor(pathName); 32 if (!bundleExtractor.Init()) { 33 APP_LOGE("bundle extractor init failed"); 34 return ERR_APPEXECFWK_PARSE_UNEXPECTED; 35 } 36 37 std::ostringstream outStream; 38 if (!bundleExtractor.ExtractProfile(outStream)) { 39 APP_LOGE("extract profile file failed"); 40 return ERR_APPEXECFWK_PARSE_NO_PROFILE; 41 } 42 43 BundleProfile bundleProfile; 44 return bundleProfile.TransformTo(outStream, innerBundleInfo); 45 } 46 47 } // namespace AppExecFwk 48 } // namespace OHOS 49