| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
| 2 | // Copyright (C) 2018 Intel Corporation. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 4 | |
| 5 | // Note: A copy of this file is used in Qt Widgets Designer (qttools/src/designer/src/lib/shared/rcc_p.h) |
| 6 | |
| 7 | #ifndef RCC_H |
| 8 | #define RCC_H |
| 9 | |
| 10 | #include <qstringlist.h> |
| 11 | #include <qhash.h> |
| 12 | #include <qstring.h> |
| 13 | |
| 14 | typedef struct ZSTD_CCtx_s ZSTD_CCtx; |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | class RCCFileInfo; |
| 19 | class QIODevice; |
| 20 | class QTextStream; |
| 21 | |
| 22 | |
| 23 | class RCCResourceLibrary |
| 24 | { |
| 25 | RCCResourceLibrary(const RCCResourceLibrary &); |
| 26 | RCCResourceLibrary &operator=(const RCCResourceLibrary &); |
| 27 | |
| 28 | public: |
| 29 | RCCResourceLibrary(quint8 formatVersion); |
| 30 | ~RCCResourceLibrary(); |
| 31 | |
| 32 | bool output(QIODevice &outDevice, QIODevice &tempDevice, QIODevice &errorDevice); |
| 33 | |
| 34 | bool readFiles(bool listMode, QIODevice &errorDevice); |
| 35 | |
| 36 | enum Format { Binary, C_Code, Pass1, Pass2, Python_Code }; |
| 37 | void setFormat(Format f) { m_format = f; } |
| 38 | Format format() const { return m_format; } |
| 39 | |
| 40 | void setInputFiles(const QStringList &files) { m_fileNames = files; } |
| 41 | QStringList inputFiles() const { return m_fileNames; } |
| 42 | |
| 43 | QStringList dataFiles() const; |
| 44 | |
| 45 | // Return a map of resource identifier (':/newPrefix/images/p1.png') to file. |
| 46 | typedef QHash<QString, QString> ResourceDataFileMap; |
| 47 | ResourceDataFileMap resourceDataFileMap() const; |
| 48 | |
| 49 | void setVerbose(bool b) { m_verbose = b; } |
| 50 | bool verbose() const { return m_verbose; } |
| 51 | |
| 52 | void setInitName(const QString &name) { m_initName = name; } |
| 53 | QString initName() const { return m_initName; } |
| 54 | |
| 55 | void setOutputName(const QString &name) { m_outputName = name; } |
| 56 | QString outputName() const { return m_outputName; } |
| 57 | |
| 58 | enum class CompressionAlgorithm { |
| 59 | Zlib, |
| 60 | Zstd, |
| 61 | |
| 62 | Best = 99, |
| 63 | None = -1 |
| 64 | }; |
| 65 | |
| 66 | static CompressionAlgorithm parseCompressionAlgorithm(QStringView algo, QString *errorMsg); |
| 67 | void setCompressionAlgorithm(CompressionAlgorithm algo) { m_compressionAlgo = algo; } |
| 68 | CompressionAlgorithm compressionAlgorithm() const { return m_compressionAlgo; } |
| 69 | |
| 70 | static int parseCompressionLevel(CompressionAlgorithm algo, const QString &level, QString *errorMsg); |
| 71 | void setCompressLevel(int c) { m_compressLevel = c; } |
| 72 | int compressLevel() const { return m_compressLevel; } |
| 73 | |
| 74 | void setCompressThreshold(int t) { m_compressThreshold = t; } |
| 75 | int compressThreshold() const { return m_compressThreshold; } |
| 76 | |
| 77 | void setResourceRoot(const QString &root) { m_resourceRoot = root; } |
| 78 | QString resourceRoot() const { return m_resourceRoot; } |
| 79 | |
| 80 | void setUseNameSpace(bool v) { m_useNameSpace = v; } |
| 81 | bool useNameSpace() const { return m_useNameSpace; } |
| 82 | |
| 83 | QStringList failedResources() const { return m_failedResources; } |
| 84 | |
| 85 | int formatVersion() const { return m_formatVersion; } |
| 86 | |
| 87 | void setNoZstd(bool v) { m_noZstd = v; } |
| 88 | bool noZstd() const { return m_noZstd; } |
| 89 | |
| 90 | private: |
| 91 | struct Strings { |
| 92 | Strings(); |
| 93 | const QString TAG_RCC; |
| 94 | const QString TAG_RESOURCE; |
| 95 | const QString TAG_FILE; |
| 96 | const QString TAG_LEGAL = QLatin1StringView("legal" ); |
| 97 | const QString ATTRIBUTE_LANG; |
| 98 | const QString ATTRIBUTE_PREFIX; |
| 99 | const QString ATTRIBUTE_ALIAS; |
| 100 | const QString ATTRIBUTE_EMPTY; |
| 101 | const QString ATTRIBUTE_THRESHOLD; |
| 102 | const QString ATTRIBUTE_COMPRESS; |
| 103 | const QString ATTRIBUTE_COMPRESSALGO; |
| 104 | }; |
| 105 | friend class RCCFileInfo; |
| 106 | void reset(); |
| 107 | bool addFile(const QString &alias, RCCFileInfo file); |
| 108 | bool interpretResourceFile(QIODevice *inputDevice, const QString &file, |
| 109 | QString currentPath = QString(), bool listMode = false); |
| 110 | bool (); |
| 111 | bool writeDataBlobs(); |
| 112 | bool writeDataNames(); |
| 113 | bool writeDataStructure(); |
| 114 | bool writeInitializer(); |
| 115 | void writeMangleNamespaceFunction(const QByteArray &name); |
| 116 | void writeAddNamespaceFunction(const QByteArray &name); |
| 117 | void writeDecimal(int value); |
| 118 | void writeHex(quint8 number); |
| 119 | void write2HexDigits(quint8 number); |
| 120 | void writeNumber2(quint16 number); |
| 121 | void writeNumber4(quint32 number); |
| 122 | void writeNumber8(quint64 number); |
| 123 | void writeChar(char c) { m_out.append(c); } |
| 124 | void writeByteArray(const QByteArray &); |
| 125 | void write(const char *, int len); |
| 126 | void writeString(const char *s) { write(s, len: static_cast<int>(strlen(s: s))); } |
| 127 | |
| 128 | #if QT_CONFIG(zstd) |
| 129 | ZSTD_CCtx *m_zstdCCtx; |
| 130 | #endif |
| 131 | |
| 132 | const Strings m_strings; |
| 133 | RCCFileInfo *m_root; |
| 134 | QStringList m_fileNames; |
| 135 | QString m_resourceRoot; |
| 136 | QString m_initName; |
| 137 | QString m_outputName; |
| 138 | QString m_legal; |
| 139 | Format m_format; |
| 140 | bool m_verbose; |
| 141 | CompressionAlgorithm m_compressionAlgo; |
| 142 | int m_compressLevel; |
| 143 | int m_compressThreshold; |
| 144 | int m_treeOffset; |
| 145 | int m_namesOffset; |
| 146 | int m_dataOffset; |
| 147 | quint32 m_overallFlags; |
| 148 | bool m_useNameSpace; |
| 149 | QStringList m_failedResources; |
| 150 | QIODevice *m_errorDevice; |
| 151 | QIODevice *m_outDevice; |
| 152 | QByteArray m_out; |
| 153 | quint8 m_formatVersion; |
| 154 | bool m_noZstd; |
| 155 | }; |
| 156 | |
| 157 | QT_END_NAMESPACE |
| 158 | |
| 159 | #endif // RCC_H |
| 160 | |