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.
|
2014-02-18 01:34:23 +00:00
|
|
|
*
|
2005-08-16 17:15:37 +00:00
|
|
|
*/
|
|
|
|
|
2011-05-03 08:33:03 +00:00
|
|
|
#if defined(__PSP__)
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2011-05-03 12:14:21 +00:00
|
|
|
// Disable printf override in common/forbidden.h to avoid
|
|
|
|
// clashes with pspdebug.h from the PSP SDK.
|
|
|
|
// That header file uses
|
|
|
|
// __attribute__((format(printf,1,2)));
|
|
|
|
// which gets messed up by our override mechanism; this could
|
|
|
|
// be avoided by either changing the PSP SDK to use the equally
|
|
|
|
// legal and valid
|
|
|
|
// __attribute__((format(__printf__,1,2)));
|
|
|
|
// or by refining our printf override to use a varadic macro
|
|
|
|
// (which then wouldn't be portable, though).
|
|
|
|
// Anyway, for now we just disable the printf override globally
|
|
|
|
// for the PSP port
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
|
|
|
|
|
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
|
|
|
|
|
2011-05-03 12:30:25 +00:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
|
2011-05-03 12:14:21 +00:00
|
|
|
|
2011-05-03 12:30:25 +00:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
|
2011-05-03 12:14:21 +00:00
|
|
|
|
2011-05-03 08:33:03 +00:00
|
|
|
#include "backends/fs/psp/psp-fs.h"
|
2009-08-17 12:57:37 +00:00
|
|
|
#include "backends/fs/psp/psp-stream.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/bufferedstream.h"
|
2011-05-03 08:33:03 +00:00
|
|
|
#include "engines/engine.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:/"
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
//#define __PSP_PRINT_TO_FILE__
|
|
|
|
//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
|
|
|
|
//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
|
2009-08-17 12:57:37 +00:00
|
|
|
#include "backends/platform/psp/trace.h"
|
|
|
|
|
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) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2006-05-26 10:42:29 +00:00
|
|
|
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;
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2006-05-26 10:42:29 +00:00
|
|
|
if (verify) {
|
2008-01-27 19:47:41 +00:00
|
|
|
struct stat st;
|
2010-04-12 07:28:54 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("Suspended\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 {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2009-08-17 12:57:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
|
2009-09-23 16:11:23 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = access(_path.c_str(), F_OK);
|
|
|
|
PowerMan.endCriticalSection();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
return (ret == 0);
|
2009-08-17 12:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PSPFilesystemNode::isReadable() const {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2009-08-17 12:57:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
|
2009-09-23 16:11:23 +00:00
|
|
|
|
2010-04-12 07:28:54 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
|
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = access(_path.c_str(), R_OK);
|
|
|
|
PowerMan.endCriticalSection();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
return (ret == 0);
|
2009-08-17 12:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PSPFilesystemNode::isWritable() const {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2009-08-17 12:57:37 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-23 16:11:23 +00:00
|
|
|
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
|
2009-09-23 16:11:23 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
ret = access(_path.c_str(), W_OK);
|
|
|
|
PowerMan.endCriticalSection();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
return ret == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *PSPFilesystemNode::getChild(const Common::String &n) const {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
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
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("child [%s]\n", newPath.c_str());
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
AbstractFSNode *node = new PSPFilesystemNode(newPath, true);
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
return node;
|
2007-05-03 02:39:33 +00:00
|
|
|
}
|
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 {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
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)
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
|
2009-09-23 16:11:23 +00:00
|
|
|
|
2010-04-12 07:28:54 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("Current path[%s]\n", _path.c_str());
|
|
|
|
|
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;
|
2010-04-12 07:28:54 +00:00
|
|
|
|
|
|
|
PSP_DEBUG_PRINT_FUNC("Child[%s], %s\n", entry._path.c_str(), entry._isDirectory ? "dir" : "file");
|
|
|
|
|
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) ||
|
2010-04-12 07:28:54 +00:00
|
|
|
(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();
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2009-08-17 12:57:37 +00:00
|
|
|
return ret;
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *PSPFilesystemNode::getParent() const {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
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
|
|
|
|
2010-04-12 07:28:54 +00:00
|
|
|
PSP_DEBUG_PRINT_FUNC("current[%s]\n", _path.c_str());
|
|
|
|
|
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
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
AbstractFSNode *node = new PSPFilesystemNode(Common::String(start, end - start), false);
|
2010-04-25 15:12:24 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
return node;
|
2006-05-26 10:42:29 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::SeekableReadStream *PSPFilesystemNode::createReadStream() {
|
2010-08-24 11:24:34 +00:00
|
|
|
const uint32 READ_BUFFER_SIZE = 1024;
|
2010-10-12 02:18:11 +00:00
|
|
|
|
2010-08-24 11:24:34 +00:00
|
|
|
Common::SeekableReadStream *stream = PspIoStream::makeFromPath(getPath(), false);
|
2010-10-12 02:18:11 +00:00
|
|
|
|
2010-11-18 17:02:51 +00:00
|
|
|
return Common::wrapBufferedSeekableReadStream(stream, READ_BUFFER_SIZE, DisposeAfterUse::YES);
|
2008-09-03 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::WriteStream *PSPFilesystemNode::createWriteStream() {
|
2010-08-24 11:24:34 +00:00
|
|
|
const uint32 WRITE_BUFFER_SIZE = 1024;
|
2010-10-12 02:18:11 +00:00
|
|
|
|
2010-08-24 11:24:34 +00:00
|
|
|
Common::WriteStream *stream = PspIoStream::makeFromPath(getPath(), true);
|
2010-10-12 02:18:11 +00:00
|
|
|
|
2010-11-18 20:27:15 +00:00
|
|
|
return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
|
2008-09-03 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 08:22:40 +00:00
|
|
|
bool PSPFilesystemNode::create(bool isDirectoryFlag) {
|
2016-05-25 10:49:17 +00:00
|
|
|
error("Not supported");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
#endif //#ifdef __PSP__
|