diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-06-20 09:44:20 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2019-07-16 22:36:27 -0300 |
commit | d80bd2f54876c2e4c0593d3d5d4d0e01824dc301 (patch) | |
tree | 9c64a81ad443104b5943d3c2c7ac8f709bbd7a2e /src/corelib/io | |
parent | a5da01c0449c4237280021a11271cd433707a523 (diff) |
QResource: deprecate isCompressed()
Current codebases assume isCompressed() implies ZlibCompression, since
there was no compressionAlgorithm() getter. In order to force codebases
to change, deprecate isCompressed() and force handling of the algorithm.
The replacement API is being introduced in 5.14, which is why the
warning is being emitted in 5.15 only.
Change-Id: Ief874765cd7b43798de3fffd15a9f5d978951ea5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qresource.cpp | 46 | ||||
-rw-r--r-- | src/corelib/io/qresource.h | 5 |
2 files changed, 34 insertions, 17 deletions
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index fcc5b69179..747f153f48 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2018 The Qt Company Ltd. -** Copyright (C) 2018 Intel Corporation. +** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -279,14 +279,14 @@ static inline QStringList *resourceSearchPaths() This enum is used by compressionAlgorithm() to indicate which algorithm the RCC tool used to compress the payload. - \value NoCompression Contents are not compressed (isCompressed() is false). + \value NoCompression Contents are not compressed \value ZlibCompression Contents are compressed using \l{zlib}{https://zlib.net} and can be decompressed using the qUncompress() function. \value ZstdCompression Contents are compressed using \l{zstd}{https://zstd.net}. To decompress, use the \c{ZSTD_decompress} function from the zstd library. - \sa compressionAlgorithm(), isCompressed() + \sa compressionAlgorithm() */ class QResourcePrivate { @@ -551,13 +551,20 @@ bool QResource::isValid() const \sa isDir() */ - +#if QT_DEPRECATED_SINCE(5, 13) /*! + \obsolete + Returns \c true if the resource represents a file and the data backing it is in a compressed format, false otherwise. If the data is compressed, check compressionAlgorithm() to verify what algorithm to use to decompress the data. + \note This function is deprecated and can be replaced with + \code + compressionAlgorithm() != NoCompression + \endcode + \sa data(), compressionAlgorithm(), isFile() */ @@ -565,6 +572,7 @@ bool QResource::isCompressed() const { return compressionAlgorithm() != NoCompression; } +#endif /*! \since 5.13 @@ -582,7 +590,7 @@ bool QResource::isCompressed() const See \l{http://facebook.github.io/zstd/zstd_manual.html}{Zstandard manual}. - \sa isCompressed(), data(), isFile() + \sa data(), isFile() */ QResource::Compression QResource::compressionAlgorithm() const { @@ -606,11 +614,11 @@ qint64 QResource::size() const /*! Returns direct access to a read only segment of data that this resource - represents. If the resource is compressed the data returns is - compressed and qUncompress() must be used to access the data. If the - resource is a directory \nullptr is returned. + represents. If the resource is compressed the data returned is compressed + and the appropriate library functions must be used to access the data. If + the resource is a directory \nullptr is returned. - \sa size(), isCompressed(), isFile() + \sa size(), compressionAlgorithm(), isFile() */ const uchar *QResource::data() const @@ -1366,9 +1374,15 @@ bool QResourceFileEngine::open(QIODevice::OpenMode flags) qWarning("QResourceFileEngine::open: Missing file name"); return false; } - if(flags & QIODevice::WriteOnly) + if (flags & QIODevice::WriteOnly) return false; - d->uncompress(); + if (d->resource.compressionAlgorithm() != QResource::NoCompression) { + d->uncompress(); + if (d->uncompressed.isNull()) { + d->errorString = QSystemError::stdString(EIO); + return false; + } + } if (!d->resource.isValid()) { d->errorString = QSystemError::stdString(ENOENT); return false; @@ -1395,7 +1409,7 @@ qint64 QResourceFileEngine::read(char *data, qint64 len) len = size()-d->offset; if(len <= 0) return 0; - if(d->resource.isCompressed()) + if (!d->uncompressed.isNull()) memcpy(data, d->uncompressed.constData()+d->offset, len); else memcpy(data, d->resource.data()+d->offset, len); @@ -1431,9 +1445,9 @@ bool QResourceFileEngine::link(const QString &) qint64 QResourceFileEngine::size() const { Q_D(const QResourceFileEngine); - if(!d->resource.isValid()) + if (!d->resource.isValid()) return 0; - if (d->resource.isCompressed()) { + if (d->resource.compressionAlgorithm() != QResource::NoCompression) { d->uncompress(); return d->uncompressed.size(); } @@ -1596,7 +1610,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory Q_UNUSED(flags); qint64 max = resource.size(); - if (resource.isCompressed()) { + if (resource.compressionAlgorithm() != QResource::NoCompression) { uncompress(); max = uncompressed.size(); } @@ -1609,7 +1623,7 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory } const uchar *address = resource.data(); - if (resource.isCompressed()) + if (resource.compressionAlgorithm() != QResource::NoCompression) address = reinterpret_cast<const uchar *>(uncompressed.constData()); return const_cast<uchar *>(address) + offset; diff --git a/src/corelib/io/qresource.h b/src/corelib/io/qresource.h index 5e798de436..5ee8d5d266 100644 --- a/src/corelib/io/qresource.h +++ b/src/corelib/io/qresource.h @@ -72,7 +72,6 @@ public: bool isValid() const; - bool isCompressed() const; Compression compressionAlgorithm() const; qint64 size() const; const uchar *data() const; @@ -84,6 +83,10 @@ public: QT_DEPRECATED_X("Use QDir::searchPaths() instead") static QStringList searchPaths(); #endif +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_VERSION_X_5_15("Use QResource::compressionAlgorithm() instead") + bool isCompressed() const; +#endif static bool registerResource(const QString &rccFilename, const QString &resourceRoot=QString()); static bool unregisterResource(const QString &rccFilename, const QString &resourceRoot=QString()); |