aboutsummaryrefslogtreecommitdiff
path: root/backends/fs/morphos
diff options
context:
space:
mode:
authorMax Horn2007-09-18 20:02:04 +0000
committerMax Horn2007-09-18 20:02:04 +0000
commitc3d3aebe87d16d4fc3b7ac8581b99fb97241c9ac (patch)
tree17b2ba9f45743d2cf8f8e5faa6c9511e213f15f3 /backends/fs/morphos
parent5c08cb1bcf84828cc93114fadbc89dd6f9909d06 (diff)
parent1dc13a641dd82825334e81bb3eb3b4ebd69d2552 (diff)
downloadscummvm-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/morphos')
-rw-r--r--backends/fs/morphos/abox-fs-factory.cpp40
-rw-r--r--backends/fs/morphos/abox-fs-factory.h51
-rw-r--r--backends/fs/morphos/abox-fs.cpp268
3 files changed, 232 insertions, 127 deletions
diff --git a/backends/fs/morphos/abox-fs-factory.cpp b/backends/fs/morphos/abox-fs-factory.cpp
new file mode 100644
index 0000000000..e182513002
--- /dev/null
+++ b/backends/fs/morphos/abox-fs-factory.cpp
@@ -0,0 +1,40 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "backends/fs/morphos/abox-fs-factory.h"
+#include "backends/fs/morphos/abox-fs.cpp"
+
+DECLARE_SINGLETON(ABoxFilesystemFactory);
+
+AbstractFilesystemNode *ABoxFilesystemFactory::makeRootFileNode() const {
+ return new ABoxFilesystemNode();
+}
+
+AbstractFilesystemNode *ABoxFilesystemFactory::makeCurrentDirectoryFileNode() const {
+ return new ABoxFilesystemNode();
+}
+
+AbstractFilesystemNode *ABoxFilesystemFactory::makeFileNodePath(const String &path) const {
+ return new ABoxFilesystemNode(path);
+}
diff --git a/backends/fs/morphos/abox-fs-factory.h b/backends/fs/morphos/abox-fs-factory.h
new file mode 100644
index 0000000000..19ef2b097f
--- /dev/null
+++ b/backends/fs/morphos/abox-fs-factory.h
@@ -0,0 +1,51 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef ABOX_FILESYSTEM_FACTORY_H
+#define ABOX_FILESYSTEM_FACTORY_H
+
+#include "common/singleton.h"
+#include "backends/fs/abstract-fs-factory.h"
+
+/**
+ * Creates ABoxFilesystemNode objects.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
+ */
+class ABoxFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<ABoxFilesystemFactory> {
+public:
+ typedef Common::String String;
+
+ virtual AbstractFilesystemNode *makeRootFileNode() const;
+ virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
+ virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
+
+protected:
+ ABoxFilesystemFactory() {};
+
+private:
+ friend class Common::Singleton<SingletonBaseType>;
+};
+
+#endif /*ABOX_FILESYSTEM_FACTORY_H*/
diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp
index 8206e83030..ef50a11e4e 100644
--- a/backends/fs/morphos/abox-fs.cpp
+++ b/backends/fs/morphos/abox-fs.cpp
@@ -35,52 +35,66 @@
#include "base/engine.h"
#include "backends/fs/abstract-fs.h"
-/*
+/**
* Implementation of the ScummVM file system API based on the MorphOS A-Box API.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
*/
-
class ABoxFilesystemNode : public AbstractFilesystemNode {
- protected:
- BPTR _lock;
- String _displayName;
- bool _isDirectory;
- bool _isValid;
- String _path;
-
- public:
- ABoxFilesystemNode();
- ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL);
- ABoxFilesystemNode(const String &p);
- ABoxFilesystemNode(const ABoxFilesystemNode &node);
-
- ~ABoxFilesystemNode();
-
- virtual String displayName() const { return _displayName; }
- virtual String name() const { return _displayName; };
- virtual bool isValid() const { return _isValid; }
- virtual bool isDirectory() const { return _isDirectory; }
- virtual String path() const { return _path; }
-
- virtual bool listDir(AbstractFSList &list, ListMode mode) const;
- static AbstractFSList listRoot();
- virtual AbstractFilesystemNode *parent() const;
- virtual AbstractFilesystemNode *child(const String &name) const;
+protected:
+ BPTR _lock;
+ String _displayName;
+ String _path;
+ bool _isDirectory;
+ bool _isValid;
+
+public:
+ /**
+ * Creates a ABoxFilesystemNode with the root node as path.
+ */
+ ABoxFilesystemNode();
+
+ /**
+ * Creates a ABoxFilesystemNode for a given path.
+ *
+ * @param path String with the path the new node should point to.
+ */
+ ABoxFilesystemNode(const String &p);
+
+ /**
+ * FIXME: document this constructor.
+ */
+ ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL);
+
+ /**
+ * Copy constructor.
+ */
+ ABoxFilesystemNode(const ABoxFilesystemNode &node);
+
+ /**
+ * Destructor.
+ */
+ ~ABoxFilesystemNode();
+
+ 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 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 AbstractFilesystemNode *getChild(const String &name) const;
+ virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
+ virtual AbstractFilesystemNode *getParent() const;
+
+ /**
+ * Return the list of child nodes for the root node.
+ */
+ static AbstractFSList getRootChildren();
};
-
-AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() {
- return AbstractFilesystemNode::getRoot();
-}
-
-AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) {
- return new ABoxFilesystemNode(path);
-}
-
-AbstractFilesystemNode *AbstractFilesystemNode::getRoot()
-{
- return new ABoxFilesystemNode();
-}
-
ABoxFilesystemNode::ABoxFilesystemNode()
{
_displayName = "Mounted Volumes";
@@ -90,57 +104,6 @@ ABoxFilesystemNode::ABoxFilesystemNode()
_lock = NULL;
}
-ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name)
-{
- int bufsize = 256;
-
- _lock = NULL;
- for (;;)
- {
- char name[bufsize];
- if (NameFromLock(lock, name, bufsize) != DOSFALSE)
- {
- _path = name;
- _displayName = display_name ? display_name : FilePart(name);
- break;
- }
- if (IoErr() != ERROR_LINE_TOO_LONG)
- {
- _isValid = false;
- debug(6, "Error while retrieving path name: %ld", IoErr());
- return;
- }
- bufsize *= 2;
- }
-
- _isDirectory = false;
- _isValid = false;
-
- FileInfoBlock *fib = (FileInfoBlock*) AllocDosObject(DOS_FIB, NULL);
- if (fib == NULL)
- {
- debug(6, "Failed to allocate memory for FileInfoBlock");
- return;
- }
-
- if (Examine(lock, fib) != DOSFALSE)
- {
- _isDirectory = fib->fib_EntryType > 0;
- if (_isDirectory)
- {
- if (fib->fib_EntryType != ST_ROOT)
- _path += "/";
- _lock = DupLock(lock);
- _isValid = (_lock != NULL);
- }
- else
- {
- _isValid = true;
- }
- }
- FreeDosObject(DOS_FIB, fib);
-}
-
ABoxFilesystemNode::ABoxFilesystemNode(const String &p) {
int len = 0, offset = p.size();
@@ -168,7 +131,6 @@ ABoxFilesystemNode::ABoxFilesystemNode(const String &p) {
}
// Check whether the node exists and if it is a directory
-
BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK);
if (pLock)
{
@@ -198,6 +160,58 @@ ABoxFilesystemNode::ABoxFilesystemNode(const String &p) {
FreeDosObject(DOS_FIB, fib);
}
+ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name)
+{
+ int bufsize = 256;
+
+ _lock = NULL;
+ for (;;)
+ {
+ char name[bufsize];
+ if (NameFromLock(lock, name, bufsize) != DOSFALSE)
+ {
+ _path = name;
+ _displayName = display_name ? display_name : FilePart(name);
+ break;
+ }
+ if (IoErr() != ERROR_LINE_TOO_LONG)
+ {
+ _isValid = false;
+ debug(6, "Error while retrieving path name: %ld", IoErr());
+ return;
+ }
+ bufsize *= 2;
+ }
+
+ _isDirectory = false;
+ _isValid = false;
+
+ FileInfoBlock *fib = (FileInfoBlock*) AllocDosObject(DOS_FIB, NULL);
+ if (fib == NULL)
+ {
+ debug(6, "Failed to allocate memory for FileInfoBlock");
+ return;
+ }
+
+ if (Examine(lock, fib) != DOSFALSE)
+ {
+ _isDirectory = fib->fib_EntryType > 0;
+ if (_isDirectory)
+ {
+ if (fib->fib_EntryType != ST_ROOT)
+ _path += "/";
+ _lock = DupLock(lock);
+ _isValid = (_lock != NULL);
+ }
+ else
+ {
+ _isValid = true;
+ }
+ }
+
+ FreeDosObject(DOS_FIB, fib);
+}
+
ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node)
{
_displayName = node._displayName;
@@ -216,8 +230,30 @@ ABoxFilesystemNode::~ABoxFilesystemNode()
}
}
-bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const
+AbstractFilesystemNode *ABoxFilesystemNode::getChild(const String &name) const {
+ assert(_isDirectory);
+ String newPath(_path);
+
+ if (_path.lastChar() != '/')
+ newPath += '/';
+ newPath += name;
+
+ BPTR lock = Lock(newPath.c_str(), SHARED_LOCK);
+
+ if (!lock)
+ {
+ return 0;
+ }
+
+ UnLock(lock);
+
+ return new ABoxFilesystemNode(newPath);
+}
+
+bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const
{
+ //TODO: honor the hidden flag
+
if (!_isValid)
{
debug(6, "listDir() called on invalid node");
@@ -232,7 +268,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const
if (_lock == NULL)
{
/* This is the root node */
- myList = listRoot();
+ list = getRootChildren();
return true;
}
@@ -266,7 +302,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const
if (entry)
{
if (entry->isValid())
- myList.push_back(entry);
+ list.push_back(entry);
else
delete entry;
}
@@ -284,7 +320,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const
return true;
}
-AbstractFilesystemNode *ABoxFilesystemNode::parent() const
+AbstractFilesystemNode *ABoxFilesystemNode::getParent() const
{
AbstractFilesystemNode *node = NULL;
@@ -309,29 +345,9 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const
return node;
}
-AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const {
- assert(_isDirectory);
- String newPath(_path);
-
- if (_path.lastChar() != '/')
- newPath += '/';
- newPath += name;
-
- BPTR lock = Lock(newPath.c_str(), SHARED_LOCK);
-
- if (!lock)
- {
- return 0;
- }
-
- UnLock(lock);
-
- return new ABoxFilesystemNode(newPath);
-}
-
-AbstractFSList ABoxFilesystemNode::listRoot()
+AbstractFSList ABoxFilesystemNode::getRootChildren()
{
- AbstractFSList myList;
+ AbstractFSList list;
DosList *dosList;
CONST ULONG lockDosListFlags = LDF_READ | LDF_VOLUMES;
char name[256];
@@ -339,15 +355,15 @@ AbstractFSList ABoxFilesystemNode::listRoot()
dosList = LockDosList(lockDosListFlags);
if (dosList == NULL)
{
- return myList;
+ return list;
}
dosList = NextDosEntry(dosList, LDF_VOLUMES);
while (dosList)
{
- if (dosList->dol_Type == DLT_VOLUME && // Should always be true, but ...
- dosList->dol_Name && // Same here
- dosList->dol_Task // Will be NULL if volume is removed from drive but still in use by some program
+ if (dosList->dol_Type == DLT_VOLUME && // Should always be true, but ...
+ dosList->dol_Name && // Same here
+ dosList->dol_Task // Will be NULL if volume is removed from drive but still in use by some program
)
{
ABoxFilesystemNode *entry;
@@ -365,7 +381,7 @@ AbstractFSList ABoxFilesystemNode::listRoot()
if (entry)
{
if (entry->isValid())
- myList.push_back(entry);
+ list.push_back(entry);
else
delete entry;
}
@@ -377,9 +393,7 @@ AbstractFSList ABoxFilesystemNode::listRoot()
UnLockDosList(lockDosListFlags);
- return myList;
+ return list;
}
#endif // defined(__MORPHOS__)
-
-