1 /* 2 * Copyright (c) 2021-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 #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 class BaseExtractor { 26 public: 27 explicit BaseExtractor(const std::string &source); 28 virtual ~BaseExtractor(); 29 /** 30 * @brief Open compressed file. 31 * @return Returns true if the file is successfully opened; returns false otherwise. 32 */ 33 virtual bool Init(); 34 /** 35 * @brief Extract to dest stream by file name. 36 * @param fileName Indicates the file name. 37 * @param dest Indicates the obtained std::ostream object. 38 * @return Returns true if the file extracted successfully; returns false otherwise. 39 */ 40 bool ExtractByName(const std::string &fileName, std::ostream &dest) const; 41 /** 42 * @brief Extract to dest path on filesystem. 43 * @param fileName Indicates the file name. 44 * @param targetPath Indicates the target Path. 45 * @return Returns true if the file extracted to filesystem successfully; returns false otherwise. 46 */ 47 bool ExtractFile(const std::string &fileName, const std::string &targetPath) const; 48 /** 49 * @brief Get all file names in a hap file. 50 * @param fileName Indicates the obtained file names in hap. 51 * @return Returns true if the file names obtained successfully; returns false otherwise. 52 */ 53 bool GetZipFileNames(std::vector<std::string> &fileNames) const; 54 /** 55 * @brief Has entry by name. 56 * @param entryName Indicates the entry name. 57 * @return Returns true if the ZipEntry is successfully finded; returns false otherwise. 58 */ 59 bool HasEntry(const std::string &fileName) const; 60 bool IsDirExist(const std::string &dir) const; 61 bool IsStageBasedModel(std::string abilityName); 62 bool IsNewVersion() const; 63 bool GetFileInfo(const std::string &fileName, uint32_t &offset, uint32_t &length) const; 64 65 protected: 66 const std::string sourceFile_; 67 ZipFile zipFile_; 68 bool initial_ = false; 69 private: 70 bool isNewVersion_ = true; 71 }; 72 } // namespace AppExecFwk 73 } // namespace OHOS 74 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BASE_EXTRACTOR_H 75