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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_EXTRACTOR_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_EXTRACTOR_H 18 19 #include <string> 20 21 #include "zip_file.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 26 class BaseExtractor { 27 public: 28 explicit BaseExtractor(const std::string &source); 29 virtual ~BaseExtractor(); 30 /** 31 * @brief Open compressed file. 32 * @return Returns true if the file is successfully opened; returns false otherwise. 33 */ 34 virtual bool Init(); 35 /** 36 * @brief Extract the Profile to dest stream. 37 * @param dest Indicates the obtained std::ostream object.. 38 * @return Returns true if the profile extracted successfully; returns false otherwise. 39 */ 40 virtual bool ExtractProfile(std::ostream &dest) const = 0; 41 /** 42 * @brief Extract to dest stream by file name. 43 * @param fileName Indicates the file name. 44 * @param dest Indicates the obtained std::ostream object. 45 * @return Returns true if the file extracted successfully; returns false otherwise. 46 */ 47 bool ExtractByName(const std::string &fileName, std::ostream &dest) const; 48 /** 49 * @brief Extract to dest path on filesystem. 50 * @param fileName Indicates the file name. 51 * @param targetPath Indicates the target Path. 52 * @return Returns true if the file extracted to filesystem successfully; returns false otherwise. 53 */ 54 bool ExtractFile(const std::string &fileName, const std::string &targetPath) const; 55 /** 56 * @brief Get all file names in a hap file. 57 * @param fileName Indicates the obtained file names in hap. 58 * @return Returns true if the file names obtained successfully; returns false otherwise. 59 */ 60 bool GetZipFileNames(std::vector<std::string> &fileNames); 61 62 protected: 63 const std::string sourceFile_; 64 ZipFile zipFile_; 65 bool initial_ = false; 66 }; 67 68 } // namespace AppExecFwk 69 } // namespace OHOS 70 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_EXTRACTOR_H 71