aboutsummaryrefslogtreecommitdiff
path: root/backends/fs/dc/dc-fs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/fs/dc/dc-fs.cpp')
-rw-r--r--backends/fs/dc/dc-fs.cpp104
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__)