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.
|
2005-08-16 17:15:37 +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.
|
2005-08-16 17:15:37 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-08-16 17:15:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __PSP__
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
#include "engines/engine.h"
|
2006-05-12 21:01:50 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
2009-08-17 12:57:37 +00:00
|
|
|
#include "backends/fs/psp/psp-stream.h"
|
2006-05-26 10:42:29 +00:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-03-25 21:58:16 +00:00
|
|
|
#include <pspkernel.h>
|
|
|
|
|
2006-05-28 22:02:38 +00:00
|
|
|
#define ROOT_PATH "ms0:/"
|
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
#include "backends/platform/psp/trace.h"
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
2005-08-16 17:15:37 +00:00
|
|
|
* Implementation of the ScummVM file system API based on PSPSDK API.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-10-02 16:58:59 +00:00
|
|
|
* Parts of this class are documented in the base interface class, AbstractFSNode.
|
2005-08-16 17:15:37 +00:00
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
class PSPFilesystemNode : public AbstractFSNode {
|
2005-08-16 17:15:37 +00:00
|
|
|
protected:
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::String _displayName;
|
|
|
|
Common::String _path;
|
2005-08-16 17:15:37 +00:00
|
|
|
bool _isDirectory;
|
|
|
|
bool _isValid;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-08-16 17:15:37 +00:00
|
|
|
public:
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Creates a PSPFilesystemNode with the root node as path.
|
|
|
|
*/
|
2005-08-16 17:15:37 +00:00
|
|
|
PSPFilesystemNode();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Creates a PSPFilesystemNode for a given path.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-09-03 11:22:51 +00:00
|
|
|
* @param path Common::String with the path the new node should point to.
|
2007-05-03 02:39:33 +00:00
|
|
|
* @param verify true if the isValid and isDirectory flags should be verified during the construction.
|
|
|
|
*/
|
2009-08-15 10:44:58 +00:00
|
|
|
PSPFilesystemNode(const Common::String &p, bool verify = true);
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
virtual bool exists() const;
|
2008-09-03 11:22:51 +00:00
|
|
|
virtual Common::String getDisplayName() const { return _displayName; }
|
|
|
|
virtual Common::String getName() const { return _displayName; }
|
|
|
|
virtual Common::String getPath() const { return _path; }
|
2005-08-16 17:15:37 +00:00
|
|
|
virtual bool isDirectory() const { return _isDirectory; }
|
2009-08-17 12:57:37 +00:00
|
|
|
virtual bool isReadable() const;
|
|
|
|
virtual bool isWritable() const;
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual AbstractFSNode *getChild(const Common::String &n) const;
|
2007-07-09 01:26:54 +00:00
|
|
|
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual AbstractFSNode *getParent() const;
|
2008-09-03 12:56:46 +00:00
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
virtual Common::SeekableReadStream *createReadStream();
|
|
|
|
virtual Common::WriteStream *createWriteStream();
|
2005-08-16 17:15:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PSPFilesystemNode::PSPFilesystemNode() {
|
|
|
|
_isDirectory = true;
|
|
|
|
_displayName = "Root";
|
|
|
|
_isValid = true;
|
2006-05-28 22:02:38 +00:00
|
|
|
_path = ROOT_PATH;
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) {
|
|
|
|
assert(p.size() > 0);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
_path = p;
|
2008-08-27 20:31:22 +00:00
|
|
|
_displayName = lastPathComponent(_path, '/');
|
2006-05-26 10:42:29 +00:00
|
|
|
_isValid = true;
|
|
|
|
_isDirectory = true;
|
|
|
|
|
|
|
|
if (verify) {
|
2008-01-27 19:47:41 +00:00
|
|
|
struct stat st;
|
2009-09-23 16:11:23 +00:00
|
|
|
if(PowerMan.beginCriticalSection()==PowerManager::Blocked)
|
|
|
|
PSPDebugSuspend("Suspended in PSPFilesystemNode::PSPFilesystemNode\n");
|
2006-05-26 10:42:29 +00:00
|
|
|
_isValid = (0 == stat(_path.c_str(), &st));
|
2009-08-17 12:57:37 +00:00
|
|
|
PowerMan.endCriticalSection();
|
2006-05-26 10:42:29 +00:00
|
|
|
_isDirectory = S_ISDIR(st.st_mode);
|
2008-01-27 19:47:41 +00:00
|
|
|
}
|
2006-05-26 10:42:29 +00:00
|
|
|
}
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
bool PSPFilesystemNode::exists() const {
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
|
|
|
PSPDebugSuspend("Suspended in PSPFilesystemNode::exists()\n"); // Make sure to block in case of suspend
|
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = access(_path.c_str(), F_OK);
|
|
|
|
PowerMan.endCriticalSection();
|
|
|
|
|
|
|
|
return ret == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PSPFilesystemNode::isReadable() const {
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
|
|
|
PSPDebugSuspend("Suspended in PSPFilesystemNode::isReadable()\n"); // Make sure to block in case of suspend
|
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = access(_path.c_str(), R_OK);
|
|
|
|
PowerMan.endCriticalSection();
|
|
|
|
|
|
|
|
return ret == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PSPFilesystemNode::isWritable() const {
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
|
|
|
PSPDebugSuspend("Suspended in PSPFilesystemNode::isWritable()\n"); // Make sure to block in case of suspend
|
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = access(_path.c_str(), W_OK);
|
|
|
|
PowerMan.endCriticalSection();
|
|
|
|
|
|
|
|
return ret == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *PSPFilesystemNode::getChild(const Common::String &n) const {
|
2007-05-03 02:39:33 +00:00
|
|
|
// FIXME: Pretty lame implementation! We do no error checking to speak
|
|
|
|
// of, do not check if this is a special node, etc.
|
|
|
|
assert(_isDirectory);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::String newPath(_path);
|
2007-05-03 02:39:33 +00:00
|
|
|
if (_path.lastChar() != '/')
|
|
|
|
newPath += '/';
|
|
|
|
newPath += n;
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
return new PSPFilesystemNode(newPath, true);
|
|
|
|
}
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
|
2005-08-16 17:15:37 +00:00
|
|
|
assert(_isDirectory);
|
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
//TODO: honor the hidden flag
|
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
|
|
|
PSPDebugSuspend("Suspended in PSPFilesystemNode::getChildren\n"); // Make sure to block in case of suspend
|
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
int dfd = sceIoDopen(_path.c_str());
|
2005-08-16 17:15:37 +00:00
|
|
|
if (dfd > 0) {
|
2008-01-27 19:47:41 +00:00
|
|
|
SceIoDirent dir;
|
2006-05-26 10:42:29 +00:00
|
|
|
memset(&dir, 0, sizeof(dir));
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
while (sceIoDread(dfd, &dir) > 0) {
|
|
|
|
// Skip 'invisible files
|
2008-01-27 19:47:41 +00:00
|
|
|
if (dir.d_name[0] == '.')
|
2006-05-26 10:42:29 +00:00
|
|
|
continue;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
PSPFilesystemNode entry;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
entry._isValid = true;
|
|
|
|
entry._displayName = dir.d_name;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2009-01-24 20:46:20 +00:00
|
|
|
Common::String newPath(_path);
|
|
|
|
if (newPath.lastChar() != '/')
|
|
|
|
newPath += '/';
|
|
|
|
newPath += dir.d_name;
|
|
|
|
|
|
|
|
entry._path = newPath;
|
|
|
|
entry._isDirectory = dir.d_stat.st_attr & FIO_SO_IFDIR;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
// Honor the chosen mode
|
2008-10-02 16:58:59 +00:00
|
|
|
if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) ||
|
|
|
|
(mode == Common::FSNode::kListDirectoriesOnly && !entry._isDirectory))
|
2006-05-26 10:42:29 +00:00
|
|
|
continue;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
myList.push_back(new PSPFilesystemNode(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
sceIoDclose(dfd);
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = true;
|
|
|
|
} else { // dfd <= 0
|
|
|
|
ret = false;
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
2009-08-17 12:57:37 +00:00
|
|
|
|
|
|
|
PowerMan.endCriticalSection();
|
|
|
|
return ret;
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *PSPFilesystemNode::getParent() const {
|
2006-05-28 22:02:38 +00:00
|
|
|
if (_path == ROOT_PATH)
|
2005-08-16 17:15:37 +00:00
|
|
|
return 0;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-28 22:02:38 +00:00
|
|
|
const char *start = _path.c_str();
|
2008-08-27 20:31:22 +00:00
|
|
|
const char *end = lastPathComponent(_path, '/');
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
return new PSPFilesystemNode(Common::String(start, end - start), false);
|
2006-05-26 10:42:29 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::SeekableReadStream *PSPFilesystemNode::createReadStream() {
|
2009-08-17 12:57:37 +00:00
|
|
|
return PSPIoStream::makeFromPath(getPath(), false);
|
2008-09-03 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::WriteStream *PSPFilesystemNode::createWriteStream() {
|
2009-08-17 12:57:37 +00:00
|
|
|
return PSPIoStream::makeFromPath(getPath(), true);
|
2008-09-03 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
#endif //#ifdef __PSP__
|