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