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
|
|
|
|
2004-12-18 02:33:37 +00:00
|
|
|
#include "backends/fs/fs.h"
|
|
|
|
#include "common/util.h"
|
|
|
|
|
2006-04-07 11:47:58 +00:00
|
|
|
|
|
|
|
static AbstractFilesystemNode *_rootNode = 0;
|
|
|
|
static int *_rootRefCount = 0;
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
FilesystemNode AbstractFilesystemNode::wrap(AbstractFilesystemNode *node) {
|
2006-04-03 21:54:26 +00:00
|
|
|
FilesystemNode wrapper(node);
|
2004-11-20 21:35:49 +00:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
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-04-07 11:47:58 +00:00
|
|
|
if (_rootNode == 0) {
|
|
|
|
_rootNode = getRoot();
|
|
|
|
_rootRefCount = new int(1);
|
|
|
|
}
|
|
|
|
_realNode = _rootNode;
|
|
|
|
_refCount = _rootRefCount;
|
|
|
|
++(*_refCount);
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FilesystemNode::FilesystemNode(const FilesystemNode &node)
|
|
|
|
: AbstractFilesystemNode() {
|
|
|
|
_realNode = node._realNode;
|
|
|
|
_refCount = node._refCount;
|
|
|
|
++(*_refCount);
|
|
|
|
}
|
|
|
|
|
2006-04-03 21:54:26 +00:00
|
|
|
FilesystemNode::FilesystemNode(const Common::String &p) {
|
2004-11-20 21:35:49 +00:00
|
|
|
_realNode = getNodeForPath(p);
|
|
|
|
_refCount = new int(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
FilesystemNode::~FilesystemNode() {
|
|
|
|
decRefCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilesystemNode::decRefCount() {
|
|
|
|
--(*_refCount);
|
|
|
|
if (*_refCount <= 0) {
|
|
|
|
delete _refCount;
|
|
|
|
delete _realNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
|
|
|
|
++(*node._refCount);
|
|
|
|
|
|
|
|
decRefCount();
|
|
|
|
|
|
|
|
_realNode = node._realNode;
|
|
|
|
_refCount = node._refCount;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2004-11-21 13:18:07 +00:00
|
|
|
return AbstractFilesystemNode::wrap(node);
|
|
|
|
}
|
2004-11-20 21:35:49 +00:00
|
|
|
}
|
2006-04-03 21:54:26 +00:00
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
FilesystemNode FilesystemNode::getChild(const String &name) const {
|
|
|
|
if (_realNode == 0)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
assert(_realNode->isDirectory());
|
|
|
|
AbstractFilesystemNode *node = _realNode->child(name);
|
|
|
|
return AbstractFilesystemNode::wrap(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
FSList FilesystemNode::listDir(ListMode mode) const {
|
|
|
|
assert(_realNode);
|
|
|
|
assert(_realNode->isDirectory());
|
|
|
|
return _realNode->listDir(mode);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FilesystemNode::isValid() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
2006-04-03 21:54:26 +00:00
|
|
|
return _realNode->isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FilesystemNode::isDirectory() const {
|
2006-04-30 22:52:10 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
2006-04-03 21:54:26 +00:00
|
|
|
return _realNode->isDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|