1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2018 The Qt Company Ltd. |
4 | ** Copyright (C) 2018 Intel Corporation. |
5 | ** Contact: https://www.qt.io/licensing/ |
6 | ** |
7 | ** This file is part of the tools applications of the Qt Toolkit. |
8 | ** |
9 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
10 | ** Commercial License Usage |
11 | ** Licensees holding valid commercial Qt licenses may use this file in |
12 | ** accordance with the commercial license agreement provided with the |
13 | ** Software or, alternatively, in accordance with the terms contained in |
14 | ** a written agreement between you and The Qt Company. For licensing terms |
15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
16 | ** information use the contact form at https://www.qt.io/contact-us. |
17 | ** |
18 | ** GNU General Public License Usage |
19 | ** Alternatively, this file may be used under the terms of the GNU |
20 | ** General Public License version 3 as published by the Free Software |
21 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | // Note: A copy of this file is used in Qt Designer (qttools/src/designer/src/lib/shared/rcc_p.h) |
31 | |
32 | #ifndef RCC_H |
33 | #define RCC_H |
34 | |
35 | #include <qstringlist.h> |
36 | #include <qhash.h> |
37 | #include <qstring.h> |
38 | |
39 | typedef struct ZSTD_CCtx_s ZSTD_CCtx; |
40 | |
41 | QT_BEGIN_NAMESPACE |
42 | |
43 | class RCCFileInfo; |
44 | class QIODevice; |
45 | class QTextStream; |
46 | |
47 | |
48 | class RCCResourceLibrary |
49 | { |
50 | RCCResourceLibrary(const RCCResourceLibrary &); |
51 | RCCResourceLibrary &operator=(const RCCResourceLibrary &); |
52 | |
53 | public: |
54 | RCCResourceLibrary(quint8 formatVersion); |
55 | ~RCCResourceLibrary(); |
56 | |
57 | bool output(QIODevice &outDevice, QIODevice &tempDevice, QIODevice &errorDevice); |
58 | |
59 | bool readFiles(bool listMode, QIODevice &errorDevice); |
60 | |
61 | enum Format { Binary, C_Code, Pass1, Pass2, Python3_Code, Python2_Code }; |
62 | void setFormat(Format f) { m_format = f; } |
63 | Format format() const { return m_format; } |
64 | |
65 | void setInputFiles(const QStringList &files) { m_fileNames = files; } |
66 | QStringList inputFiles() const { return m_fileNames; } |
67 | |
68 | QStringList dataFiles() const; |
69 | |
70 | // Return a map of resource identifier (':/newPrefix/images/p1.png') to file. |
71 | typedef QHash<QString, QString> ResourceDataFileMap; |
72 | ResourceDataFileMap resourceDataFileMap() const; |
73 | |
74 | void setVerbose(bool b) { m_verbose = b; } |
75 | bool verbose() const { return m_verbose; } |
76 | |
77 | void setInitName(const QString &name) { m_initName = name; } |
78 | QString initName() const { return m_initName; } |
79 | |
80 | void setOutputName(const QString &name) { m_outputName = name; } |
81 | QString outputName() const { return m_outputName; } |
82 | |
83 | enum class CompressionAlgorithm { |
84 | Zlib, |
85 | Zstd, |
86 | |
87 | Best = 99, |
88 | None = -1 |
89 | }; |
90 | |
91 | static CompressionAlgorithm parseCompressionAlgorithm(QStringView algo, QString *errorMsg); |
92 | void setCompressionAlgorithm(CompressionAlgorithm algo) { m_compressionAlgo = algo; } |
93 | CompressionAlgorithm compressionAlgorithm() const { return m_compressionAlgo; } |
94 | |
95 | static int parseCompressionLevel(CompressionAlgorithm algo, const QString &level, QString *errorMsg); |
96 | void setCompressLevel(int c) { m_compressLevel = c; } |
97 | int compressLevel() const { return m_compressLevel; } |
98 | |
99 | void setCompressThreshold(int t) { m_compressThreshold = t; } |
100 | int compressThreshold() const { return m_compressThreshold; } |
101 | |
102 | void setResourceRoot(const QString &root) { m_resourceRoot = root; } |
103 | QString resourceRoot() const { return m_resourceRoot; } |
104 | |
105 | void setUseNameSpace(bool v) { m_useNameSpace = v; } |
106 | bool useNameSpace() const { return m_useNameSpace; } |
107 | |
108 | QStringList failedResources() const { return m_failedResources; } |
109 | |
110 | int formatVersion() const { return m_formatVersion; } |
111 | |
112 | void setNoZstd(bool v) { m_noZstd = v; } |
113 | bool noZstd() const { return m_noZstd; } |
114 | |
115 | private: |
116 | struct Strings { |
117 | Strings(); |
118 | const QString TAG_RCC; |
119 | const QString TAG_RESOURCE; |
120 | const QString TAG_FILE; |
121 | const QString ATTRIBUTE_LANG; |
122 | const QString ATTRIBUTE_PREFIX; |
123 | const QString ATTRIBUTE_ALIAS; |
124 | const QString ATTRIBUTE_THRESHOLD; |
125 | const QString ATTRIBUTE_COMPRESS; |
126 | const QString ATTRIBUTE_COMPRESSALGO; |
127 | }; |
128 | friend class RCCFileInfo; |
129 | void reset(); |
130 | bool addFile(const QString &alias, const RCCFileInfo &file); |
131 | bool interpretResourceFile(QIODevice *inputDevice, const QString &file, |
132 | QString currentPath = QString(), bool listMode = false); |
133 | bool (); |
134 | bool writeDataBlobs(); |
135 | bool writeDataNames(); |
136 | bool writeDataStructure(); |
137 | bool writeInitializer(); |
138 | void writeMangleNamespaceFunction(const QByteArray &name); |
139 | void writeAddNamespaceFunction(const QByteArray &name); |
140 | void writeDecimal(int value); |
141 | void writeHex(quint8 number); |
142 | void write2HexDigits(quint8 number); |
143 | void writeNumber2(quint16 number); |
144 | void writeNumber4(quint32 number); |
145 | void writeNumber8(quint64 number); |
146 | void writeChar(char c) { m_out.append(c); } |
147 | void writeByteArray(const QByteArray &); |
148 | void write(const char *, int len); |
149 | void writeString(const char *s) { write(s, static_cast<int>(strlen(s))); } |
150 | |
151 | #if QT_CONFIG(zstd) |
152 | ZSTD_CCtx *m_zstdCCtx; |
153 | #endif |
154 | |
155 | const Strings m_strings; |
156 | RCCFileInfo *m_root; |
157 | QStringList m_fileNames; |
158 | QString m_resourceRoot; |
159 | QString m_initName; |
160 | QString m_outputName; |
161 | Format m_format; |
162 | bool m_verbose; |
163 | CompressionAlgorithm m_compressionAlgo; |
164 | int m_compressLevel; |
165 | int m_compressThreshold; |
166 | int m_treeOffset; |
167 | int m_namesOffset; |
168 | int m_dataOffset; |
169 | quint32 m_overallFlags; |
170 | bool m_useNameSpace; |
171 | QStringList m_failedResources; |
172 | QIODevice *m_errorDevice; |
173 | QIODevice *m_outDevice; |
174 | QByteArray m_out; |
175 | quint8 m_formatVersion; |
176 | bool m_noZstd; |
177 | }; |
178 | |
179 | QT_END_NAMESPACE |
180 | |
181 | #endif // RCC_H |
182 | |