File indexing completed on 2025-01-26 04:24:54
0001 #ifndef QUAZIP_QUAZIPDIR_H 0002 #define QUAZIP_QUAZIPDIR_H 0003 0004 /* 0005 Copyright (C) 2005-2014 Sergey A. Tachenov 0006 0007 This file is part of QuaZIP. 0008 0009 QuaZIP is free software: you can redistribute it and/or modify 0010 it under the terms of the GNU Lesser General Public License as published by 0011 the Free Software Foundation, either version 2.1 of the License, or 0012 (at your option) any later version. 0013 0014 QuaZIP is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public License 0020 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. 0021 0022 See COPYING file for the full LGPL text. 0023 0024 Original ZIP package is copyrighted by Gilles Vollant and contributors, 0025 see quazip/(un)zip.h files for details. Basically it's the zlib license. 0026 */ 0027 0028 class QuaZipDirPrivate; 0029 0030 #include "quazip.h" 0031 #include "quazipfileinfo.h" 0032 #include <QDir> 0033 #include <QList> 0034 #include <QSharedDataPointer> 0035 0036 /// Provides ZIP archive navigation. 0037 /** 0038 * This class is modelled after QDir, and is designed to provide similar 0039 * features for ZIP archives. 0040 * 0041 * The only significant difference from QDir is that the root path is not 0042 * '/', but an empty string since that's how the file paths are stored in 0043 * the archive. However, QuaZipDir understands the paths starting with 0044 * '/'. It is important in a few places: 0045 * 0046 * - In the cd() function. 0047 * - In the constructor. 0048 * - In the exists() function. 0049 * - In the relativePath() function. 0050 * 0051 * Note that since ZIP uses '/' on all platforms, the '\' separator is 0052 * not supported. 0053 */ 0054 class QUAZIP_EXPORT QuaZipDir { 0055 private: 0056 QSharedDataPointer<QuaZipDirPrivate> d; 0057 public: 0058 /// The copy constructor. 0059 QuaZipDir(const QuaZipDir &that); 0060 /// Constructs a QuaZipDir instance pointing to the specified directory. 0061 /** 0062 If \a dir is not specified, points to the root of the archive. 0063 The same happens if the \a dir is "/". 0064 */ 0065 QuaZipDir(QuaZip *zip, const QString &dir = QString()); 0066 /// Destructor. 0067 ~QuaZipDir(); 0068 /// The assignment operator. 0069 bool operator==(const QuaZipDir &that); 0070 /// operator!= 0071 /** 0072 \return \c true if either this and \a that use different QuaZip 0073 instances or if they point to different directories. 0074 */ 0075 inline bool operator!=(const QuaZipDir &that) {return !operator==(that);} 0076 /// operator== 0077 /** 0078 \return \c true if both this and \a that use the same QuaZip 0079 instance and point to the same directory. 0080 */ 0081 QuaZipDir& operator=(const QuaZipDir &that); 0082 /// Returns the name of the entry at the specified position. 0083 QString operator[](int pos) const; 0084 /// Returns the current case sensitivity mode. 0085 QuaZip::CaseSensitivity caseSensitivity() const; 0086 /// Changes the 'current' directory. 0087 /** 0088 * If the path starts with '/', it is interpreted as an absolute 0089 * path from the root of the archive. Otherwise, it is interpreted 0090 * as a path relative to the current directory as was set by the 0091 * previous cd() or the constructor. 0092 * 0093 * Note that the subsequent path() call will not return a path 0094 * starting with '/' in all cases. 0095 */ 0096 bool cd(const QString &dirName); 0097 /// Goes up. 0098 bool cdUp(); 0099 /// Returns the number of entries in the directory. 0100 uint count() const; 0101 /// Returns the current directory name. 0102 /** 0103 The name doesn't include the path. 0104 */ 0105 QString dirName() const; 0106 /// Returns the list of the entries in the directory. 0107 /** 0108 \param nameFilters The list of file patterns to list, uses the same 0109 syntax as QDir. 0110 \param filters The entry type filters, only Files and Dirs are 0111 accepted. 0112 \param sort Sorting mode. 0113 */ 0114 QList<QuaZipFileInfo> entryInfoList(const QStringList &nameFilters, 0115 QDir::Filters filters = QDir::NoFilter, 0116 QDir::SortFlags sort = QDir::NoSort) const; 0117 /// Returns the list of the entries in the directory. 0118 /** 0119 \overload 0120 0121 The same as entryInfoList(QStringList(), filters, sort). 0122 */ 0123 QList<QuaZipFileInfo> entryInfoList(QDir::Filters filters = QDir::NoFilter, 0124 QDir::SortFlags sort = QDir::NoSort) const; 0125 /// Returns the list of the entries in the directory with zip64 support. 0126 /** 0127 \param nameFilters The list of file patterns to list, uses the same 0128 syntax as QDir. 0129 \param filters The entry type filters, only Files and Dirs are 0130 accepted. 0131 \param sort Sorting mode. 0132 */ 0133 QList<QuaZipFileInfo64> entryInfoList64(const QStringList &nameFilters, 0134 QDir::Filters filters = QDir::NoFilter, 0135 QDir::SortFlags sort = QDir::NoSort) const; 0136 /// Returns the list of the entries in the directory with zip64 support. 0137 /** 0138 \overload 0139 0140 The same as entryInfoList64(QStringList(), filters, sort). 0141 */ 0142 QList<QuaZipFileInfo64> entryInfoList64(QDir::Filters filters = QDir::NoFilter, 0143 QDir::SortFlags sort = QDir::NoSort) const; 0144 /// Returns the list of the entry names in the directory. 0145 /** 0146 The same as entryInfoList(nameFilters, filters, sort), but only 0147 returns entry names. 0148 */ 0149 QStringList entryList(const QStringList &nameFilters, 0150 QDir::Filters filters = QDir::NoFilter, 0151 QDir::SortFlags sort = QDir::NoSort) const; 0152 /// Returns the list of the entry names in the directory. 0153 /** 0154 \overload 0155 0156 The same as entryList(QStringList(), filters, sort). 0157 */ 0158 QStringList entryList(QDir::Filters filters = QDir::NoFilter, 0159 QDir::SortFlags sort = QDir::NoSort) const; 0160 /// Returns \c true if the entry with the specified name exists. 0161 /** 0162 The ".." is considered to exist if the current directory 0163 is not root. The "." and "/" are considered to 0164 always exist. Paths starting with "/" are relative to 0165 the archive root, other paths are relative to the current dir. 0166 */ 0167 bool exists(const QString &fileName) const; 0168 /// Return \c true if the directory pointed by this QuaZipDir exists. 0169 bool exists() const; 0170 /// Returns the full path to the specified file. 0171 /** 0172 Doesn't check if the file actually exists. 0173 */ 0174 QString filePath(const QString &fileName) const; 0175 /// Returns the default filter. 0176 QDir::Filters filter(); 0177 /// Returns if the QuaZipDir points to the root of the archive. 0178 /** 0179 Not that the root path is the empty string, not '/'. 0180 */ 0181 bool isRoot() const; 0182 /// Return the default name filter. 0183 QStringList nameFilters() const; 0184 /// Returns the path to the current dir. 0185 /** 0186 The path never starts with '/', and the root path is an empty 0187 string. 0188 */ 0189 QString path() const; 0190 /// Returns the path to the specified file relative to the current dir. 0191 /** 0192 * This function is mostly useless, provided only for the sake of 0193 * completeness. 0194 * 0195 * @param fileName The path to the file, should start with "/" 0196 * if relative to the archive root. 0197 * @return Path relative to the current dir. 0198 */ 0199 QString relativeFilePath(const QString &fileName) const; 0200 /// Sets the default case sensitivity mode. 0201 void setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity); 0202 /// Sets the default filter. 0203 void setFilter(QDir::Filters filters); 0204 /// Sets the default name filter. 0205 void setNameFilters(const QStringList &nameFilters); 0206 /// Goes to the specified path. 0207 /** 0208 The difference from cd() is that this function never checks if the 0209 path actually exists and doesn't use relative paths, so it's 0210 possible to go to the root directory with setPath(""). 0211 0212 Note that this function still chops the trailing and/or leading 0213 '/' and treats a single '/' as the root path (path() will still 0214 return an empty string). 0215 */ 0216 void setPath(const QString &path); 0217 /// Sets the default sorting mode. 0218 void setSorting(QDir::SortFlags sort); 0219 /// Returns the default sorting mode. 0220 QDir::SortFlags sorting() const; 0221 }; 0222 0223 #endif // QUAZIP_QUAZIPDIR_H