56 #include <qplatformdefs.h> 57 #include "private/qabstractfileengine_p.h" 60 # include "private/qcore_unix_p.h" 65 #if defined(Q_OS_VXWORKS) 117 int hash(
int node)
const;
119 short flags(
int node)
const;
127 inline bool isContainer(
int node)
const {
return flags(node) & Directory; }
128 inline bool isCompressed(
int node)
const {
return flags(node) & Compressed; }
134 {
return tree == other.
tree && names == other.
names && payloads == other.
payloads; }
235 void ensureChildren()
const;
256 absoluteFilePath.
clear();
262 for(
int i = 0; i < related.
size(); ++i) {
277 for(
int i = 0; i < list->
size(); ++i) {
279 const int node = res->
findNode(cleaned, locale);
330 for(
int i = 0; i < searchPaths.
size(); ++i) {
332 if(that->
load(searchPath)) {
347 QString path = absoluteFilePath, k;
352 for(
int i = 0; i < related.
size(); ++i) {
360 const int node = res->
findNode(cleaned);
363 for(
int kid = 0; kid < related_children.
size(); ++kid) {
364 k = related_children.
at(kid);
446 d->ensureInitialized();
460 d->ensureInitialized();
461 return d->absoluteFilePath;
473 d->ensureInitialized();
474 return !
d->related.isEmpty();
500 d->ensureInitialized();
501 return d->compressed;
513 d->ensureInitialized();
529 d->ensureInitialized();
543 d->ensureInitialized();
580 qWarning(
"QResource::addResourceSearchPath: Search paths must be absolute (start with /) [%s]",
585 resourceSearchPaths()->prepend(path);
606 return *resourceSearchPaths();
613 const int offset = findOffset(node);
614 int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
615 (tree[offset+2] << 8) + (tree[offset+3] << 0);
617 return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) +
618 (names[name_offset+2] << 8) + (names[name_offset+3] << 0);
624 const int offset = findOffset(node);
627 int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
628 (tree[offset+2] << 8) + (tree[offset+3] << 0);
629 const short name_length = (names[name_offset+0] << 8) +
630 (names[name_offset+1] << 0);
636 for(
int i = 0; i < name_length*2; i+=2) {
637 QChar c(names[name_offset+i+1], names[name_offset+i]);
662 #ifdef DEBUG_RESOURCE_MATCH 670 int child_count = (tree[6] << 24) + (tree[7] << 16) +
671 (tree[8] << 8) + (tree[9] << 0);
672 int child = (tree[10] << 24) + (tree[11] << 16) +
673 (tree[12] << 8) + (tree[13] << 0);
679 while (child_count && splitter.
hasNext()) {
682 #ifdef DEBUG_RESOURCE_MATCH 683 qDebug() <<
" CHILDREN" << segment;
684 for(
int j = 0; j < child_count; ++j) {
685 qDebug() <<
" " << child+j <<
" :: " <<
name(child+j);
688 const int h =
qHash(segment);
691 int l = 0, r = child_count-1;
692 int sub_node = (l+r+1)/2;
694 const int sub_node_hash =
hash(child+sub_node);
695 if(h == sub_node_hash)
697 else if(h < sub_node_hash)
701 sub_node = (l + r + 1) / 2;
707 if(
hash(sub_node) == h) {
708 while(sub_node > child &&
hash(sub_node-1) == h)
710 for(; sub_node < child+child_count &&
hash(sub_node) == h; ++sub_node) {
711 if(
name(sub_node) == segment) {
713 int offset = findOffset(sub_node);
714 #ifdef DEBUG_RESOURCE_MATCH 715 qDebug() <<
" TRY" << sub_node <<
name(sub_node) << offset;
719 const short flags = (tree[offset+0] << 8) +
720 (tree[offset+1] << 0);
724 if(!(flags & Directory)) {
725 const short country = (tree[offset+0] << 8) +
726 (tree[offset+1] << 0);
729 const short language = (tree[offset+0] << 8) +
730 (tree[offset+1] << 0);
732 #ifdef DEBUG_RESOURCE_MATCH 736 #ifdef DEBUG_RESOURCE_MATCH 737 qDebug() <<
"!!!!" <<
"FINISHED" << __LINE__ << sub_node;
746 #ifdef DEBUG_RESOURCE_MATCH 747 qDebug() <<
"!!!!" <<
"FINISHED" << __LINE__ << sub_node;
754 if(!(flags & Directory))
757 child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
758 (tree[offset+2] << 8) + (tree[offset+3] << 0);
760 child = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
761 (tree[offset+2] << 8) + (tree[offset+3] << 0);
769 #ifdef DEBUG_RESOURCE_MATCH 770 qDebug() <<
"!!!!" <<
"FINISHED" << __LINE__ << node;
778 const int offset = findOffset(node) + 4;
779 return (tree[offset+0] << 8) + (tree[offset+1] << 0);
787 int offset = findOffset(node) + 4;
789 const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0);
794 if(!(flags & Directory)) {
795 const int data_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
796 (tree[offset+2] << 8) + (tree[offset+3] << 0);
797 const uint data_length = (payloads[data_offset+0] << 24) + (payloads[data_offset+1] << 16) +
798 (payloads[data_offset+2] << 8) + (payloads[data_offset+3] << 0);
799 const uchar *ret = payloads+data_offset+4;
810 int offset = findOffset(node) + 4;
812 const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0);
816 if(flags & Directory) {
817 const int child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
818 (tree[offset+2] << 8) + (tree[offset+3] << 0);
820 const int child_off = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
821 (tree[offset+2] << 8) + (tree[offset+3] << 0);
822 for(
int i = child_off; i < child_off+child_count; ++i)
829 const QString root = mappingRoot();
833 if(path_segments.size() <= root_segments.
size()) {
835 for(
int i = 0; i < path_segments.size(); ++i) {
836 if(root_segments[i] != path_segments[i])
840 if(matched == path_segments.size()) {
841 if(match && root_segments.
size() > matched)
842 *match = root_segments.
at(matched);
851 const unsigned char *
name,
const unsigned char *
data)
854 if(version == 0x01 && resourceList()) {
857 for(
int i = 0; i < resourceList()->size(); ++i) {
858 if(*resourceList()->at(i) == res) {
866 resourceList()->append(root);
874 const unsigned char *
name,
const unsigned char *
data)
877 if(version == 0x01 && resourceList()) {
879 for(
int i = 0; i < resourceList()->size(); ) {
880 if(*resourceList()->at(i) == res) {
912 if(b[offset+0] !=
'q' || b[offset+1] !=
'r' ||
913 b[offset+2] !=
'e' || b[offset+3] !=
's') {
918 const int version = (b[offset+0] << 24) + (b[offset+1] << 16) +
919 (b[offset+2] << 8) + (b[offset+3] << 0);
922 const int tree_offset = (b[offset+0] << 24) + (b[offset+1] << 16) +
923 (b[offset+2] << 8) + (b[offset+3] << 0);
926 const int data_offset = (b[offset+0] << 24) + (b[offset+1] << 16) +
927 (b[offset+2] << 8) + (b[offset+3] << 0);
930 const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) +
931 (b[offset+2] << 8) + (b[offset+3] << 0);
934 if(version == 0x01) {
936 setSource(b+tree_offset, b+name_offset, b+data_offset);
943 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined (Q_OS_NACL) && !defined(Q_OS_INTEGRITY) 949 #if defined(QT_USE_MMAP) 952 #include <sys/mman.h> 969 #if defined(QT_USE_MMAP) 971 munmap((
char*)unmapPointer, unmapLength);
977 delete [] (
uchar *)mappingBuffer();
986 unsigned int data_len = 0;
994 #define MAP_FAILED -1 1006 if (!QT_FSTAT(fd, &st)) {
1008 ptr =
reinterpret_cast<uchar *
>(
1013 if (ptr && ptr != reinterpret_cast<uchar *>(
MAP_FAILED)) {
1015 data_len = st.st_size;
1021 #endif // QT_USE_MMAP 1026 data_len = file.
size();
1027 data =
new uchar[data_len];
1031 ok = (data_len == (
uint)file.
read((
char*)data, data_len));
1042 unmapPointer =
data;
1043 unmapLength = data_len;
1081 qWarning(
"QDir::registerResource: Registering a resource [%s] must be rooted in an absolute path (start with /) [%s]",
1090 resourceList()->append(root);
1118 for(
int i = 0; i < list->
size(); ++i) {
1123 resourceList()->removeAt(i);
1155 qWarning(
"QDir::registerResource: Registering a resource [%p] must be rooted in an absolute path (start with /) [%s]",
1164 resourceList()->append(root);
1189 for(
int i = 0; i < list->
size(); ++i) {
1194 resourceList()->removeAt(i);
1250 d->resource.setFileName(file);
1251 if(
d->resource.isCompressed() &&
d->resource.size()) {
1252 #ifndef QT_NO_COMPRESS 1253 d->uncompressed =
qUncompress(
d->resource.data(),
d->resource.size());
1255 Q_ASSERT(!
"QResourceFileEngine::open: Qt built without support for compression");
1267 d->resource.setFileName(file);
1273 if (
d->resource.fileName().isEmpty()) {
1274 qWarning(
"QResourceFileEngine::open: Missing file name");
1279 if(!
d->resource.isValid())
1288 d->uncompressed.clear();
1300 if(len >
size()-
d->offset)
1301 len =
size()-
d->offset;
1304 if(
d->resource.isCompressed())
1305 memcpy(data,
d->uncompressed.constData()+
d->offset, len);
1307 memcpy(data,
d->resource.data()+
d->offset, len);
1340 if(!
d->resource.isValid())
1342 if(
d->resource.isCompressed())
1343 return d->uncompressed.size();
1344 return d->resource.size();
1356 if(!
d->resource.isValid())
1358 return d->offset ==
size();
1364 if(!
d->resource.isValid())
1367 if(
d->offset >
size())
1381 QAbstractFileEngine::FileFlags ret = 0;
1382 if(!
d->resource.isValid())
1388 if(
d->resource.isDir())
1410 int slash =
d->resource.fileName().lastIndexOf(
QLatin1Char(
'/'));
1412 return d->resource.fileName();
1413 return d->resource.fileName().mid(slash + 1);
1419 else if (slash <= 1)
1421 return path.
left(slash);
1424 const QString absoluteFilePath =
d->resource.absoluteFilePath();
1428 return absoluteFilePath.
left(slash);
1430 return absoluteFilePath;
1432 return d->resource.fileName();
1442 static const uint nobodyID = (
uint) -2;
1480 return (returnValue->
address != 0);
1498 if (offset < 0 || size <= 0 || !resource.isValid() || offset + size > resource.size()) {
1502 uchar *address =
const_cast<uchar *
>(resource.data());
1503 return (address + offset);
virtual bool open(QIODevice::OpenMode flags)
Opens the file in the specified mode.
QString absoluteFilePath() const
Returns the real path that this QResource represents, if the resource was found via the QDir::searchP...
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const
Requests that the directory dirName be created.
virtual bool flush()
Flushes the open file, returning true if successful; otherwise returns false.
static uint hash(const uchar *p, int n)
virtual bool seek(qint64)
Sets the file position to the given offset.
uint qHash(const QProcEnvKey &key)
virtual bool setPermissions(uint perms)
Requests that the file's permissions be set to perms.
virtual bool caseSensitive() const
Should return true if the underlying file system is case-sensitive; otherwise return false...
const uchar * data(int node, qint64 *size) const
Language language() const
Returns the language of this locale.
QLocale locale() const
Returns the locale used to locate the data for the QResource.
#define QT_END_NAMESPACE
This macro expands to.
The QMutex class provides access serialization between threads.
void setLocale(const QLocale &locale)
Sets a QResource to only load the localization of resource to for locale.
char * data()
Returns a pointer to the data stored in the byte array.
Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes)
QString name(int node) const
The QAtomicInt class provides platform-independent atomic operations on integers. ...
QResourceFileEngine(const QString &path)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
void setSource(const uchar *t, const uchar *n, const uchar *d)
The QByteArray class provides an array of bytes.
int length() const
Returns the number of characters in this string.
Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data)
QString & prepend(QChar c)
virtual bool rename(const QString &newName)
Requests that the file be renamed to newName in the file system.
static void clear(QVariant::Private *d)
bool registerSelf(const QString &f)
static bool match(const uchar *found, const char *target, uint len)
void setFileName(const QString &file)
Sets a QResource to point to file.
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Requests that a list of all the files matching the filters list based on the filterNames in the file ...
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
virtual QString owner(FileOwner) const
If owner is OwnerUser return the name of the user who owns the file.
FileName
These values are used to request a file name in a particular format.
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
bool isCompressed(int node) const
static QString qt_resource_fixResourceRoot(QString r)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool ref()
Atomically increments the value of this QAtomicInt.
The QString class provides a Unicode character string.
bool load(const QString &file)
qint64 size() const
Returns the size of the data backing the resource.
QFile::MemoryMapFlags flags
virtual QString mappingRoot() const
The QChar class provides a 16-bit Unicode character.
QChar * data()
Returns a pointer to the data stored in the QString.
QResource(const QString &file=QString(), const QLocale &locale=QLocale())
Constructs a QResource pointing to file.
QString fileName() const
Returns the full path to the file that this QResource represents as it was passed.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Requests that a list of all the files matching the filters list based on the filterNames in the file ...
provides an extended output argument to QAbstractFileEngine's extension support.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
virtual ResourceRootType type() const
QResourceFileEnginePrivate()
Q_CORE_EXPORT void qDebug(const char *,...)
QStringSplitter(const QString &s)
void append(const T &t)
Inserts value at the end of the list.
virtual QString fileName(QAbstractFileEngine::FileName file) const
Return the file engine's current file name in the format specified by file.
Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data)
QLocale::Language language
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
bool supportsExtension(Extension extension) const
This virtual function returns true if the file engine supports extension; otherwise, false is returned.
static QStringList searchPaths()
Use QDir::searchPaths() instead.
The QResource class provides an interface for reading directly from resources.
Extension
This enum describes the types of extensions that the file engine can support.
virtual Iterator * endEntryList()
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
virtual FileFlags fileFlags(FileFlags type) const
This function should return the set of OR'd flags that are true for the file engine's file...
bool contains(const T &value) const
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
virtual QString mappingRoot() const
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
const T & at(int i) const
Returns the item at index position i in the list.
bool deref()
Atomically decrements the value of this QAtomicInt.
The QStringList class provides a list of strings.
Q_DECLARE_TYPEINFO(QResourceRoot, Q_MOVABLE_TYPE)
provides an extended input argument to QAbstractFileEngine's extension support.
QDynamicFileResourceRoot(const QString &_root)
const uchar * data() const
Returns direct access to a read only segment of data that this resource represents.
static void addSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
Q_CORE_EXPORT void qWarning(const char *,...)
The QAbstractFileEngine class provides an abstraction for accessing the filesystem.
const_iterator insert(const T &value)
virtual bool isRelativePath() const
Return true if the file referred to by this file engine has a relative path; otherwise return false...
bool operator==(const QResourceRoot &other) const
static const char * data(const QByteArray &arr)
QString mappingFile() const
static void ensureInitialized()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
bool isCompressed() const
Returns true if the resource represents a file and the data backing it is in a compressed format...
virtual QDateTime fileTime(FileTime time) const
If time is CreationTime, return when the file was created.
short flags(int node) const
const T * ptr(const T &t)
static bool registerResource(const QString &rccFilename, const QString &resourceRoot=QString())
Registers the resource with the given rccFileName at the location in the resource tree specified by m...
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
bool isDir() const
Returns true if the resource represents a directory and thus may have children() in it...
void clear()
Removes all items from the list.
virtual bool copy(const QString &newName)
Copies the contents of this file to a file with the name newName.
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
virtual ResourceRootType type() const
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
static QString cleanPath(const QString &_path)
FileTime
These are used by the fileTime() function.
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const
Requests that the directory dirName is deleted from the file system.
QResourceRoot(const uchar *t, const uchar *n, const uchar *d)
int findNode(const QString &path, const QLocale &locale=QLocale()) const
The QStringRef class provides a thin wrapper around QString substrings.
~QResource()
Releases the resources of the QResource object.
qint64 size() const
Returns the size of the file.
void resize(int size)
Sets the size of the string to size characters.
const char * constData() const
Returns a pointer to the data stored in the byte array.
virtual qint64 size() const
Returns the size of the file.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
bool operator!=(const QResourceRoot &other) const
static const char *const filters[3]
bool registerSelf(const uchar *b)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
uchar * map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
#define Q_DECLARE_PUBLIC(Class)
The QDateTime class provides date and time functions.
The QFile class provides an interface for reading from and writing to files.
~QDynamicFileResourceRoot()
int findOffset(int node) const
virtual qint64 pos() const
Returns the current file position.
void clear()
Clears the contents of the string and makes it empty.
const uchar * mappingBuffer() const
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Q_CORE_EXPORT void qInitResourceIO()
QResourcePrivate(QResource *_q)
virtual bool setSize(qint64 size)
Requests that the file be set to size size.
#define st(var, type, card)
int size() const
Returns the number of items in the list.
bool mappingRootSubdir(const QString &path, QString *match=0) const
void ensureChildren() const
static QReadWriteLock lock
virtual bool link(const QString &newName)
Creates a link from the file currently specified by fileName() to newName.
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines...
bool extension(Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0)
This virtual function can be reimplemented in a QAbstractFileEngine subclass to provide support for e...
virtual bool remove()
Requests that the file is deleted from the file system.
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
virtual qint64 read(char *data, qint64 maxlen)
Reads a number of characters from the file into data.
virtual bool close()
Closes the file, returning true if successful; otherwise returns false.
void ensureInitialized() const
QStringList children(int node) const
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
virtual uint ownerId(FileOwner) const
If owner is OwnerUser return the ID of the user who owns the file.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
virtual qint64 write(const char *data, qint64 len)
Writes len bytes from data to the file.
MemoryMapFlags
This enum describes special options that may be used by the map() function.
Country country() const
Returns the country of this locale.
QStringList children() const
Returns a list of all resources in this directory, if the resource represents a file the list will be...
bool isContainer(int node) const
virtual bool isSequential() const
Returns true if the file is a sequential access device; returns false if the file is a direct access ...
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
~QDynamicBufferResourceRoot()
QDynamicBufferResourceRoot(const QString &_root)
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
virtual void setFileName(const QString &file)
Sets the file engine's file name to file.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
bool operator==(QBool b1, bool b2)
QList< QResourceRoot * > related
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
static bool unregisterResource(const QString &rccFilename, const QString &resourceRoot=QString())
Unregisters the resource with the given rccFileName at the location in the resource tree specified by...
virtual bool atEnd() const
virtual ResourceRootType type() const
The QList class is a template class that provides lists.
virtual Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames)