diff options
Diffstat (limited to 'backends/fs/palmos/palmos-fs.cpp')
| -rw-r--r-- | backends/fs/palmos/palmos-fs.cpp | 72 |
1 files changed, 30 insertions, 42 deletions
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 5edb6c2d26..7c415aa320 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -28,6 +28,7 @@ #include "globals.h" #include "backends/fs/abstract-fs.h" +#include "backends/fs/stdiostream.h" /** * Implementation of the ScummVM file system API based on PalmOS VFS API. @@ -36,8 +37,8 @@ */ class PalmOSFilesystemNode : public AbstractFilesystemNode { protected: - String _displayName; - String _path; + Common::String _displayName; + Common::String _path; bool _isDirectory; bool _isValid; bool _isPseudoRoot; @@ -51,22 +52,25 @@ public: /** * Creates a POSIXFilesystemNode for a given path. * - * @param path String with the path the new node should point to. + * @param path Common::String with the path the new node should point to. */ - PalmOSFilesystemNode(const String &p); + PalmOSFilesystemNode(const Common::String &p); virtual bool exists() const { return _isValid; } - virtual String getDisplayName() const { return _displayName; } - virtual String getName() const { return _displayName; } - virtual String getPath() const { return _path; } + virtual Common::String getDisplayName() const { return _displayName; } + virtual Common::String getName() const { return _displayName; } + virtual Common::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 isWritable() const { return true; } //FIXME: this is just a stub - virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual AbstractFilesystemNode *getChild(const Common::String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; + virtual Common::SeekableReadStream *openForReading(); + virtual Common::WriteStream *openForWriting(); + private: /** * Adds a single WindowsFilesystemNode to a given list. @@ -74,44 +78,20 @@ private: * * @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 base Common::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. - */ -const char *lastPathComponent(const Common::String &str) { - if(str.empty()) - return ""; - - const char *start = str.c_str(); - const char *cur = start + str.size() - 2; - - while (cur >= start && *cur != '/') { - --cur; - } - - return cur + 1; -} - void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) { PalmOSFilesystemNode entry; bool isDir; isDir = (find_data->attributes & vfsFileAttrDirectory); - if ((!isDir && mode == FilesystemNode::kListDirectoriesOnly) || - (isDir && mode == FilesystemNode::kListFilesOnly)) + if ((!isDir && mode == Common::FilesystemNode::kListDirectoriesOnly) || + (isDir && mode == Common::FilesystemNode::kListFilesOnly)) return; entry._isDirectory = isDir; @@ -136,9 +116,9 @@ PalmOSFilesystemNode::PalmOSFilesystemNode() { _isPseudoRoot = false; } -PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { +PalmOSFilesystemNode::PalmOSFilesystemNode(const Common::String &p) { _path = p; - _displayName = lastPathComponent(_path); + _displayName = lastPathComponent(_path, '/'); UInt32 attr; FileRef handle; @@ -159,10 +139,10 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { _isPseudoRoot = false; } -AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const { +AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const Common::String &n) const { assert(_isDirectory); - String newPath(_path); + Common::String newPath(_path); if (_path.lastChar() != '/') newPath += '/'; newPath += n; @@ -215,17 +195,25 @@ AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { if (!_isPseudoRoot) { const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char *end = lastPathComponent(_path, '/'); p = new PalmOSFilesystemNode(); - p->_path = String(start, end - start); + p->_path = Common::String(start, end - start); p->_isValid = true; p->_isDirectory = true; - p->_displayName = lastPathComponent(p->_path); + p->_displayName = lastPathComponent(p->_path, '/'); p->_isPseudoRoot =(p->_path == "/"); } return p; } +Common::SeekableReadStream *PalmOSFilesystemNode::openForReading() { + return StdioStream::makeFromPath(getPath().c_str(), false); +} + +Common::WriteStream *PalmOSFilesystemNode::openForWriting() { + return StdioStream::makeFromPath(getPath().c_str(), true); +} + #endif // PALMOS_MODE |
