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