• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ID_DEFINED_FILE = "id_defined.json";
33 const static std::string RESOURCE_INDEX_FILE = "resources.index";
34 const static std::string JSON_EXTENSION = ".json";
35 const static std::string SEPARATOR = "/";
36 const static std::string WIN_SEPARATOR = "\\";
37 const static std::string NEW_LINE_PATH = "\nat ";
38 const static std::string LONG_PATH_HEAD = "\\\\?\\";
39 const static std::string ID_DEFINED_INDENTATION = "    ";
40 const static int32_t VERSION_MAX_LEN = 128;
41 const static int32_t INT_TO_BYTES = sizeof(uint32_t);
42 static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 4.005" };
43 const static int32_t TAG_LEN = 4;
44 
45 enum class KeyType {
46     LANGUAGE = 0,
47     REGION = 1,
48     RESOLUTION = 2,
49     ORIENTATION = 3,
50     DEVICETYPE = 4,
51     SCRIPT = 5,
52     NIGHTMODE = 6,
53     MCC = 7,
54     MNC = 8,
55     // RESERVER 9
56     INPUTDEVICE = 10,
57     KEY_TYPE_MAX,
58 };
59 
60 enum class ResType {
61     ELEMENT = 0,
62     RAW = 6,
63     INTEGER = 8,
64     STRING = 9,
65     STRARRAY = 10,
66     INTARRAY = 11,
67     BOOLEAN = 12,
68     COLOR = 14,
69     ID = 15,
70     THEME = 16,
71     PLURAL = 17,
72     FLOAT = 18,
73     MEDIA = 19,
74     PROF = 20,
75     PATTERN = 22,
76     INVALID_RES_TYPE = -1,
77 };
78 
79 enum class OrientationType {
80     VERTICAL = 0,
81     HORIZONTAL = 1,
82 };
83 
84 enum class DeviceType {
85     PHONE = 0,
86     TABLET = 1,
87     CAR = 2,
88     // RESERVER 3
89     TV = 4,
90     WEARABLE = 6,
91 };
92 
93 enum class ResolutionType {
94     SDPI = 120,
95     MDPI = 160,
96     LDPI = 240,
97     XLDPI = 320,
98     XXLDPI = 480,
99     XXXLDPI = 640,
100 };
101 
102 enum class NightMode {
103     DARK = 0,
104     LIGHT = 1,
105 };
106 
107 enum class InputDevice {
108     INPUTDEVICE_NOT_SET = -1,
109     INPUTDEVICE_POINTINGDEVICE = 0,
110 };
111 
112 enum Option {
113     END = -1,
114     IDS = 1,
115     DEFINED_IDS = 2,
116     DEPENDENTRY = 3,
117     ICON_CHECK = 4,
118     STARTID = 'e',
119     FORCEWRITE = 'f',
120     HELP = 'h',
121     INPUTPATH = 'i',
122     JSON = 'j',
123     FILELIST = 'l',
124     MODULES = 'm',
125     OUTPUTPATH = 'o',
126     PACKAGENAME = 'p',
127     RESHEADER = 'r',
128     VERSION = 'v',
129     APPEND = 'x',
130     COMBINE = 'z',
131     UNKNOWN = '?',
132     NO_ARGUMENT = ':',
133 };
134 
135 const std::map<std::string, OrientationType> g_orientaionMap = {
136     { "vertical", OrientationType::VERTICAL },
137     { "horizontal", OrientationType::HORIZONTAL },
138 };
139 
140 const std::map<std::string, DeviceType> g_deviceMap = {
141     { "phone", DeviceType::PHONE },
142     { "tablet", DeviceType::TABLET },
143     { "car", DeviceType::CAR },
144     { "tv", DeviceType::TV },
145     { "wearable", DeviceType::WEARABLE },
146 };
147 
148 const std::map<std::string, ResolutionType> g_resolutionMap = {
149     { "sdpi", ResolutionType::SDPI },
150     { "mdpi",  ResolutionType::MDPI },
151     { "ldpi",  ResolutionType::LDPI },
152     { "xldpi", ResolutionType::XLDPI },
153     { "xxldpi", ResolutionType::XXLDPI },
154     { "xxxldpi", ResolutionType::XXXLDPI },
155 };
156 
157 const std::map<std::string, NightMode> g_nightModeMap = {
158     { "dark", NightMode::DARK },
159     { "light", NightMode::LIGHT },
160 };
161 
162 const std::map<std::string, InputDevice> g_inputDeviceMap = {
163     { "pointingdevice", InputDevice::INPUTDEVICE_POINTINGDEVICE },
164 };
165 
166 struct KeyParam {
167     KeyType keyType;
168     uint32_t value;
169 };
170 
171 struct IdData {
172     uint32_t id;
173     uint32_t dataOffset;
174 };
175 
176 const std::map<std::string, ResType> g_fileClusterMap = {
177     { "element", ResType::ELEMENT },
178     { "media", ResType::MEDIA },
179     { "profile", ResType::PROF },
180 };
181 
182 const std::map<std::string, ResType> g_contentClusterMap = {
183     { "id", ResType::ID },
184     { "integer", ResType::INTEGER },
185     { "string", ResType::STRING },
186     { "strarray", ResType::STRARRAY },
187     { "intarray", ResType::INTARRAY },
188     { "color", ResType::COLOR },
189     { "plural", ResType::PLURAL },
190     { "boolean", ResType::BOOLEAN },
191     { "pattern", ResType::PATTERN },
192     { "theme", ResType::THEME },
193     { "float", ResType::FLOAT }
194 };
195 
196 const std::map<int32_t, ResType> g_resTypeMap = {
197     { static_cast<int32_t>(ResType::ELEMENT), ResType::ELEMENT},
198     { static_cast<int32_t>(ResType::RAW), ResType::RAW},
199     { static_cast<int32_t>(ResType::INTEGER), ResType::INTEGER},
200     { static_cast<int32_t>(ResType::STRING), ResType::STRING},
201     { static_cast<int32_t>(ResType::STRARRAY), ResType::STRARRAY},
202     { static_cast<int32_t>(ResType::INTARRAY), ResType::INTARRAY},
203     { static_cast<int32_t>(ResType::BOOLEAN), ResType::BOOLEAN},
204     { static_cast<int32_t>(ResType::COLOR), ResType::COLOR},
205     { static_cast<int32_t>(ResType::ID), ResType::ID},
206     { static_cast<int32_t>(ResType::THEME), ResType::THEME},
207     { static_cast<int32_t>(ResType::PLURAL), ResType::PLURAL},
208     { static_cast<int32_t>(ResType::FLOAT), ResType::FLOAT},
209     { static_cast<int32_t>(ResType::MEDIA), ResType::MEDIA},
210     { static_cast<int32_t>(ResType::PROF), ResType::PROF},
211     { static_cast<int32_t>(ResType::PATTERN), ResType::PATTERN},
212     { static_cast<int32_t>(ResType::INVALID_RES_TYPE), ResType::INVALID_RES_TYPE},
213 };
214 
215 const std::map<std::string, std::vector<uint32_t>> g_normalIconMap = {
216     { "sdpi-phone", {41, 144} },
217     { "sdpi-tablet", {51, 192} },
218     { "mdpi-phone", {54, 192} },
219     { "mdpi-tablet", {68, 256} },
220     { "ldpi-phone", {81, 288} },
221     { "ldpi-tablet", {102, 384} },
222     { "xldpi-phone", {108, 384} },
223     { "xldpi-tablet", {136, 512} },
224     { "xxldpi-phone", {162, 576} },
225     { "xxldpi-tablet", {204, 768} },
226     { "xxxldpi-phone", {216, 768} },
227     { "xxxldpi-tablet", {272, 1024} },
228 };
229 
230 const std::map<std::string, uint32_t> g_keyNodeIndexs = {
231     { "icon", 0 },
232     { "startWindowIcon", 1 },
233 };
234 
235 struct DirectoryInfo {
236     std::string limitKey;
237     std::string fileCluster;
238     std::string dirPath;
239     std::vector<KeyParam> keyParams;
240     ResType dirType;
241 };
242 
243 struct FileInfo : DirectoryInfo {
244     std::string filePath;
245     std::string filename;
246     ResType fileType;
247 };
248 }
249 }
250 }
251 #endif
252