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.
|
2004-11-20 21:35:49 +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.
|
2004-11-20 21:35:49 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-11-20 21:35:49 +00:00
|
|
|
*/
|
|
|
|
|
2004-12-18 02:33:37 +00:00
|
|
|
#include "common/util.h"
|
2008-02-23 23:03:08 +00:00
|
|
|
#include "common/system.h"
|
2007-05-12 20:00:52 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
2008-02-23 19:01:12 +00:00
|
|
|
#include "backends/fs/fs-factory.h"
|
2004-12-18 02:33:37 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
namespace Common {
|
2008-08-03 18:35:51 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
FSNode::FSNode() {
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 11:22:15 +00:00
|
|
|
FSNode::FSNode(AbstractFSNode *realNode)
|
2008-03-29 21:12:36 +00:00
|
|
|
: _realNode(realNode) {
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
FSNode::FSNode(const Common::String &p) {
|
2009-01-29 22:09:06 +00:00
|
|
|
assert(g_system);
|
2008-02-23 23:03:08 +00:00
|
|
|
FilesystemFactory *factory = g_system->getFilesystemFactory();
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *tmp = 0;
|
2008-12-22 11:22:15 +00:00
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
if (p.empty() || p == ".")
|
2008-03-29 21:12:36 +00:00
|
|
|
tmp = factory->makeCurrentDirectoryFileNode();
|
2006-05-12 21:41:54 +00:00
|
|
|
else
|
2008-03-29 21:12:36 +00:00
|
|
|
tmp = factory->makeFileNodePath(p);
|
2008-10-02 16:58:59 +00:00
|
|
|
_realNode = Common::SharedPtr<AbstractFSNode>(tmp);
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FSNode::operator<(const FSNode& node) const {
|
2008-02-20 21:49:05 +00:00
|
|
|
if (isDirectory() != node.isDirectory())
|
|
|
|
return isDirectory();
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-08-27 20:41:28 +00:00
|
|
|
return getDisplayName().compareToIgnoreCase(node.getDisplayName()) < 0;
|
2006-07-22 17:01:50 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FSNode::exists() const {
|
2007-06-05 21:02:35 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-05 21:02:35 +00:00
|
|
|
return _realNode->exists();
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
FSNode FSNode::getChild(const Common::String &n) const {
|
2008-09-07 21:47:01 +00:00
|
|
|
// If this node is invalid or not a directory, return an invalid node
|
2008-09-07 21:51:59 +00:00
|
|
|
if (_realNode == 0 || !_realNode->isDirectory())
|
2008-10-02 16:58:59 +00:00
|
|
|
return FSNode();
|
2006-04-30 22:52:10 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *node = _realNode->getChild(n);
|
|
|
|
return FSNode(node);
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FSNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const {
|
2006-05-03 20:43:26 +00:00
|
|
|
if (!_realNode || !_realNode->isDirectory())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AbstractFSList tmp;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-17 17:17:38 +00:00
|
|
|
if (!_realNode->getChildren(tmp, mode, hidden))
|
2006-05-03 20:43:26 +00:00
|
|
|
return false;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
fslist.clear();
|
|
|
|
for (AbstractFSList::iterator i = tmp.begin(); i != tmp.end(); ++i) {
|
2008-10-02 16:58:59 +00:00
|
|
|
fslist.push_back(FSNode(*i));
|
2006-05-03 11:13:21 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
return true;
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::String FSNode::getDisplayName() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
assert(_realNode);
|
2007-05-03 02:39:33 +00:00
|
|
|
return _realNode->getDisplayName();
|
2006-04-03 21:54:26 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::String FSNode::getName() const {
|
2006-07-22 14:14:16 +00:00
|
|
|
assert(_realNode);
|
2007-05-03 02:39:33 +00:00
|
|
|
return _realNode->getName();
|
2006-04-03 21:54:26 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
FSNode FSNode::getParent() const {
|
2007-06-05 21:02:35 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return *this;
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
AbstractFSNode *node = _realNode->getParent();
|
2007-06-05 21:02:35 +00:00
|
|
|
if (node == 0) {
|
|
|
|
return *this;
|
|
|
|
} else {
|
2008-10-02 16:58:59 +00:00
|
|
|
return FSNode(node);
|
2007-06-05 21:02:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::String FSNode::getPath() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
assert(_realNode);
|
2007-05-03 02:39:33 +00:00
|
|
|
return _realNode->getPath();
|
2006-04-03 21:54:26 +00:00
|
|
|
}
|
2006-05-03 10:14:05 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FSNode::isDirectory() const {
|
2006-07-22 14:14:16 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-07-22 14:14:16 +00:00
|
|
|
return _realNode->isDirectory();
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FSNode::isReadable() const {
|
2007-06-05 21:02:35 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-05 21:02:35 +00:00
|
|
|
return _realNode->isReadable();
|
2006-04-03 21:54:26 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FSNode::isWritable() const {
|
2007-06-05 21:02:35 +00:00
|
|
|
if (_realNode == 0)
|
2006-05-03 10:14:05 +00:00
|
|
|
return false;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-05 21:02:35 +00:00
|
|
|
return _realNode->isWritable();
|
2006-04-03 21:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::SeekableReadStream *FSNode::createReadStream() const {
|
2008-08-03 18:35:51 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return 0;
|
2008-09-03 10:40:46 +00:00
|
|
|
|
|
|
|
if (!_realNode->exists()) {
|
2009-01-23 03:41:36 +00:00
|
|
|
warning("FSNode::createReadStream: FSNode does not exist");
|
2008-09-03 10:40:46 +00:00
|
|
|
return false;
|
|
|
|
} else if (_realNode->isDirectory()) {
|
2009-01-23 03:41:36 +00:00
|
|
|
warning("FSNode::createReadStream: FSNode is a directory");
|
2008-09-03 10:40:46 +00:00
|
|
|
return false;
|
2008-08-03 18:35:51 +00:00
|
|
|
}
|
2008-09-03 10:40:46 +00:00
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
return _realNode->createReadStream();
|
2008-08-03 18:35:51 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
Common::WriteStream *FSNode::createWriteStream() const {
|
2008-08-03 18:35:51 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return 0;
|
2008-09-03 10:40:46 +00:00
|
|
|
|
|
|
|
if (_realNode->isDirectory()) {
|
2009-01-23 03:41:36 +00:00
|
|
|
warning("FSNode::createWriteStream: FSNode is a directory");
|
2008-09-03 10:40:46 +00:00
|
|
|
return 0;
|
2008-08-03 18:35:51 +00:00
|
|
|
}
|
2008-09-03 10:40:46 +00:00
|
|
|
|
2009-01-23 03:41:36 +00:00
|
|
|
return _realNode->createWriteStream();
|
2008-08-03 18:35:51 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
} // End of namespace Common
|