Make it possible to specify the RCC data version format
After commit d207738245 we unconditionally
write version two, but it seems useful to allow users to specify the
version explicitly.
Change-Id: I81d3de3d7f87318653f89bf10e3618becd8329d6
Task-number: QTBUG-58769
Reviewed-by: hjk <hjk@qt.io>
bb10
parent
e7f019011a
commit
4a31eca4ce
|
|
@ -153,6 +153,9 @@ int runRcc(int argc, char *argv[])
|
|||
QCommandLineOption projectOption(QStringLiteral("project"), QStringLiteral("Output a resource file containing all files from the current directory."));
|
||||
parser.addOption(projectOption);
|
||||
|
||||
QCommandLineOption formatVersionOption(QStringLiteral("format-version"), QStringLiteral("The RCC format version to write"), QStringLiteral("number"));
|
||||
parser.addOption(formatVersionOption);
|
||||
|
||||
parser.addPositionalArgument(QStringLiteral("inputs"), QStringLiteral("Input files (*.qrc)."));
|
||||
|
||||
|
||||
|
|
@ -160,7 +163,19 @@ int runRcc(int argc, char *argv[])
|
|||
parser.process(app);
|
||||
|
||||
QString errorMsg;
|
||||
RCCResourceLibrary library;
|
||||
|
||||
quint8 formatVersion = 2;
|
||||
if (parser.isSet(formatVersionOption)) {
|
||||
bool ok = false;
|
||||
formatVersion = parser.value(formatVersionOption).toUInt(&ok);
|
||||
if (!ok) {
|
||||
errorMsg = QLatin1String("Invalid format version specified");
|
||||
} else if (formatVersion != 1 && formatVersion != 2) {
|
||||
errorMsg = QLatin1String("Unsupported format version specified");
|
||||
}
|
||||
}
|
||||
|
||||
RCCResourceLibrary library(formatVersion);
|
||||
if (parser.isSet(nameOption))
|
||||
library.setInitName(parser.value(nameOption));
|
||||
if (parser.isSet(rootOption)) {
|
||||
|
|
|
|||
|
|
@ -204,11 +204,13 @@ void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib)
|
|||
if (text || pass1)
|
||||
lib.writeChar('\n');
|
||||
|
||||
// last modified time stamp
|
||||
const QDateTime lastModified = m_fileInfo.lastModified();
|
||||
lib.writeNumber8(quint64(lastModified.isValid() ? lastModified.toMSecsSinceEpoch() : 0));
|
||||
if (text || pass1)
|
||||
lib.writeChar('\n');
|
||||
if (lib.formatVersion() >= 2) {
|
||||
// last modified time stamp
|
||||
const QDateTime lastModified = m_fileInfo.lastModified();
|
||||
lib.writeNumber8(quint64(lastModified.isValid() ? lastModified.toMSecsSinceEpoch() : 0));
|
||||
if (text || pass1)
|
||||
lib.writeChar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset,
|
||||
|
|
@ -341,7 +343,7 @@ RCCResourceLibrary::Strings::Strings() :
|
|||
{
|
||||
}
|
||||
|
||||
RCCResourceLibrary::RCCResourceLibrary()
|
||||
RCCResourceLibrary::RCCResourceLibrary(quint8 formatVersion)
|
||||
: m_root(0),
|
||||
m_format(C_Code),
|
||||
m_verbose(false),
|
||||
|
|
@ -352,7 +354,8 @@ RCCResourceLibrary::RCCResourceLibrary()
|
|||
m_dataOffset(0),
|
||||
m_useNameSpace(CONSTANT_USENAMESPACE),
|
||||
m_errorDevice(0),
|
||||
m_outDevice(0)
|
||||
m_outDevice(0),
|
||||
m_formatVersion(formatVersion)
|
||||
{
|
||||
m_out.reserve(30 * 1000 * 1000);
|
||||
}
|
||||
|
|
@ -1114,7 +1117,9 @@ bool RCCResourceLibrary::writeInitializer()
|
|||
if (m_root) {
|
||||
writeString(" ");
|
||||
writeAddNamespaceFunction("qRegisterResourceData");
|
||||
writeString("\n (0x02, qt_resource_struct, "
|
||||
writeString("\n (");
|
||||
writeHex(m_formatVersion);
|
||||
writeString(" qt_resource_struct, "
|
||||
"qt_resource_name, qt_resource_data);\n");
|
||||
}
|
||||
writeString(" return 1;\n");
|
||||
|
|
@ -1135,7 +1140,9 @@ bool RCCResourceLibrary::writeInitializer()
|
|||
if (m_root) {
|
||||
writeString(" ");
|
||||
writeAddNamespaceFunction("qUnregisterResourceData");
|
||||
writeString("\n (0x02, qt_resource_struct, "
|
||||
writeString("\n (");
|
||||
writeHex(m_formatVersion);
|
||||
writeString(" qt_resource_struct, "
|
||||
"qt_resource_name, qt_resource_data);\n");
|
||||
}
|
||||
writeString(" return 1;\n");
|
||||
|
|
@ -1152,10 +1159,10 @@ bool RCCResourceLibrary::writeInitializer()
|
|||
} else if (m_format == Binary) {
|
||||
int i = 4;
|
||||
char *p = m_out.data();
|
||||
p[i++] = 0; // 0x02
|
||||
p[i++] = 0;
|
||||
p[i++] = 0;
|
||||
p[i++] = 2;
|
||||
p[i++] = 0;
|
||||
p[i++] = m_formatVersion;
|
||||
|
||||
p[i++] = (m_treeOffset >> 24) & 0xff;
|
||||
p[i++] = (m_treeOffset >> 16) & 0xff;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class RCCResourceLibrary
|
|||
RCCResourceLibrary &operator=(const RCCResourceLibrary &);
|
||||
|
||||
public:
|
||||
RCCResourceLibrary();
|
||||
RCCResourceLibrary(quint8 formatVersion);
|
||||
~RCCResourceLibrary();
|
||||
|
||||
bool output(QIODevice &outDevice, QIODevice &tempDevice, QIODevice &errorDevice);
|
||||
|
|
@ -91,6 +91,8 @@ public:
|
|||
|
||||
QStringList failedResources() const { return m_failedResources; }
|
||||
|
||||
int formatVersion() const { return m_formatVersion; }
|
||||
|
||||
private:
|
||||
struct Strings {
|
||||
Strings();
|
||||
|
|
@ -141,6 +143,7 @@ private:
|
|||
QIODevice *m_errorDevice;
|
||||
QIODevice *m_outDevice;
|
||||
QByteArray m_out;
|
||||
quint8 m_formatVersion;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ int QT_RCC_MANGLE_NAMESPACE(qInitResources)();
|
|||
int QT_RCC_MANGLE_NAMESPACE(qInitResources)()
|
||||
{
|
||||
QT_RCC_PREPEND_NAMESPACE(qRegisterResourceData)
|
||||
(0x02, qt_resource_struct, qt_resource_name, qt_resource_data);
|
||||
(0x2, qt_resource_struct, qt_resource_name, qt_resource_data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ int QT_RCC_MANGLE_NAMESPACE(qCleanupResources)();
|
|||
int QT_RCC_MANGLE_NAMESPACE(qCleanupResources)()
|
||||
{
|
||||
QT_RCC_PREPEND_NAMESPACE(qUnregisterResourceData)
|
||||
(0x02, qt_resource_struct, qt_resource_name, qt_resource_data);
|
||||
(0x2, qt_resource_struct, qt_resource_name, qt_resource_data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue