diff options
Diffstat (limited to 'backends/fs/palmos')
-rw-r--r-- | backends/fs/palmos/palmos-fs-factory.cpp | 16 | ||||
-rw-r--r-- | backends/fs/palmos/palmos-fs-factory.h | 26 | ||||
-rw-r--r-- | backends/fs/palmos/palmos-fs.cpp | 134 |
3 files changed, 116 insertions, 60 deletions
diff --git a/backends/fs/palmos/palmos-fs-factory.cpp b/backends/fs/palmos/palmos-fs-factory.cpp new file mode 100644 index 0000000000..1b0db0f042 --- /dev/null +++ b/backends/fs/palmos/palmos-fs-factory.cpp @@ -0,0 +1,16 @@ +#include "backends/fs/palmos/palmos-fs-factory.h" +#include "backends/fs/palmos/palmos-fs.cpp" + +DECLARE_SINGLETON(PalmOSFilesystemFactory); + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const { + return new PalmOSFilesystemNode(); +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new PalmOSFilesystemNode(); +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeFileNodePath(const String &path) const { + return new PalmOSFilesystemNode(path); +} diff --git a/backends/fs/palmos/palmos-fs-factory.h b/backends/fs/palmos/palmos-fs-factory.h new file mode 100644 index 0000000000..4bb94ab4c1 --- /dev/null +++ b/backends/fs/palmos/palmos-fs-factory.h @@ -0,0 +1,26 @@ +#ifndef PALMOS_FILESYSTEM_FACTORY_H +#define PALMOS_FILESYSTEM_FACTORY_H + +#include "backends/fs/abstract-fs-factory.h" + +/** + * Creates PalmOSFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class PalmOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<PalmOSFilesystemFactory> { +public: + typedef Common::String String; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + PalmOSFilesystemFactory() {}; + +private: + friend class Common::Singleton<SingletonBaseType>; +}; + +#endif /*PALMOS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 4740dcc64b..af09d79a12 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -27,36 +27,65 @@ #include "common/stdafx.h" #include "backends/fs/abstract-fs.h" -/* +/** * Implementation of the ScummVM file system API based on PalmOS VFS API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class PalmOSFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; bool _isPseudoRoot; - String _path; public: + /** + * Creates a PalmOSFilesystemNode with the root node as path. + */ PalmOSFilesystemNode(); + + /** + * Creates a POSIXFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ PalmOSFilesystemNode(const String &p); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + 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 isValid() const { return _isValid; } - 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; private: - static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); + /** + * Adds a single WindowsFilesystemNode to a given list. + * This method is used by getChildren() to populate the directory entries list. + * + * @param list List to put the file entry node in. + * @param mode Mode to use while adding the file entry to the list. + * @param base String with the directory being listed. + * @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find. + */ + static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); }; +/** + * 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; @@ -92,19 +121,6 @@ void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const ch list.push_back(new PalmOSFilesystemNode(entry)); } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new PalmOSFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new PalmOSFilesystemNode(path); -} - - PalmOSFilesystemNode::PalmOSFilesystemNode() { _isDirectory = true; _displayName = "Root"; @@ -119,13 +135,13 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { UInt32 attr; FileRef handle; - Err e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (!e) { - e = VFSFileGetAttributes(handle, &attr); + Err error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + if (!error) { + error = VFSFileGetAttributes(handle, &attr); VFSFileClose(handle); } - if (e) { + if (error) { _isValid = false; _isDirectory = false; @@ -136,8 +152,31 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { _isPseudoRoot = false; } -bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { - Err e; +AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const { + assert(_isDirectory); + + String newPath(_path); + if (_path.lastChar() != '/') + newPath += '/'; + newPath += n; + + FileRef handle; + UInt32 attr; + Err error = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); + if (error) + return 0; + + error = VFSFileGetAttributes(handle, &attr); + VFSFileClose(handle); + + if (error || !(attr & vfsFileAttrDirectory)) + return 0; + + return new PalmOSFilesystemNode(newPath); +} + +bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { + Err error; Char nameP[256]; FileInfoType desc; FileRef handle; @@ -145,14 +184,14 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const desc.nameP = nameP; desc.nameBufLen = 256; - e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (e) + if (error) return false; while(dirIterator != expIteratorStop) { - e = VFSDirEntryEnumerate(handle, &dirIterator, &desc); - if (!e) { + error = VFSDirEntryEnumerate(handle, &dirIterator, &desc); + if (!error) { addFile(myList, mode, _path.c_str(), &desc); } } @@ -162,8 +201,7 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } - -AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { +AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { PalmOSFilesystemNode *p = 0; if (!_isPseudoRoot) { @@ -177,31 +215,7 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { p->_displayName = lastPathComponent(p->_path); p->_isPseudoRoot =(p->_path == "/"); } - return p; -} - - -AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &n) const { - assert(_isDirectory); - String newPath(_path); - - if (_path.lastChar() != '/') - newPath += '/'; - newPath += n; - - FileRef handle; - UInt32 attr; - Err e = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); - if (e) - return 0; - e = VFSFileGetAttributes(handle, &attr); - VFSFileClose(handle); - - if (e || !(attr & vfsFileAttrDirectory)) - return 0; - - PalmOSFilesystemNode *p = new PalmOSFilesystemNode(newPath); return p; } |