summaryrefslogtreecommitdiffstats
path: root/src/tools/rcc/rcc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/rcc/rcc.cpp')
-rw-r--r--src/tools/rcc/rcc.cpp54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp
index 7188c81300..8b1ebad14c 100644
--- a/src/tools/rcc/rcc.cpp
+++ b/src/tools/rcc/rcc.cpp
@@ -37,7 +37,6 @@
#include <qfile.h>
#include <qiodevice.h>
#include <qlocale.h>
-#include <qregexp.h>
#include <qstack.h>
#include <qxmlstream.h>
@@ -113,7 +112,8 @@ public:
uint flags = NoFlags,
RCCResourceLibrary::CompressionAlgorithm compressAlgo = CONSTANT_COMPRESSALGO_DEFAULT,
int compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT,
- int compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT);
+ int compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT,
+ bool noZstd = false);
~RCCFileInfo();
QString resourceName() const;
@@ -137,11 +137,13 @@ public:
qint64 m_nameOffset;
qint64 m_dataOffset;
qint64 m_childOffset;
+ bool m_noZstd;
};
RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo,
QLocale::Language language, QLocale::Country country, uint flags,
- RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, int compressThreshold)
+ RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, int compressThreshold,
+ bool noZstd)
{
m_name = name;
m_fileInfo = fileInfo;
@@ -155,6 +157,7 @@ RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo,
m_compressAlgo = compressAlgo;
m_compressLevel = compressLevel;
m_compressThreshold = compressThreshold;
+ m_noZstd = noZstd;
}
RCCFileInfo::~RCCFileInfo()
@@ -267,11 +270,11 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset,
// Check if compression is useful for this file
if (data.size() != 0) {
#if QT_CONFIG(zstd)
- if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) {
+ if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best && !m_noZstd) {
m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zstd;
m_compressLevel = 19; // not ZSTD_maxCLevel(), as 20+ are experimental
}
- if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zstd) {
+ if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zstd && !m_noZstd) {
if (lib.m_zstdCCtx == nullptr)
lib.m_zstdCCtx = ZSTD_createCCtx();
qsizetype size = data.size();
@@ -471,7 +474,8 @@ RCCResourceLibrary::RCCResourceLibrary(quint8 formatVersion)
m_useNameSpace(CONSTANT_USENAMESPACE),
m_errorDevice(0),
m_outDevice(0),
- m_formatVersion(formatVersion)
+ m_formatVersion(formatVersion),
+ m_noZstd(false)
{
m_out.reserve(30 * 1000 * 1000);
#if QT_CONFIG(zstd)
@@ -651,7 +655,8 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
child.isDir() ? RCCFileInfo::Directory : RCCFileInfo::NoFlags,
compressAlgo,
compressLevel,
- compressThreshold)
+ compressThreshold,
+ m_noZstd)
);
if (!arc)
m_failedResources.push_back(child.fileName());
@@ -667,7 +672,8 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
RCCFileInfo::NoFlags,
compressAlgo,
compressLevel,
- compressThreshold)
+ compressThreshold,
+ m_noZstd)
);
if (!arc)
m_failedResources.push_back(absFileName);
@@ -744,10 +750,9 @@ bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file)
const QString filename = nodes.at(nodes.size()-1);
RCCFileInfo *s = new RCCFileInfo(file);
s->m_parent = parent;
- typedef QHash<QString, RCCFileInfo*>::const_iterator ChildConstIterator;
- const ChildConstIterator cbegin = parent->m_children.constFind(filename);
- const ChildConstIterator cend = parent->m_children.constEnd();
- for (ChildConstIterator it = cbegin; it != cend; ++it) {
+ auto cbegin = parent->m_children.constFind(filename);
+ auto cend = parent->m_children.constEnd();
+ for (auto it = cbegin; it != cend; ++it) {
if (it.key() == filename && it.value()->m_language == s->m_language &&
it.value()->m_country == s->m_country) {
for (const QString &name : qAsConst(m_fileNames)) {
@@ -823,7 +828,7 @@ QStringList RCCResourceLibrary::dataFiles() const
pending.push(m_root);
while (!pending.isEmpty()) {
RCCFileInfo *file = pending.pop();
- for (QHash<QString, RCCFileInfo*>::iterator it = file->m_children.begin();
+ for (auto it = file->m_children.begin();
it != file->m_children.end(); ++it) {
RCCFileInfo *child = it.value();
if (child->m_flags & RCCFileInfo::Directory)
@@ -838,10 +843,9 @@ QStringList RCCResourceLibrary::dataFiles() const
// Determine map of resource identifier (':/newPrefix/images/p1.png') to file via recursion
static void resourceDataFileMapRecursion(const RCCFileInfo *m_root, const QString &path, RCCResourceLibrary::ResourceDataFileMap &m)
{
- typedef QHash<QString, RCCFileInfo*>::const_iterator ChildConstIterator;
const QChar slash = QLatin1Char('/');
- const ChildConstIterator cend = m_root->m_children.constEnd();
- for (ChildConstIterator it = m_root->m_children.constBegin(); it != cend; ++it) {
+ const auto cend = m_root->m_children.constEnd();
+ for (auto it = m_root->m_children.constBegin(); it != cend; ++it) {
const RCCFileInfo *child = it.value();
const QString childName = path + slash + child->m_name;
if (child->m_flags & RCCFileInfo::Directory) {
@@ -1149,8 +1153,7 @@ bool RCCResourceLibrary::writeDataBlobs()
QString errorMessage;
while (!pending.isEmpty()) {
RCCFileInfo *file = pending.pop();
- for (QHash<QString, RCCFileInfo*>::iterator it = file->m_children.begin();
- it != file->m_children.end(); ++it) {
+ for (auto it = file->m_children.cbegin(); it != file->m_children.cend(); ++it) {
RCCFileInfo *child = it.value();
if (child->m_flags & RCCFileInfo::Directory)
pending.push(child);
@@ -1214,8 +1217,7 @@ bool RCCResourceLibrary::writeDataNames()
qint64 offset = 0;
while (!pending.isEmpty()) {
RCCFileInfo *file = pending.pop();
- for (QHash<QString, RCCFileInfo*>::iterator it = file->m_children.begin();
- it != file->m_children.end(); ++it) {
+ for (auto it = file->m_children.cbegin(); it != file->m_children.cend(); ++it) {
RCCFileInfo *child = it.value();
if (child->m_flags & RCCFileInfo::Directory)
pending.push(child);
@@ -1359,7 +1361,17 @@ bool RCCResourceLibrary::writeInitializer()
QString initNameStr = m_initName;
if (!initNameStr.isEmpty()) {
initNameStr.prepend(QLatin1Char('_'));
- initNameStr.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
+ auto isAsciiLetterOrNumber = [] (QChar c) -> bool {
+ ushort ch = c.unicode();
+ return (ch >= '0' && ch <= '9') ||
+ (ch >= 'A' && ch <= 'Z') ||
+ (ch >= 'a' && ch <= 'z') ||
+ ch == '_';
+ };
+ for (QChar &c : initNameStr) {
+ if (!isAsciiLetterOrNumber(c))
+ c = QLatin1Char('_');
+ }
}
QByteArray initName = initNameStr.toLatin1();