diff options
author | Max Horn | 2007-09-18 20:02:04 +0000 |
---|---|---|
committer | Max Horn | 2007-09-18 20:02:04 +0000 |
commit | c3d3aebe87d16d4fc3b7ac8581b99fb97241c9ac (patch) | |
tree | 17b2ba9f45743d2cf8f8e5faa6c9511e213f15f3 /backends/fs/dc/dc-fs.cpp | |
parent | 5c08cb1bcf84828cc93114fadbc89dd6f9909d06 (diff) | |
parent | 1dc13a641dd82825334e81bb3eb3b4ebd69d2552 (diff) | |
download | scummvm-rg350-c3d3aebe87d16d4fc3b7ac8581b99fb97241c9ac.tar.gz scummvm-rg350-c3d3aebe87d16d4fc3b7ac8581b99fb97241c9ac.tar.bz2 scummvm-rg350-c3d3aebe87d16d4fc3b7ac8581b99fb97241c9ac.zip |
Patch #1768757: Merge fsnode-gsoc into trunk (MAJOR change, will break compilation on some ports)
svn-id: r28944
Diffstat (limited to 'backends/fs/dc/dc-fs.cpp')
-rw-r--r-- | backends/fs/dc/dc-fs.cpp | 104 |
1 files changed, 56 insertions, 48 deletions
diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index 010ca20276..6554544c7f 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -25,40 +25,62 @@ #if defined(__DC__) #include "common/stdafx.h" - #include "backends/fs/abstract-fs.h" #include <ronin/cdfs.h> #include <stdio.h> #include <unistd.h> -/* - * Implementation of the ScummVM file system API based on ronin. +/** + * Implementation of the ScummVM file system API based on Ronin. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class RoninCDFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; - String _path; public: + /** + * Creates a RoninCDFilesystemNode with the root node as path. + */ RoninCDFilesystemNode(); + + /** + * Creates a RoninCDFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + * @param verify true if the isValid and isDirectory flags should be verified during the construction. + */ RoninCDFilesystemNode(const String &path, bool verify); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + virtual bool exists() const { return true; } //FIXME: this is just a stub + virtual String getDisplayName() const { return _displayName; } + virtual String getName() const { return _displayName; } + virtual String getPath() const { return _path; } virtual bool isDirectory() const { return _isDirectory; } - virtual String path() const { return _path; } + virtual bool isReadable() const { return true; } //FIXME: this is just a stub + virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; + virtual AbstractFilesystemNode *getParent() const; }; - +/** + * Returns the last component of a given path. + * + * Examples: + * /foo/bar.txt would return /bar.txt + * /foo/bar/ would return /bar/ + * + * @param str String containing the path. + * @return Pointer to the first char of the last component inside str. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -70,22 +92,6 @@ static const char *lastPathComponent(const Common::String &str) { return cur + 1; } - -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - // Since there is no way to _set_ the current directory, - // it will always be /... - - return getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new RoninCDFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new RoninCDFilesystemNode(path, true); -} - RoninCDFilesystemNode::RoninCDFilesystemNode() { // The root dir. _path = "/"; @@ -118,10 +124,25 @@ RoninCDFilesystemNode::RoninCDFilesystemNode(const String &p, bool verify) { } } -bool RoninCDFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +AbstractFilesystemNode *RoninCDFilesystemNode::getChild(const String &n) const { + // FIXME: Pretty lame implementation! We do no error checking to speak + // of, do not check if this is a special node, etc. assert(_isDirectory); - DIR *dirp = opendir(_path.c_str()); + + String newPath(_path); + if (_path.lastChar() != '/') + newPath += '/'; + newPath += n; + + return new RoninCDFilesystemNode(newPath, true); +} +bool RoninCDFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { + assert(_isDirectory); + + //TODO: honor the hidden flag + + DIR *dirp = opendir(_path.c_str()); struct dirent *dp; if (dirp == NULL) @@ -150,35 +171,22 @@ bool RoninCDFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const if (entry._isDirectory) entry._path += "/"; + myList.push_back(new RoninCDFilesystemNode(entry)); } closedir(dirp); + return true; } -AbstractFilesystemNode *RoninCDFilesystemNode::parent() const { +AbstractFilesystemNode *RoninCDFilesystemNode::getParent() const { if (_path == "/") return 0; const char *start = _path.c_str(); const char *end = lastPathComponent(_path); - RoninCDFilesystemNode *p = new RoninCDFilesystemNode(String(start, end - start), false); - - return p; -} - -AbstractFilesystemNode *RoninCDFilesystemNode::child(const String &n) const { - // FIXME: Pretty lame implementation! We do no error checking to speak - // of, do not check if this is a special node, etc. - assert(_isDirectory); - String newPath(_path); - if (_path.lastChar() != '/') - newPath += '/'; - newPath += n; - RoninCDFilesystemNode *p = new RoninCDFilesystemNode(newPath, true); - - return p; + return new RoninCDFilesystemNode(String(start, end - start), false); } #endif // defined(__DC__) |