Skip to content

Commit

Permalink
Add PathType argument to dirContentList()
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Nov 6, 2023
1 parent 2d574bd commit 757ed90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/io/include/qx/io/qx-common-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum ReadOption {
Q_DECLARE_FLAGS(ReadOptions, ReadOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(ReadOptions)

enum PathType {Absolute, Relative};

//-Namespace Variables-------------------------------------------------------------------------------------------------
//TODO: Ensure these work in shared build. Don't think they need to be exported since they are defined here
const QChar ENDL = '\n'; //Auto cross platform thanks to QIODevice::OpenMode Text
Expand Down Expand Up @@ -74,7 +76,7 @@ QX_IO_EXPORT IoOpReport dirContainsFiles(bool& returnBuffer, QDir directory, QDi
QX_IO_EXPORT IoOpReport dirContentInfoList(QFileInfoList& returnBuffer, QDir directory, QStringList nameFilters = QStringList(),
QDir::Filters filters = QDir::NoFilter, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
QX_IO_EXPORT IoOpReport dirContentList(QStringList& returnBuffer, QDir directory, QStringList nameFilters = QStringList(),
QDir::Filters filters = QDir::NoFilter, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
QDir::Filters filters = QDir::NoFilter, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags, PathType pathType = Absolute);

// Integrity
QX_IO_EXPORT IoOpReport calculateFileChecksum(QString& returnBuffer, QFile& file, QCryptographicHash::Algorithm hashAlgorithm);
Expand Down
20 changes: 18 additions & 2 deletions lib/io/src/qx-common-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ namespace Qx
* @qflag{ReadOptions, ReadOption}
*/

/*!
* @enum PathType
*
* This denotes the type of a path in terms of relativity.
*
* @var PathType Absolute
* An absolute path.
*
* @var PathType Relative
* A relative path.
*/

//-Namespace Variables-------------------------------------------------------------------------------------------------
/*!
* @var QChar ENDL
Expand Down Expand Up @@ -1312,6 +1324,7 @@ IoOpReport dirContentInfoList(QFileInfoList& returnBuffer, QDir directory, QStri
/*!
* Fills @a returnBuffer with a list of names for all the files and directories in @a directory, limited according
* to the name and attribute filters previously set with QDir::setNameFilters() and QDir::setFilter(), while sort flags are ignored.
* The paths will be relative to @a directory if @a pathType is @c PathType::Relative.
*
* The name filter and file attribute filter can be overridden using the @a nameFilters and @a filters arguments respectively.
*
Expand All @@ -1322,7 +1335,7 @@ IoOpReport dirContentInfoList(QFileInfoList& returnBuffer, QDir directory, QStri
* @sa QDir::entryList
*/
IoOpReport dirContentList(QStringList& returnBuffer, QDir directory, QStringList nameFilters,
QDir::Filters filters, QDirIterator::IteratorFlags flags)
QDir::Filters filters, QDirIterator::IteratorFlags flags, PathType pathType)
{
// Empty buffer
returnBuffer = QStringList();
Expand All @@ -1344,7 +1357,10 @@ IoOpReport dirContentList(QStringList& returnBuffer, QDir directory, QStringList
QDirIterator listIterator(directory.path(), nameFilters, filters, flags);

while(listIterator.hasNext())
returnBuffer.append(listIterator.next());
{
QString absPath = listIterator.next();
returnBuffer.append(pathType == PathType::Absolute ? absPath : directory.relativeFilePath(absPath));
}

return IoOpReport(IO_OP_ENUMERATE, IO_SUCCESS, directory);
}
Expand Down

0 comments on commit 757ed90

Please sign in to comment.