Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qresource.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | class QStringSplitter | - | ||||||||||||||||||
11 | { | - | ||||||||||||||||||
12 | public: | - | ||||||||||||||||||
13 | QStringSplitter(const QString &s) | - | ||||||||||||||||||
14 | : m_string(s), m_data(m_string.constData()), m_len(s.length()), m_pos(0) | - | ||||||||||||||||||
15 | { | - | ||||||||||||||||||
16 | m_splitChar = QLatin1Char('/'); | - | ||||||||||||||||||
17 | } | - | ||||||||||||||||||
18 | - | |||||||||||||||||||
19 | inline bool hasNext() { | - | ||||||||||||||||||
20 | while (m_pos < m_len && m_data[m_pos] == m_splitChar) | - | ||||||||||||||||||
21 | ++m_pos; | - | ||||||||||||||||||
22 | return m_pos < m_len; | - | ||||||||||||||||||
23 | } | - | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | inline QStringRef next() { | - | ||||||||||||||||||
26 | int start = m_pos; | - | ||||||||||||||||||
27 | while (m_pos < m_len && m_data[m_pos] != m_splitChar) | - | ||||||||||||||||||
28 | ++m_pos; | - | ||||||||||||||||||
29 | return QStringRef(&m_string, start, m_pos - start); | - | ||||||||||||||||||
30 | } | - | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | QString m_string; | - | ||||||||||||||||||
33 | const QChar *m_data; | - | ||||||||||||||||||
34 | QChar m_splitChar; | - | ||||||||||||||||||
35 | int m_len; | - | ||||||||||||||||||
36 | int m_pos; | - | ||||||||||||||||||
37 | }; | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | - | |||||||||||||||||||
40 | - | |||||||||||||||||||
41 | class QResourceRoot | - | ||||||||||||||||||
42 | { | - | ||||||||||||||||||
43 | enum Flags | - | ||||||||||||||||||
44 | { | - | ||||||||||||||||||
45 | Compressed = 0x01, | - | ||||||||||||||||||
46 | Directory = 0x02 | - | ||||||||||||||||||
47 | }; | - | ||||||||||||||||||
48 | const uchar *tree, *names, *payloads; | - | ||||||||||||||||||
49 | inline int findOffset(int node) const { return node * 14; } | - | ||||||||||||||||||
50 | uint hash(int node) const; | - | ||||||||||||||||||
51 | QString name(int node) const; | - | ||||||||||||||||||
52 | short flags(int node) const; | - | ||||||||||||||||||
53 | public: | - | ||||||||||||||||||
54 | mutable QAtomicInt ref; | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | inline QResourceRoot(): tree(0), names(0), payloads(0) {} | - | ||||||||||||||||||
57 | inline QResourceRoot(const uchar *t, const uchar *n, const uchar *d) { setSource(t, n, d); } | - | ||||||||||||||||||
58 | virtual ~QResourceRoot() { } | - | ||||||||||||||||||
59 | int findNode(const QString &path, const QLocale &locale=QLocale()) const; | - | ||||||||||||||||||
60 | inline bool isContainer(int node) const { return flags(node) & Directory; } | - | ||||||||||||||||||
61 | inline bool isCompressed(int node) const { return flags(node) & Compressed; } | - | ||||||||||||||||||
62 | const uchar *data(int node, qint64 *size) const; | - | ||||||||||||||||||
63 | QStringList children(int node) const; | - | ||||||||||||||||||
64 | virtual QString mappingRoot() const { return QString(); } | - | ||||||||||||||||||
65 | bool mappingRootSubdir(const QString &path, QString *match=0) const; | - | ||||||||||||||||||
66 | inline bool operator==(const QResourceRoot &other) const | - | ||||||||||||||||||
67 | { return tree == other.tree && names == other.names && payloads == other.payloads; } | - | ||||||||||||||||||
68 | inline bool operator!=(const QResourceRoot &other) const | - | ||||||||||||||||||
69 | { return !operator==(other); } | - | ||||||||||||||||||
70 | enum ResourceRootType { Resource_Builtin, Resource_File, Resource_Buffer }; | - | ||||||||||||||||||
71 | virtual ResourceRootType type() const { return Resource_Builtin; } | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | protected: | - | ||||||||||||||||||
74 | inline void setSource(const uchar *t, const uchar *n, const uchar *d) { | - | ||||||||||||||||||
75 | tree = t; | - | ||||||||||||||||||
76 | names = n; | - | ||||||||||||||||||
77 | payloads = d; | - | ||||||||||||||||||
78 | } | - | ||||||||||||||||||
79 | }; | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | static QString cleanPath(const QString &_path) | - | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | QString path = QDir::cleanPath(_path); | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | - | |||||||||||||||||||
86 | if (path.startsWith(QLatin1String("//"))) | - | ||||||||||||||||||
87 | path.remove(0, 1); | - | ||||||||||||||||||
88 | return path; | - | ||||||||||||||||||
89 | } | - | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | template<> class QTypeInfo<QResourceRoot > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QResourceRoot)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QResourceRoot >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QResourceRoot) }; static inline const char *name() { return "QResourceRoot"; } }; | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | namespace { namespace Q_QGS_resourceMutex { typedef QMutex Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type (QMutex::Recursive))) : value (QMutex::Recursive) { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QMutex, Q_QGS_resourceMutex::innerFunction, Q_QGS_resourceMutex::guard> resourceMutex; | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | typedef QList<QResourceRoot*> ResourceList; | - | ||||||||||||||||||
96 | namespace { namespace Q_QGS_resourceList { typedef ResourceList Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<ResourceList, Q_QGS_resourceList::innerFunction, Q_QGS_resourceList::guard> resourceList; | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | namespace { namespace Q_QGS_resourceSearchPaths { typedef QStringList Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QStringList, Q_QGS_resourceSearchPaths::innerFunction, Q_QGS_resourceSearchPaths::guard> resourceSearchPaths; | - | ||||||||||||||||||
99 | class QResourcePrivate { | - | ||||||||||||||||||
100 | public: | - | ||||||||||||||||||
101 | inline QResourcePrivate(QResource *_q) : q_ptr(_q) { clear(); } | - | ||||||||||||||||||
102 | inline ~QResourcePrivate() { clear(); } | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | void ensureInitialized() const; | - | ||||||||||||||||||
105 | void ensureChildren() const; | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | bool load(const QString &file); | - | ||||||||||||||||||
108 | void clear(); | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | QLocale locale; | - | ||||||||||||||||||
111 | QString fileName, absoluteFilePath; | - | ||||||||||||||||||
112 | QList<QResourceRoot*> related; | - | ||||||||||||||||||
113 | uint container : 1; | - | ||||||||||||||||||
114 | mutable uint compressed : 1; | - | ||||||||||||||||||
115 | mutable qint64 size; | - | ||||||||||||||||||
116 | mutable const uchar *data; | - | ||||||||||||||||||
117 | mutable QStringList children; | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | QResource *q_ptr; | - | ||||||||||||||||||
120 | inline QResource* q_func() { return static_cast<QResource *>(q_ptr); } inline const QResource* q_func() const { return static_cast<const QResource *>(q_ptr); } friend class QResource; | - | ||||||||||||||||||
121 | }; | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | void | - | ||||||||||||||||||
124 | QResourcePrivate::clear() | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | absoluteFilePath.clear(); | - | ||||||||||||||||||
127 | compressed = 0; | - | ||||||||||||||||||
128 | data = 0; | - | ||||||||||||||||||
129 | size = 0; | - | ||||||||||||||||||
130 | children.clear(); | - | ||||||||||||||||||
131 | container = 0; | - | ||||||||||||||||||
132 | for(int i = 0; i < related.size(); ++i) { | - | ||||||||||||||||||
133 | QResourceRoot *root = related.at(i); | - | ||||||||||||||||||
134 | if(!root->ref.deref()) | - | ||||||||||||||||||
135 | delete root; | - | ||||||||||||||||||
136 | } | - | ||||||||||||||||||
137 | related.clear(); | - | ||||||||||||||||||
138 | } | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | bool | - | ||||||||||||||||||
141 | QResourcePrivate::load(const QString &file) | - | ||||||||||||||||||
142 | { | - | ||||||||||||||||||
143 | related.clear(); | - | ||||||||||||||||||
144 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
145 | const ResourceList *list = resourceList(); | - | ||||||||||||||||||
146 | QString cleaned = cleanPath(file); | - | ||||||||||||||||||
147 | for(int i = 0; i < list->size(); ++i) { | - | ||||||||||||||||||
148 | QResourceRoot *res = list->at(i); | - | ||||||||||||||||||
149 | const int node = res->findNode(cleaned, locale); | - | ||||||||||||||||||
150 | if(node != -1) { | - | ||||||||||||||||||
151 | if(related.isEmpty()) { | - | ||||||||||||||||||
152 | container = res->isContainer(node); | - | ||||||||||||||||||
153 | if(!container) { | - | ||||||||||||||||||
154 | data = res->data(node, &size); | - | ||||||||||||||||||
155 | compressed = res->isCompressed(node); | - | ||||||||||||||||||
156 | } else { | - | ||||||||||||||||||
157 | data = 0; | - | ||||||||||||||||||
158 | size = 0; | - | ||||||||||||||||||
159 | compressed = 0; | - | ||||||||||||||||||
160 | } | - | ||||||||||||||||||
161 | } else if(res->isContainer(node) != container) { | - | ||||||||||||||||||
162 | QMessageLogger(__FILE__, 272278, __PRETTY_FUNCTION__).warning("QResourceInfo: Resource [%s] has both data and children!", file.toLatin1().constData()); | - | ||||||||||||||||||
163 | } | - | ||||||||||||||||||
164 | res->ref.ref(); | - | ||||||||||||||||||
165 | related.append(res); | - | ||||||||||||||||||
166 | } else if(res->mappingRootSubdir(file)) { | - | ||||||||||||||||||
167 | container = true; | - | ||||||||||||||||||
168 | data = 0; | - | ||||||||||||||||||
169 | size = 0; | - | ||||||||||||||||||
170 | compressed = 0; | - | ||||||||||||||||||
171 | res->ref.ref(); | - | ||||||||||||||||||
172 | related.append(res); | - | ||||||||||||||||||
173 | } | - | ||||||||||||||||||
174 | } | - | ||||||||||||||||||
175 | return !related.isEmpty(); | - | ||||||||||||||||||
176 | } | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | void | - | ||||||||||||||||||
179 | QResourcePrivate::ensureInitialized() const | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | if(!related.isEmpty()) | - | ||||||||||||||||||
182 | return; | - | ||||||||||||||||||
183 | QResourcePrivate *that = const_cast<QResourcePrivate *>(this); | - | ||||||||||||||||||
184 | if(fileName == QLatin1String(":")) | - | ||||||||||||||||||
185 | that->fileName += QLatin1Char('/'); | - | ||||||||||||||||||
186 | that->absoluteFilePath = fileName; | - | ||||||||||||||||||
187 | if(!that->absoluteFilePath.startsWith(QLatin1Char(':'))) | - | ||||||||||||||||||
188 | that->absoluteFilePath.prepend(QLatin1Char(':')); | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | QString path = fileName; | - | ||||||||||||||||||
191 | if(path.startsWith(QLatin1Char(':'))) | - | ||||||||||||||||||
192 | path = path.mid(1); | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | if(path.startsWith(QLatin1Char('/'))) { | - | ||||||||||||||||||
195 | that->load(path); | - | ||||||||||||||||||
196 | } else { | - | ||||||||||||||||||
197 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
198 | QStringList searchPaths = *resourceSearchPaths(); | - | ||||||||||||||||||
199 | searchPaths << QLatin1String(""); | - | ||||||||||||||||||
200 | for(int i = 0; i < searchPaths.size(); ++i) { | - | ||||||||||||||||||
201 | const QString searchPath(searchPaths.at(i) + QLatin1Char('/') + path); | - | ||||||||||||||||||
202 | if(that->load(searchPath)) { | - | ||||||||||||||||||
203 | that->absoluteFilePath = QLatin1Char(':') + searchPath; | - | ||||||||||||||||||
204 | break; | - | ||||||||||||||||||
205 | } | - | ||||||||||||||||||
206 | } | - | ||||||||||||||||||
207 | } | - | ||||||||||||||||||
208 | } | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | void | - | ||||||||||||||||||
211 | QResourcePrivate::ensureChildren() const | - | ||||||||||||||||||
212 | { | - | ||||||||||||||||||
213 | ensureInitialized(); | - | ||||||||||||||||||
214 | if(!children.isEmpty() || !container || related.isEmpty()) | - | ||||||||||||||||||
215 | return; | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | QString path = absoluteFilePath, k; | - | ||||||||||||||||||
218 | if(path.startsWith(QLatin1Char(':'))) | - | ||||||||||||||||||
219 | path = path.mid(1); | - | ||||||||||||||||||
220 | QSet<QString> kids; | - | ||||||||||||||||||
221 | QString cleaned = cleanPath(path); | - | ||||||||||||||||||
222 | for(int i = 0; i < related.size(); ++i) { | - | ||||||||||||||||||
223 | QResourceRoot *res = related.at(i); | - | ||||||||||||||||||
224 | if(res->mappingRootSubdir(path, &k) && !k.isEmpty()) { | - | ||||||||||||||||||
225 | if(!kids.contains(k)) { | - | ||||||||||||||||||
226 | children += k; | - | ||||||||||||||||||
227 | kids.insert(k); | - | ||||||||||||||||||
228 | } | - | ||||||||||||||||||
229 | } else { | - | ||||||||||||||||||
230 | const int node = res->findNode(cleaned); | - | ||||||||||||||||||
231 | if(node != -1) { | - | ||||||||||||||||||
232 | QStringList related_children = res->children(node); | - | ||||||||||||||||||
233 | for(int kid = 0; kid < related_children.size(); ++kid) { | - | ||||||||||||||||||
234 | k = related_children.at(kid); | - | ||||||||||||||||||
235 | if(!kids.contains(k)) { | - | ||||||||||||||||||
236 | children += k; | - | ||||||||||||||||||
237 | kids.insert(k); | - | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | } | - | ||||||||||||||||||
240 | } | - | ||||||||||||||||||
241 | } | - | ||||||||||||||||||
242 | } | - | ||||||||||||||||||
243 | } | - | ||||||||||||||||||
244 | QResource::QResource(const QString &file, const QLocale &locale) : d_ptr(new QResourcePrivate(this)) | - | ||||||||||||||||||
245 | { | - | ||||||||||||||||||
246 | QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
247 | d->fileName = file; | - | ||||||||||||||||||
248 | d->locale = locale; | - | ||||||||||||||||||
249 | } | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | - | |||||||||||||||||||
252 | - | |||||||||||||||||||
253 | - | |||||||||||||||||||
254 | QResource::~QResource() | - | ||||||||||||||||||
255 | { | - | ||||||||||||||||||
256 | } | - | ||||||||||||||||||
257 | void QResource::setLocale(const QLocale &locale) | - | ||||||||||||||||||
258 | { | - | ||||||||||||||||||
259 | QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
260 | d->clear(); | - | ||||||||||||||||||
261 | d->locale = locale; | - | ||||||||||||||||||
262 | } | - | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | - | |||||||||||||||||||
265 | - | |||||||||||||||||||
266 | - | |||||||||||||||||||
267 | - | |||||||||||||||||||
268 | QLocale QResource::locale() const | - | ||||||||||||||||||
269 | { | - | ||||||||||||||||||
270 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
271 | return d->locale; | - | ||||||||||||||||||
272 | } | - | ||||||||||||||||||
273 | void QResource::setFileName(const QString &file) | - | ||||||||||||||||||
274 | { | - | ||||||||||||||||||
275 | QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
276 | d->clear(); | - | ||||||||||||||||||
277 | d->fileName = file; | - | ||||||||||||||||||
278 | } | - | ||||||||||||||||||
279 | QString QResource::fileName() const | - | ||||||||||||||||||
280 | { | - | ||||||||||||||||||
281 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
282 | d->ensureInitialized(); | - | ||||||||||||||||||
283 | return d->fileName; | - | ||||||||||||||||||
284 | } | - | ||||||||||||||||||
285 | QString QResource::absoluteFilePath() const | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
288 | d->ensureInitialized(); | - | ||||||||||||||||||
289 | return d->absoluteFilePath; | - | ||||||||||||||||||
290 | } | - | ||||||||||||||||||
291 | - | |||||||||||||||||||
292 | - | |||||||||||||||||||
293 | - | |||||||||||||||||||
294 | - | |||||||||||||||||||
295 | - | |||||||||||||||||||
296 | - | |||||||||||||||||||
297 | - | |||||||||||||||||||
298 | bool QResource::isValid() const | - | ||||||||||||||||||
299 | { | - | ||||||||||||||||||
300 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
301 | d->ensureInitialized(); | - | ||||||||||||||||||
302 | return !d->related.isEmpty(); | - | ||||||||||||||||||
303 | } | - | ||||||||||||||||||
304 | bool QResource::isCompressed() const | - | ||||||||||||||||||
305 | { | - | ||||||||||||||||||
306 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
307 | d->ensureInitialized(); | - | ||||||||||||||||||
308 | return d->compressed; | - | ||||||||||||||||||
309 | } | - | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | - | |||||||||||||||||||
312 | - | |||||||||||||||||||
313 | - | |||||||||||||||||||
314 | - | |||||||||||||||||||
315 | - | |||||||||||||||||||
316 | - | |||||||||||||||||||
317 | qint64 QResource::size() const | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
320 | d->ensureInitialized(); | - | ||||||||||||||||||
321 | return d->size; | - | ||||||||||||||||||
322 | } | - | ||||||||||||||||||
323 | const uchar *QResource::data() const | - | ||||||||||||||||||
324 | { | - | ||||||||||||||||||
325 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
326 | d->ensureInitialized(); | - | ||||||||||||||||||
327 | return d->data; | - | ||||||||||||||||||
328 | } | - | ||||||||||||||||||
329 | bool QResource::isDir() const | - | ||||||||||||||||||
330 | { | - | ||||||||||||||||||
331 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
332 | d->ensureInitialized(); | - | ||||||||||||||||||
333 | return d->container; | - | ||||||||||||||||||
334 | } | - | ||||||||||||||||||
335 | QStringList QResource::children() const | - | ||||||||||||||||||
336 | { | - | ||||||||||||||||||
337 | const QResourcePrivate * const d = d_func(); | - | ||||||||||||||||||
338 | d->ensureChildren(); | - | ||||||||||||||||||
339 | return d->children; | - | ||||||||||||||||||
340 | } | - | ||||||||||||||||||
341 | void | - | ||||||||||||||||||
342 | QResource::addSearchPath(const QString &path) | - | ||||||||||||||||||
343 | { | - | ||||||||||||||||||
344 | if (!path.startsWith(QLatin1Char('/'))) { | - | ||||||||||||||||||
345 | QMessageLogger(__FILE__, 554560, __PRETTY_FUNCTION__).warning("QResource::addResourceSearchPath: Search paths must be absolute (start with /) [%s]", | - | ||||||||||||||||||
346 | path.toLocal8Bit().data()); | - | ||||||||||||||||||
347 | return; | - | ||||||||||||||||||
348 | } | - | ||||||||||||||||||
349 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
350 | resourceSearchPaths()->prepend(path); | - | ||||||||||||||||||
351 | } | - | ||||||||||||||||||
352 | QStringList | - | ||||||||||||||||||
353 | QResource::searchPaths() | - | ||||||||||||||||||
354 | { | - | ||||||||||||||||||
355 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
356 | return *resourceSearchPaths(); | - | ||||||||||||||||||
357 | } | - | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | inline uint QResourceRoot::hash(int node) const | - | ||||||||||||||||||
360 | { | - | ||||||||||||||||||
361 | if(!node) | - | ||||||||||||||||||
362 | return 0; | - | ||||||||||||||||||
363 | const int offset = findOffset(node); | - | ||||||||||||||||||
364 | int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
365 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
366 | name_offset += 2; | - | ||||||||||||||||||
367 | return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) + | - | ||||||||||||||||||
368 | (names[name_offset+2] << 8) + (names[name_offset+3] << 0); | - | ||||||||||||||||||
369 | } | - | ||||||||||||||||||
370 | inline QString QResourceRoot::name(int node) const | - | ||||||||||||||||||
371 | { | - | ||||||||||||||||||
372 | if(!node) | - | ||||||||||||||||||
373 | return QString(); | - | ||||||||||||||||||
374 | const int offset = findOffset(node); | - | ||||||||||||||||||
375 | - | |||||||||||||||||||
376 | QString ret; | - | ||||||||||||||||||
377 | int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
378 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
379 | const short name_length = (names[name_offset+0] << 8) + | - | ||||||||||||||||||
380 | (names[name_offset+1] << 0); | - | ||||||||||||||||||
381 | name_offset += 2; | - | ||||||||||||||||||
382 | name_offset += 4; | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | ret.resize(name_length); | - | ||||||||||||||||||
385 | QChar *strData = ret.data(); | - | ||||||||||||||||||
386 | for(int i = 0; i < name_length*2; i+=2) { | - | ||||||||||||||||||
387 | QChar c(names[name_offset+i+1], names[name_offset+i]); | - | ||||||||||||||||||
388 | *strData = c; | - | ||||||||||||||||||
389 | ++strData; | - | ||||||||||||||||||
390 | } | - | ||||||||||||||||||
391 | return ret; | - | ||||||||||||||||||
392 | } | - | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const | - | ||||||||||||||||||
395 | { | - | ||||||||||||||||||
396 | QString path = _path; | - | ||||||||||||||||||
397 | { | - | ||||||||||||||||||
398 | QString root = mappingRoot(); | - | ||||||||||||||||||
399 | if(!root.isEmpty()) { | - | ||||||||||||||||||
400 | if(root == path) { | - | ||||||||||||||||||
401 | path = QLatin1Char('/'); | - | ||||||||||||||||||
402 | } else { | - | ||||||||||||||||||
403 | if(!root.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||
404 | root += QLatin1Char('/'); | - | ||||||||||||||||||
405 | if(path.size() >= root.size() && path.startsWith(root)) | - | ||||||||||||||||||
406 | path = path.mid(root.length()-1); | - | ||||||||||||||||||
407 | if(path.isEmpty()) | - | ||||||||||||||||||
408 | path = QLatin1Char('/'); | - | ||||||||||||||||||
409 | } | - | ||||||||||||||||||
410 | } | - | ||||||||||||||||||
411 | } | - | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | - | |||||||||||||||||||
414 | - | |||||||||||||||||||
415 | - | |||||||||||||||||||
416 | if(path == QLatin1String("/")) | - | ||||||||||||||||||
417 | return 0; | - | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | - | |||||||||||||||||||
420 | int child_count = (tree[6] << 24) + (tree[7] << 16) + | - | ||||||||||||||||||
421 | (tree[8] << 8) + (tree[9] << 0); | - | ||||||||||||||||||
422 | int child = (tree[10] << 24) + (tree[11] << 16) + | - | ||||||||||||||||||
423 | (tree[12] << 8) + (tree[13] << 0); | - | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | - | |||||||||||||||||||
426 | int node = -1; | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | QStringSplitter splitter(path); | - | ||||||||||||||||||
429 | while (child_count && splitter.hasNext()) { | - | ||||||||||||||||||
430 | QStringRef segment = splitter.next(); | - | ||||||||||||||||||
431 | - | |||||||||||||||||||
432 | - | |||||||||||||||||||
433 | - | |||||||||||||||||||
434 | - | |||||||||||||||||||
435 | - | |||||||||||||||||||
436 | - | |||||||||||||||||||
437 | - | |||||||||||||||||||
438 | const uint h = qt_hash(segment); | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | - | |||||||||||||||||||
441 | int l = 0, r = child_count-1; | - | ||||||||||||||||||
442 | int sub_node = (l+r+1)/2; | - | ||||||||||||||||||
443 | while(r != l) { | - | ||||||||||||||||||
444 | const uint sub_node_hash = hash(child+sub_node); | - | ||||||||||||||||||
445 | if(h == sub_node_hash) | - | ||||||||||||||||||
446 | break; | - | ||||||||||||||||||
447 | else if(h < sub_node_hash) | - | ||||||||||||||||||
448 | r = sub_node - 1; | - | ||||||||||||||||||
449 | else | - | ||||||||||||||||||
450 | l = sub_node; | - | ||||||||||||||||||
451 | sub_node = (l + r + 1) / 2; | - | ||||||||||||||||||
452 | } | - | ||||||||||||||||||
453 | sub_node += child; | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | - | |||||||||||||||||||
456 | bool found = false; | - | ||||||||||||||||||
457 | if(hash(sub_node) == h) { | - | ||||||||||||||||||
458 | while(sub_node > child && hash(sub_node-1) == h) | - | ||||||||||||||||||
459 | --sub_node; | - | ||||||||||||||||||
460 | for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) { | - | ||||||||||||||||||
461 | if(name(sub_node) == segment) { | - | ||||||||||||||||||
462 | found = true; | - | ||||||||||||||||||
463 | int offset = findOffset(sub_node); | - | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | - | |||||||||||||||||||
466 | - | |||||||||||||||||||
467 | offset += 4; | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | const short flags = (tree[offset+0] << 8) + | - | ||||||||||||||||||
470 | (tree[offset+1] << 0); | - | ||||||||||||||||||
471 | offset += 2; | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | if(!splitter.hasNext()) { | - | ||||||||||||||||||
474 | if(!(flags & Directory)) { | - | ||||||||||||||||||
475 | const short country = (tree[offset+0] << 8) + | - | ||||||||||||||||||
476 | (tree[offset+1] << 0); | - | ||||||||||||||||||
477 | offset += 2; | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | const short language = (tree[offset+0] << 8) + | - | ||||||||||||||||||
480 | (tree[offset+1] << 0); | - | ||||||||||||||||||
481 | offset += 2; | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | - | |||||||||||||||||||
484 | - | |||||||||||||||||||
485 | if(country == locale.country() && language == locale.language()) { | - | ||||||||||||||||||
486 | - | |||||||||||||||||||
487 | - | |||||||||||||||||||
488 | - | |||||||||||||||||||
489 | return sub_node; | - | ||||||||||||||||||
490 | } else if((country == QLocale::AnyCountry && language == locale.language()) || | - | ||||||||||||||||||
491 | (country == QLocale::AnyCountry && language == QLocale::C && node == -1)) { | - | ||||||||||||||||||
492 | node = sub_node; | - | ||||||||||||||||||
493 | } | - | ||||||||||||||||||
494 | continue; | - | ||||||||||||||||||
495 | } else { | - | ||||||||||||||||||
496 | - | |||||||||||||||||||
497 | - | |||||||||||||||||||
498 | - | |||||||||||||||||||
499 | - | |||||||||||||||||||
500 | return sub_node; | - | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | } | - | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | if(!(flags & Directory)) | - | ||||||||||||||||||
505 | return -1; | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
508 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
509 | offset += 4; | - | ||||||||||||||||||
510 | child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
511 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
512 | break; | - | ||||||||||||||||||
513 | } | - | ||||||||||||||||||
514 | } | - | ||||||||||||||||||
515 | } | - | ||||||||||||||||||
516 | if(!found) | - | ||||||||||||||||||
517 | break; | - | ||||||||||||||||||
518 | } | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | - | |||||||||||||||||||
521 | - | |||||||||||||||||||
522 | return node; | - | ||||||||||||||||||
523 | } | - | ||||||||||||||||||
524 | short QResourceRoot::flags(int node) const | - | ||||||||||||||||||
525 | { | - | ||||||||||||||||||
526 | if(node == -1) | - | ||||||||||||||||||
527 | return 0; | - | ||||||||||||||||||
528 | const int offset = findOffset(node) + 4; | - | ||||||||||||||||||
529 | return (tree[offset+0] << 8) + (tree[offset+1] << 0); | - | ||||||||||||||||||
530 | } | - | ||||||||||||||||||
531 | const uchar *QResourceRoot::data(int node, qint64 *size) const | - | ||||||||||||||||||
532 | { | - | ||||||||||||||||||
533 | if(node == -1) { | - | ||||||||||||||||||
534 | *size = 0; | - | ||||||||||||||||||
535 | return 0; | - | ||||||||||||||||||
536 | } | - | ||||||||||||||||||
537 | int offset = findOffset(node) + 4; | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); | - | ||||||||||||||||||
540 | offset += 2; | - | ||||||||||||||||||
541 | - | |||||||||||||||||||
542 | offset += 4; | - | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | if(!(flags & Directory)) { | - | ||||||||||||||||||
545 | const int data_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
546 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
547 | const uint data_length = (payloads[data_offset+0] << 24) + (payloads[data_offset+1] << 16) + | - | ||||||||||||||||||
548 | (payloads[data_offset+2] << 8) + (payloads[data_offset+3] << 0); | - | ||||||||||||||||||
549 | const uchar *ret = payloads+data_offset+4; | - | ||||||||||||||||||
550 | *size = data_length; | - | ||||||||||||||||||
551 | return ret; | - | ||||||||||||||||||
552 | } | - | ||||||||||||||||||
553 | *size = 0; | - | ||||||||||||||||||
554 | return 0; | - | ||||||||||||||||||
555 | } | - | ||||||||||||||||||
556 | QStringList QResourceRoot::children(int node) const | - | ||||||||||||||||||
557 | { | - | ||||||||||||||||||
558 | if(node == -1) | - | ||||||||||||||||||
559 | return QStringList(); | - | ||||||||||||||||||
560 | int offset = findOffset(node) + 4; | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); | - | ||||||||||||||||||
563 | offset += 2; | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | QStringList ret; | - | ||||||||||||||||||
566 | if(flags & Directory) { | - | ||||||||||||||||||
567 | const int child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
568 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
569 | offset += 4; | - | ||||||||||||||||||
570 | const int child_off = (tree[offset+0] << 24) + (tree[offset+1] << 16) + | - | ||||||||||||||||||
571 | (tree[offset+2] << 8) + (tree[offset+3] << 0); | - | ||||||||||||||||||
572 | ret.reserve(child_count); | - | ||||||||||||||||||
573 | for(int i = child_off; i < child_off+child_count; ++i) | - | ||||||||||||||||||
574 | ret << name(i); | - | ||||||||||||||||||
575 | } | - | ||||||||||||||||||
576 | return ret; | - | ||||||||||||||||||
577 | } | - | ||||||||||||||||||
578 | bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const | - | ||||||||||||||||||
579 | { | - | ||||||||||||||||||
580 | const QString root = mappingRoot(); | - | ||||||||||||||||||
581 | if(!root.isEmpty()) { | - | ||||||||||||||||||
582 | const QVector<QStringRef> root_segments = root.splitRef(QLatin1Char('/'), QString::SkipEmptyParts), | - | ||||||||||||||||||
583 | path_segments = path.splitRef(QLatin1Char('/'), QString::SkipEmptyParts); | - | ||||||||||||||||||
584 | if(path_segments.size() <= root_segments.size()) { | - | ||||||||||||||||||
585 | int matched = 0; | - | ||||||||||||||||||
586 | for(int i = 0; i < path_segments.size(); ++i) { | - | ||||||||||||||||||
587 | if(root_segments[i] != path_segments[i]) | - | ||||||||||||||||||
588 | break; | - | ||||||||||||||||||
589 | ++matched; | - | ||||||||||||||||||
590 | } | - | ||||||||||||||||||
591 | if(matched == path_segments.size()) { | - | ||||||||||||||||||
592 | if(match && root_segments.size() > matched) | - | ||||||||||||||||||
593 | *match = root_segments.at(matched).toString(); | - | ||||||||||||||||||
594 | return true; | - | ||||||||||||||||||
595 | } | - | ||||||||||||||||||
596 | } | - | ||||||||||||||||||
597 | } | - | ||||||||||||||||||
598 | return false; | - | ||||||||||||||||||
599 | } | - | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | __attribute__((visibility("default"))) bool qRegisterResourceData(int version, const unsigned char *tree, | - | ||||||||||||||||||
602 | const unsigned char *name, const unsigned char *data) | - | ||||||||||||||||||
603 | { | - | ||||||||||||||||||
604 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
605 | if(version == 0x01 && resourceList()) { | - | ||||||||||||||||||
606 | bool found = false; | - | ||||||||||||||||||
607 | QResourceRoot res(tree, name, data); | - | ||||||||||||||||||
608 | for(int i = 0; i < resourceList()->size(); ++i) { | - | ||||||||||||||||||
609 | if(*resourceList()->at(i) == res) { | - | ||||||||||||||||||
610 | found = true; | - | ||||||||||||||||||
611 | break; | - | ||||||||||||||||||
612 | } | - | ||||||||||||||||||
613 | } | - | ||||||||||||||||||
614 | if(!found) { | - | ||||||||||||||||||
615 | QResourceRoot *root = new QResourceRoot(tree, name, data); | - | ||||||||||||||||||
616 | root->ref.ref(); | - | ||||||||||||||||||
617 | resourceList()->append(root); | - | ||||||||||||||||||
618 | } | - | ||||||||||||||||||
619 | return true; | - | ||||||||||||||||||
620 | } | - | ||||||||||||||||||
621 | return false; | - | ||||||||||||||||||
622 | } | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | __attribute__((visibility("default"))) bool qUnregisterResourceData(int version, const unsigned char *tree, | - | ||||||||||||||||||
625 | const unsigned char *name, const unsigned char *data) | - | ||||||||||||||||||
626 | { | - | ||||||||||||||||||
627 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
628 | if(version == 0x01 && resourceList()) { | - | ||||||||||||||||||
629 | QResourceRoot res(tree, name, data); | - | ||||||||||||||||||
630 | for(int i = 0; i < resourceList()->size(); ) { | - | ||||||||||||||||||
631 | if(*resourceList()->at(i) == res) { | - | ||||||||||||||||||
632 | QResourceRoot *root = resourceList()->takeAt(i); | - | ||||||||||||||||||
633 | if(!root->ref.deref()) | - | ||||||||||||||||||
634 | delete root; | - | ||||||||||||||||||
635 | } else { | - | ||||||||||||||||||
636 | ++i; | - | ||||||||||||||||||
637 | } | - | ||||||||||||||||||
638 | } | - | ||||||||||||||||||
639 | return true; | - | ||||||||||||||||||
640 | } | - | ||||||||||||||||||
641 | return false; | - | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | - | |||||||||||||||||||
645 | - | |||||||||||||||||||
646 | class QDynamicBufferResourceRoot: public QResourceRoot | - | ||||||||||||||||||
647 | { | - | ||||||||||||||||||
648 | QString root; | - | ||||||||||||||||||
649 | const uchar *buffer; | - | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | public: | - | ||||||||||||||||||
652 | inline QDynamicBufferResourceRoot(const QString &_root) : root(_root), buffer(0) { } | - | ||||||||||||||||||
653 | inline ~QDynamicBufferResourceRoot() { } | - | ||||||||||||||||||
654 | inline const uchar *mappingBuffer() const { return buffer; } | - | ||||||||||||||||||
655 | virtual QString mappingRoot() const override { return root; } | - | ||||||||||||||||||
656 | virtual ResourceRootType type() const override { return Resource_Buffer; } | - | ||||||||||||||||||
657 | - | |||||||||||||||||||
658 | - | |||||||||||||||||||
659 | bool registerSelf(const uchar *b, int size) | - | ||||||||||||||||||
660 | { | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | if (size >= 0 && size < 20) | - | ||||||||||||||||||
663 | return false; | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | - | |||||||||||||||||||
666 | int offset = 0; | - | ||||||||||||||||||
667 | - | |||||||||||||||||||
668 | - | |||||||||||||||||||
669 | if(b[offset+0] != 'q' || b[offset+1] != 'r' || | - | ||||||||||||||||||
670 | b[offset+2] != 'e' || b[offset+3] != 's') { | - | ||||||||||||||||||
671 | return false; | - | ||||||||||||||||||
672 | } | - | ||||||||||||||||||
673 | offset += 4; | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | const int version = (b[offset+0] << 24) + (b[offset+1] << 16) + | - | ||||||||||||||||||
676 | (b[offset+2] << 8) + (b[offset+3] << 0); | - | ||||||||||||||||||
677 | offset += 4; | - | ||||||||||||||||||
678 | - | |||||||||||||||||||
679 | const int tree_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + | - | ||||||||||||||||||
680 | (b[offset+2] << 8) + (b[offset+3] << 0); | - | ||||||||||||||||||
681 | offset += 4; | - | ||||||||||||||||||
682 | - | |||||||||||||||||||
683 | const int data_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + | - | ||||||||||||||||||
684 | (b[offset+2] << 8) + (b[offset+3] << 0); | - | ||||||||||||||||||
685 | offset += 4; | - | ||||||||||||||||||
686 | - | |||||||||||||||||||
687 | const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + | - | ||||||||||||||||||
688 | (b[offset+2] << 8) + (b[offset+3] << 0); | - | ||||||||||||||||||
689 | offset += 4; | - | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | - | |||||||||||||||||||
692 | if (size >= 0 && (tree_offset >= size || data_offset >= size || name_offset >= size)) | - | ||||||||||||||||||
693 | return false; | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | if(version == 0x01) { | - | ||||||||||||||||||
696 | buffer = b; | - | ||||||||||||||||||
697 | setSource(b+tree_offset, b+name_offset, b+data_offset); | - | ||||||||||||||||||
698 | return true; | - | ||||||||||||||||||
699 | } | - | ||||||||||||||||||
700 | return false; | - | ||||||||||||||||||
701 | } | - | ||||||||||||||||||
702 | }; | - | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | - | |||||||||||||||||||
705 | - | |||||||||||||||||||
706 | - | |||||||||||||||||||
707 | - | |||||||||||||||||||
708 | - | |||||||||||||||||||
709 | class QDynamicFileResourceRoot: public QDynamicBufferResourceRoot | - | ||||||||||||||||||
710 | { | - | ||||||||||||||||||
711 | QString fileName; | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | uchar *unmapPointer; | - | ||||||||||||||||||
714 | unsigned int unmapLength; | - | ||||||||||||||||||
715 | - | |||||||||||||||||||
716 | public: | - | ||||||||||||||||||
717 | inline QDynamicFileResourceRoot(const QString &_root) : QDynamicBufferResourceRoot(_root), unmapPointer(0), unmapLength(0) { } | - | ||||||||||||||||||
718 | ~QDynamicFileResourceRoot() { | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | if (unmapPointer) { | - | ||||||||||||||||||
721 | munmap((char*)unmapPointer, unmapLength); | - | ||||||||||||||||||
722 | unmapPointer = 0; | - | ||||||||||||||||||
723 | unmapLength = 0; | - | ||||||||||||||||||
724 | } else | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | { | - | ||||||||||||||||||
727 | delete [] mappingBuffer(); | - | ||||||||||||||||||
728 | } | - | ||||||||||||||||||
729 | } | - | ||||||||||||||||||
730 | QString mappingFile() const { return fileName; } | - | ||||||||||||||||||
731 | virtual ResourceRootType type() const override { return Resource_File; } | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | bool registerSelf(const QString &f) { | - | ||||||||||||||||||
734 | bool fromMM = false; | - | ||||||||||||||||||
735 | uchar *data = 0; | - | ||||||||||||||||||
736 | unsigned int data_len = 0; | - | ||||||||||||||||||
737 | int fd = qt_safe_open(QFile::encodeName(f), 00, | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | - | |||||||||||||||||||
740 | - | |||||||||||||||||||
741 | 0666 | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | ); | - | ||||||||||||||||||
744 | if (fd >= 0) { | - | ||||||||||||||||||
745 | struct stat64 st; | - | ||||||||||||||||||
746 | if (!::fstat64(fd, &st)) { | - | ||||||||||||||||||
747 | uchar *ptr; | - | ||||||||||||||||||
748 | ptr = reinterpret_cast<uchar *>( | - | ||||||||||||||||||
749 | mmap(0, st.st_size, | - | ||||||||||||||||||
750 | 0x1, | - | ||||||||||||||||||
751 | 0 | 0x02, | - | ||||||||||||||||||
752 | fd, 0)); | - | ||||||||||||||||||
753 | if (ptr && ptr != reinterpret_cast<uchar *>(((void *) -1))) { | - | ||||||||||||||||||
754 | data = ptr; | - | ||||||||||||||||||
755 | data_len = st.st_size; | - | ||||||||||||||||||
756 | fromMM = true; | - | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | } | - | ||||||||||||||||||
759 | ::close(fd); | - | ||||||||||||||||||
760 | } | - | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | if(!data) { | - | ||||||||||||||||||
763 | QFile file(f); | - | ||||||||||||||||||
764 | if (!file.exists()) | - | ||||||||||||||||||
765 | return false; | - | ||||||||||||||||||
766 | data_len = file.size(); | - | ||||||||||||||||||
767 | data = new uchar[data_len]; | - | ||||||||||||||||||
768 | - | |||||||||||||||||||
769 | bool ok = false; | - | ||||||||||||||||||
770 | if (file.open(QIODevice::ReadOnly)) | - | ||||||||||||||||||
771 | ok = (data_len == (uint)file.read((char*)data, data_len)); | - | ||||||||||||||||||
772 | if (!ok) { | - | ||||||||||||||||||
773 | delete [] data; | - | ||||||||||||||||||
774 | data = 0; | - | ||||||||||||||||||
775 | data_len = 0; | - | ||||||||||||||||||
776 | return false; | - | ||||||||||||||||||
777 | } | - | ||||||||||||||||||
778 | fromMM = false; | - | ||||||||||||||||||
779 | } | - | ||||||||||||||||||
780 | if (data && QDynamicBufferResourceRoot::registerSelf(data, data_len)) { | - | ||||||||||||||||||
781 | if(fromMM) { | - | ||||||||||||||||||
782 | unmapPointer = data; | - | ||||||||||||||||||
783 | unmapLength = data_len; | - | ||||||||||||||||||
784 | } | - | ||||||||||||||||||
785 | fileName = f; | - | ||||||||||||||||||
786 | return true; | - | ||||||||||||||||||
787 | } | - | ||||||||||||||||||
788 | return false; | - | ||||||||||||||||||
789 | } | - | ||||||||||||||||||
790 | }; | - | ||||||||||||||||||
791 | - | |||||||||||||||||||
792 | static QString qt_resource_fixResourceRoot(QString r) { | - | ||||||||||||||||||
793 | if(!r.isEmpty()) { | - | ||||||||||||||||||
794 | if(r.startsWith(QLatin1Char(':'))) | - | ||||||||||||||||||
795 | r = r.mid(1); | - | ||||||||||||||||||
796 | if(!r.isEmpty()) | - | ||||||||||||||||||
797 | r = QDir::cleanPath(r); | - | ||||||||||||||||||
798 | } | - | ||||||||||||||||||
799 | return r; | - | ||||||||||||||||||
800 | } | - | ||||||||||||||||||
801 | bool | - | ||||||||||||||||||
802 | QResource::registerResource(const QString &rccFilename, const QString &resourceRoot) | - | ||||||||||||||||||
803 | { | - | ||||||||||||||||||
804 | QString r = qt_resource_fixResourceRoot(resourceRoot); | - | ||||||||||||||||||
805 | if(!r.isEmpty() && r[0] != QLatin1Char('/')) { | - | ||||||||||||||||||
806 | QMessageLogger(__FILE__, 10601066, __PRETTY_FUNCTION__).warning("QDir::registerResource: Registering a resource [%s] must be rooted in an absolute path (start with /) [%s]", | - | ||||||||||||||||||
807 | rccFilename.toLocal8Bit().data(), resourceRoot.toLocal8Bit().data()); | - | ||||||||||||||||||
808 | return false; | - | ||||||||||||||||||
809 | } | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | QDynamicFileResourceRoot *root = new QDynamicFileResourceRoot(r); | - | ||||||||||||||||||
812 | if(root->registerSelf(rccFilename)) { | - | ||||||||||||||||||
813 | root->ref.ref(); | - | ||||||||||||||||||
814 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
815 | resourceList()->append(root); | - | ||||||||||||||||||
816 | return true; | - | ||||||||||||||||||
817 | } | - | ||||||||||||||||||
818 | delete root; | - | ||||||||||||||||||
819 | return false; | - | ||||||||||||||||||
820 | } | - | ||||||||||||||||||
821 | bool | - | ||||||||||||||||||
822 | QResource::unregisterResource(const QString &rccFilename, const QString &resourceRoot) | - | ||||||||||||||||||
823 | { | - | ||||||||||||||||||
824 | QString r = qt_resource_fixResourceRoot(resourceRoot); | - | ||||||||||||||||||
825 | - | |||||||||||||||||||
826 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
827 | ResourceList *list = resourceList(); | - | ||||||||||||||||||
828 | for(int i = 0; i < list->size(); ++i) { | - | ||||||||||||||||||
829 | QResourceRoot *res = list->at(i); | - | ||||||||||||||||||
830 | if(res->type() == QResourceRoot::Resource_File) { | - | ||||||||||||||||||
831 | QDynamicFileResourceRoot *root = reinterpret_cast<QDynamicFileResourceRoot*>(res); | - | ||||||||||||||||||
832 | if (root->mappingFile() == rccFilename && root->mappingRoot() == r) { | - | ||||||||||||||||||
833 | resourceList()->removeAt(i); | - | ||||||||||||||||||
834 | if(!root->ref.deref()) { | - | ||||||||||||||||||
835 | delete root; | - | ||||||||||||||||||
836 | return true; | - | ||||||||||||||||||
837 | } | - | ||||||||||||||||||
838 | return false; | - | ||||||||||||||||||
839 | } | - | ||||||||||||||||||
840 | } | - | ||||||||||||||||||
841 | } | - | ||||||||||||||||||
842 | return false; | - | ||||||||||||||||||
843 | } | - | ||||||||||||||||||
844 | bool | - | ||||||||||||||||||
845 | QResource::registerResource(const uchar *rccData, const QString &resourceRoot) | - | ||||||||||||||||||
846 | { | - | ||||||||||||||||||
847 | QString r = qt_resource_fixResourceRoot(resourceRoot); | - | ||||||||||||||||||
848 | if(!r.isEmpty() && r[0] != QLatin1Char('/')) { | - | ||||||||||||||||||
849 | QMessageLogger(__FILE__, 11311137, __PRETTY_FUNCTION__).warning("QDir::registerResource: Registering a resource [%p] must be rooted in an absolute path (start with /) [%s]", | - | ||||||||||||||||||
850 | rccData, resourceRoot.toLocal8Bit().data()); | - | ||||||||||||||||||
851 | return false; | - | ||||||||||||||||||
852 | } | - | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | QDynamicBufferResourceRoot *root = new QDynamicBufferResourceRoot(r); | - | ||||||||||||||||||
855 | if (root->registerSelf(rccData, -1)) { | - | ||||||||||||||||||
856 | root->ref.ref(); | - | ||||||||||||||||||
857 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
858 | resourceList()->append(root); | - | ||||||||||||||||||
859 | return true; | - | ||||||||||||||||||
860 | } | - | ||||||||||||||||||
861 | delete root; | - | ||||||||||||||||||
862 | return false; | - | ||||||||||||||||||
863 | } | - | ||||||||||||||||||
864 | bool | - | ||||||||||||||||||
865 | QResource::unregisterResource(const uchar *rccData, const QString &resourceRoot) | - | ||||||||||||||||||
866 | { | - | ||||||||||||||||||
867 | QString r = qt_resource_fixResourceRoot(resourceRoot); | - | ||||||||||||||||||
868 | - | |||||||||||||||||||
869 | QMutexLocker lock(resourceMutex()); | - | ||||||||||||||||||
870 | ResourceList *list = resourceList(); | - | ||||||||||||||||||
871 | for(int i = 0; i < list->size(); ++i) { | - | ||||||||||||||||||
872 | QResourceRoot *res = list->at(i); | - | ||||||||||||||||||
873 | if(res->type() == QResourceRoot::Resource_Buffer) { | - | ||||||||||||||||||
874 | QDynamicBufferResourceRoot *root = reinterpret_cast<QDynamicBufferResourceRoot*>(res); | - | ||||||||||||||||||
875 | if (root->mappingBuffer() == rccData && root->mappingRoot() == r) { | - | ||||||||||||||||||
876 | resourceList()->removeAt(i); | - | ||||||||||||||||||
877 | if(!root->ref.deref()) { | - | ||||||||||||||||||
878 | delete root; | - | ||||||||||||||||||
879 | return true; | - | ||||||||||||||||||
880 | } | - | ||||||||||||||||||
881 | return false; | - | ||||||||||||||||||
882 | } | - | ||||||||||||||||||
883 | } | - | ||||||||||||||||||
884 | } | - | ||||||||||||||||||
885 | return false; | - | ||||||||||||||||||
886 | } | - | ||||||||||||||||||
887 | - | |||||||||||||||||||
888 | - | |||||||||||||||||||
889 | - | |||||||||||||||||||
890 | class QResourceFileEnginePrivate : public QAbstractFileEnginePrivate | - | ||||||||||||||||||
891 | { | - | ||||||||||||||||||
892 | protected: | - | ||||||||||||||||||
893 | inline QResourceFileEngine* q_func() { return static_cast<QResourceFileEngine *>(q_ptr); } inline const QResourceFileEngine* q_func() const { return static_cast<const QResourceFileEngine *>(q_ptr); } friend class QResourceFileEngine; | - | ||||||||||||||||||
894 | private: | - | ||||||||||||||||||
895 | uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags); | - | ||||||||||||||||||
896 | bool unmap(uchar *ptr); | - | ||||||||||||||||||
897 | void uncompress() const; | - | ||||||||||||||||||
898 | qint64 offset; | - | ||||||||||||||||||
899 | QResource resource; | - | ||||||||||||||||||
900 | mutable QByteArray uncompressed; | - | ||||||||||||||||||
901 | protected: | - | ||||||||||||||||||
902 | QResourceFileEnginePrivate() : offset(0) { } | - | ||||||||||||||||||
903 | }; | - | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | bool QResourceFileEngine::mkdir(const QString &, bool) const | - | ||||||||||||||||||
906 | { | - | ||||||||||||||||||
907 | return false; | - | ||||||||||||||||||
908 | } | - | ||||||||||||||||||
909 | - | |||||||||||||||||||
910 | bool QResourceFileEngine::rmdir(const QString &, bool) const | - | ||||||||||||||||||
911 | { | - | ||||||||||||||||||
912 | return false; | - | ||||||||||||||||||
913 | } | - | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | bool QResourceFileEngine::setSize(qint64) | - | ||||||||||||||||||
916 | { | - | ||||||||||||||||||
917 | return false; | - | ||||||||||||||||||
918 | } | - | ||||||||||||||||||
919 | - | |||||||||||||||||||
920 | QStringList QResourceFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const | - | ||||||||||||||||||
921 | { | - | ||||||||||||||||||
922 | return QAbstractFileEngine::entryList(filters, filterNames); | - | ||||||||||||||||||
923 | } | - | ||||||||||||||||||
924 | - | |||||||||||||||||||
925 | bool QResourceFileEngine::caseSensitive() const | - | ||||||||||||||||||
926 | { | - | ||||||||||||||||||
927 | return true; | - | ||||||||||||||||||
928 | } | - | ||||||||||||||||||
929 | - | |||||||||||||||||||
930 | QResourceFileEngine::QResourceFileEngine(const QString &file) : | - | ||||||||||||||||||
931 | QAbstractFileEngine(*new QResourceFileEnginePrivate) | - | ||||||||||||||||||
932 | { | - | ||||||||||||||||||
933 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
934 | d->resource.setFileName(file); | - | ||||||||||||||||||
if(d->resource.isCompressed() && d->resource.size()) { | ||||||||||||||||||||
d->uncompressed = qUncompress(d->resource.data(), d->resource.size()); | ||||||||||||||||||||
}} executed 48997 times by 114 tests: end of block Executed by:
| ||||||||||||||||||||
936 | - | |||||||||||||||||||
937 | QResourceFileEngine::~QResourceFileEngine() | - | ||||||||||||||||||
938 | { | - | ||||||||||||||||||
939 | } | - | ||||||||||||||||||
940 | - | |||||||||||||||||||
941 | void QResourceFileEngine::setFileName(const QString &file) | - | ||||||||||||||||||
942 | { | - | ||||||||||||||||||
943 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
944 | d->resource.setFileName(file); | - | ||||||||||||||||||
945 | } | - | ||||||||||||||||||
946 | - | |||||||||||||||||||
947 | bool QResourceFileEngine::open(QIODevice::OpenMode flags) | - | ||||||||||||||||||
948 | { | - | ||||||||||||||||||
949 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
950 | if (d->resource.fileName().isEmpty()
| 0-14854 | ||||||||||||||||||
951 | QMessageLogger(__FILE__, 12501251, __PRETTY_FUNCTION__).warning("QResourceFileEngine::open: Missing file name"); | - | ||||||||||||||||||
952 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
953 | } | - | ||||||||||||||||||
954 | if(flags & QIODevice::WriteOnly
| 3-14851 | ||||||||||||||||||
955 | return executed 3 times by 1 test: false;return false; Executed by:
executed 3 times by 1 test: return false; Executed by:
| 3 | ||||||||||||||||||
956 | d->uncompress(); | - | ||||||||||||||||||
957 | if (!d->resource.isValid()
| 212-14639 | ||||||||||||||||||
958 | d->errorString = qt_error_string(2); | - | ||||||||||||||||||
959 | return executed 212 times by 7 tests: false;return false; Executed by:
executed 212 times by 7 tests: return false; Executed by:
| 212 | ||||||||||||||||||
960 | } | - | ||||||||||||||||||
961 | return executed 14639 times by 81 tests: true;return true; Executed by:
executed 14639 times by 81 tests: return true; Executed by:
| 14639 | ||||||||||||||||||
962 | } | - | ||||||||||||||||||
963 | - | |||||||||||||||||||
964 | bool QResourceFileEngine::close() | - | ||||||||||||||||||
965 | { | - | ||||||||||||||||||
966 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
967 | d->offset = 0; | - | ||||||||||||||||||
968 | d->uncompressed.clear(); | - | ||||||||||||||||||
969 | return true; | - | ||||||||||||||||||
970 | } | - | ||||||||||||||||||
971 | - | |||||||||||||||||||
972 | bool QResourceFileEngine::flush() | - | ||||||||||||||||||
973 | { | - | ||||||||||||||||||
974 | return true; | - | ||||||||||||||||||
975 | } | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | qint64 QResourceFileEngine::read(char *data, qint64 len) | - | ||||||||||||||||||
978 | { | - | ||||||||||||||||||
979 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
980 | if(len > size()-d->offset) | - | ||||||||||||||||||
981 | len = size()-d->offset; | - | ||||||||||||||||||
982 | if(len <= 0) | - | ||||||||||||||||||
983 | return 0; | - | ||||||||||||||||||
984 | if(d->resource.isCompressed()) | - | ||||||||||||||||||
985 | memcpy(data, d->uncompressed.constData()+d->offset, len); | - | ||||||||||||||||||
986 | else | - | ||||||||||||||||||
987 | memcpy(data, d->resource.data()+d->offset, len); | - | ||||||||||||||||||
988 | d->offset += len; | - | ||||||||||||||||||
989 | return len; | - | ||||||||||||||||||
990 | } | - | ||||||||||||||||||
991 | - | |||||||||||||||||||
992 | qint64 QResourceFileEngine::write(const char *, qint64) | - | ||||||||||||||||||
993 | { | - | ||||||||||||||||||
994 | return -1; | - | ||||||||||||||||||
995 | } | - | ||||||||||||||||||
996 | - | |||||||||||||||||||
997 | bool QResourceFileEngine::remove() | - | ||||||||||||||||||
998 | { | - | ||||||||||||||||||
999 | return false; | - | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | bool QResourceFileEngine::copy(const QString &) | - | ||||||||||||||||||
1003 | { | - | ||||||||||||||||||
1004 | return false; | - | ||||||||||||||||||
1005 | } | - | ||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | bool QResourceFileEngine::rename(const QString &) | - | ||||||||||||||||||
1008 | { | - | ||||||||||||||||||
1009 | return false; | - | ||||||||||||||||||
1010 | } | - | ||||||||||||||||||
1011 | - | |||||||||||||||||||
1012 | bool QResourceFileEngine::link(const QString &) | - | ||||||||||||||||||
1013 | { | - | ||||||||||||||||||
1014 | return false; | - | ||||||||||||||||||
1015 | } | - | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | qint64 QResourceFileEngine::size() const | - | ||||||||||||||||||
1018 | { | - | ||||||||||||||||||
1019 | const QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1020 | if(!d->resource.isValid()
| 0-179590 | ||||||||||||||||||
1021 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
1022 | if (d->resource.isCompressed()
| 2845-176745 | ||||||||||||||||||
1023 | d->uncompress(); | - | ||||||||||||||||||
1024 | return executed 2845 times by 8 tests: d->uncompressed.size();return d->uncompressed.size(); Executed by:
executed 2845 times by 8 tests: return d->uncompressed.size(); Executed by:
| 2845 | ||||||||||||||||||
1025 | } | - | ||||||||||||||||||
1026 | return executed 176745 times by 80 tests: d->resource.size();return d->resource.size(); Executed by:
executed 176745 times by 80 tests: return d->resource.size(); Executed by:
| 176745 | ||||||||||||||||||
1027 | } | - | ||||||||||||||||||
1028 | - | |||||||||||||||||||
1029 | qint64 QResourceFileEngine::pos() const | - | ||||||||||||||||||
1030 | { | - | ||||||||||||||||||
1031 | const QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1032 | return d->offset; | - | ||||||||||||||||||
1033 | } | - | ||||||||||||||||||
1034 | - | |||||||||||||||||||
1035 | bool QResourceFileEngine::atEnd() const | - | ||||||||||||||||||
1036 | { | - | ||||||||||||||||||
1037 | const QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1038 | if(!d->resource.isValid()) | - | ||||||||||||||||||
1039 | return true; | - | ||||||||||||||||||
1040 | return d->offset == size(); | - | ||||||||||||||||||
1041 | } | - | ||||||||||||||||||
1042 | - | |||||||||||||||||||
1043 | bool QResourceFileEngine::seek(qint64 pos) | - | ||||||||||||||||||
1044 | { | - | ||||||||||||||||||
1045 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1046 | if(!d->resource.isValid()) | - | ||||||||||||||||||
1047 | return false; | - | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | if(d->offset > size()) | - | ||||||||||||||||||
1050 | return false; | - | ||||||||||||||||||
1051 | d->offset = pos; | - | ||||||||||||||||||
1052 | return true; | - | ||||||||||||||||||
1053 | } | - | ||||||||||||||||||
1054 | - | |||||||||||||||||||
1055 | bool QResourceFileEngine::isSequential() const | - | ||||||||||||||||||
1056 | { | - | ||||||||||||||||||
1057 | return false; | - | ||||||||||||||||||
1058 | } | - | ||||||||||||||||||
1059 | - | |||||||||||||||||||
1060 | QAbstractFileEngine::FileFlags QResourceFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const | - | ||||||||||||||||||
1061 | { | - | ||||||||||||||||||
1062 | const QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1063 | QAbstractFileEngine::FileFlags ret = 0; | - | ||||||||||||||||||
1064 | if(!d->resource.isValid()) | - | ||||||||||||||||||
1065 | return ret; | - | ||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | if(type & PermsMask) | - | ||||||||||||||||||
1068 | ret |= QAbstractFileEngine::FileFlags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm); | - | ||||||||||||||||||
1069 | if(type & TypesMask) { | - | ||||||||||||||||||
1070 | if(d->resource.isDir()) | - | ||||||||||||||||||
1071 | ret |= DirectoryType; | - | ||||||||||||||||||
1072 | else | - | ||||||||||||||||||
1073 | ret |= FileType; | - | ||||||||||||||||||
1074 | } | - | ||||||||||||||||||
1075 | if(type & FlagsMask) { | - | ||||||||||||||||||
1076 | ret |= ExistsFlag; | - | ||||||||||||||||||
1077 | if(d->resource.absoluteFilePath() == QLatin1String(":/")) | - | ||||||||||||||||||
1078 | ret |= RootFlag; | - | ||||||||||||||||||
1079 | } | - | ||||||||||||||||||
1080 | return ret; | - | ||||||||||||||||||
1081 | } | - | ||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | bool QResourceFileEngine::setPermissions(uint) | - | ||||||||||||||||||
1084 | { | - | ||||||||||||||||||
1085 | return false; | - | ||||||||||||||||||
1086 | } | - | ||||||||||||||||||
1087 | - | |||||||||||||||||||
1088 | QString QResourceFileEngine::fileName(FileName file) const | - | ||||||||||||||||||
1089 | { | - | ||||||||||||||||||
1090 | const QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1091 | if(file == BaseName) { | - | ||||||||||||||||||
1092 | int slash = d->resource.fileName().lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
1093 | if (slash == -1) | - | ||||||||||||||||||
1094 | return d->resource.fileName(); | - | ||||||||||||||||||
1095 | return d->resource.fileName().mid(slash + 1); | - | ||||||||||||||||||
1096 | } else if(file == PathName || file == AbsolutePathName) { | - | ||||||||||||||||||
1097 | const QString path = (file == AbsolutePathName) ? d->resource.absoluteFilePath() : d->resource.fileName(); | - | ||||||||||||||||||
1098 | const int slash = path.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
1099 | if (slash == -1) | - | ||||||||||||||||||
1100 | return QLatin1String(":"); | - | ||||||||||||||||||
1101 | else if (slash <= 1) | - | ||||||||||||||||||
1102 | return QLatin1String(":/"); | - | ||||||||||||||||||
1103 | return path.left(slash); | - | ||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | } else if(file == CanonicalName || file == CanonicalPathName) { | - | ||||||||||||||||||
1106 | const QString absoluteFilePath = d->resource.absoluteFilePath(); | - | ||||||||||||||||||
1107 | if(file == CanonicalPathName) { | - | ||||||||||||||||||
1108 | const int slash = absoluteFilePath.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
1109 | if (slash != -1) | - | ||||||||||||||||||
1110 | return absoluteFilePath.left(slash); | - | ||||||||||||||||||
1111 | } | - | ||||||||||||||||||
1112 | return absoluteFilePath; | - | ||||||||||||||||||
1113 | } | - | ||||||||||||||||||
1114 | return d->resource.fileName(); | - | ||||||||||||||||||
1115 | } | - | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | bool QResourceFileEngine::isRelativePath() const | - | ||||||||||||||||||
1118 | { | - | ||||||||||||||||||
1119 | return false; | - | ||||||||||||||||||
1120 | } | - | ||||||||||||||||||
1121 | - | |||||||||||||||||||
1122 | uint QResourceFileEngine::ownerId(FileOwner) const | - | ||||||||||||||||||
1123 | { | - | ||||||||||||||||||
1124 | static const uint nobodyID = (uint) -2; | - | ||||||||||||||||||
1125 | return nobodyID; | - | ||||||||||||||||||
1126 | } | - | ||||||||||||||||||
1127 | - | |||||||||||||||||||
1128 | QString QResourceFileEngine::owner(FileOwner) const | - | ||||||||||||||||||
1129 | { | - | ||||||||||||||||||
1130 | return QString(); | - | ||||||||||||||||||
1131 | } | - | ||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | QDateTime QResourceFileEngine::fileTime(FileTime) const | - | ||||||||||||||||||
1134 | { | - | ||||||||||||||||||
1135 | return QDateTime(); | - | ||||||||||||||||||
1136 | } | - | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | - | |||||||||||||||||||
1139 | - | |||||||||||||||||||
1140 | - | |||||||||||||||||||
1141 | QAbstractFileEngine::Iterator *QResourceFileEngine::beginEntryList(QDir::Filters filters, | - | ||||||||||||||||||
1142 | const QStringList &filterNames) | - | ||||||||||||||||||
1143 | { | - | ||||||||||||||||||
1144 | return new QResourceFileEngineIterator(filters, filterNames); | - | ||||||||||||||||||
1145 | } | - | ||||||||||||||||||
1146 | - | |||||||||||||||||||
1147 | - | |||||||||||||||||||
1148 | - | |||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | QAbstractFileEngine::Iterator *QResourceFileEngine::endEntryList() | - | ||||||||||||||||||
1151 | { | - | ||||||||||||||||||
1152 | return 0; | - | ||||||||||||||||||
1153 | } | - | ||||||||||||||||||
1154 | - | |||||||||||||||||||
1155 | bool QResourceFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) | - | ||||||||||||||||||
1156 | { | - | ||||||||||||||||||
1157 | QResourceFileEnginePrivate * const d = d_func(); | - | ||||||||||||||||||
1158 | if (extension == MapExtension) { | - | ||||||||||||||||||
1159 | const MapExtensionOption *options = (const MapExtensionOption*)(option); | - | ||||||||||||||||||
1160 | MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); | - | ||||||||||||||||||
1161 | returnValue->address = d->map(options->offset, options->size, options->flags); | - | ||||||||||||||||||
1162 | return (returnValue->address != 0); | - | ||||||||||||||||||
1163 | } | - | ||||||||||||||||||
1164 | if (extension == UnMapExtension) { | - | ||||||||||||||||||
1165 | const UnMapExtensionOption *options = (const UnMapExtensionOption*)option; | - | ||||||||||||||||||
1166 | return d->unmap(options->address); | - | ||||||||||||||||||
1167 | } | - | ||||||||||||||||||
1168 | return false; | - | ||||||||||||||||||
1169 | } | - | ||||||||||||||||||
1170 | - | |||||||||||||||||||
1171 | bool QResourceFileEngine::supportsExtension(Extension extension) const | - | ||||||||||||||||||
1172 | { | - | ||||||||||||||||||
1173 | return (extension == UnMapExtension || extension == MapExtension); | - | ||||||||||||||||||
1174 | } | - | ||||||||||||||||||
1175 | - | |||||||||||||||||||
1176 | uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags) | - | ||||||||||||||||||
1177 | { | - | ||||||||||||||||||
1178 | QResourceFileEngine * const q = q_func(); | - | ||||||||||||||||||
1179 | (void)flags;; | - | ||||||||||||||||||
1180 | if (offset < 0 || size <= 0 || !resource.isValid() || offset + size > resource.size()) { | - | ||||||||||||||||||
1181 | q->setError(QFile::UnspecifiedError, QString()); | - | ||||||||||||||||||
1182 | return 0; | - | ||||||||||||||||||
1183 | } | - | ||||||||||||||||||
1184 | uchar *address = const_cast<uchar *>(resource.data()); | - | ||||||||||||||||||
1185 | return (address + offset); | - | ||||||||||||||||||
1186 | } | - | ||||||||||||||||||
1187 | - | |||||||||||||||||||
1188 | bool QResourceFileEnginePrivate::unmap(uchar *ptr) | - | ||||||||||||||||||
1189 | { | - | ||||||||||||||||||
1190 | (void)ptr;; | - | ||||||||||||||||||
1191 | return true; | - | ||||||||||||||||||
1192 | } | - | ||||||||||||||||||
1193 | - | |||||||||||||||||||
1194 | void QResourceFileEnginePrivate::uncompress() const | - | ||||||||||||||||||
1195 | { | - | ||||||||||||||||||
1196 | if (resource.isCompressed()
| 0-14238 | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | uncompressed = qUncompress(resource.data(), resource.size()); | - | ||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | - | |||||||||||||||||||
1202 | } executed 619 times by 8 tests: end of block Executed by:
| 619 | ||||||||||||||||||
1203 | } executed 17696 times by 83 tests: end of block Executed by:
| 17696 | ||||||||||||||||||
1204 | - | |||||||||||||||||||
1205 | - | |||||||||||||||||||
1206 | - | |||||||||||||||||||
1207 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |