quazipdir.h 8.1 KB

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