• 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 #ifndef OHOS_ABILITY_RUNTIME_RUNTIME_EXTRACTOR_H
17 #define OHOS_ABILITY_RUNTIME_RUNTIME_EXTRACTOR_H
18 
19 #include <string>
20 
21 #include "zip_file.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 class RuntimeExtractor {
26 public:
27     explicit RuntimeExtractor(const std::string &source);
28     virtual ~RuntimeExtractor();
29     static std::shared_ptr<RuntimeExtractor> Create(const std::string& hapPath);
30 
31     /**
32      * @brief Open compressed file.
33      * @return Returns true if the file is successfully opened; returns false otherwise.
34      */
35     virtual bool Init();
36 
37     /**
38      * @brief Extract to dest stream by file name.
39      * @param fileName Indicates the file name.
40      * @param dest Indicates the obtained std::ostream object.
41      * @return Returns true if the file extracted successfully; returns false otherwise.
42      */
43     bool ExtractByName(const std::string &fileName, std::ostream &dest) const;
44     /**
45      * @brief Extract to dest path on filesystem.
46      * @param fileName Indicates the file name.
47      * @param targetPath Indicates the target Path.
48      * @return Returns true if the file extracted to filesystem successfully; returns false otherwise.
49      */
50     bool ExtractFile(const std::string &fileName, const std::string &targetPath) const;
51     /**
52      * @brief Get all file names in a hap file.
53      * @param fileName Indicates the obtained file names in hap.
54      * @return Returns true if the file names obtained successfully; returns false otherwise.
55      */
56     bool GetZipFileNames(std::vector<std::string> &fileNames);
57     /**
58      * @brief Get specified type names in a zip file.
59      * @param fileNames Indicates the obtained file names in zip.
60      * @param suffix Indicates the suffix of file.
61      */
62     void GetSpecifiedTypeFiles(std::vector<std::string> &fileNames, const std::string &suffix);
63     /**
64      * @brief Has entry by name.
65      * @param entryName Indicates the entry name.
66      * @return Returns true if the ZipEntry is successfully finded; returns false otherwise.
67      */
68     bool HasEntry(const std::string &fileName) const;
69     bool IsDirExist(const std::string &dir) const;
70     bool IsStageBasedModel(std::string abilityName);
71     bool GetFileBuffer(const std::string& srcPath, std::ostringstream& dest);
72     bool GetFileList(const std::string& srcPath, std::vector<std::string>& assetList);
73     bool IsSameHap(const std::string& hapPath) const;
74     void SetRuntimeFlag(bool isRuntime);
75 
76 private:
77     const std::string sourceFile_;
78     ZipFile zipFile_;
79     bool initial_ = false;
80     std::string hapPath_;
81 };
82 }  // namespace AbilityRuntime
83 }  // namespace OHOS
84 #endif  // OHOS_ABILITY_RUNTIME_RUNTIME_EXTRACTOR_H
85