2003-04-30 11:37:10 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2003-2006 The ScummVM Team
|
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
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2006-04-05 00:18:22 +00:00
|
|
|
#include "backends/fs/fs.h"
|
2003-04-30 11:37:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of the ScummVM file system API based on PalmOS VFS API.
|
|
|
|
*/
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
class PalmOSFilesystemNode : public AbstractFilesystemNode {
|
2003-04-30 11:37:10 +00:00
|
|
|
protected:
|
|
|
|
String _displayName;
|
|
|
|
bool _isDirectory;
|
|
|
|
bool _isValid;
|
|
|
|
bool _isPseudoRoot;
|
|
|
|
String _path;
|
2005-09-03 16:24:58 +00:00
|
|
|
|
2003-04-30 11:37:10 +00:00
|
|
|
public:
|
|
|
|
PalmOSFilesystemNode();
|
|
|
|
PalmOSFilesystemNode(const Char *path);
|
|
|
|
|
|
|
|
virtual String displayName() const { return _displayName; }
|
|
|
|
virtual bool isValid() const { return _isValid; }
|
|
|
|
virtual bool isDirectory() const { return _isDirectory; }
|
|
|
|
virtual String path() const { return _path; }
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
virtual FSList listDir(ListMode) const;
|
|
|
|
virtual AbstractFilesystemNode *parent() const;
|
2003-04-30 11:37:10 +00:00
|
|
|
|
|
|
|
private:
|
2004-11-20 21:35:49 +00:00
|
|
|
static void addFile (FSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
|
2003-04-30 11:37:10 +00:00
|
|
|
};
|
|
|
|
|
2006-04-04 20:54:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-04-04 21:03:17 +00:00
|
|
|
return cur + 1;
|
2006-04-04 20:54:55 +00:00
|
|
|
}
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
void PalmOSFilesystemNode::addFile(FSList &list, ListMode mode, const char *base, FileInfoType* find_data) {
|
2003-04-30 11:37:10 +00:00
|
|
|
PalmOSFilesystemNode entry;
|
|
|
|
bool isDirectory;
|
|
|
|
|
|
|
|
isDirectory = (find_data->attributes & vfsFileAttrDirectory);
|
|
|
|
|
|
|
|
if ((!isDirectory && mode == kListDirectoriesOnly) ||
|
|
|
|
(isDirectory && mode == kListFilesOnly))
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry._isDirectory = isDirectory;
|
|
|
|
entry._displayName = find_data->nameP;
|
|
|
|
entry._path = base;
|
|
|
|
entry._path += find_data->nameP;
|
|
|
|
if (entry._isDirectory)
|
|
|
|
entry._path += "/";
|
|
|
|
|
2005-09-03 16:24:58 +00:00
|
|
|
entry._isValid = true;
|
2003-04-30 11:37:10 +00:00
|
|
|
entry._isPseudoRoot = false;
|
2006-04-04 20:54:55 +00:00
|
|
|
list.push_back(wrap(new PalmOSFilesystemNode(entry)));
|
2003-04-30 11:37:10 +00:00
|
|
|
}
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
AbstractFilesystemNode *FilesystemNode::getRoot() {
|
2003-04-30 11:37:10 +00:00
|
|
|
return new PalmOSFilesystemNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
PalmOSFilesystemNode::PalmOSFilesystemNode() {
|
|
|
|
_isDirectory = true;
|
|
|
|
_displayName = "Root";
|
|
|
|
_isValid = true;
|
|
|
|
_path = "/";
|
|
|
|
_isPseudoRoot = true;
|
|
|
|
}
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
FSList PalmOSFilesystemNode::listDir(ListMode mode) const {
|
2003-04-30 11:37:10 +00:00
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
FSList myList;
|
2003-04-30 11:37:10 +00:00
|
|
|
Err e;
|
|
|
|
Char nameP[256];
|
|
|
|
FileInfoType desc;
|
|
|
|
FileRef handle;
|
|
|
|
UInt32 dirIterator = expIteratorStart;
|
|
|
|
|
|
|
|
desc.nameP = nameP;
|
|
|
|
desc.nameBufLen = 256;
|
2005-09-03 16:24:58 +00:00
|
|
|
e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle);
|
2003-04-30 11:37:10 +00:00
|
|
|
|
|
|
|
if (e)
|
|
|
|
return myList;
|
2005-09-03 16:24:58 +00:00
|
|
|
|
2003-04-30 11:37:10 +00:00
|
|
|
while(dirIterator != expIteratorStop) {
|
|
|
|
e = VFSDirEntryEnumerate(handle, &dirIterator, &desc);
|
|
|
|
if (!e) {
|
|
|
|
addFile(myList, mode, _path.c_str(), &desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VFSFileClose(handle);
|
|
|
|
|
|
|
|
return myList;
|
|
|
|
}
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
|
2004-11-21 13:18:07 +00:00
|
|
|
PalmOSFilesystemNode *p = 0;
|
2005-09-03 16:24:58 +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);
|
2005-09-03 16:24:58 +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 == "/");
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-09-03 16:24:58 +00:00
|
|
|
#endif // PALMOS_MODE
|