aboutsummaryrefslogtreecommitdiff
path: root/backends/fs/gp32
diff options
context:
space:
mode:
authorDavid Corrales2007-05-03 02:39:33 +0000
committerDavid Corrales2007-05-03 02:39:33 +0000
commitc459f054b46b8791ce206c2ee13d455a9c10fe4d (patch)
treeb36dc6034bfb9659e57e28de8a509a7b1de4554d /backends/fs/gp32
parent8f5abc1924d5d7bdbc9684b870394f93ad80d2ff (diff)
downloadscummvm-rg350-c459f054b46b8791ce206c2ee13d455a9c10fe4d.tar.gz
scummvm-rg350-c459f054b46b8791ce206c2ee13d455a9c10fe4d.tar.bz2
scummvm-rg350-c459f054b46b8791ce206c2ee13d455a9c10fe4d.zip
Use abstract factories to initialize FilesystemNode objects.
svn-id: r26739
Diffstat (limited to 'backends/fs/gp32')
-rw-r--r--backends/fs/gp32/GP32FilesystemFactory.cpp23
-rw-r--r--backends/fs/gp32/GP32FilesystemFactory.h38
-rw-r--r--backends/fs/gp32/gp32-fs.cpp123
3 files changed, 131 insertions, 53 deletions
diff --git a/backends/fs/gp32/GP32FilesystemFactory.cpp b/backends/fs/gp32/GP32FilesystemFactory.cpp
new file mode 100644
index 0000000000..fa98079a8d
--- /dev/null
+++ b/backends/fs/gp32/GP32FilesystemFactory.cpp
@@ -0,0 +1,23 @@
+#include "backends/fs/gp32/GP32FilesystemFactory.h"
+#include "backends/fs/gp32/gp32-fs.cpp"
+
+GP32FilesystemFactory *GP32FilesystemFactory::_instance = 0;
+
+GP32FilesystemFactory *GP32FilesystemFactory::instance(){
+ if(_instance == 0){
+ _instance = new GP32FilesystemFactory();
+ }
+ return _instance;
+}
+
+AbstractFilesystemNode *GP32FilesystemFactory::makeRootFileNode() const {
+ return new GP32FilesystemNode();
+}
+
+AbstractFilesystemNode *GP32FilesystemFactory::makeCurrentDirectoryFileNode() const {
+ return new GP32FilesystemNode();
+}
+
+AbstractFilesystemNode *GP32FilesystemFactory::makeFileNodePath(const String &path) const {
+ return new GP32FilesystemNode(path);
+}
diff --git a/backends/fs/gp32/GP32FilesystemFactory.h b/backends/fs/gp32/GP32FilesystemFactory.h
new file mode 100644
index 0000000000..d31642acd2
--- /dev/null
+++ b/backends/fs/gp32/GP32FilesystemFactory.h
@@ -0,0 +1,38 @@
+#ifndef GP32FILESYSTEMFACTORY_H_
+#define GP32FILESYSTEMFACTORY_H_
+
+#include "backends/fs/AbstractFilesystemFactory.h"
+
+/**
+ * Creates GP32FilesystemNode objects.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
+ */
+class GP32FilesystemFactory : public AbstractFilesystemFactory {
+public:
+ typedef Common::String String;
+
+ /**
+ * Creates an instance of GP32FilesystemFactory using the Singleton pattern.
+ *
+ * @return A unique instance of GP32FilesytemFactory.
+ */
+ static GP32FilesystemFactory *instance();
+
+ /**
+ * Destructor.
+ */
+ virtual ~GP32FilesystemFactory() {};
+
+ virtual AbstractFilesystemNode *makeRootFileNode() const;
+ virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
+ virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
+
+protected:
+ GP32FilesystemFactory() {};
+
+private:
+ static GP32FilesystemFactory *_instance;
+};
+
+#endif /*GP32FILESYSTEMFACTORY_H_*/
diff --git a/backends/fs/gp32/gp32-fs.cpp b/backends/fs/gp32/gp32-fs.cpp
index c80e5a4f8f..4fe6cfabde 100644
--- a/backends/fs/gp32/gp32-fs.cpp
+++ b/backends/fs/gp32/gp32-fs.cpp
@@ -24,38 +24,78 @@
*/
#include "stdafx.h"
-
#include "backends/fs/abstract-fs.h"
+#define MAX_PATH_SIZE 256
+
+/**
+ * Implementation of the ScummVM file system API.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
+ */
class GP32FilesystemNode : public AbstractFilesystemNode {
protected:
String _displayName;
+ String _path;
bool _isDirectory;
bool _isRoot;
- String _path;
public:
+ /**
+ * Creates a GP32FilesystemNode with the root node as path.
+ */
GP32FilesystemNode();
+
+ /**
+ * Creates a GP32FilesystemNode for a given path.
+ *
+ * @param path String with the path the new node should point to.
+ */
GP32FilesystemNode(const String &path);
- virtual String displayName() const { return _displayName; }
- virtual String name() const { return _displayName; }
+ virtual String getDisplayName() const { return _displayName; }
+ virtual String getName() const { return _displayName; }
+ virtual String getPath() const { return _path; }
+ virtual bool isDirectory() const { return _isDirectory; }
// FIXME: isValid should return false if this Node can't be used!
- // client code can rely on the return value.
+ // so client code can rely on the return value.
virtual bool isValid() const { return true; }
- virtual bool isDirectory() const { return _isDirectory; }
- virtual String path() const { return _path; }
- 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) const;
+ virtual AbstractFilesystemNode *getParent() const;
};
-#define MAX_PATH_SIZE 256
-
const char gpRootPath[] = "gp:\\";
//char gpCurrentPath[MAX_PATH_SIZE] = "gp:\\"; // must end with '\'
+/**
+ * Returns the last component of a given path.
+ *
+ * Examples:
+ * gp:\foo\bar.txt would return "\bar.txt"
+ * gp:\foo\bar\ would return "\bar\"
+ *
+ * @param str Path to obtain the last component from.
+ * @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;
+
+ while (cur >= start && *cur != '\\') {
+ --cur;
+ }
+
+ return cur + 1;
+}
+
+/**
+ * FIXME: document this function.
+ *
+ * @param path
+ * @param convPath
+ */
int gpMakePath(const char *path, char *convPath) {
// copy root or current directory
const char *p;
@@ -106,18 +146,6 @@ int gpMakePath(const char *path, char *convPath) {
return 0;
}
-AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() {
- return AbstractFilesystemNode::getRoot();
-}
-
-AbstractFilesystemNode *AbstractFilesystemNode::getRoot() {
- return new GP32FilesystemNode();
-}
-
-AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) {
- return new GP32FilesystemNode(path);
-}
-
GP32FilesystemNode::GP32FilesystemNode() {
_isDirectory = true;
_isRoot = true;
@@ -132,8 +160,8 @@ GP32FilesystemNode::GP32FilesystemNode(const String &path) {
gpMakePath(path.c_str(), convPath);
_path = convPath;
-
pos = convPath;
+
while (*pos)
if (*pos++ == '\\')
dsplName = pos;
@@ -150,14 +178,25 @@ GP32FilesystemNode::GP32FilesystemNode(const String &path) {
_isDirectory = true;
}
-bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
+AbstractFilesystemNode *GP32FilesystemNode::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);
+
+ String newPath(_path);
+ if (_path.lastChar() != '\\')
+ newPath += '\\';
+ newPath += n;
+
+ return new GP32FilesystemNode(newPath);
+}
+
+bool GP32FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const {
assert(_isDirectory);
GPDIRENTRY dirEntry;
GPFILEATTR attr;
-
GP32FilesystemNode entry;
-
uint32 read;
if (mode == FilesystemNode::kListAll)
@@ -168,9 +207,11 @@ bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
int startIdx = 0; // current file
String listDir(_path);
//listDir += "/";
+
while (GpDirEnumList(listDir.c_str(), startIdx++, 1, &dirEntry, &read) == SM_OK) {
if (dirEntry.name[0] == '.')
continue;
+
entry._displayName = dirEntry.name;
entry._path = _path;
entry._path += dirEntry.name;
@@ -194,18 +235,7 @@ bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
return true;
}
-static const char *lastPathComponent(const Common::String &str) {
- const char *start = str.c_str();
- const char *cur = start + str.size() - 2;
-
- while (cur >= start && *cur != '\\') {
- --cur;
- }
-
- return cur + 1;
-}
-
-AbstractFilesystemNode *GP32FilesystemNode::parent() const {
+AbstractFilesystemNode *GP32FilesystemNode::getParent() const {
if(_isRoot)
return 0;
@@ -218,16 +248,3 @@ AbstractFilesystemNode *GP32FilesystemNode::parent() const {
return p;
}
-
-AbstractFilesystemNode *GP32FilesystemNode::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;
- GP32FilesystemNode *p = new GP32FilesystemNode(newPath);
-
- return p;
-}