2004-11-20 21:35:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2002-2006 The ScummVM project
|
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
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2004-11-20 21:35:49 +00:00
|
|
|
|
2006-05-03 10:14:05 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
2004-12-18 02:33:37 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
2006-04-07 11:47:58 +00:00
|
|
|
|
2006-04-03 21:54:26 +00:00
|
|
|
FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) {
|
|
|
|
_realNode = realNode;
|
|
|
|
_refCount = new int(1);
|
|
|
|
}
|
2004-11-20 21:35:49 +00:00
|
|
|
|
|
|
|
FilesystemNode::FilesystemNode() {
|
2006-05-12 21:41:54 +00:00
|
|
|
_realNode = 0;
|
|
|
|
_refCount = 0;
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 10:14:05 +00:00
|
|
|
FilesystemNode::FilesystemNode(const FilesystemNode &node) {
|
2004-11-20 21:35:49 +00:00
|
|
|
_realNode = node._realNode;
|
|
|
|
_refCount = node._refCount;
|
2006-05-12 21:41:54 +00:00
|
|
|
if (_refCount)
|
|
|
|
++(*_refCount);
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 21:54:26 +00:00
|
|
|
FilesystemNode::FilesystemNode(const Common::String &p) {
|
2006-05-12 21:41:54 +00:00
|
|
|
if (p.empty() || p == ".")
|
|
|
|
_realNode = AbstractFilesystemNode::getCurrentDirectory();
|
|
|
|
else
|
|
|
|
_realNode = AbstractFilesystemNode::getNodeForPath(p);
|
2004-11-20 21:35:49 +00:00
|
|
|
_refCount = new int(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
FilesystemNode::~FilesystemNode() {
|
|
|
|
decRefCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilesystemNode::decRefCount() {
|
2006-05-12 21:41:54 +00:00
|
|
|
if (_refCount) {
|
|
|
|
assert(*_refCount > 0);
|
|
|
|
--(*_refCount);
|
|
|
|
if (*_refCount == 0) {
|
|
|
|
delete _refCount;
|
|
|
|
delete _realNode;
|
|
|
|
}
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
|
2006-05-12 21:41:54 +00:00
|
|
|
if (node._refCount)
|
|
|
|
++(*node._refCount);
|
2004-11-20 21:35:49 +00:00
|
|
|
|
|
|
|
decRefCount();
|
|
|
|
|
|
|
|
_realNode = node._realNode;
|
|
|
|
_refCount = node._refCount;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2006-07-22 17:01:50 +00:00
|
|
|
bool FilesystemNode::isValid() const {
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
return _realNode->isValid();
|
|
|
|
}
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
FilesystemNode FilesystemNode::getParent() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return *this;
|
|
|
|
|
2004-11-21 13:18:07 +00:00
|
|
|
AbstractFilesystemNode *node = _realNode->parent();
|
2004-11-29 11:14:12 +00:00
|
|
|
if (node == 0) {
|
2004-11-21 13:18:07 +00:00
|
|
|
return *this;
|
2004-11-29 11:14:12 +00:00
|
|
|
} else {
|
2006-05-03 11:13:21 +00:00
|
|
|
return FilesystemNode(node);
|
2004-11-21 13:18:07 +00:00
|
|
|
}
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
2006-04-03 21:54:26 +00:00
|
|
|
|
2006-07-22 14:14:16 +00:00
|
|
|
FilesystemNode FilesystemNode::getChild(const String &n) const {
|
2006-04-30 22:52:10 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
assert(_realNode->isDirectory());
|
2006-07-22 14:14:16 +00:00
|
|
|
AbstractFilesystemNode *node = _realNode->child(n);
|
2006-05-03 11:13:21 +00:00
|
|
|
return FilesystemNode(node);
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const {
|
|
|
|
if (!_realNode || !_realNode->isDirectory())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AbstractFSList tmp;
|
|
|
|
|
|
|
|
if (!_realNode->listDir(tmp, mode))
|
|
|
|
return false;
|
2006-05-03 11:13:21 +00:00
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
fslist.clear();
|
|
|
|
for (AbstractFSList::iterator i = tmp.begin(); i != tmp.end(); ++i) {
|
|
|
|
fslist.push_back(FilesystemNode(*i));
|
2006-05-03 11:13:21 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
return true;
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 14:14:16 +00:00
|
|
|
bool FilesystemNode::isDirectory() const {
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
return _realNode->isDirectory();
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:54:26 +00:00
|
|
|
Common::String FilesystemNode::displayName() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
assert(_realNode);
|
2006-04-03 21:54:26 +00:00
|
|
|
return _realNode->displayName();
|
|
|
|
}
|
|
|
|
|
2006-07-22 14:14:16 +00:00
|
|
|
Common::String FilesystemNode::name() const {
|
|
|
|
assert(_realNode);
|
|
|
|
return _realNode->name();
|
2006-04-03 21:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::String FilesystemNode::path() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
assert(_realNode);
|
2006-04-03 21:54:26 +00:00
|
|
|
return _realNode->path();
|
|
|
|
}
|
2006-05-03 10:14:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool FilesystemNode::operator< (const FilesystemNode& node) const
|
|
|
|
{
|
|
|
|
if (isDirectory() && !node.isDirectory())
|
|
|
|
return true;
|
|
|
|
if (!isDirectory() && node.isDirectory())
|
|
|
|
return false;
|
|
|
|
return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
|
|
|
|
}
|