diff options
author | Chris Apers | 2006-06-03 11:21:39 +0000 |
---|---|---|
committer | Chris Apers | 2006-06-03 11:21:39 +0000 |
commit | d224f5a6cece26d8d7a033ff0e2b51cd96cc2382 (patch) | |
tree | db40bc7f7f50edbb7e44ab8dcf97fc2f10b7a817 | |
parent | ced30c34445409c72dcafd1ac0840f7ab0739ae9 (diff) | |
download | scummvm-rg350-d224f5a6cece26d8d7a033ff0e2b51cd96cc2382.tar.gz scummvm-rg350-d224f5a6cece26d8d7a033ff0e2b51cd96cc2382.tar.bz2 scummvm-rg350-d224f5a6cece26d8d7a033ff0e2b51cd96cc2382.zip |
Updated palmos FS based on lastest changes to the base class
svn-id: r22867
-rw-r--r-- | backends/fs/palmos/palmos-fs.cpp | 101 |
1 files changed, 63 insertions, 38 deletions
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 709dddb7d0..e1effd0838 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -22,7 +22,9 @@ #if defined(PALMOS_MODE) #include "common/stdafx.h" -#include "fs/fs.h" +#include "backends/fs/abstract-fs.h" +#include "backends/fs/fs.h" + #include <stdio.h> #include <stdlib.h> @@ -40,8 +42,7 @@ protected: public: PalmOSFilesystemNode(); - PalmOSFilesystemNode(const PalmOSFilesystemNode &node); - PalmOSFilesystemNode(const String &path); + PalmOSFilesystemNode(const String &p); virtual String displayName() const { return _displayName; } virtual bool isValid() const { return _isValid; } @@ -56,25 +57,37 @@ private: static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); }; +static const char *lastPathComponent(const Common::String &str) { + 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 isDirectory; + bool isDir; - isDirectory = (find_data->attributes & vfsFileAttrDirectory); + isDir = (find_data->attributes & vfsFileAttrDirectory); - if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) || - (isDirectory && mode == FilesystemNode::kListFilesOnly)) + if ((!isDir && mode == FilesystemNode::kListDirectoriesOnly) || + (isDir && mode == FilesystemNode::kListFilesOnly)) return; - entry._isDirectory = isDirectory; + entry._isDirectory = isDir; entry._displayName = find_data->nameP; entry._path = base; entry._path += find_data->nameP; + if (entry._isDirectory) entry._path += "/"; entry._isValid = true; entry._isPseudoRoot = false; + list.push_back(new PalmOSFilesystemNode(entry)); } @@ -96,28 +109,30 @@ PalmOSFilesystemNode::PalmOSFilesystemNode() { _displayName = "Root"; _isValid = true; _path = "/"; - _isPseudoRoot = true; + _isPseudoRoot = false; } -PalmOSFilesystemNode::PalmOSFilesystemNode(const String &path) { - if (path.size() == 0) - _isPseudoRoot = true; - _path = path; - const char *dsplName = NULL, *pos = path.c_str(); - while (*pos) - if (*pos++ == '/') - dsplName = pos; - _displayName = String(dsplName); - _isValid = true; - _isDirectory = true; -} +PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { + _path = p; + _displayName = lastPathComponent(p); + + UInt32 attr; + FileRef handle; + Err e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + if (!e) { + e = VFSFileGetAttributes(handle, &attr); + VFSFileClose(handle); + } + + if (e) { + _isValid = false; + _isDirectory = false; -PalmOSFilesystemNode::PalmOSFilesystemNode(const PalmOSFilesystemNode &node) { - _displayName = node._displayName; - _isDirectory = node._isDirectory; - _isValid = node._isValid; - _isPseudoRoot = node._isPseudoRoot; - _path = node._path; + } else { + _isValid = true; + _isDirectory = (attr & vfsFileAttrDirectory); + } + _isPseudoRoot = false; } bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { @@ -146,16 +161,6 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } -const char *lastPathComponent(const Common::String &str) { - const char *start = str.c_str(); - const char *cur = start + str.size() - 2; - - while (cur > start && *cur != '/') { - --cur; - } - - return cur+1; -} AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { PalmOSFilesystemNode *p = 0; @@ -176,7 +181,27 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &name) const { - TODO + assert(_isDirectory); + String newPath(_path); + + if (_path.lastChar() != '/') + newPath += '/'; + newPath += name; + + 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; } #endif // PALMOS_MODE |