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 }; setFormat(Format f)62 void setFormat(Format f) { m_format = f; } format()63 Format format() const { return m_format; } 64 setInputFiles(const QStringList & files)65 void setInputFiles(const QStringList &files) { m_fileNames = files; } inputFiles()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 setVerbose(bool b)74 void setVerbose(bool b) { m_verbose = b; } verbose()75 bool verbose() const { return m_verbose; } 76 setInitName(const QString & name)77 void setInitName(const QString &name) { m_initName = name; } initName()78 QString initName() const { return m_initName; } 79 setOutputName(const QString & name)80 void setOutputName(const QString &name) { m_outputName = name; } outputName()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); setCompressionAlgorithm(CompressionAlgorithm algo)92 void setCompressionAlgorithm(CompressionAlgorithm algo) { m_compressionAlgo = algo; } compressionAlgorithm()93 CompressionAlgorithm compressionAlgorithm() const { return m_compressionAlgo; } 94 95 static int parseCompressionLevel(CompressionAlgorithm algo, const QString &level, QString *errorMsg); setCompressLevel(int c)96 void setCompressLevel(int c) { m_compressLevel = c; } compressLevel()97 int compressLevel() const { return m_compressLevel; } 98 setCompressThreshold(int t)99 void setCompressThreshold(int t) { m_compressThreshold = t; } compressThreshold()100 int compressThreshold() const { return m_compressThreshold; } 101 setResourceRoot(const QString & root)102 void setResourceRoot(const QString &root) { m_resourceRoot = root; } resourceRoot()103 QString resourceRoot() const { return m_resourceRoot; } 104 setUseNameSpace(bool v)105 void setUseNameSpace(bool v) { m_useNameSpace = v; } useNameSpace()106 bool useNameSpace() const { return m_useNameSpace; } 107 failedResources()108 QStringList failedResources() const { return m_failedResources; } 109 formatVersion()110 int formatVersion() const { return m_formatVersion; } 111 112 private: 113 struct Strings { 114 Strings(); 115 const QString TAG_RCC; 116 const QString TAG_RESOURCE; 117 const QString TAG_FILE; 118 const QString ATTRIBUTE_LANG; 119 const QString ATTRIBUTE_PREFIX; 120 const QString ATTRIBUTE_ALIAS; 121 const QString ATTRIBUTE_THRESHOLD; 122 const QString ATTRIBUTE_COMPRESS; 123 const QString ATTRIBUTE_COMPRESSALGO; 124 }; 125 friend class RCCFileInfo; 126 void reset(); 127 bool addFile(const QString &alias, const RCCFileInfo &file); 128 bool interpretResourceFile(QIODevice *inputDevice, const QString &file, 129 QString currentPath = QString(), bool listMode = false); 130 bool writeHeader(); 131 bool writeDataBlobs(); 132 bool writeDataNames(); 133 bool writeDataStructure(); 134 bool writeInitializer(); 135 void writeMangleNamespaceFunction(const QByteArray &name); 136 void writeAddNamespaceFunction(const QByteArray &name); 137 void writeDecimal(int value); 138 void writeHex(quint8 number); 139 void write2HexDigits(quint8 number); 140 void writeNumber2(quint16 number); 141 void writeNumber4(quint32 number); 142 void writeNumber8(quint64 number); writeChar(char c)143 void writeChar(char c) { m_out.append(c); } 144 void writeByteArray(const QByteArray &); 145 void write(const char *, int len); writeString(const char * s)146 void writeString(const char *s) { write(s, static_cast<int>(strlen(s))); } 147 148 #if QT_CONFIG(zstd) 149 ZSTD_CCtx *m_zstdCCtx; 150 #endif 151 152 const Strings m_strings; 153 RCCFileInfo *m_root; 154 QStringList m_fileNames; 155 QString m_resourceRoot; 156 QString m_initName; 157 QString m_outputName; 158 Format m_format; 159 bool m_verbose; 160 CompressionAlgorithm m_compressionAlgo; 161 int m_compressLevel; 162 int m_compressThreshold; 163 int m_treeOffset; 164 int m_namesOffset; 165 int m_dataOffset; 166 quint32 m_overallFlags; 167 bool m_useNameSpace; 168 QStringList m_failedResources; 169 QIODevice *m_errorDevice; 170 QIODevice *m_outDevice; 171 QByteArray m_out; 172 quint8 m_formatVersion; 173 }; 174 175 QT_END_NAMESPACE 176 177 #endif // RCC_H 178