source: Vago/Libs/quazip-0.7.2/quazip/quazipdir.h@ 1089

Last change on this file since 1089 was 1050, checked in by s10k, 8 years ago
File size: 8.3 KB
RevLine 
[1050]1#ifndef QUAZIP_QUAZIPDIR_H
2#define QUAZIP_QUAZIPDIR_H
3
4/*
5Copyright (C) 2005-2014 Sergey A. Tachenov
6
7This file is part of QuaZIP.
8
9QuaZIP is free software: you can redistribute it and/or modify
10it under the terms of the GNU Lesser General Public License as published by
11the Free Software Foundation, either version 2.1 of the License, or
12(at your option) any later version.
13
14QuaZIP is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License
20along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
21
22See COPYING file for the full LGPL text.
23
24Original ZIP package is copyrighted by Gilles Vollant and contributors,
25see quazip/(un)zip.h files for details. Basically it's the zlib license.
26*/
27
28class QuaZipDirPrivate;
29
30#include "quazip.h"
31#include "quazipfileinfo.h"
32#include <QDir>
33#include <QList>
34#include <QSharedDataPointer>
35
36/// Provides ZIP archive navigation.
37/**
38* This class is modelled after QDir, and is designed to provide similar
39* features for ZIP archives.
40*
41* The only significant difference from QDir is that the root path is not
42* '/', but an empty string since that's how the file paths are stored in
43* the archive. However, QuaZipDir understands the paths starting with
44* '/'. It is important in a few places:
45*
46* - In the cd() function.
47* - In the constructor.
48* - In the exists() function.
49* - In the relativePath() function.
50*
51* Note that since ZIP uses '/' on all platforms, the '\' separator is
52* not supported.
53*/
54class QUAZIP_EXPORT QuaZipDir {
55private:
56 QSharedDataPointer<QuaZipDirPrivate> d;
57public:
58 /// The copy constructor.
59 QuaZipDir(const QuaZipDir &that);
60 /// Constructs a QuaZipDir instance pointing to the specified directory.
61 /**
62 If \a dir is not specified, points to the root of the archive.
63 The same happens if the \a dir is &quot;/&quot;.
64 */
65 QuaZipDir(QuaZip *zip, const QString &dir = QString());
66 /// Destructor.
67 ~QuaZipDir();
68 /// The assignment operator.
69 bool operator==(const QuaZipDir &that);
70 /// operator!=
71 /**
72 \return \c true if either this and \a that use different QuaZip
73 instances or if they point to different directories.
74 */
75 inline bool operator!=(const QuaZipDir &that) {return !operator==(that);}
76 /// operator==
77 /**
78 \return \c true if both this and \a that use the same QuaZip
79 instance and point to the same directory.
80 */
81 QuaZipDir& operator=(const QuaZipDir &that);
82 /// Returns the name of the entry at the specified position.
83 QString operator[](int pos) const;
84 /// Returns the current case sensitivity mode.
85 QuaZip::CaseSensitivity caseSensitivity() const;
86 /// Changes the 'current' directory.
87 /**
88 * If the path starts with '/', it is interpreted as an absolute
89 * path from the root of the archive. Otherwise, it is interpreted
90 * as a path relative to the current directory as was set by the
91 * previous cd() or the constructor.
92 *
93 * Note that the subsequent path() call will not return a path
94 * starting with '/' in all cases.
95 */
96 bool cd(const QString &dirName);
97 /// Goes up.
98 bool cdUp();
99 /// Returns the number of entries in the directory.
100 uint count() const;
101 /// Returns the current directory name.
102 /**
103 The name doesn't include the path.
104 */
105 QString dirName() const;
106 /// Returns the list of the entries in the directory.
107 /**
108 \param nameFilters The list of file patterns to list, uses the same
109 syntax as QDir.
110 \param filters The entry type filters, only Files and Dirs are
111 accepted.
112 \param sort Sorting mode.
113 */
114 QList<QuaZipFileInfo> entryInfoList(const QStringList &nameFilters,
115 QDir::Filters filters = QDir::NoFilter,
116 QDir::SortFlags sort = QDir::NoSort) const;
117 /// Returns the list of the entries in the directory.
118 /**
119 \overload
120
121 The same as entryInfoList(QStringList(), filters, sort).
122 */
123 QList<QuaZipFileInfo> entryInfoList(QDir::Filters filters = QDir::NoFilter,
124 QDir::SortFlags sort = QDir::NoSort) const;
125 /// Returns the list of the entries in the directory with zip64 support.
126 /**
127 \param nameFilters The list of file patterns to list, uses the same
128 syntax as QDir.
129 \param filters The entry type filters, only Files and Dirs are
130 accepted.
131 \param sort Sorting mode.
132 */
133 QList<QuaZipFileInfo64> entryInfoList64(const QStringList &nameFilters,
134 QDir::Filters filters = QDir::NoFilter,
135 QDir::SortFlags sort = QDir::NoSort) const;
136 /// Returns the list of the entries in the directory with zip64 support.
137 /**
138 \overload
139
140 The same as entryInfoList64(QStringList(), filters, sort).
141 */
142 QList<QuaZipFileInfo64> entryInfoList64(QDir::Filters filters = QDir::NoFilter,
143 QDir::SortFlags sort = QDir::NoSort) const;
144 /// Returns the list of the entry names in the directory.
145 /**
146 The same as entryInfoList(nameFilters, filters, sort), but only
147 returns entry names.
148 */
149 QStringList entryList(const QStringList &nameFilters,
150 QDir::Filters filters = QDir::NoFilter,
151 QDir::SortFlags sort = QDir::NoSort) const;
152 /// Returns the list of the entry names in the directory.
153 /**
154 \overload
155
156 The same as entryList(QStringList(), filters, sort).
157 */
158 QStringList entryList(QDir::Filters filters = QDir::NoFilter,
159 QDir::SortFlags sort = QDir::NoSort) const;
160 /// Returns \c true if the entry with the specified name exists.
161 /**
162 The &quot;..&quot; is considered to exist if the current directory
163 is not root. The &quot;.&quot; and &quot;/&quot; are considered to
164 always exist. Paths starting with &quot;/&quot; are relative to
165 the archive root, other paths are relative to the current dir.
166 */
167 bool exists(const QString &fileName) const;
168 /// Return \c true if the directory pointed by this QuaZipDir exists.
169 bool exists() const;
170 /// Returns the full path to the specified file.
171 /**
172 Doesn't check if the file actually exists.
173 */
174 QString filePath(const QString &fileName) const;
175 /// Returns the default filter.
176 QDir::Filters filter();
177 /// Returns if the QuaZipDir points to the root of the archive.
178 /**
179 Not that the root path is the empty string, not '/'.
180 */
181 bool isRoot() const;
182 /// Return the default name filter.
183 QStringList nameFilters() const;
184 /// Returns the path to the current dir.
185 /**
186 The path never starts with '/', and the root path is an empty
187 string.
188 */
189 QString path() const;
190 /// Returns the path to the specified file relative to the current dir.
191 /**
192 * This function is mostly useless, provided only for the sake of
193 * completeness.
194 *
195 * @param fileName The path to the file, should start with &quot;/&quot;
196 * if relative to the archive root.
197 * @return Path relative to the current dir.
198 */
199 QString relativeFilePath(const QString &fileName) const;
200 /// Sets the default case sensitivity mode.
201 void setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity);
202 /// Sets the default filter.
203 void setFilter(QDir::Filters filters);
204 /// Sets the default name filter.
205 void setNameFilters(const QStringList &nameFilters);
206 /// Goes to the specified path.
207 /**
208 The difference from cd() is that this function never checks if the
209 path actually exists and doesn't use relative paths, so it's
210 possible to go to the root directory with setPath(&quot;&quot;).
211
212 Note that this function still chops the trailing and/or leading
213 '/' and treats a single '/' as the root path (path() will still
214 return an empty string).
215 */
216 void setPath(const QString &path);
217 /// Sets the default sorting mode.
218 void setSorting(QDir::SortFlags sort);
219 /// Returns the default sorting mode.
220 QDir::SortFlags sorting() const;
221};
222
223#endif // QUAZIP_QUAZIPDIR_H
Note: See TracBrowser for help on using the repository browser.