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 #include <vector> 23 24 namespace OHOS { 25 namespace Global { 26 namespace Restool { 27 const static std::string TOOL_NAME = "restool"; 28 const static std::string RESOURCES_DIR = "resources"; 29 const static std::string CONFIG_JSON = "config.json"; 30 const static std::string MODULE_JSON = "module.json"; 31 const static std::string RAW_FILE_DIR = "rawfile"; 32 const static std::string RES_FILE_DIR = "resfile"; 33 const static std::string ID_DEFINED_FILE = "id_defined.json"; 34 const static std::string RESOURCE_INDEX_FILE = "resources.index"; 35 const static std::string JSON_EXTENSION = ".json"; 36 const static std::string SEPARATOR = "/"; 37 const static std::string WIN_SEPARATOR = "\\"; 38 const static std::string NEW_LINE_PATH = "\nat "; 39 const static std::string LONG_PATH_HEAD = "\\\\?\\"; 40 const static std::string ID_DEFINED_INDENTATION = " "; 41 const static int32_t VERSION_MAX_LEN = 128; 42 const static int32_t INT_TO_BYTES = sizeof(uint32_t); 43 static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.105" }; 44 const static int32_t TAG_LEN = 4; 45 46 enum class KeyType { 47 LANGUAGE = 0, 48 REGION = 1, 49 RESOLUTION = 2, 50 ORIENTATION = 3, 51 DEVICETYPE = 4, 52 SCRIPT = 5, 53 NIGHTMODE = 6, 54 MCC = 7, 55 MNC = 8, 56 // RESERVER 9 57 INPUTDEVICE = 10, 58 KEY_TYPE_MAX, 59 OTHER, 60 }; 61 62 enum class ResType { 63 ELEMENT = 0, 64 RAW = 6, 65 INTEGER = 8, 66 STRING = 9, 67 STRARRAY = 10, 68 INTARRAY = 11, 69 BOOLEAN = 12, 70 COLOR = 14, 71 ID = 15, 72 THEME = 16, 73 PLURAL = 17, 74 FLOAT = 18, 75 MEDIA = 19, 76 PROF = 20, 77 PATTERN = 22, 78 SYMBOL = 23, 79 RES = 24, 80 INVALID_RES_TYPE = -1, 81 }; 82 83 enum class OrientationType { 84 VERTICAL = 0, 85 HORIZONTAL = 1, 86 }; 87 88 enum class DeviceType { 89 PHONE = 0, 90 TABLET = 1, 91 CAR = 2, 92 // RESERVER 3 93 TV = 4, 94 WEARABLE = 6, 95 TWOINONE = 7, 96 }; 97 98 enum class ResolutionType { 99 SDPI = 120, 100 MDPI = 160, 101 LDPI = 240, 102 XLDPI = 320, 103 XXLDPI = 480, 104 XXXLDPI = 640, 105 }; 106 107 enum class NightMode { 108 DARK = 0, 109 LIGHT = 1, 110 }; 111 112 enum class InputDevice { 113 INPUTDEVICE_NOT_SET = -1, 114 INPUTDEVICE_POINTINGDEVICE = 0, 115 }; 116 117 enum Option { 118 END = -1, 119 IDS = 1, 120 DEFINED_IDS = 2, 121 DEPENDENTRY = 3, 122 ICON_CHECK = 4, 123 TARGET_CONFIG = 5, 124 STARTID = 'e', 125 FORCEWRITE = 'f', 126 HELP = 'h', 127 INPUTPATH = 'i', 128 JSON = 'j', 129 FILELIST = 'l', 130 MODULES = 'm', 131 OUTPUTPATH = 'o', 132 PACKAGENAME = 'p', 133 RESHEADER = 'r', 134 VERSION = 'v', 135 APPEND = 'x', 136 COMBINE = 'z', 137 UNKNOWN = '?', 138 NO_ARGUMENT = ':', 139 }; 140 141 const std::map<std::string, OrientationType> g_orientaionMap = { 142 { "vertical", OrientationType::VERTICAL }, 143 { "horizontal", OrientationType::HORIZONTAL }, 144 }; 145 146 const std::map<std::string, DeviceType> g_deviceMap = { 147 { "phone", DeviceType::PHONE }, 148 { "tablet", DeviceType::TABLET }, 149 { "car", DeviceType::CAR }, 150 { "tv", DeviceType::TV }, 151 { "wearable", DeviceType::WEARABLE }, 152 { "2in1", DeviceType::TWOINONE }, 153 }; 154 155 const std::map<std::string, ResolutionType> g_resolutionMap = { 156 { "sdpi", ResolutionType::SDPI }, 157 { "mdpi", ResolutionType::MDPI }, 158 { "ldpi", ResolutionType::LDPI }, 159 { "xldpi", ResolutionType::XLDPI }, 160 { "xxldpi", ResolutionType::XXLDPI }, 161 { "xxxldpi", ResolutionType::XXXLDPI }, 162 }; 163 164 const std::map<std::string, NightMode> g_nightModeMap = { 165 { "dark", NightMode::DARK }, 166 { "light", NightMode::LIGHT }, 167 }; 168 169 const std::map<std::string, InputDevice> g_inputDeviceMap = { 170 { "pointingdevice", InputDevice::INPUTDEVICE_POINTINGDEVICE }, 171 }; 172 173 struct KeyParam { 174 KeyType keyType; 175 uint32_t value; 176 bool operator == (const KeyParam &other) 177 { 178 return keyType == other.keyType && value == other.value; 179 } 180 }; 181 182 struct IdData { 183 uint32_t id; 184 uint32_t dataOffset; 185 }; 186 187 const std::map<std::string, ResType> g_copyFileMap = { 188 { RAW_FILE_DIR, ResType::RAW }, 189 { RES_FILE_DIR, ResType::RES }, 190 }; 191 192 const std::map<std::string, ResType> g_fileClusterMap = { 193 { "element", ResType::ELEMENT }, 194 { "media", ResType::MEDIA }, 195 { "profile", ResType::PROF }, 196 }; 197 198 const std::map<std::string, ResType> g_contentClusterMap = { 199 { "id", ResType::ID }, 200 { "integer", ResType::INTEGER }, 201 { "string", ResType::STRING }, 202 { "strarray", ResType::STRARRAY }, 203 { "intarray", ResType::INTARRAY }, 204 { "color", ResType::COLOR }, 205 { "plural", ResType::PLURAL }, 206 { "boolean", ResType::BOOLEAN }, 207 { "pattern", ResType::PATTERN }, 208 { "theme", ResType::THEME }, 209 { "float", ResType::FLOAT }, 210 { "symbol", ResType::SYMBOL } 211 }; 212 213 const std::map<int32_t, ResType> g_resTypeMap = { 214 { static_cast<int32_t>(ResType::ELEMENT), ResType::ELEMENT}, 215 { static_cast<int32_t>(ResType::RAW), ResType::RAW}, 216 { static_cast<int32_t>(ResType::INTEGER), ResType::INTEGER}, 217 { static_cast<int32_t>(ResType::STRING), ResType::STRING}, 218 { static_cast<int32_t>(ResType::STRARRAY), ResType::STRARRAY}, 219 { static_cast<int32_t>(ResType::INTARRAY), ResType::INTARRAY}, 220 { static_cast<int32_t>(ResType::BOOLEAN), ResType::BOOLEAN}, 221 { static_cast<int32_t>(ResType::COLOR), ResType::COLOR}, 222 { static_cast<int32_t>(ResType::ID), ResType::ID}, 223 { static_cast<int32_t>(ResType::THEME), ResType::THEME}, 224 { static_cast<int32_t>(ResType::PLURAL), ResType::PLURAL}, 225 { static_cast<int32_t>(ResType::FLOAT), ResType::FLOAT}, 226 { static_cast<int32_t>(ResType::MEDIA), ResType::MEDIA}, 227 { static_cast<int32_t>(ResType::PROF), ResType::PROF}, 228 { static_cast<int32_t>(ResType::PATTERN), ResType::PATTERN}, 229 { static_cast<int32_t>(ResType::SYMBOL), ResType::SYMBOL}, 230 { static_cast<int32_t>(ResType::RES), ResType::RES}, 231 { static_cast<int32_t>(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE}, 232 }; 233 234 const std::map<std::string, std::vector<uint32_t>> g_normalIconMap = { 235 { "sdpi-phone", {41, 144} }, 236 { "sdpi-tablet", {51, 192} }, 237 { "mdpi-phone", {54, 192} }, 238 { "mdpi-tablet", {68, 256} }, 239 { "ldpi-phone", {81, 288} }, 240 { "ldpi-tablet", {102, 384} }, 241 { "xldpi-phone", {108, 384} }, 242 { "xldpi-tablet", {136, 512} }, 243 { "xxldpi-phone", {162, 576} }, 244 { "xxldpi-tablet", {204, 768} }, 245 { "xxxldpi-phone", {216, 768} }, 246 { "xxxldpi-tablet", {272, 1024} }, 247 }; 248 249 const std::map<std::string, uint32_t> g_keyNodeIndexs = { 250 { "icon", 0 }, 251 { "startWindowIcon", 1 }, 252 }; 253 254 struct DirectoryInfo { 255 std::string limitKey; 256 std::string fileCluster; 257 std::string dirPath; 258 std::vector<KeyParam> keyParams; 259 ResType dirType; 260 }; 261 262 struct FileInfo : DirectoryInfo { 263 std::string filePath; 264 std::string filename; 265 ResType fileType; 266 }; 267 268 struct TargetConfig { 269 std::vector<KeyParam> mccmnc; 270 std::vector<KeyParam> locale; 271 std::vector<KeyParam> orientation; 272 std::vector<KeyParam> device; 273 std::vector<KeyParam> colormode; 274 std::vector<KeyParam> density; 275 }; 276 277 struct Mccmnc { 278 KeyParam mcc; 279 KeyParam mnc; 280 bool operator == (const Mccmnc &other) 281 { 282 if (mcc.value != other.mcc.value) { 283 return false; 284 } 285 if (mnc.keyType != KeyType::OTHER && other.mnc.keyType != KeyType::OTHER && 286 mnc.value != other.mnc.value) { 287 return false; 288 } 289 return true; 290 } 291 }; 292 293 struct Locale { 294 KeyParam language; 295 KeyParam script; 296 KeyParam region; 297 bool operator == (const Locale &other) 298 { 299 if (language.value != other.language.value) { 300 return false; 301 } 302 if (script.keyType != KeyType::OTHER && other.script.keyType != KeyType::OTHER && 303 script.value != other.script.value) { 304 return false; 305 } 306 if (region.keyType != KeyType::OTHER && other.region.keyType != KeyType::OTHER && 307 region.value != other.region.value) { 308 return false; 309 } 310 return true; 311 } 312 }; 313 314 } 315 } 316 } 317 #endif 318