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 #ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACKAGER_H 17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACKAGER_H 18 19 #include <filesystem> 20 #include <functional> 21 #include <iostream> 22 #include <list> 23 #include <map> 24 #include <regex> 25 #include <string> 26 #include <vector> 27 28 #include "constants.h" 29 #include "json/module_json.h" 30 31 namespace fs = std::filesystem; 32 33 namespace OHOS { 34 namespace AppPackingTool { 35 36 enum ErrCode { 37 ERR_OK = 0, 38 ERR_INVALID_VALUE, 39 }; 40 41 struct Parameter { 42 std::string paramName; 43 bool required; 44 Constants::PARAM_TYPE paramType; 45 std::string paramRegrex; 46 std::string zipEntry; 47 }; 48 49 class Packager { 50 public: 51 Packager(const std::map<std::string, std::string> ¶meterMap, std::string &resultReceiver); 52 virtual ~Packager(); 53 54 int32_t MakePackage(); 55 56 static int32_t getAtomicServiceEntrySizeLimit(); 57 static void setAtomicServiceEntrySizeLimit(int32_t atomicServiceEntrySizeLimit); 58 static int32_t getAtomicServiceNonEntrySizeLimit(); 59 static void setAtomicServiceNonEntrySizeLimit(int32_t atomicServiceNonEntrySizeLimit); 60 61 virtual int32_t InitAllowedParam() = 0; 62 virtual int32_t PreProcess() = 0; 63 virtual int32_t Process() = 0; 64 virtual int32_t PostProcess() = 0; 65 66 protected: 67 const std::map<std::string, std::string> ¶meterMap_; 68 std::string &resultReceiver_; 69 std::vector<Parameter> allowedParameters_; 70 bool buildHashFinish_ = false; 71 bool generateBuildHash_ = false; 72 73 bool CheckForceFlag(); 74 bool IsPathValid(const std::string &path, const bool &isFile, const std::string suffix = ""); 75 bool IsFileMatch(const std::string &path, const std::string &matchFileName); 76 bool SplitDirList(const std::string &dirList, std::list<std::string> &fileList); 77 void RemoveDuplicatePath(const std::string &path, std::list<std::string> &pathList); 78 bool CompatibleProcess(const std::string &inputPath, std::list<std::string> &fileList, const std::string &suffix); 79 bool CompatibleProcess(const std::string &inputPath, std::list<std::string> &fileList, 80 const std::string &suffix, const std::string &extraSuffix); 81 bool EnsureParentDirectoryExists(const std::filesystem::path& filePath); 82 bool IsOutPathValid(const std::string &outPath, const std::string &forceRewrite, const std::string &suffix); 83 bool SetGenerateBuildHash(std::string &jsonPath, bool &generateBuildHash, bool &buildHashFinish); 84 bool CopyFileToTempDir(std::string &jsonPath); 85 bool BuildHash(bool &buildHashFinish, const bool &generateBuildHash, 86 const std::map<std::string, std::string> ¶meterMap, const std::string &jsonPath); 87 bool PutBuildHash(const std::string &jsonPath, const std::string &hash, bool &buildHashFinish); 88 bool IsOutDirectoryValid(); 89 bool IsModuleHap(const std::string& hapPath); 90 void CompressPackinfoIntoHap(const std::string& hapPathItem, const std::string& unzipPathString, 91 const std::string& outPathString, const std::string& packInfoPath); 92 bool ParseAtomicServiceSizeLimit(); 93 bool ParseAtomicServiceEntrySizeLimitParameter(); 94 bool ParseAtomicServiceNonEntrySizeLimitParameter(); 95 96 private: 97 static int32_t atomicServiceEntrySizeLimit_; 98 static int32_t atomicServiceNonEntrySizeLimit_; 99 }; 100 101 } // namespace AppExecFwk 102 } // namespace OHOS 103 104 #endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACKAGER_H