diff options
Diffstat (limited to 'backends/fs/morphos/abox-fs.cpp')
-rw-r--r-- | backends/fs/morphos/abox-fs.cpp | 266 |
1 files changed, 139 insertions, 127 deletions
diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp index 8206e83030..8f46f9a9a8 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) 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,7 +230,27 @@ 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) const { if (!_isValid) { @@ -232,7 +266,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 +300,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 +318,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } -AbstractFilesystemNode *ABoxFilesystemNode::parent() const +AbstractFilesystemNode *ABoxFilesystemNode::getParent() const { AbstractFilesystemNode *node = NULL; @@ -309,29 +343,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 +353,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 +379,7 @@ AbstractFSList ABoxFilesystemNode::listRoot() if (entry) { if (entry->isValid()) - myList.push_back(entry); + list.push_back(entry); else delete entry; } @@ -377,9 +391,7 @@ AbstractFSList ABoxFilesystemNode::listRoot() UnLockDosList(lockDosListFlags); - return myList; + return list; } #endif // defined(__MORPHOS__) - - |