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