diff options
Diffstat (limited to 'backends/fs')
-rw-r--r-- | backends/fs/fs.h | 12 | ||||
-rw-r--r-- | backends/fs/posix/posix-fs.cpp | 10 |
2 files changed, 17 insertions, 5 deletions
diff --git a/backends/fs/fs.h b/backends/fs/fs.h index 47e47d3a9e..7bb63c9671 100644 --- a/backends/fs/fs.h +++ b/backends/fs/fs.h @@ -68,6 +68,16 @@ protected: typedef ScummVM::String String; public: + + /* + * Flag to tell listDir() which kind of files to list. + */ + typedef enum { + kListFilesOnly = 1, + kListDirectoriesOnly = 2, + kListAll = 3 + } ListMode; + /* * The starting point for any file system browsing. Returns a special node * representing the FS root. @@ -110,7 +120,7 @@ public: * List the content of this directory node. * If this node is not a directory, throw an exception or call error(). */ - virtual FSList *listDir() const = 0; + virtual FSList *listDir(ListMode mode = kListDirectoriesOnly) const = 0; /* * The parent node of this directory. diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 0ea131b3f9..5cdda13bc2 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -50,7 +50,7 @@ public: virtual bool isDirectory() const { return _isDirectory; } virtual String path() const { return _path; } - virtual FSList *listDir() const; + virtual FSList *listDir(ListMode mode = kListDirectoriesOnly) const; virtual FilesystemNode *parent() const; virtual FilesystemNode *clone() const { return new POSIXFilesystemNode(this); } }; @@ -85,7 +85,7 @@ POSIXFilesystemNode::POSIXFilesystemNode(const POSIXFilesystemNode *node) { _path = node->_path; } -FSList *POSIXFilesystemNode::listDir() const { +FSList *POSIXFilesystemNode::listDir(ListMode mode) const { assert(_isDirectory); DIR *dirp = opendir(_path.c_str()); struct stat st; @@ -109,8 +109,10 @@ FSList *POSIXFilesystemNode::listDir() const { continue; entry._isDirectory = S_ISDIR(st.st_mode); - // FIXME - skip any non-directories for now - if (!entry._isDirectory) continue; + // Honor the chosen mode + if ((mode == kListFilesOnly && entry._isDirectory) || + (mode == kListDirectoriesOnly && !entry._isDirectory)) + continue; if (entry._isDirectory) entry._path += "/"; |