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 RESOURCE_MANAGER_ZIPARCHIVE_H 17 #define RESOURCE_MANAGER_ZIPARCHIVE_H 18 19 #include <cstdint> 20 #include <cstdio> 21 #include <string> 22 #include "res_desc.h" 23 #include "res_config_impl.h" 24 25 namespace OHOS { 26 namespace Global { 27 namespace Resource { 28 class HapParser { 29 public: 30 /** 31 * Read specified file in zip to buffer 32 * @param zipFile 33 * @param fileName file name in zip which we will read 34 * @param buffer bytes will write to buffer 35 * @param bufLen the file length in bytes 36 * @param errInfo 37 * @return 38 */ 39 static int32_t ReadFileFromZip(const char *zipFile, const char *fileName, void **buffer, 40 size_t &bufLen, std::string &errInfo); 41 42 /** 43 * Read resource.index in hap to buffer 44 * @param zipFile hap file path 45 * @param buffer bytes will write to buffer 46 * @param bufLen length in bytes 47 * @param errInfo 48 * @return 49 */ 50 static int32_t ReadIndexFromFile(const char *zipFile, void **buffer, 51 size_t &bufLen, std::string &errInfo); 52 53 static int32_t ParseResHex(const char *buffer, const size_t bufLen, ResDesc &resDesc, 54 const ResConfigImpl *defaultConfig = nullptr); 55 56 static ResConfigImpl *CreateResConfigFromKeyParams(const std::vector<KeyParam *> &keyParams); 57 58 static std::string ToFolderPath(const std::vector<KeyParam *> &keyParams); 59 60 static ScreenDensity GetScreenDensity(uint32_t value); 61 62 static DeviceType GetDeviceType(uint32_t value); 63 64 static ColorMode GetColorMode(uint32_t value); 65 66 private: 67 static const char *RES_FILE_NAME; 68 }; 69 } // namespace Resource 70 } // namespace Global 71 } // namespace OHOS 72 #endif 73