1 /* 2 * Copyright (c) 2021 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_RESTOOL_RESOURCE_DATA_H 17 #define OHOS_RESTOOL_RESOURCE_DATA_H 18 19 #include<map> 20 #include<stdint.h> 21 #include<string> 22 23 namespace OHOS { 24 namespace Global { 25 namespace Restool { 26 const static std::string TOOL_NAME = "restool"; 27 const static std::string RESOURCES_DIR = "resources"; 28 const static std::string CONFIG_JSON = "config.json"; 29 const static std::string MODULE_JSON = "module.json"; 30 const static std::string RAW_FILE_DIR = "rawfile"; 31 const static std::string ID_DEFINED_FILE = "id_defined.json"; 32 const static std::string RESOURCE_INDEX_FILE = "resources.index"; 33 const static std::string SEPARATOR = "/"; 34 const static std::string WIN_SEPARATOR = "\\"; 35 const static int32_t VERSION_MAX_LEN = 128; 36 const static int32_t INT_TO_BYTES = sizeof(uint32_t); 37 static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 2.008" }; 38 const static int32_t TAG_LEN = 4; 39 40 enum class KeyType { 41 LANGUAGE = 0, 42 REGION = 1, 43 RESOLUTION = 2, 44 ORIENTATION = 3, 45 DEVICETYPE = 4, 46 SCRIPT = 5, 47 NIGHTMODE = 6, 48 MCC = 7, 49 MNC = 8, 50 KEY_TYPE_MAX, 51 }; 52 53 enum class ResType { 54 ELEMENT = 0, 55 ANIMATION = 1, 56 LAYOUT = 3, 57 RAW = 6, 58 INTEGER = 8, 59 STRING = 9, 60 STRARRAY = 10, 61 INTARRAY = 11, 62 BOOLEAN = 12, 63 COLOR = 14, 64 ID = 15, 65 THEME = 16, 66 PLURAL = 17, 67 FLOAT = 18, 68 MEDIA = 19, 69 PROF = 20, 70 GRAPHIC = 21, 71 PATTERN = 22, 72 INVALID_RES_TYPE = -1, 73 }; 74 75 enum class OrientationType { 76 VERTICAL = 0, 77 HORIZONTAL = 1, 78 }; 79 80 const std::map<std::string, OrientationType> g_orientaionMap = { 81 { "vertical", OrientationType::VERTICAL }, 82 { "horizontal", OrientationType::HORIZONTAL }, 83 }; 84 85 enum class DeviceType { 86 PHONE = 0, 87 TABLET = 1, 88 CAR = 2, 89 // RESERVER 3 90 TV = 4, 91 WEARABLE = 6, 92 }; 93 94 const std::map<std::string, DeviceType> g_deviceMap = { 95 { "phone", DeviceType::PHONE }, 96 { "tablet", DeviceType::TABLET }, 97 { "car", DeviceType::CAR }, 98 { "tv", DeviceType::TV }, 99 { "wearable", DeviceType::WEARABLE }, 100 }; 101 102 enum class ResolutionType { 103 SDPI = 120, 104 MDPI = 160, 105 LDPI = 240, 106 XLDPI = 320, 107 XXLDPI = 480, 108 XXXLDPI = 640, 109 }; 110 111 const std::map<std::string, ResolutionType> g_resolutionMap = { 112 { "sdpi", ResolutionType::SDPI }, 113 { "mdpi", ResolutionType::MDPI }, 114 { "ldpi", ResolutionType::LDPI }, 115 { "xldpi", ResolutionType::XLDPI }, 116 { "xxldpi", ResolutionType::XXLDPI }, 117 { "xxxldpi", ResolutionType::XXXLDPI }, 118 }; 119 120 enum class NightMode { 121 DARK = 0, 122 LIGHT = 1, 123 }; 124 125 const std::map<std::string, NightMode> g_nightModeMap = { 126 { "dark", NightMode::DARK }, 127 { "light", NightMode::LIGHT }, 128 }; 129 130 struct KeyParam { 131 KeyType keyType; 132 uint32_t value; 133 }; 134 135 struct IdData { 136 uint32_t id; 137 uint32_t dataOffset; 138 }; 139 140 const std::map<std::string, ResType> g_fileClusterMap = { 141 { "element", ResType::ELEMENT }, 142 { "media", ResType::MEDIA }, 143 { "profile", ResType::PROF }, 144 }; 145 146 const std::map<std::string, ResType> g_contentClusterMap = { 147 { "id", ResType::ID }, 148 { "integer", ResType::INTEGER }, 149 { "string", ResType::STRING }, 150 { "strarray", ResType::STRARRAY }, 151 { "intarray", ResType::INTARRAY }, 152 { "color", ResType::COLOR }, 153 { "plural", ResType::PLURAL }, 154 { "boolean", ResType::BOOLEAN }, 155 { "pattern", ResType::PATTERN }, 156 { "theme", ResType::THEME }, 157 { "float", ResType::FLOAT } 158 }; 159 160 const std::map<int32_t, ResType> g_resTypeMap = { 161 { static_cast<int32_t>(ResType::ELEMENT), ResType::ELEMENT}, 162 { static_cast<int32_t>(ResType::ANIMATION), ResType::ANIMATION}, 163 { static_cast<int32_t>(ResType::LAYOUT), ResType::LAYOUT}, 164 { static_cast<int32_t>(ResType::RAW), ResType::RAW}, 165 { static_cast<int32_t>(ResType::INTEGER), ResType::INTEGER}, 166 { static_cast<int32_t>(ResType::STRING), ResType::STRING}, 167 { static_cast<int32_t>(ResType::STRARRAY), ResType::STRARRAY}, 168 { static_cast<int32_t>(ResType::INTARRAY), ResType::INTARRAY}, 169 { static_cast<int32_t>(ResType::BOOLEAN), ResType::BOOLEAN}, 170 { static_cast<int32_t>(ResType::COLOR), ResType::COLOR}, 171 { static_cast<int32_t>(ResType::ID), ResType::ID}, 172 { static_cast<int32_t>(ResType::THEME), ResType::THEME}, 173 { static_cast<int32_t>(ResType::PLURAL), ResType::PLURAL}, 174 { static_cast<int32_t>(ResType::FLOAT), ResType::FLOAT}, 175 { static_cast<int32_t>(ResType::MEDIA), ResType::MEDIA}, 176 { static_cast<int32_t>(ResType::PROF), ResType::PROF}, 177 { static_cast<int32_t>(ResType::GRAPHIC), ResType::GRAPHIC}, 178 { static_cast<int32_t>(ResType::PATTERN), ResType::PATTERN}, 179 { static_cast<int32_t>(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE}, 180 }; 181 182 struct DirectoryInfo { 183 std::string limitKey; 184 std::string fileCluster; 185 std::string dirPath; 186 std::vector<KeyParam> keyParams; 187 ResType dirType; 188 }; 189 190 struct FileInfo : DirectoryInfo { 191 std::string filePath; 192 std::string filename; 193 ResType fileType; 194 }; 195 } 196 } 197 } 198 #endif 199