2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-04-30 11:37:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-04-30 11:37:10 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-04-30 11:37:10 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-03 16:24:58 +00:00
|
|
|
#if defined(PALMOS_MODE)
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2007-05-01 09:50:50 +00:00
|
|
|
#include "PalmVersion.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
2003-04-30 11:37:10 +00:00
|
|
|
* Implementation of the ScummVM file system API based on PalmOS VFS API.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* Parts of this class are documented in the base interface class, AbstractFilesystemNode.
|
2003-04-30 11:37:10 +00:00
|
|
|
*/
|
2004-11-20 21:35:49 +00:00
|
|
|
class PalmOSFilesystemNode : public AbstractFilesystemNode {
|
2003-04-30 11:37:10 +00:00
|
|
|
protected:
|
|
|
|
String _displayName;
|
2007-05-03 02:39:33 +00:00
|
|
|
String _path;
|
2003-04-30 11:37:10 +00:00
|
|
|
bool _isDirectory;
|
|
|
|
bool _isValid;
|
|
|
|
bool _isPseudoRoot;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2003-04-30 11:37:10 +00:00
|
|
|
public:
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Creates a PalmOSFilesystemNode with the root node as path.
|
|
|
|
*/
|
2003-04-30 11:37:10 +00:00
|
|
|
PalmOSFilesystemNode();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Creates a POSIXFilesystemNode for a given path.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* @param path String with the path the new node should point to.
|
|
|
|
*/
|
2006-06-03 11:21:39 +00:00
|
|
|
PalmOSFilesystemNode(const String &p);
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2008-02-26 20:54:02 +00:00
|
|
|
virtual bool exists() const { return _isValid; }
|
2007-05-03 02:39:33 +00:00
|
|
|
virtual String getDisplayName() const { return _displayName; }
|
|
|
|
virtual String getName() const { return _displayName; }
|
|
|
|
virtual String getPath() const { return _path; }
|
2003-04-30 11:37:10 +00:00
|
|
|
virtual bool isDirectory() const { return _isDirectory; }
|
2007-06-04 22:02:35 +00:00
|
|
|
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
|
|
|
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
2007-07-09 01:26:54 +00:00
|
|
|
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
|
2007-05-03 02:39:33 +00:00
|
|
|
virtual AbstractFilesystemNode *getParent() const;
|
2003-04-30 11:37:10 +00:00
|
|
|
|
|
|
|
private:
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Adds a single WindowsFilesystemNode to a given list.
|
2008-01-27 19:47:41 +00:00
|
|
|
* This method is used by getChildren() to populate the directory entries list.
|
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* @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.
|
2008-01-28 00:14:17 +00:00
|
|
|
*/
|
2007-05-03 02:39:33 +00:00
|
|
|
static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
|
2003-04-30 11:37:10 +00:00
|
|
|
};
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Returns the last component of a given path.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* Examples:
|
2008-01-28 00:14:17 +00:00
|
|
|
* /foo/bar.txt would return /bar.txt
|
|
|
|
* /foo/bar/ would return /bar/
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* @param str String containing the path.
|
|
|
|
* @return Pointer to the first char of the last component inside str.
|
|
|
|
*/
|
2007-09-18 21:34:57 +00:00
|
|
|
const char *lastPathComponent(const Common::String &str) {
|
2007-10-07 00:28:38 +00:00
|
|
|
if(str.empty())
|
|
|
|
return "";
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
const char *start = str.c_str();
|
|
|
|
const char *cur = start + str.size() - 2;
|
|
|
|
|
2006-08-28 13:34:15 +00:00
|
|
|
while (cur >= start && *cur != '/') {
|
2006-06-03 11:21:39 +00:00
|
|
|
--cur;
|
2006-08-28 13:34:15 +00:00
|
|
|
}
|
2006-06-03 11:21:39 +00:00
|
|
|
|
|
|
|
return cur + 1;
|
|
|
|
}
|
|
|
|
|
2006-05-03 11:13:21 +00:00
|
|
|
void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) {
|
2003-04-30 11:37:10 +00:00
|
|
|
PalmOSFilesystemNode entry;
|
2006-06-03 11:21:39 +00:00
|
|
|
bool isDir;
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
isDir = (find_data->attributes & vfsFileAttrDirectory);
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
if ((!isDir && mode == FilesystemNode::kListDirectoriesOnly) ||
|
|
|
|
(isDir && mode == FilesystemNode::kListFilesOnly))
|
2003-04-30 11:37:10 +00:00
|
|
|
return;
|
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
entry._isDirectory = isDir;
|
2003-04-30 11:37:10 +00:00
|
|
|
entry._displayName = find_data->nameP;
|
|
|
|
entry._path = base;
|
|
|
|
entry._path += find_data->nameP;
|
2006-06-03 11:21:39 +00:00
|
|
|
|
2003-04-30 11:37:10 +00:00
|
|
|
if (entry._isDirectory)
|
|
|
|
entry._path += "/";
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
entry._isValid = true;
|
2003-04-30 11:37:10 +00:00
|
|
|
entry._isPseudoRoot = false;
|
2006-06-03 11:21:39 +00:00
|
|
|
|
2006-05-03 11:13:21 +00:00
|
|
|
list.push_back(new PalmOSFilesystemNode(entry));
|
2003-04-30 11:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PalmOSFilesystemNode::PalmOSFilesystemNode() {
|
|
|
|
_isDirectory = true;
|
|
|
|
_displayName = "Root";
|
|
|
|
_isValid = true;
|
|
|
|
_path = "/";
|
2006-06-03 11:21:39 +00:00
|
|
|
_isPseudoRoot = false;
|
2003-04-30 11:37:10 +00:00
|
|
|
}
|
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) {
|
|
|
|
_path = p;
|
2007-10-07 00:28:38 +00:00
|
|
|
_displayName = lastPathComponent(_path);
|
2006-06-03 11:21:39 +00:00
|
|
|
|
|
|
|
UInt32 attr;
|
|
|
|
FileRef handle;
|
2007-05-03 02:39:33 +00:00
|
|
|
Err error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle);
|
|
|
|
if (!error) {
|
|
|
|
error = VFSFileGetAttributes(handle, &attr);
|
2006-06-03 11:21:39 +00:00
|
|
|
VFSFileClose(handle);
|
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
if (error) {
|
2006-06-03 11:21:39 +00:00
|
|
|
_isValid = false;
|
|
|
|
_isDirectory = false;
|
2006-04-11 18:13:04 +00:00
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
} else {
|
|
|
|
_isValid = true;
|
|
|
|
_isDirectory = (attr & vfsFileAttrDirectory);
|
|
|
|
}
|
|
|
|
_isPseudoRoot = false;
|
2006-04-11 18:13:04 +00:00
|
|
|
}
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const {
|
|
|
|
assert(_isDirectory);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
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;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
error = VFSFileGetAttributes(handle, &attr);
|
|
|
|
VFSFileClose(handle);
|
|
|
|
|
|
|
|
if (error || !(attr & vfsFileAttrDirectory))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return new PalmOSFilesystemNode(newPath);
|
|
|
|
}
|
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
|
|
|
|
//TODO: honor the hidden flag
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
Err error;
|
2003-04-30 11:37:10 +00:00
|
|
|
Char nameP[256];
|
|
|
|
FileInfoType desc;
|
|
|
|
FileRef handle;
|
|
|
|
UInt32 dirIterator = expIteratorStart;
|
|
|
|
|
|
|
|
desc.nameP = nameP;
|
|
|
|
desc.nameBufLen = 256;
|
2007-05-03 02:39:33 +00:00
|
|
|
error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle);
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
if (error)
|
2006-05-03 20:43:26 +00:00
|
|
|
return false;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 20:16:33 +00:00
|
|
|
while (dirIterator != expIteratorStop) {
|
2007-05-03 02:39:33 +00:00
|
|
|
error = VFSDirEntryEnumerate(handle, &dirIterator, &desc);
|
|
|
|
if (!error) {
|
2003-04-30 11:37:10 +00:00
|
|
|
addFile(myList, mode, _path.c_str(), &desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VFSFileClose(handle);
|
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
return true;
|
2003-04-30 11:37:10 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const {
|
2004-11-21 13:18:07 +00:00
|
|
|
PalmOSFilesystemNode *p = 0;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2003-04-30 11:37:10 +00:00
|
|
|
if (!_isPseudoRoot) {
|
2004-11-21 13:18:07 +00:00
|
|
|
const char *start = _path.c_str();
|
|
|
|
const char *end = lastPathComponent(_path);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2004-11-21 13:18:07 +00:00
|
|
|
p = new PalmOSFilesystemNode();
|
2003-04-30 11:37:10 +00:00
|
|
|
p->_path = String(start, end - start);
|
|
|
|
p->_isValid = true;
|
|
|
|
p->_isDirectory = true;
|
|
|
|
p->_displayName = lastPathComponent(p->_path);
|
|
|
|
p->_isPseudoRoot =(p->_path == "/");
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-06-03 11:21:39 +00:00
|
|
|
return p;
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2005-09-03 16:24:58 +00:00
|
|
|
#endif // PALMOS_MODE
|