diff options
author | David Corrales | 2007-05-03 02:39:33 +0000 |
---|---|---|
committer | David Corrales | 2007-05-03 02:39:33 +0000 |
commit | c459f054b46b8791ce206c2ee13d455a9c10fe4d (patch) | |
tree | b36dc6034bfb9659e57e28de8a509a7b1de4554d /backends/fs/amigaos4/amigaos4-fs.cpp | |
parent | 8f5abc1924d5d7bdbc9684b870394f93ad80d2ff (diff) | |
download | scummvm-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/amigaos4/amigaos4-fs.cpp')
-rw-r--r-- | backends/fs/amigaos4/amigaos4-fs.cpp | 163 |
1 files changed, 89 insertions, 74 deletions
diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp index 3abf5672c8..8768519a76 100644 --- a/backends/fs/amigaos4/amigaos4-fs.cpp +++ b/backends/fs/amigaos4/amigaos4-fs.cpp @@ -1,5 +1,5 @@ /* ScummVM - Scumm Interpreter - * Copyright (C) 2005-2006 The ScummVM project, contribution by Hans-Jörg Frieden and Juha Niemimäki + * Copyright (C) 2005-2006 The ScummVM project, contribution by Hans-J�rg Frieden and Juha Niemim�ki * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,58 +35,73 @@ #include <common/stdafx.h> #include "common/util.h" - #include "engines/engine.h" #include "backends/fs/abstract-fs.h" #define ENTER() /* debug(6, "Enter") */ #define LEAVE() /* debug(6, "Leave") */ - const uint32 kExAllBufferSize = 40960; // TODO: is this okay for sure? +/** + * Implementation of the ScummVM file system API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. + */ class AmigaOSFilesystemNode : public AbstractFilesystemNode { - protected: - BPTR _pFileLock; - String _sDisplayName; - bool _bIsDirectory; - bool _bIsValid; - String _sPath; - - public: - AmigaOSFilesystemNode(); - AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0); - AmigaOSFilesystemNode(const String &p); - - // Note: Copy constructor is needed because it duplicates the file lock - AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node); - - virtual ~AmigaOSFilesystemNode(); - - virtual String displayName() const { return _sDisplayName; }; - virtual String name() const { return _sDisplayName; }; - virtual bool isValid() const { return _bIsValid; }; - virtual bool isDirectory() const { return _bIsDirectory; }; - virtual String path() const { return _sPath; }; - - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFSList listVolumes() const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; +protected: + BPTR _pFileLock; + String _sDisplayName; + String _sPath; + bool _bIsDirectory; + bool _bIsValid; + +public: + /** + * Creates a AmigaOSFilesystemNode with the root node as path. + */ + AmigaOSFilesystemNode(); + + /** + * Creates a AmigaOSFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ + AmigaOSFilesystemNode(const String &p); + + /** + * FIXME: document this constructor. + */ + AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0); + + /** + * Copy constructor. + * + * @note Needed because it duplicates the file lock + */ + AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node); + + /** + * Destructor. + */ + virtual ~AmigaOSFilesystemNode(); + + virtual String getDisplayName() const { return _sDisplayName; }; + virtual String getName() const { return _sDisplayName; }; + virtual String getPath() const { return _sPath; }; + virtual bool isValid() const { return _bIsValid; }; + virtual bool isDirectory() const { return _bIsDirectory; }; + + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; + + /** + * Creates a list with all the volumes present in the root node. + */ + virtual AbstractFSList listVolumes() const; }; -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new AmigaOSFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new AmigaOSFilesystemNode(path); -} - AmigaOSFilesystemNode::AmigaOSFilesystemNode() { ENTER(); _sDisplayName = "Available Disks"; @@ -97,7 +112,6 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode() { LEAVE(); } - AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) { ENTER(); @@ -147,7 +161,6 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) { const char c = _sPath.lastChar(); if (c != '/' && c != ':') _sPath += '/'; - } else { //_bIsDirectory = false; @@ -167,7 +180,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayNam int bufSize = MAXPATHLEN; _pFileLock = 0; - while (1) { + while (true) { char *n = new char[bufSize]; if (IDOS->NameFromLock(pLock, (STRPTR)n, bufSize) != DOSFALSE) { _sPath = n; @@ -183,6 +196,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayNam delete [] n; return; } + bufSize *= 2; delete [] n; } @@ -235,7 +249,31 @@ AmigaOSFilesystemNode::~AmigaOSFilesystemNode() { LEAVE(); } -bool AmigaOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +AbstractFilesystemNode *AmigaOSFilesystemNode::getChild(const String &n) const { + if (!_bIsDirectory) { + debug(6, "Not a directory"); + return 0; + } + + String newPath(_sPath); + + if (_sPath.lastChar() != '/') + newPath += '/'; + + newPath += n; + BPTR lock = IDOS->Lock(newPath.c_str(), SHARED_LOCK); + + if (!lock) { + debug(6, "Bad path"); + return 0; + } + + IDOS->UnLock(lock); + + return new AmigaOSFilesystemNode(newPath); +} + +bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { ENTER(); if (!_bIsValid) { @@ -305,10 +343,11 @@ bool AmigaOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const } LEAVE(); + return true; } -AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const { +AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const { ENTER(); if (!_bIsDirectory) { @@ -334,33 +373,8 @@ AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const { node = new AmigaOSFilesystemNode(); LEAVE(); - return node; -} - -AbstractFilesystemNode *AmigaOSFilesystemNode::child(const String &n) const { - if (!_bIsDirectory) { - debug(6, "Not a directory"); - return 0; - } - - String newPath(_sPath); - - if (_sPath.lastChar() != '/') - newPath += '/'; - - newPath += n; - - BPTR lock = IDOS->Lock(newPath.c_str(), SHARED_LOCK); - - if (!lock) { - debug(6, "Bad path"); - return 0; - } - - IDOS->UnLock(lock); - - return new AmigaOSFilesystemNode(newPath); + return node; } AbstractFSList AmigaOSFilesystemNode::listVolumes() const { @@ -428,7 +442,8 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const { IDOS->UnLockDosList(kLockFlags); LEAVE(); + return myList; } -#endif +#endif //defined(__amigaos4__) |