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_PACK_INFO_H 17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H 18 19 #include <list> 20 #include <string> 21 22 #include "pt_json.h" 23 24 namespace OHOS { 25 namespace AppPackingTool { 26 struct PackInfoVersion { 27 int32_t code = -1; 28 std::string name = ""; 29 }; 30 31 class PackInfo { 32 public: PackInfo()33 PackInfo() {}; ~PackInfo()34 virtual ~PackInfo() {}; 35 36 bool ParseFromString(const std::string& jsonString); 37 bool ParseFromFile(const std::string& jsonFile); 38 std::string ToString(); 39 void Release(); 40 41 bool IsValid(); 42 43 // object funcs 44 bool GetSummaryObject(std::unique_ptr<PtJson>& summaryObj); 45 bool GetPackagesObject(std::unique_ptr<PtJson>& packagesObj); 46 bool GetAppObject(std::unique_ptr<PtJson>& appObj); 47 bool GetModulesObject(std::unique_ptr<PtJson>& modulesObj); 48 bool GetVersionObject(std::unique_ptr<PtJson>& versionObj); 49 bool GetDistroObject(int32_t moduleIndex, std::unique_ptr<PtJson>& distroObj); 50 bool GetDistroObjectByModulesObj(const std::unique_ptr<PtJson>& modulesObj, 51 int32_t moduleIndex, std::unique_ptr<PtJson>& distroObj); 52 bool GetDistroObjectByModuleObj(const std::unique_ptr<PtJson>& moduleObj, 53 std::unique_ptr<PtJson>& distroObj); 54 bool GetPackageObject(int32_t packageIndex, std::unique_ptr<PtJson>& packageObj); 55 bool GetExtensionAbilitiesObj(int32_t moduleIndex, std::unique_ptr<PtJson>& extensionAbilitiesObj); 56 bool GetExtensionAbilitiesObjByModulesObj(const std::unique_ptr<PtJson>& modulesObj, 57 int32_t moduleIndex, std::unique_ptr<PtJson>& extensionAbilitiesObj); 58 bool GetExtensionAbilitiesObjByModuleObj(const std::unique_ptr<PtJson>& moduleObj, 59 std::unique_ptr<PtJson>& extensionAbilitiesObj); 60 bool GetFormsObjByExtensionAbilityObj(const std::unique_ptr<PtJson>& extensionAbilityObj, 61 std::unique_ptr<PtJson>& formsObj); 62 63 // funcs 64 bool GetBundleName(std::string& bundleName); 65 bool GetBundleNameByAppObj(const std::unique_ptr<PtJson>& appObj, std::string& bundleName); 66 bool SetBundleName(const std::string& bundleName); 67 bool GetBundleType(std::string& bundleType, const std::string& defaultBundleType); 68 bool GetBundleTypeByAppObj(const std::unique_ptr<PtJson>& appObj, std::string& bundleType, 69 const std::string& defaultBundleType); 70 bool GetVersion(PackInfoVersion& version); 71 bool GetVersionByVersionObj(const std::unique_ptr<PtJson>& appObj, PackInfoVersion& version); 72 bool SetVersionCode(const int32_t& versionCode); 73 bool SetVersionName(const std::string& versionName); 74 bool GetModuleNameByDistroObj(const std::unique_ptr<PtJson>& distroObj, std::string& moduleName); 75 bool GetNameByPackageObj(const std::unique_ptr<PtJson>& packageObj, std::string& name); 76 bool GetNameByFormObj(const std::unique_ptr<PtJson>& formObj, std::string& name); 77 bool GetDefaultDimensionByFormObj(const std::unique_ptr<PtJson>& formObj, std::string& defaultDimension); 78 bool GetSupportDimensionsByFormObj(const std::unique_ptr<PtJson>& formObj, 79 std::list<std::string>& supportDimensions); 80 bool GetFormNames(std::list<std::string>& formNames, std::list<std::string>& formFullNames); 81 bool GetFormNamesByExtensionAbilitiesObj(const std::unique_ptr<PtJson>& extensionAbilitiesObj, 82 std::string moduleName, std::list<std::string>& formNames, std::list<std::string>& formFullNames); 83 bool GetFormNamesByFormsObj(const std::unique_ptr<PtJson>& formsObj, 84 std::string moduleName, std::list<std::string>& formNames, std::list<std::string>& formFullNames); 85 bool GetPackageNames(std::list<std::string> &packageNames); 86 bool GetPackageNamesByPackagesObj(const std::unique_ptr<PtJson>& appObj, std::list<std::string> &packageNames); 87 88 private: 89 std::unique_ptr<PtJson> root_ = nullptr; 90 }; 91 } // namespace AppPackingTool 92 } // namespace OHOS 93 #endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H 94