Qt 4.8
qresource.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qresource.h"
43 #include "qresource_p.h"
44 #include "qresource_iterator_p.h"
45 #include "qset.h"
46 #include "qhash.h"
47 #include "qmutex.h"
48 #include "qdebug.h"
49 #include "qlocale.h"
50 #include "qglobal.h"
51 #include "qvector.h"
52 #include "qdatetime.h"
53 #include "qbytearray.h"
54 #include "qstringlist.h"
55 #include <qshareddata.h>
56 #include <qplatformdefs.h>
57 #include "private/qabstractfileengine_p.h"
58 
59 #ifdef Q_OS_UNIX
60 # include "private/qcore_unix_p.h"
61 #endif
62 
63 //#define DEBUG_RESOURCE_MATCH
64 
65 #if defined(Q_OS_VXWORKS)
66 # if defined(m_data)
67 # undef m_data
68 # endif
69 # if defined(m_len)
70 # undef m_len
71 # endif
72 #endif
73 
75 
76 
78 {
79 public:
81  : m_string(s), m_data(m_string.constData()), m_len(s.length()), m_pos(0)
82  {
83  m_splitChar = QLatin1Char('/');
84  }
85 
86  inline bool hasNext() {
87  while (m_pos < m_len && m_data[m_pos] == m_splitChar)
88  ++m_pos;
89  return m_pos < m_len;
90  }
91 
92  inline QStringRef next() {
93  int start = m_pos;
94  while (m_pos < m_len && m_data[m_pos] != m_splitChar)
95  ++m_pos;
96  return QStringRef(&m_string, start, m_pos - start);
97  }
98 
100  const QChar *m_data;
102  int m_len;
103  int m_pos;
104 };
105 
106 
107 //resource glue
109 {
110  enum Flags
111  {
112  Compressed = 0x01,
113  Directory = 0x02
114  };
115  const uchar *tree, *names, *payloads;
116  inline int findOffset(int node) const { return node * 14; } //sizeof each tree element
117  int hash(int node) const;
118  QString name(int node) const;
119  short flags(int node) const;
120 public:
121  mutable QAtomicInt ref;
122 
123  inline QResourceRoot(): tree(0), names(0), payloads(0) {}
124  inline QResourceRoot(const uchar *t, const uchar *n, const uchar *d) { setSource(t, n, d); }
125  virtual ~QResourceRoot() { }
126  int findNode(const QString &path, const QLocale &locale=QLocale()) const;
127  inline bool isContainer(int node) const { return flags(node) & Directory; }
128  inline bool isCompressed(int node) const { return flags(node) & Compressed; }
129  const uchar *data(int node, qint64 *size) const;
130  QStringList children(int node) const;
131  virtual QString mappingRoot() const { return QString(); }
132  bool mappingRootSubdir(const QString &path, QString *match=0) const;
133  inline bool operator==(const QResourceRoot &other) const
134  { return tree == other.tree && names == other.names && payloads == other.payloads; }
135  inline bool operator!=(const QResourceRoot &other) const
136  { return !operator==(other); }
137  enum ResourceRootType { Resource_Builtin, Resource_File, Resource_Buffer };
138  virtual ResourceRootType type() const { return Resource_Builtin; }
139 
140 protected:
141  inline void setSource(const uchar *t, const uchar *n, const uchar *d) {
142  tree = t;
143  names = n;
144  payloads = d;
145  }
146 };
147 
148 static QString cleanPath(const QString &_path)
149 {
150  QString path = QDir::cleanPath(_path);
151  // QDir::cleanPath does not remove two trailing slashes under _Windows_
152  // due to support for UNC paths. Remove those manually.
153  if (path.startsWith(QLatin1String("//")))
154  path.remove(0, 1);
155  return path;
156 }
157 
159 
161 
163 Q_GLOBAL_STATIC(ResourceList, resourceList)
164 
165 Q_GLOBAL_STATIC(QStringList, resourceSearchPaths)
166 
230 public:
231  inline QResourcePrivate(QResource *_q) : q_ptr(_q) { clear(); }
232  inline ~QResourcePrivate() { clear(); }
233 
234  void ensureInitialized() const;
235  void ensureChildren() const;
236 
237  bool load(const QString &file);
238  void clear();
239 
241  QString fileName, absoluteFilePath;
244  mutable uint compressed : 1;
245  mutable qint64 size;
246  mutable const uchar *data;
248 
251 };
252 
253 void
255 {
256  absoluteFilePath.clear();
257  compressed = 0;
258  data = 0;
259  size = 0;
260  children.clear();
261  container = 0;
262  for(int i = 0; i < related.size(); ++i) {
263  QResourceRoot *root = related.at(i);
264  if(!root->ref.deref())
265  delete root;
266  }
267  related.clear();
268 }
269 
270 bool
272 {
273  related.clear();
274  QMutexLocker lock(resourceMutex());
275  const ResourceList *list = resourceList();
276  QString cleaned = cleanPath(file);
277  for(int i = 0; i < list->size(); ++i) {
278  QResourceRoot *res = list->at(i);
279  const int node = res->findNode(cleaned, locale);
280  if(node != -1) {
281  if(related.isEmpty()) {
282  container = res->isContainer(node);
283  if(!container) {
284  data = res->data(node, &size);
285  compressed = res->isCompressed(node);
286  } else {
287  data = 0;
288  size = 0;
289  compressed = 0;
290  }
291  } else if(res->isContainer(node) != container) {
292  qWarning("QResourceInfo: Resource [%s] has both data and children!", file.toLatin1().constData());
293  }
294  res->ref.ref();
295  related.append(res);
296  } else if(res->mappingRootSubdir(file)) {
297  container = true;
298  data = 0;
299  size = 0;
300  compressed = 0;
301  res->ref.ref();
302  related.append(res);
303  }
304  }
305  return !related.isEmpty();
306 }
307 
308 void
310 {
311  if(!related.isEmpty())
312  return;
313  QResourcePrivate *that = const_cast<QResourcePrivate *>(this);
314  if(fileName == QLatin1String(":"))
315  that->fileName += QLatin1Char('/');
316  that->absoluteFilePath = fileName;
317  if(!that->absoluteFilePath.startsWith(QLatin1Char(':')))
319 
320  QString path = fileName;
321  if(path.startsWith(QLatin1Char(':')))
322  path = path.mid(1);
323 
324  if(path.startsWith(QLatin1Char('/'))) {
325  that->load(path);
326  } else {
327  QMutexLocker lock(resourceMutex());
328  QStringList searchPaths = *resourceSearchPaths();
329  searchPaths << QLatin1String("");
330  for(int i = 0; i < searchPaths.size(); ++i) {
331  const QString searchPath(searchPaths.at(i) + QLatin1Char('/') + path);
332  if(that->load(searchPath)) {
333  that->absoluteFilePath = QLatin1Char(':') + searchPath;
334  break;
335  }
336  }
337  }
338 }
339 
340 void
342 {
344  if(!children.isEmpty() || !container || related.isEmpty())
345  return;
346 
347  QString path = absoluteFilePath, k;
348  if(path.startsWith(QLatin1Char(':')))
349  path = path.mid(1);
350  QSet<QString> kids;
351  QString cleaned = cleanPath(path);
352  for(int i = 0; i < related.size(); ++i) {
353  QResourceRoot *res = related.at(i);
354  if(res->mappingRootSubdir(path, &k) && !k.isEmpty()) {
355  if(!kids.contains(k)) {
356  children += k;
357  kids.insert(k);
358  }
359  } else {
360  const int node = res->findNode(cleaned);
361  if(node != -1) {
362  QStringList related_children = res->children(node);
363  for(int kid = 0; kid < related_children.size(); ++kid) {
364  k = related_children.at(kid);
365  if(!kids.contains(k)) {
366  children += k;
367  kids.insert(k);
368  }
369  }
370  }
371  }
372  }
373 }
374 
382 QResource::QResource(const QString &file, const QLocale &locale) : d_ptr(new QResourcePrivate(this))
383 {
384  Q_D(QResource);
385  d->fileName = file;
386  d->locale = locale;
387 }
388 
393 {
394 }
395 
404 void QResource::setLocale(const QLocale &locale)
405 {
406  Q_D(QResource);
407  d->clear();
408  d->locale = locale;
409 }
410 
416 {
417  Q_D(const QResource);
418  return d->locale;
419 }
420 
430 {
431  Q_D(QResource);
432  d->clear();
433  d->fileName = file;
434 }
435 
444 {
445  Q_D(const QResource);
446  d->ensureInitialized();
447  return d->fileName;
448 }
449 
458 {
459  Q_D(const QResource);
460  d->ensureInitialized();
461  return d->absoluteFilePath;
462 }
463 
470 bool QResource::isValid() const
471 {
472  Q_D(const QResource);
473  d->ensureInitialized();
474  return !d->related.isEmpty();
475 }
476 
498 {
499  Q_D(const QResource);
500  d->ensureInitialized();
501  return d->compressed;
502 }
503 
511 {
512  Q_D(const QResource);
513  d->ensureInitialized();
514  return d->size;
515 }
516 
526 const uchar *QResource::data() const
527 {
528  Q_D(const QResource);
529  d->ensureInitialized();
530  return d->data;
531 }
532 
540 bool QResource::isDir() const
541 {
542  Q_D(const QResource);
543  d->ensureInitialized();
544  return d->container;
545 }
546 
555 {
556  Q_D(const QResource);
557  d->ensureChildren();
558  return d->children;
559 }
560 
576 void
578 {
579  if (!path.startsWith(QLatin1Char('/'))) {
580  qWarning("QResource::addResourceSearchPath: Search paths must be absolute (start with /) [%s]",
581  path.toLocal8Bit().data());
582  return;
583  }
584  QMutexLocker lock(resourceMutex());
585  resourceSearchPaths()->prepend(path);
586 }
587 
604 {
605  QMutexLocker lock(resourceMutex());
606  return *resourceSearchPaths();
607 }
608 
609 inline int QResourceRoot::hash(int node) const
610 {
611  if(!node) //root
612  return 0;
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);
616  name_offset += 2; //jump past name length
617  return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) +
618  (names[name_offset+2] << 8) + (names[name_offset+3] << 0);
619 }
620 inline QString QResourceRoot::name(int node) const
621 {
622  if(!node) // root
623  return QString();
624  const int offset = findOffset(node);
625 
626  QString ret;
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);
631  name_offset += 2;
632  name_offset += 4; //jump past hash
633 
634  ret.resize(name_length);
635  QChar *strData = ret.data();
636  for(int i = 0; i < name_length*2; i+=2) {
637  QChar c(names[name_offset+i+1], names[name_offset+i]);
638  *strData = c;
639  ++strData;
640  }
641  return ret;
642 }
643 
644 int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
645 {
646  QString path = _path;
647  {
648  QString root = mappingRoot();
649  if(!root.isEmpty()) {
650  if(root == path) {
651  path = QLatin1Char('/');
652  } else {
653  if(!root.endsWith(QLatin1Char('/')))
654  root += QLatin1Char('/');
655  if(path.size() >= root.size() && path.startsWith(root))
656  path = path.mid(root.length()-1);
657  if(path.isEmpty())
658  path = QLatin1Char('/');
659  }
660  }
661  }
662 #ifdef DEBUG_RESOURCE_MATCH
663  qDebug() << "!!!!" << "START" << path << locale.country() << locale.language();
664 #endif
665 
666  if(path == QLatin1String("/"))
667  return 0;
668 
669  //the root node is always first
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);
674 
675  //now iterate up the tree
676  int node = -1;
677 
678  QStringSplitter splitter(path);
679  while (child_count && splitter.hasNext()) {
680  QStringRef segment = splitter.next();
681 
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);
686  }
687 #endif
688  const int h = qHash(segment);
689 
690  //do the binary search for the hash
691  int l = 0, r = child_count-1;
692  int sub_node = (l+r+1)/2;
693  while(r != l) {
694  const int sub_node_hash = hash(child+sub_node);
695  if(h == sub_node_hash)
696  break;
697  else if(h < sub_node_hash)
698  r = sub_node - 1;
699  else
700  l = sub_node;
701  sub_node = (l + r + 1) / 2;
702  }
703  sub_node += child;
704 
705  //now do the "harder" compares
706  bool found = false;
707  if(hash(sub_node) == h) {
708  while(sub_node > child && hash(sub_node-1) == h) //backup for collisions
709  --sub_node;
710  for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) { //here we go...
711  if(name(sub_node) == segment) {
712  found = true;
713  int offset = findOffset(sub_node);
714 #ifdef DEBUG_RESOURCE_MATCH
715  qDebug() << " TRY" << sub_node << name(sub_node) << offset;
716 #endif
717  offset += 4; //jump past name
718 
719  const short flags = (tree[offset+0] << 8) +
720  (tree[offset+1] << 0);
721  offset += 2;
722 
723  if(!splitter.hasNext()) {
724  if(!(flags & Directory)) {
725  const short country = (tree[offset+0] << 8) +
726  (tree[offset+1] << 0);
727  offset += 2;
728 
729  const short language = (tree[offset+0] << 8) +
730  (tree[offset+1] << 0);
731  offset += 2;
732 #ifdef DEBUG_RESOURCE_MATCH
733  qDebug() << " " << "LOCALE" << country << language;
734 #endif
735  if(country == locale.country() && language == locale.language()) {
736 #ifdef DEBUG_RESOURCE_MATCH
737  qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node;
738 #endif
739  return sub_node;
740  } else if((country == QLocale::AnyCountry && language == locale.language()) ||
741  (country == QLocale::AnyCountry && language == QLocale::C && node == -1)) {
742  node = sub_node;
743  }
744  continue;
745  } else {
746 #ifdef DEBUG_RESOURCE_MATCH
747  qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node;
748 #endif
749 
750  return sub_node;
751  }
752  }
753 
754  if(!(flags & Directory))
755  return -1;
756 
757  child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
758  (tree[offset+2] << 8) + (tree[offset+3] << 0);
759  offset += 4;
760  child = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
761  (tree[offset+2] << 8) + (tree[offset+3] << 0);
762  break;
763  }
764  }
765  }
766  if(!found)
767  break;
768  }
769 #ifdef DEBUG_RESOURCE_MATCH
770  qDebug() << "!!!!" << "FINISHED" << __LINE__ << node;
771 #endif
772  return node;
773 }
774 short QResourceRoot::flags(int node) const
775 {
776  if(node == -1)
777  return 0;
778  const int offset = findOffset(node) + 4; //jump past name
779  return (tree[offset+0] << 8) + (tree[offset+1] << 0);
780 }
781 const uchar *QResourceRoot::data(int node, qint64 *size) const
782 {
783  if(node == -1) {
784  *size = 0;
785  return 0;
786  }
787  int offset = findOffset(node) + 4; //jump past name
788 
789  const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0);
790  offset += 2;
791 
792  offset += 4; //jump past locale
793 
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;
800  *size = data_length;
801  return ret;
802  }
803  *size = 0;
804  return 0;
805 }
807 {
808  if(node == -1)
809  return QStringList();
810  int offset = findOffset(node) + 4; //jump past name
811 
812  const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0);
813  offset += 2;
814 
815  QStringList ret;
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);
819  offset += 4;
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)
823  ret << name(i);
824  }
825  return ret;
826 }
828 {
829  const QString root = mappingRoot();
830  if(!root.isEmpty()) {
831  const QStringList root_segments = root.split(QLatin1Char('/'), QString::SkipEmptyParts),
832  path_segments = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
833  if(path_segments.size() <= root_segments.size()) {
834  int matched = 0;
835  for(int i = 0; i < path_segments.size(); ++i) {
836  if(root_segments[i] != path_segments[i])
837  break;
838  ++matched;
839  }
840  if(matched == path_segments.size()) {
841  if(match && root_segments.size() > matched)
842  *match = root_segments.at(matched);
843  return true;
844  }
845  }
846  }
847  return false;
848 }
849 
850 Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree,
851  const unsigned char *name, const unsigned char *data)
852 {
853  QMutexLocker lock(resourceMutex());
854  if(version == 0x01 && resourceList()) {
855  bool found = false;
856  QResourceRoot res(tree, name, data);
857  for(int i = 0; i < resourceList()->size(); ++i) {
858  if(*resourceList()->at(i) == res) {
859  found = true;
860  break;
861  }
862  }
863  if(!found) {
864  QResourceRoot *root = new QResourceRoot(tree, name, data);
865  root->ref.ref();
866  resourceList()->append(root);
867  }
868  return true;
869  }
870  return false;
871 }
872 
873 Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tree,
874  const unsigned char *name, const unsigned char *data)
875 {
876  QMutexLocker lock(resourceMutex());
877  if(version == 0x01 && resourceList()) {
878  QResourceRoot res(tree, name, data);
879  for(int i = 0; i < resourceList()->size(); ) {
880  if(*resourceList()->at(i) == res) {
881  QResourceRoot *root = resourceList()->takeAt(i);
882  if(!root->ref.deref())
883  delete root;
884  } else {
885  ++i;
886  }
887  }
888  return true;
889  }
890  return false;
891 }
892 
893 //run time resource creation
894 
896 {
898  const uchar *buffer;
899 
900 public:
901  inline QDynamicBufferResourceRoot(const QString &_root) : root(_root), buffer(0) { }
903  inline const uchar *mappingBuffer() const { return buffer; }
904  virtual QString mappingRoot() const { return root; }
905  virtual ResourceRootType type() const { return Resource_Buffer; }
906 
907  bool registerSelf(const uchar *b) {
908  //setup the data now
909  int offset = 0;
910 
911  //magic number
912  if(b[offset+0] != 'q' || b[offset+1] != 'r' ||
913  b[offset+2] != 'e' || b[offset+3] != 's') {
914  return false;
915  }
916  offset += 4;
917 
918  const int version = (b[offset+0] << 24) + (b[offset+1] << 16) +
919  (b[offset+2] << 8) + (b[offset+3] << 0);
920  offset += 4;
921 
922  const int tree_offset = (b[offset+0] << 24) + (b[offset+1] << 16) +
923  (b[offset+2] << 8) + (b[offset+3] << 0);
924  offset += 4;
925 
926  const int data_offset = (b[offset+0] << 24) + (b[offset+1] << 16) +
927  (b[offset+2] << 8) + (b[offset+3] << 0);
928  offset += 4;
929 
930  const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) +
931  (b[offset+2] << 8) + (b[offset+3] << 0);
932  offset += 4;
933 
934  if(version == 0x01) {
935  buffer = b;
936  setSource(b+tree_offset, b+name_offset, b+data_offset);
937  return true;
938  }
939  return false;
940  }
941 };
942 
943 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) && !defined (Q_OS_NACL) && !defined(Q_OS_INTEGRITY)
944 #define QT_USE_MMAP
945 #endif
946 
947 // most of the headers below are already included in qplatformdefs.h
948 // also this lacks Large File support but that's probably irrelevant
949 #if defined(QT_USE_MMAP)
950 // for mmap
952 #include <sys/mman.h>
953 #include <errno.h>
955 #endif
956 
957 
958 
960 {
962  // for mmap'ed files, this is what needs to be unmapped.
964  unsigned int unmapLength;
965 
966 public:
967  inline QDynamicFileResourceRoot(const QString &_root) : QDynamicBufferResourceRoot(_root), unmapPointer(0), unmapLength(0) { }
969 #if defined(QT_USE_MMAP)
970  if (unmapPointer) {
971  munmap((char*)unmapPointer, unmapLength);
972  unmapPointer = 0;
973  unmapLength = 0;
974  } else
975 #endif
976  {
977  delete [] (uchar *)mappingBuffer();
978  }
979  }
980  QString mappingFile() const { return fileName; }
981  virtual ResourceRootType type() const { return Resource_File; }
982 
983  bool registerSelf(const QString &f) {
984  bool fromMM = false;
985  uchar *data = 0;
986  unsigned int data_len = 0;
987 
988 #ifdef QT_USE_MMAP
989 
990 #ifndef MAP_FILE
991 #define MAP_FILE 0
992 #endif
993 #ifndef MAP_FAILED
994 #define MAP_FAILED -1
995 #endif
996 
997  int fd = QT_OPEN(QFile::encodeName(f), O_RDONLY,
998 #if defined(Q_OS_WIN)
1000 #else
1001  0666
1002 #endif
1003  );
1004  if (fd >= 0) {
1005  QT_STATBUF st;
1006  if (!QT_FSTAT(fd, &st)) {
1007  uchar *ptr;
1008  ptr = reinterpret_cast<uchar *>(
1009  mmap(0, st.st_size, // any address, whole file
1010  PROT_READ, // read-only memory
1011  MAP_FILE | MAP_PRIVATE, // swap-backed map from file
1012  fd, 0)); // from offset 0 of fd
1013  if (ptr && ptr != reinterpret_cast<uchar *>(MAP_FAILED)) {
1014  data = ptr;
1015  data_len = st.st_size;
1016  fromMM = true;
1017  }
1018  }
1019  ::close(fd);
1020  }
1021 #endif // QT_USE_MMAP
1022  if(!data) {
1023  QFile file(f);
1024  if (!file.exists())
1025  return false;
1026  data_len = file.size();
1027  data = new uchar[data_len];
1028 
1029  bool ok = false;
1030  if (file.open(QIODevice::ReadOnly))
1031  ok = (data_len == (uint)file.read((char*)data, data_len));
1032  if (!ok) {
1033  delete [] data;
1034  data = 0;
1035  data_len = 0;
1036  return false;
1037  }
1038  fromMM = false;
1039  }
1040  if(data && QDynamicBufferResourceRoot::registerSelf(data)) {
1041  if(fromMM) {
1042  unmapPointer = data;
1043  unmapLength = data_len;
1044  }
1045  fileName = f;
1046  return true;
1047  }
1048  return false;
1049  }
1050 };
1051 
1053  if(!r.isEmpty()) {
1054  if(r.startsWith(QLatin1Char(':')))
1055  r = r.mid(1);
1056  if(!r.isEmpty())
1057  r = QDir::cleanPath(r);
1058  }
1059  return r;
1060 }
1061 
1062 
1076 bool
1077 QResource::registerResource(const QString &rccFilename, const QString &resourceRoot)
1078 {
1079  QString r = qt_resource_fixResourceRoot(resourceRoot);
1080  if(!r.isEmpty() && r[0] != QLatin1Char('/')) {
1081  qWarning("QDir::registerResource: Registering a resource [%s] must be rooted in an absolute path (start with /) [%s]",
1082  rccFilename.toLocal8Bit().data(), resourceRoot.toLocal8Bit().data());
1083  return false;
1084  }
1085 
1087  if(root->registerSelf(rccFilename)) {
1088  root->ref.ref();
1089  QMutexLocker lock(resourceMutex());
1090  resourceList()->append(root);
1091  return true;
1092  }
1093  delete root;
1094  return false;
1095 }
1096 
1111 bool
1112 QResource::unregisterResource(const QString &rccFilename, const QString &resourceRoot)
1113 {
1114  QString r = qt_resource_fixResourceRoot(resourceRoot);
1115 
1116  QMutexLocker lock(resourceMutex());
1117  ResourceList *list = resourceList();
1118  for(int i = 0; i < list->size(); ++i) {
1119  QResourceRoot *res = list->at(i);
1120  if(res->type() == QResourceRoot::Resource_File) {
1121  QDynamicFileResourceRoot *root = reinterpret_cast<QDynamicFileResourceRoot*>(res);
1122  if(root->mappingFile() == rccFilename && root->mappingRoot() == r) {
1123  resourceList()->removeAt(i);
1124  if(!root->ref.deref()) {
1125  delete root;
1126  return true;
1127  }
1128  return false;
1129  }
1130  }
1131  }
1132  return false;
1133 }
1134 
1135 
1150 bool
1151 QResource::registerResource(const uchar *rccData, const QString &resourceRoot)
1152 {
1153  QString r = qt_resource_fixResourceRoot(resourceRoot);
1154  if(!r.isEmpty() && r[0] != QLatin1Char('/')) {
1155  qWarning("QDir::registerResource: Registering a resource [%p] must be rooted in an absolute path (start with /) [%s]",
1156  rccData, resourceRoot.toLocal8Bit().data());
1157  return false;
1158  }
1159 
1161  if(root->registerSelf(rccData)) {
1162  root->ref.ref();
1163  QMutexLocker lock(resourceMutex());
1164  resourceList()->append(root);
1165  return true;
1166  }
1167  delete root;
1168  return false;
1169 }
1170 
1182 bool
1183 QResource::unregisterResource(const uchar *rccData, const QString &resourceRoot)
1184 {
1185  QString r = qt_resource_fixResourceRoot(resourceRoot);
1186 
1187  QMutexLocker lock(resourceMutex());
1188  ResourceList *list = resourceList();
1189  for(int i = 0; i < list->size(); ++i) {
1190  QResourceRoot *res = list->at(i);
1191  if(res->type() == QResourceRoot::Resource_Buffer) {
1192  QDynamicBufferResourceRoot *root = reinterpret_cast<QDynamicBufferResourceRoot*>(res);
1193  if(root->mappingBuffer() == rccData && root->mappingRoot() == r) {
1194  resourceList()->removeAt(i);
1195  if(!root->ref.deref()) {
1196  delete root;
1197  return true;
1198  }
1199  return false;
1200  }
1201  }
1202  }
1203  return false;
1204 }
1205 
1206 //resource engine
1208 {
1209 protected:
1211 private:
1212  uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
1213  bool unmap(uchar *ptr);
1217 protected:
1218  QResourceFileEnginePrivate() : offset(0) { }
1219 };
1220 
1221 bool QResourceFileEngine::mkdir(const QString &, bool) const
1222 {
1223  return false;
1224 }
1225 
1226 bool QResourceFileEngine::rmdir(const QString &, bool) const
1227 {
1228  return false;
1229 }
1230 
1232 {
1233  return false;
1234 }
1235 
1236 QStringList QResourceFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const
1237 {
1238  return QAbstractFileEngine::entryList(filters, filterNames);
1239 }
1240 
1242 {
1243  return true;
1244 }
1245 
1248 {
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());
1254 #else
1255  Q_ASSERT(!"QResourceFileEngine::open: Qt built without support for compression");
1256 #endif
1257  }
1258 }
1259 
1261 {
1262 }
1263 
1265 {
1267  d->resource.setFileName(file);
1268 }
1269 
1270 bool QResourceFileEngine::open(QIODevice::OpenMode flags)
1271 {
1273  if (d->resource.fileName().isEmpty()) {
1274  qWarning("QResourceFileEngine::open: Missing file name");
1275  return false;
1276  }
1277  if(flags & QIODevice::WriteOnly)
1278  return false;
1279  if(!d->resource.isValid())
1280  return false;
1281  return true;
1282 }
1283 
1285 {
1287  d->offset = 0;
1288  d->uncompressed.clear();
1289  return true;
1290 }
1291 
1293 {
1294  return true;
1295 }
1296 
1298 {
1300  if(len > size()-d->offset)
1301  len = size()-d->offset;
1302  if(len <= 0)
1303  return 0;
1304  if(d->resource.isCompressed())
1305  memcpy(data, d->uncompressed.constData()+d->offset, len);
1306  else
1307  memcpy(data, d->resource.data()+d->offset, len);
1308  d->offset += len;
1309  return len;
1310 }
1311 
1313 {
1314  return -1;
1315 }
1316 
1318 {
1319  return false;
1320 }
1321 
1323 {
1324  return false;
1325 }
1326 
1328 {
1329  return false;
1330 }
1331 
1333 {
1334  return false;
1335 }
1336 
1338 {
1339  Q_D(const QResourceFileEngine);
1340  if(!d->resource.isValid())
1341  return 0;
1342  if(d->resource.isCompressed())
1343  return d->uncompressed.size();
1344  return d->resource.size();
1345 }
1346 
1348 {
1349  Q_D(const QResourceFileEngine);
1350  return d->offset;
1351 }
1352 
1354 {
1355  Q_D(const QResourceFileEngine);
1356  if(!d->resource.isValid())
1357  return true;
1358  return d->offset == size();
1359 }
1360 
1362 {
1364  if(!d->resource.isValid())
1365  return false;
1366 
1367  if(d->offset > size())
1368  return false;
1369  d->offset = pos;
1370  return true;
1371 }
1372 
1374 {
1375  return false;
1376 }
1377 
1378 QAbstractFileEngine::FileFlags QResourceFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const
1379 {
1380  Q_D(const QResourceFileEngine);
1381  QAbstractFileEngine::FileFlags ret = 0;
1382  if(!d->resource.isValid())
1383  return ret;
1384 
1385  if(type & PermsMask)
1386  ret |= QAbstractFileEngine::FileFlags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm);
1387  if(type & TypesMask) {
1388  if(d->resource.isDir())
1389  ret |= DirectoryType;
1390  else
1391  ret |= FileType;
1392  }
1393  if(type & FlagsMask) {
1394  ret |= ExistsFlag;
1395  if(d->resource.absoluteFilePath() == QLatin1String(":/"))
1396  ret |= RootFlag;
1397  }
1398  return ret;
1399 }
1400 
1402 {
1403  return false;
1404 }
1405 
1407 {
1408  Q_D(const QResourceFileEngine);
1409  if(file == BaseName) {
1410  int slash = d->resource.fileName().lastIndexOf(QLatin1Char('/'));
1411  if (slash == -1)
1412  return d->resource.fileName();
1413  return d->resource.fileName().mid(slash + 1);
1414  } else if(file == PathName || file == AbsolutePathName) {
1415  const QString path = (file == AbsolutePathName) ? d->resource.absoluteFilePath() : d->resource.fileName();
1416  const int slash = path.lastIndexOf(QLatin1Char('/'));
1417  if (slash == -1)
1418  return QLatin1String(":");
1419  else if (slash <= 1)
1420  return QLatin1String(":/");
1421  return path.left(slash);
1422 
1423  } else if(file == CanonicalName || file == CanonicalPathName) {
1424  const QString absoluteFilePath = d->resource.absoluteFilePath();
1425  if(file == CanonicalPathName) {
1426  const int slash = absoluteFilePath.lastIndexOf(QLatin1Char('/'));
1427  if (slash != -1)
1428  return absoluteFilePath.left(slash);
1429  }
1430  return absoluteFilePath;
1431  }
1432  return d->resource.fileName();
1433 }
1434 
1436 {
1437  return false;
1438 }
1439 
1441 {
1442  static const uint nobodyID = (uint) -2;
1443  return nobodyID;
1444 }
1445 
1447 {
1448  return QString();
1449 }
1450 
1452 {
1453  return QDateTime();
1454 }
1455 
1460  const QStringList &filterNames)
1461 {
1462  return new QResourceFileEngineIterator(filters, filterNames);
1463 }
1464 
1469 {
1470  return 0;
1471 }
1472 
1474 {
1476  if (extension == MapExtension) {
1477  const MapExtensionOption *options = (MapExtensionOption*)(option);
1478  MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output);
1479  returnValue->address = d->map(options->offset, options->size, options->flags);
1480  return (returnValue->address != 0);
1481  }
1482  if (extension == UnMapExtension) {
1483  UnMapExtensionOption *options = (UnMapExtensionOption*)option;
1484  return d->unmap(options->address);
1485  }
1486  return false;
1487 }
1488 
1490 {
1491  return (extension == UnMapExtension || extension == MapExtension);
1492 }
1493 
1495 {
1497  Q_UNUSED(flags);
1498  if (offset < 0 || size <= 0 || !resource.isValid() || offset + size > resource.size()) {
1499  q->setError(QFile::UnspecifiedError, QString());
1500  return 0;
1501  }
1502  uchar *address = const_cast<uchar *>(resource.data());
1503  return (address + offset);
1504 }
1505 
1507 {
1508  Q_UNUSED(ptr);
1509  return true;
1510 }
1511 
1512 Q_CORE_EXPORT void qInitResourceIO() { } // ### Qt 5: remove
1513 
virtual bool open(QIODevice::OpenMode flags)
Opens the file in the specified mode.
Definition: qresource.cpp:1270
QString absoluteFilePath() const
Returns the real path that this QResource represents, if the resource was found via the QDir::searchP...
Definition: qresource.cpp:457
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const
Requests that the directory dirName be created.
Definition: qresource.cpp:1221
double d
Definition: qnumeric_p.h:62
virtual bool flush()
Flushes the open file, returning true if successful; otherwise returns false.
Definition: qresource.cpp:1292
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
virtual bool seek(qint64)
Sets the file position to the given offset.
Definition: qresource.cpp:1361
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
#define _S_IREAD
virtual bool setPermissions(uint perms)
Requests that the file&#39;s permissions be set to perms.
Definition: qresource.cpp:1401
virtual bool caseSensitive() const
Should return true if the underlying file system is case-sensitive; otherwise return false...
Definition: qresource.cpp:1241
const uchar * data(int node, qint64 *size) const
Definition: qresource.cpp:781
int type
Definition: qmetatype.cpp:239
#define MAP_FAILED
Language language() const
Returns the language of this locale.
Definition: qlocale.cpp:920
QLocale locale() const
Returns the locale used to locate the data for the QResource.
Definition: qresource.cpp:415
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
void setLocale(const QLocale &locale)
Sets a QResource to only load the localization of resource to for locale.
Definition: qresource.cpp:404
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes)
QString name(int node) const
Definition: qresource.cpp:620
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
QResourceFileEngine(const QString &path)
Definition: qresource.cpp:1246
virtual ~QResourceRoot()
Definition: qresource.cpp:125
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
void setSource(const uchar *t, const uchar *n, const uchar *d)
Definition: qresource.cpp:141
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data)
Definition: qresource.cpp:850
QString & prepend(QChar c)
Definition: qstring.h:261
#define O_RDONLY
virtual bool rename(const QString &newName)
Requests that the file be renamed to newName in the file system.
Definition: qresource.cpp:1327
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
bool registerSelf(const QString &f)
Definition: qresource.cpp:983
const uchar * tree
Definition: qresource.cpp:115
static bool match(const uchar *found, const char *target, uint len)
void setFileName(const QString &file)
Sets a QResource to point to file.
Definition: qresource.cpp:429
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.
Definition: qstring.cpp:3734
virtual QString owner(FileOwner) const
If owner is OwnerUser return the name of the user who owns the file.
Definition: qresource.cpp:1446
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.
Definition: qglobal.h:92
bool isCompressed(int node) const
Definition: qresource.cpp:128
static QString qt_resource_fixResourceRoot(QString r)
Definition: qresource.cpp:1052
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
unsigned int unmapLength
Definition: qresource.cpp:964
bool ref()
Atomically increments the value of this QAtomicInt.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool load(const QString &file)
Definition: qresource.cpp:271
qint64 size() const
Returns the size of the data backing the resource.
Definition: qresource.cpp:510
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QString mappingRoot() const
Definition: qresource.cpp:131
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
QResource(const QString &file=QString(), const QLocale &locale=QLocale())
Constructs a QResource pointing to file.
Definition: qresource.cpp:382
QString fileName() const
Returns the full path to the file that this QResource represents as it was passed.
Definition: qresource.cpp:443
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
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 ...
Definition: qresource.cpp:1236
const uchar * names
Definition: qresource.cpp:115
provides an extended output argument to QAbstractFileEngine&#39;s extension support.
#define Q_Q(Class)
Definition: qglobal.h:2483
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
virtual ResourceRootType type() const
Definition: qresource.cpp:981
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
QStringSplitter(const QString &s)
Definition: qresource.cpp:80
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual QString fileName(QAbstractFileEngine::FileName file) const
Return the file engine&#39;s current file name in the format specified by file.
Definition: qresource.cpp:1406
Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data)
Definition: qresource.cpp:873
QLocale::Language language
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
Definition: qresource.cpp:470
bool supportsExtension(Extension extension) const
This virtual function returns true if the file engine supports extension; otherwise, false is returned.
Definition: qresource.cpp:1489
static QStringList searchPaths()
Use QDir::searchPaths() instead.
Definition: qresource.cpp:603
The QResource class provides an interface for reading directly from resources.
Definition: qresource.h:58
QStringRef next()
Definition: qresource.cpp:92
Extension
This enum describes the types of extensions that the file engine can support.
virtual Iterator * endEntryList()
Definition: qresource.cpp:1468
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
virtual FileFlags fileFlags(FileFlags type) const
This function should return the set of OR&#39;d flags that are true for the file engine&#39;s file...
Definition: qresource.cpp:1378
bool contains(const T &value) const
Definition: qset.h:91
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
virtual QString mappingRoot() const
Definition: qresource.cpp:904
const char * name
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool deref()
Atomically decrements the value of this QAtomicInt.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_DECLARE_TYPEINFO(QResourceRoot, Q_MOVABLE_TYPE)
provides an extended input argument to QAbstractFileEngine&#39;s extension support.
QDynamicFileResourceRoot(const QString &_root)
Definition: qresource.cpp:967
const uchar * data() const
Returns direct access to a read only segment of data that this resource represents.
Definition: qresource.cpp:526
static void addSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
Definition: qresource.cpp:577
Q_CORE_EXPORT void qWarning(const char *,...)
The QAbstractFileEngine class provides an abstraction for accessing the filesystem.
const_iterator insert(const T &value)
Definition: qset.h:179
virtual bool isRelativePath() const
Return true if the file referred to by this file engine has a relative path; otherwise return false...
Definition: qresource.cpp:1435
bool operator==(const QResourceRoot &other) const
Definition: qresource.cpp:133
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
QString mappingFile() const
Definition: qresource.cpp:980
static void ensureInitialized()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool isCompressed() const
Returns true if the resource represents a file and the data backing it is in a compressed format...
Definition: qresource.cpp:497
virtual QDateTime fileTime(FileTime time) const
If time is CreationTime, return when the file was created.
Definition: qresource.cpp:1451
short flags(int node) const
Definition: qresource.cpp:774
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...
Definition: qresource.cpp:1077
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
bool isDir() const
Returns true if the resource represents a directory and thus may have children() in it...
Definition: qresource.cpp:540
void clear()
Removes all items from the list.
Definition: qlist.h:764
__int64 qint64
Definition: qglobal.h:942
virtual bool copy(const QString &newName)
Copies the contents of this file to a file with the name newName.
Definition: qresource.cpp:1322
#define MAP_FILE
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
virtual ResourceRootType type() const
Definition: qresource.cpp:138
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
static QString cleanPath(const QString &_path)
Definition: qresource.cpp:148
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.
Definition: qresource.cpp:1226
QResourceRoot(const uchar *t, const uchar *n, const uchar *d)
Definition: qresource.cpp:124
int findNode(const QString &path, const QLocale &locale=QLocale()) const
Definition: qresource.cpp:644
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
~QResource()
Releases the resources of the QResource object.
Definition: qresource.cpp:392
QResource * q_ptr
Definition: qresource.cpp:249
qint64 size() const
Returns the size of the file.
Definition: qfile.cpp:1707
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
virtual qint64 size() const
Returns the size of the file.
Definition: qresource.cpp:1337
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...
Definition: qstring.cpp:3706
bool operator!=(const QResourceRoot &other) const
Definition: qresource.cpp:135
static const char *const filters[3]
bool registerSelf(const uchar *b)
Definition: qresource.cpp:907
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
uchar * map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
Definition: qresource.cpp:1494
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
#define QT_OPEN
Definition: qcore_unix_p.h:186
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
#define load(x)
int findOffset(int node) const
Definition: qresource.cpp:116
virtual qint64 pos() const
Returns the current file position.
Definition: qresource.cpp:1347
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
const uchar * data
Definition: qresource.cpp:246
const uchar * mappingBuffer() const
Definition: qresource.cpp:903
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
Q_CORE_EXPORT void qInitResourceIO()
Definition: qresource.cpp:1512
QResourcePrivate(QResource *_q)
Definition: qresource.cpp:231
virtual bool setSize(qint64 size)
Requests that the file be set to size size.
Definition: qresource.cpp:1231
bool unmap(uchar *ptr)
Definition: qresource.cpp:1506
#define st(var, type, card)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool mappingRootSubdir(const QString &path, QString *match=0) const
Definition: qresource.cpp:827
void ensureChildren() const
Definition: qresource.cpp:341
const uchar * payloads
Definition: qresource.cpp:115
static QReadWriteLock lock
Definition: proxyconf.cpp:399
virtual bool link(const QString &newName)
Creates a link from the file currently specified by fileName() to newName.
Definition: qresource.cpp:1332
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines...
QFactoryLoader * l
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...
Definition: qresource.cpp:1473
virtual bool remove()
Requests that the file is deleted from the file system.
Definition: qresource.cpp:1317
#define Q_OS_WIN
Definition: qglobal.h:270
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
virtual qint64 read(char *data, qint64 maxlen)
Reads a number of characters from the file into data.
Definition: qresource.cpp:1297
virtual bool close()
Closes the file, returning true if successful; otherwise returns false.
Definition: qresource.cpp:1284
void ensureInitialized() const
Definition: qresource.cpp:309
QStringList children(int node) const
Definition: qresource.cpp:806
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
virtual uint ownerId(FileOwner) const
If owner is OwnerUser return the ID of the user who owns the file.
Definition: qresource.cpp:1440
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...
Definition: qstring.cpp:6526
virtual qint64 write(const char *data, qint64 len)
Writes len bytes from data to the file.
Definition: qresource.cpp:1312
int hash(int node) const
Definition: qresource.cpp:609
MemoryMapFlags
This enum describes special options that may be used by the map() function.
Definition: qfile.h:180
Country country() const
Returns the country of this locale.
Definition: qlocale.cpp:945
QStringList children() const
Returns a list of all resources in this directory, if the resource represents a file the list will be...
Definition: qresource.cpp:554
bool isContainer(int node) const
Definition: qresource.cpp:127
#define _S_IWRITE
virtual bool isSequential() const
Returns true if the file is a sequential access device; returns false if the file is a direct access ...
Definition: qresource.cpp:1373
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
QDynamicBufferResourceRoot(const QString &_root)
Definition: qresource.cpp:901
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
#define class
virtual void setFileName(const QString &file)
Sets the file engine&#39;s file name to file.
Definition: qresource.cpp:1264
QLocale::Country country
const QChar * m_data
Definition: qresource.cpp:100
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
QString absoluteFilePath
Definition: qresource.cpp:241
QString m_string
Definition: qresource.cpp:99
QList< QResourceRoot * > related
Definition: qresource.cpp:242
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
Definition: qglobal.h:1982
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
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...
Definition: qresource.cpp:1112
virtual bool atEnd() const
Definition: qresource.cpp:1353
virtual ResourceRootType type() const
Definition: qresource.cpp:905
QStringList children
Definition: qresource.cpp:247
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QAtomicInt ref
Definition: qresource.cpp:121
virtual Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames)
Definition: qresource.cpp:1459