ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QuaZipDir Class Reference

Provides ZIP archive navigation. More...

#include <src/ckb/quazip/quazipdir.h>

+ Collaboration diagram for QuaZipDir:

Public Member Functions

 QuaZipDir (const QuaZipDir &that)
 The copy constructor. More...
 
 QuaZipDir (QuaZip *zip, const QString &dir=QString())
 Constructs a QuaZipDir instance pointing to the specified directory. More...
 
 ~QuaZipDir ()
 Destructor. More...
 
bool operator== (const QuaZipDir &that)
 The assignment operator. More...
 
bool operator!= (const QuaZipDir &that)
 operator!= More...
 
QuaZipDiroperator= (const QuaZipDir &that)
 operator== More...
 
QString operator[] (int pos) const
 Returns the name of the entry at the specified position. More...
 
QuaZip::CaseSensitivity caseSensitivity () const
 Returns the current case sensitivity mode. More...
 
bool cd (const QString &dirName)
 Changes the 'current' directory. More...
 
bool cdUp ()
 Goes up. More...
 
uint count () const
 Returns the number of entries in the directory. More...
 
QString dirName () const
 Returns the current directory name. More...
 
QList< QuaZipFileInfoentryInfoList (const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
 Returns the list of the entries in the directory. More...
 
QList< QuaZipFileInfoentryInfoList (QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
 Returns the list of the entries in the directory. More...
 
QList< QuaZipFileInfo64entryInfoList64 (const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
 Returns the list of the entries in the directory with zip64 support. More...
 
QList< QuaZipFileInfo64entryInfoList64 (QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
 Returns the list of the entries in the directory with zip64 support. More...
 
QStringList entryList (const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
 Returns the list of the entry names in the directory. More...
 
QStringList entryList (QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
 Returns the list of the entry names in the directory. More...
 
bool exists (const QString &fileName) const
 Returns true if the entry with the specified name exists. More...
 
bool exists () const
 Return true if the directory pointed by this QuaZipDir exists. More...
 
QString filePath (const QString &fileName) const
 Returns the full path to the specified file. More...
 
QDir::Filters filter ()
 Returns the default filter. More...
 
bool isRoot () const
 Returns if the QuaZipDir points to the root of the archive. More...
 
QStringList nameFilters () const
 Return the default name filter. More...
 
QString path () const
 Returns the path to the current dir. More...
 
QString relativeFilePath (const QString &fileName) const
 Returns the path to the specified file relative to the current dir. More...
 
void setCaseSensitivity (QuaZip::CaseSensitivity caseSensitivity)
 Sets the default case sensitivity mode. More...
 
void setFilter (QDir::Filters filters)
 Sets the default filter. More...
 
void setNameFilters (const QStringList &nameFilters)
 Sets the default name filter. More...
 
void setPath (const QString &path)
 Goes to the specified path. More...
 
void setSorting (QDir::SortFlags sort)
 Sets the default sorting mode. More...
 
QDir::SortFlags sorting () const
 Returns the default sorting mode. More...
 

Private Attributes

QSharedDataPointer
< QuaZipDirPrivate > 
d
 

Detailed Description

This class is modelled after QDir, and is designed to provide similar features for ZIP archives.

The only significant difference from QDir is that the root path is not '/', but an empty string since that's how the file paths are stored in the archive. However, QuaZipDir understands the paths starting with '/'. It is important in a few places:

  • In the cd() function.
  • In the constructor.
  • In the exists() function.
  • In the relativePath() function.

Note that since ZIP uses '/' on all platforms, the '\' separator is not supported.

Definition at line 54 of file quazipdir.h.

Constructor & Destructor Documentation

QuaZipDir::QuaZipDir ( const QuaZipDir that)

Definition at line 50 of file quazipdir.cpp.

Referenced by exists().

50  :
51  d(that.d)
52 {
53 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QuaZipDir::QuaZipDir ( QuaZip zip,
const QString &  dir = QString() 
)

If dir is not specified, points to the root of the archive. The same happens if the dir is "/".

Definition at line 55 of file quazipdir.cpp.

References d.

55  :
56  d(new QuaZipDirPrivate(zip, dir))
57 {
58  if (d->dir.startsWith('/'))
59  d->dir = d->dir.mid(1);
60 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
QuaZipDir::~QuaZipDir ( )

Definition at line 62 of file quazipdir.cpp.

63 {
64 }

Member Function Documentation

QuaZip::CaseSensitivity QuaZipDir::caseSensitivity ( ) const

Definition at line 82 of file quazipdir.cpp.

References d.

Referenced by setCaseSensitivity().

83 {
84  return d->caseSensitivity;
85 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

bool QuaZipDir::cd ( const QString &  dirName)

If the path starts with '/', it is interpreted as an absolute path from the root of the archive. Otherwise, it is interpreted as a path relative to the current directory as was set by the previous cd() or the constructor.

Note that the subsequent path() call will not return a path starting with '/' in all cases.

Definition at line 87 of file quazipdir.cpp.

References cd(), d, dirName(), exists(), isRoot(), and path().

Referenced by cd(), and cdUp().

88 {
89  if (directoryName == "/") {
90  d->dir = "";
91  return true;
92  }
93  QString dirName = directoryName;
94  if (dirName.endsWith('/'))
95  dirName.chop(1);
96  if (dirName.contains('/')) {
97  QuaZipDir dir(*this);
98  if (dirName.startsWith('/')) {
99 #ifdef QUAZIP_QUAZIPDIR_DEBUG
100  qDebug("QuaZipDir::cd(%s): going to /",
101  dirName.toUtf8().constData());
102 #endif
103  if (!dir.cd("/"))
104  return false;
105  }
106  QStringList path = dirName.split('/', QString::SkipEmptyParts);
107  for (QStringList::const_iterator i = path.constBegin();
108  i != path.end();
109  ++i) {
110  const QString &step = *i;
111 #ifdef QUAZIP_QUAZIPDIR_DEBUG
112  qDebug("QuaZipDir::cd(%s): going to %s",
113  dirName.toUtf8().constData(),
114  step.toUtf8().constData());
115 #endif
116  if (!dir.cd(step))
117  return false;
118  }
119  d->dir = dir.path();
120  return true;
121  } else { // no '/'
122  if (dirName == ".") {
123  return true;
124  } else if (dirName == "..") {
125  if (isRoot()) {
126  return false;
127  } else {
128  int slashPos = d->dir.lastIndexOf('/');
129  if (slashPos == -1) {
130  d->dir = "";
131  } else {
132  d->dir = d->dir.left(slashPos);
133  }
134  return true;
135  }
136  } else { // a simple subdirectory
137  if (exists(dirName)) {
138  if (isRoot())
139  d->dir = dirName;
140  else
141  d->dir += "/" + dirName;
142  return true;
143  } else {
144  return false;
145  }
146  }
147  }
148 }
bool exists() const
Return true if the directory pointed by this QuaZipDir exists.
Definition: quazipdir.cpp:495
bool isRoot() const
Returns if the QuaZipDir points to the root of the archive.
Definition: quazipdir.cpp:510
QString path() const
Returns the path to the current dir.
Definition: quazipdir.cpp:520
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
Provides ZIP archive navigation.
Definition: quazipdir.h:54
QString dirName() const
Returns the current directory name.
Definition: quazipdir.cpp:160

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool QuaZipDir::cdUp ( )

Definition at line 150 of file quazipdir.cpp.

References cd().

151 {
152  return cd("..");
153 }
bool cd(const QString &dirName)
Changes the 'current' directory.
Definition: quazipdir.cpp:87

+ Here is the call graph for this function:

uint QuaZipDir::count ( ) const

Definition at line 155 of file quazipdir.cpp.

References entryList().

156 {
157  return entryList().count();
158 }
QStringList entryList(const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
Returns the list of the entry names in the directory.
Definition: quazipdir.cpp:433

+ Here is the call graph for this function:

QString QuaZipDir::dirName ( ) const

The name doesn't include the path.

Definition at line 160 of file quazipdir.cpp.

References d.

Referenced by cd().

161 {
162  return QDir(d->dir).dirName();
163 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QList< QuaZipFileInfo > QuaZipDir::entryInfoList ( const QStringList &  nameFilters,
QDir::Filters  filters = QDir::NoFilter,
QDir::SortFlags  sort = QDir::NoSort 
) const
Parameters
nameFiltersThe list of file patterns to list, uses the same syntax as QDir.
filtersThe entry type filters, only Files and Dirs are accepted.
sortSorting mode.

Definition at line 401 of file quazipdir.cpp.

References d.

Referenced by entryInfoList().

403 {
404  QList<QuaZipFileInfo> result;
405  if (d->entryInfoList(nameFilters, filters, sort, result))
406  return result;
407  else
408  return QList<QuaZipFileInfo>();
409 }
QStringList nameFilters() const
Return the default name filter.
Definition: quazipdir.cpp:515
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QList< QuaZipFileInfo > QuaZipDir::entryInfoList ( QDir::Filters  filters = QDir::NoFilter,
QDir::SortFlags  sort = QDir::NoSort 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The same as entryInfoList(QStringList(), filters, sort).

Definition at line 411 of file quazipdir.cpp.

References entryInfoList().

413 {
414  return entryInfoList(QStringList(), filters, sort);
415 }
QList< QuaZipFileInfo > entryInfoList(const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
Returns the list of the entries in the directory.
Definition: quazipdir.cpp:401

+ Here is the call graph for this function:

QList< QuaZipFileInfo64 > QuaZipDir::entryInfoList64 ( const QStringList &  nameFilters,
QDir::Filters  filters = QDir::NoFilter,
QDir::SortFlags  sort = QDir::NoSort 
) const
Parameters
nameFiltersThe list of file patterns to list, uses the same syntax as QDir.
filtersThe entry type filters, only Files and Dirs are accepted.
sortSorting mode.

Definition at line 417 of file quazipdir.cpp.

References d.

Referenced by entryInfoList64().

419 {
420  QList<QuaZipFileInfo64> result;
421  if (d->entryInfoList(nameFilters, filters, sort, result))
422  return result;
423  else
424  return QList<QuaZipFileInfo64>();
425 }
QStringList nameFilters() const
Return the default name filter.
Definition: quazipdir.cpp:515
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QList< QuaZipFileInfo64 > QuaZipDir::entryInfoList64 ( QDir::Filters  filters = QDir::NoFilter,
QDir::SortFlags  sort = QDir::NoSort 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The same as entryInfoList64(QStringList(), filters, sort).

Definition at line 427 of file quazipdir.cpp.

References entryInfoList64().

429 {
430  return entryInfoList64(QStringList(), filters, sort);
431 }
QList< QuaZipFileInfo64 > entryInfoList64(const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
Returns the list of the entries in the directory with zip64 support.
Definition: quazipdir.cpp:417

+ Here is the call graph for this function:

QStringList QuaZipDir::entryList ( const QStringList &  nameFilters,
QDir::Filters  filters = QDir::NoFilter,
QDir::SortFlags  sort = QDir::NoSort 
) const

The same as entryInfoList(nameFilters, filters, sort), but only returns entry names.

Definition at line 433 of file quazipdir.cpp.

References d.

Referenced by count(), entryList(), exists(), and operator[]().

435 {
436  QStringList result;
437  if (d->entryInfoList(nameFilters, filters, sort, result))
438  return result;
439  else
440  return QStringList();
441 }
QStringList nameFilters() const
Return the default name filter.
Definition: quazipdir.cpp:515
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QStringList QuaZipDir::entryList ( QDir::Filters  filters = QDir::NoFilter,
QDir::SortFlags  sort = QDir::NoSort 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The same as entryList(QStringList(), filters, sort).

Definition at line 443 of file quazipdir.cpp.

References entryList().

445 {
446  return entryList(QStringList(), filters, sort);
447 }
QStringList entryList(const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
Returns the list of the entry names in the directory.
Definition: quazipdir.cpp:433

+ Here is the call graph for this function:

bool QuaZipDir::exists ( const QString &  fileName) const

The ".." is considered to exist if the current directory is not root. The "." and "/" are considered to always exist. Paths starting with "/" are relative to the archive root, other paths are relative to the current dir.

Definition at line 449 of file quazipdir.cpp.

References QuaZip::convertCaseSensitivity(), d, entryList(), filePath(), and isRoot().

450 {
451  if (filePath == "/" || filePath.isEmpty())
452  return true;
453  QString fileName = filePath;
454  if (fileName.endsWith('/'))
455  fileName.chop(1);
456  if (fileName.contains('/')) {
457  QFileInfo fileInfo(fileName);
458 #ifdef QUAZIP_QUAZIPDIR_DEBUG
459  qDebug("QuaZipDir::exists(): fileName=%s, fileInfo.fileName()=%s, "
460  "fileInfo.path()=%s", fileName.toUtf8().constData(),
461  fileInfo.fileName().toUtf8().constData(),
462  fileInfo.path().toUtf8().constData());
463 #endif
464  QuaZipDir dir(*this);
465  return dir.cd(fileInfo.path()) && dir.exists(fileInfo.fileName());
466  } else {
467  if (fileName == "..") {
468  return !isRoot();
469  } else if (fileName == ".") {
470  return true;
471  } else {
472  QStringList entries = entryList(QDir::AllEntries, QDir::NoSort);
473 #ifdef QUAZIP_QUAZIPDIR_DEBUG
474  qDebug("QuaZipDir::exists(): looking for %s",
475  fileName.toUtf8().constData());
476  for (QStringList::const_iterator i = entries.constBegin();
477  i != entries.constEnd();
478  ++i) {
479  qDebug("QuaZipDir::exists(): entry: %s",
480  i->toUtf8().constData());
481  }
482 #endif
483  Qt::CaseSensitivity cs = QuaZip::convertCaseSensitivity(
484  d->caseSensitivity);
485  if (filePath.endsWith('/')) {
486  return entries.contains(filePath, cs);
487  } else {
488  return entries.contains(fileName, cs)
489  || entries.contains(fileName + "/", cs);
490  }
491  }
492  }
493 }
static Qt::CaseSensitivity convertCaseSensitivity(CaseSensitivity cs)
Returns the actual case sensitivity for the specified QuaZIP one.
Definition: quazip.cpp:747
bool isRoot() const
Returns if the QuaZipDir points to the root of the archive.
Definition: quazipdir.cpp:510
QStringList entryList(const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
Returns the list of the entry names in the directory.
Definition: quazipdir.cpp:433
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
Provides ZIP archive navigation.
Definition: quazipdir.h:54
QString filePath(const QString &fileName) const
Returns the full path to the specified file.
Definition: quazipdir.cpp:500

+ Here is the call graph for this function:

bool QuaZipDir::exists ( ) const

Definition at line 495 of file quazipdir.cpp.

References d, and QuaZipDir().

Referenced by cd().

496 {
497  return QuaZipDir(d->zip).exists(d->dir);
498 }
QuaZipDir(const QuaZipDir &that)
The copy constructor.
Definition: quazipdir.cpp:50
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString QuaZipDir::filePath ( const QString &  fileName) const

Doesn't check if the file actually exists.

Definition at line 500 of file quazipdir.cpp.

References d.

Referenced by exists().

501 {
502  return QDir(d->dir).filePath(fileName);
503 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QDir::Filters QuaZipDir::filter ( )

Definition at line 505 of file quazipdir.cpp.

References d.

506 {
507  return d->filter;
508 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
bool QuaZipDir::isRoot ( ) const

Not that the root path is the empty string, not '/'.

Definition at line 510 of file quazipdir.cpp.

References d.

Referenced by cd(), and exists().

511 {
512  return d->simplePath().isEmpty();
513 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QStringList QuaZipDir::nameFilters ( ) const

Definition at line 515 of file quazipdir.cpp.

References d.

Referenced by setNameFilters().

516 {
517  return d->nameFilters;
518 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

bool QuaZipDir::operator!= ( const QuaZipDir that)
inline
Returns
true if either this and that use different QuaZip instances or if they point to different directories.

Definition at line 75 of file quazipdir.h.

75 {return !operator==(that);}
bool operator==(const QuaZipDir &that)
The assignment operator.
Definition: quazipdir.cpp:66
QuaZipDir & QuaZipDir::operator= ( const QuaZipDir that)
Returns
true if both this and that use the same QuaZip instance and point to the same directory.

Definition at line 71 of file quazipdir.cpp.

References d.

72 {
73  this->d = that.d;
74  return *this;
75 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
bool QuaZipDir::operator== ( const QuaZipDir that)

Definition at line 66 of file quazipdir.cpp.

References d.

67 {
68  return d->zip == that.d->zip && d->dir == that.d->dir;
69 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
QString QuaZipDir::operator[] ( int  pos) const

Definition at line 77 of file quazipdir.cpp.

References entryList().

78 {
79  return entryList().at(pos);
80 }
QStringList entryList(const QStringList &nameFilters, QDir::Filters filters=QDir::NoFilter, QDir::SortFlags sort=QDir::NoSort) const
Returns the list of the entry names in the directory.
Definition: quazipdir.cpp:433

+ Here is the call graph for this function:

QString QuaZipDir::path ( ) const

The path never starts with '/', and the root path is an empty string.

Definition at line 520 of file quazipdir.cpp.

References d.

Referenced by cd(), and setPath().

521 {
522  return d->dir;
523 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the caller graph for this function:

QString QuaZipDir::relativeFilePath ( const QString &  fileName) const

This function is mostly useless, provided only for the sake of completeness.

Parameters
fileNameThe path to the file, should start with "/" if relative to the archive root.
Returns
Path relative to the current dir.

Definition at line 525 of file quazipdir.cpp.

References d.

526 {
527  return QDir("/" + d->dir).relativeFilePath(fileName);
528 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
void QuaZipDir::setCaseSensitivity ( QuaZip::CaseSensitivity  caseSensitivity)

Definition at line 530 of file quazipdir.cpp.

References caseSensitivity(), and d.

531 {
532  d->caseSensitivity = caseSensitivity;
533 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
QuaZip::CaseSensitivity caseSensitivity() const
Returns the current case sensitivity mode.
Definition: quazipdir.cpp:82

+ Here is the call graph for this function:

void QuaZipDir::setFilter ( QDir::Filters  filters)

Definition at line 535 of file quazipdir.cpp.

References d.

536 {
537  d->filter = filters;
538 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
void QuaZipDir::setNameFilters ( const QStringList &  nameFilters)

Definition at line 540 of file quazipdir.cpp.

References d, and nameFilters().

541 {
542  d->nameFilters = nameFilters;
543 }
QStringList nameFilters() const
Return the default name filter.
Definition: quazipdir.cpp:515
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the call graph for this function:

void QuaZipDir::setPath ( const QString &  path)

The difference from cd() is that this function never checks if the path actually exists and doesn't use relative paths, so it's possible to go to the root directory with setPath("").

Note that this function still chops the trailing and/or leading '/' and treats a single '/' as the root path (path() will still return an empty string).

Definition at line 545 of file quazipdir.cpp.

References d, and path().

546 {
547  QString newDir = path;
548  if (newDir == "/") {
549  d->dir = "";
550  } else {
551  if (newDir.endsWith('/'))
552  newDir.chop(1);
553  if (newDir.startsWith('/'))
554  newDir = newDir.mid(1);
555  d->dir = newDir;
556  }
557 }
QString path() const
Returns the path to the current dir.
Definition: quazipdir.cpp:520
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

+ Here is the call graph for this function:

void QuaZipDir::setSorting ( QDir::SortFlags  sort)

Definition at line 559 of file quazipdir.cpp.

References d.

560 {
561  d->sorting = sort;
562 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56
QDir::SortFlags QuaZipDir::sorting ( ) const

Definition at line 564 of file quazipdir.cpp.

References d.

565 {
566  return d->sorting;
567 }
QSharedDataPointer< QuaZipDirPrivate > d
Definition: quazipdir.h:56

Field Documentation


The documentation for this class was generated from the following files: