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.
|
2006-06-03 14:09:04 +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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2008-03-01 17:48:42 +00:00
|
|
|
#include "dc.h"
|
2006-06-03 14:09:04 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
2008-09-03 12:56:46 +00:00
|
|
|
#include "backends/fs/stdiostream.h"
|
2006-06-03 14:09:04 +00:00
|
|
|
|
|
|
|
#include <ronin/cdfs.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
2007-08-18 05:24:18 +00:00
|
|
|
* Implementation of the ScummVM file system API based on Ronin.
|
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.
|
2006-06-03 14:09:04 +00:00
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
class RoninCDFileNode : public AbstractFSNode {
|
2006-06-03 14:09:04 +00:00
|
|
|
protected:
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::String _path;
|
2006-06-03 14:09:04 +00:00
|
|
|
|
|
|
|
public:
|
2008-09-03 11:22:51 +00:00
|
|
|
RoninCDFileNode(const Common::String &path) : _path(path) {};
|
2008-04-05 23:30:12 +00:00
|
|
|
|
|
|
|
virtual bool exists() const { return true; }
|
2008-09-03 11:22:51 +00:00
|
|
|
virtual Common::String getName() const { return lastPathComponent(_path, '/'); }
|
|
|
|
virtual Common::String getPath() const { return _path; }
|
2008-04-05 23:30:12 +00:00
|
|
|
virtual bool isDirectory() const { return false; }
|
2008-02-03 17:02:51 +00:00
|
|
|
virtual bool isReadable() const { return true; }
|
|
|
|
virtual bool isWritable() const { return false; }
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual AbstractFSNode *getChild(const Common::String &n) const { return NULL; }
|
2008-04-05 23:30:12 +00:00
|
|
|
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const { return false; }
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual AbstractFSNode *getParent() const;
|
2008-04-05 23:30:12 +00:00
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
virtual Common::SeekableReadStream *createReadStream();
|
|
|
|
virtual Common::WriteStream *createWriteStream() { return 0; }
|
2008-09-03 12:56:46 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
static AbstractFSNode *makeFileNodePath(const Common::String &path);
|
2008-04-05 23:30:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A directory */
|
|
|
|
class RoninCDDirectoryNode : public RoninCDFileNode {
|
|
|
|
public:
|
2008-09-03 11:22:51 +00:00
|
|
|
RoninCDDirectoryNode(const Common::String &path) : RoninCDFileNode(path) {};
|
2008-04-05 23:30:12 +00:00
|
|
|
|
|
|
|
virtual bool isDirectory() const { return true; }
|
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;
|
2009-01-23 03:41:36 +00:00
|
|
|
virtual Common::SeekableReadStream *createReadStream() { return 0; }
|
2008-04-05 23:30:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A file/directory which does not exist */
|
|
|
|
class RoninCDNonexistingNode : public RoninCDFileNode {
|
|
|
|
public:
|
2008-09-03 11:22:51 +00:00
|
|
|
RoninCDNonexistingNode(const Common::String &path) : RoninCDFileNode(path) {};
|
2008-04-05 23:30:12 +00:00
|
|
|
|
|
|
|
virtual bool exists() const { return false; }
|
|
|
|
virtual bool isReadable() const { return false; }
|
2009-01-23 03:41:36 +00:00
|
|
|
virtual Common::SeekableReadStream *createReadStream() { return 0; }
|
2006-06-03 14:09:04 +00:00
|
|
|
};
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *RoninCDFileNode::makeFileNodePath(const Common::String &path) {
|
2008-04-05 23:30:12 +00:00
|
|
|
assert(path.size() > 0);
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
int fd;
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
if ((fd = open(path.c_str(), O_RDONLY)) >= 0) {
|
|
|
|
close(fd);
|
|
|
|
return new RoninCDFileNode(path);
|
2008-08-22 11:17:12 +00:00
|
|
|
} else if ((fd = open(path.c_str(), O_DIR|O_RDONLY)) >= 0) {
|
2008-04-05 23:30:12 +00:00
|
|
|
close(fd);
|
2009-01-01 15:06:43 +00:00
|
|
|
return new RoninCDDirectoryNode(path);
|
2008-08-22 11:17:12 +00:00
|
|
|
} else {
|
2008-04-05 23:30:12 +00:00
|
|
|
return NULL;
|
2006-06-03 14:09:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *RoninCDDirectoryNode::getChild(const Common::String &n) const {
|
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;
|
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
return makeFileNodePath(newPath);
|
2007-05-03 02:39:33 +00:00
|
|
|
}
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
bool RoninCDDirectoryNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
DIR *dirp = opendir(_path.c_str());
|
2006-06-03 14:09:04 +00:00
|
|
|
struct dirent *dp;
|
|
|
|
|
|
|
|
if (dirp == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// ... loop over dir entries using readdir
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::String newPath(_path);
|
2006-06-03 14:09:04 +00:00
|
|
|
if (newPath.lastChar() != '/')
|
|
|
|
newPath += '/';
|
|
|
|
newPath += dp->d_name;
|
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
if (dp->d_size < 0) {
|
|
|
|
// Honor the chosen mode
|
2008-10-02 16:58:59 +00:00
|
|
|
if (mode == Common::FSNode::kListFilesOnly)
|
2008-04-05 23:30:12 +00:00
|
|
|
continue;
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
myList.push_back(new RoninCDDirectoryNode(newPath+"/"));
|
|
|
|
} else {
|
|
|
|
// Honor the chosen mode
|
2008-10-02 16:58:59 +00:00
|
|
|
if (mode == Common::FSNode::kListDirectoriesOnly)
|
2008-04-05 23:30:12 +00:00
|
|
|
continue;
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-04-05 23:30:12 +00:00
|
|
|
myList.push_back(new RoninCDFileNode(newPath));
|
|
|
|
}
|
2006-06-03 14:09:04 +00:00
|
|
|
}
|
|
|
|
closedir(dirp);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-06-03 14:09:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *RoninCDFileNode::getParent() const {
|
2006-06-03 14:09:04 +00:00
|
|
|
if (_path == "/")
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const char *start = _path.c_str();
|
2008-08-27 20:31:22 +00:00
|
|
|
const char *end = lastPathComponent(_path, '/');
|
2006-06-03 14:09:04 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
return new RoninCDDirectoryNode(Common::String(start, end - start));
|
2006-06-03 14:09:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 12:56:46 +00:00
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::SeekableReadStream *RoninCDFileNode::createReadStream() {
|
2008-09-03 12:56:46 +00:00
|
|
|
return StdioStream::makeFromPath(getPath().c_str(), false);
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *OSystem_Dreamcast::makeRootFileNode() const {
|
2008-04-05 23:30:12 +00:00
|
|
|
return new RoninCDDirectoryNode("/");
|
2008-03-01 17:48:42 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *OSystem_Dreamcast::makeCurrentDirectoryFileNode() const {
|
2008-04-05 23:30:12 +00:00
|
|
|
return makeRootFileNode();
|
2008-03-01 17:48:42 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *OSystem_Dreamcast::makeFileNodePath(const Common::String &path) const {
|
|
|
|
AbstractFSNode *node = RoninCDFileNode::makeFileNodePath(path);
|
2008-04-05 23:30:12 +00:00
|
|
|
return (node? node : new RoninCDNonexistingNode(path));
|
2008-03-01 17:48:42 +00:00
|
|
|
}
|
2008-04-05 23:30:12 +00:00
|
|
|
|