diff options
Diffstat (limited to 'common/fs.h')
-rw-r--r-- | common/fs.h | 120 |
1 files changed, 85 insertions, 35 deletions
diff --git a/common/fs.h b/common/fs.h index 4c275b5b2a..6a2f049be1 100644 --- a/common/fs.h +++ b/common/fs.h @@ -33,7 +33,6 @@ class FilesystemNode; class AbstractFilesystemNode; - /** * List of multiple file system nodes. E.g. the contents of a given directory. * This is subclass instead of just a typedef so that we can use forward @@ -41,9 +40,8 @@ class AbstractFilesystemNode; */ class FSList : public Common::Array<FilesystemNode> {}; - /** - * FilesystemNode provides an abstraction for file pathes, allowing for portable + * FilesystemNode provides an abstraction for file paths, allowing for portable * file system browsing. To this ends, multiple or single roots have to be supported * (compare Unix with a single root, Windows with multiple roots C:, D:, ...). * @@ -67,9 +65,8 @@ class FSList : public Common::Array<FilesystemNode> {}; */ class FilesystemNode { private: - AbstractFilesystemNode *_realNode; int *_refCount; - + AbstractFilesystemNode *_realNode; FilesystemNode(AbstractFilesystemNode *realNode); public: @@ -113,51 +110,42 @@ public: /** * Copy operator. */ - FilesystemNode &operator =(const FilesystemNode &node); - + FilesystemNode &operator= (const FilesystemNode &node); + /** - * Checks if the FilesystemNode is valid for any usage + * Compare the name of this node to the name of another. Directories + * go before normal files. */ - bool isValid() const; + bool operator< (const FilesystemNode& node) const; - /** - * Get the parent node of this node. If this node has no parent node, - * then it returns a duplicate of this node. + /* + * Indicates whether the object refered by this path exists in the filesystem or not. */ - FilesystemNode getParent() const; + virtual bool exists() const; /** * Fetch a child node of this node, with the given name. Only valid for - * directory nodes (an assertion is triggered otherwise). If no no child - * node with the given name exists, an invalid node is returned. + * directory nodes (an assertion is triggered otherwise). + * If no child node with the given name exists, an invalid node is returned. */ FilesystemNode getChild(const Common::String &name) const; - + /** * Return a list of child nodes of this directory node. If called on a node * that does not represent a directory, false is returned. + * * @return true if succesful, false otherwise (e.g. when the directory does not exist). - * @todo Rename this to listChildren or getChildren. - */ - virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; - - /** - * Is this node pointing to a directory? - * @todo Currently we assume that a valid node that is not a directory - * automatically is a file (ignoring things like symlinks). That might - * actually be OK... but we could still add an isFile method. Or even replace - * isValid and isDirectory by a getType() method that can return values like - * kDirNodeType, kFileNodeType, kInvalidNodeType. */ - virtual bool isDirectory() const; + virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = false) const; /** * Return a human readable string for this node, usable for display (e.g. * in the GUI code). Do *not* rely on it being usable for anything else, * like constructing paths! + * * @return the display name */ - virtual Common::String displayName() const; + virtual Common::String getDisplayName() const; /** * Return a string representation of the name of the file. This is can be @@ -167,7 +155,7 @@ public: * * @return the file name */ - virtual Common::String name() const; + virtual Common::String getName() const; /** * Return a string representation of the file which can be passed to fopen(), @@ -180,18 +168,80 @@ public: * * @return the 'path' represented by this filesystem node */ - virtual Common::String path() const; + virtual Common::String getPath() const; + + /** + * Get the parent node of this node. If this node has no parent node, + * then it returns a duplicate of this node. + */ + FilesystemNode getParent() const; /** - * Compare the name of this node to the name of another. Directories - * go before normal files. + * Indicates whether this path refers to a directory or not. + * + * @todo Currently we assume that a valid node that is not a directory + * automatically is a file (ignoring things like symlinks). That might + * actually be OK... but we could still add an isFile method. Or even replace + * isValid and isDirectory by a getType() method that can return values like + * kDirNodeType, kFileNodeType, kInvalidNodeType. */ - bool operator< (const FilesystemNode& node) const; + virtual bool isDirectory() const; + + /** + * Indicates whether this path can be read from or not. + */ + virtual bool isReadable() const; + + /** + * Indicates whether this path can be written to or not. + */ + virtual bool isWritable() const; + + /** + * Searches recursively for a filename inside the given directories. + * + * @param results List to put the matches in. + * @param fslist List of directories to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. Default: false + * @param exhaustive Whether to continue searching after one match has been found. Default: false + * + * @return true if matches could be found, false otherwise. + */ + virtual bool lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const; + + /** + * Searches recursively for a filename inside the given directory. + * + * @param results List to put the matches in. + * @param FilesystemNode Directory to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. Default: false + * @param exhaustive Whether to continue searching after one match has been found. Default: false + * + * @return true if matches could be found, false otherwise. + */ + virtual bool lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; protected: + /** + * Decreases the reference count to the FilesystemNode, and if necessary, + * deletes the corresponding underlying references. + */ void decRefCount(); + + /** + * Searches recursively for a filename inside the given directory. + * + * @param results List to put the matches in. + * @param FilesystemNode Directory to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. + */ + void lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; }; //} // End of namespace Common -#endif +#endif //COMMON_FS_H |