Since we do ref counting on the nodes now, we can re-use the root nodes now

svn-id: r15851
This commit is contained in:
Max Horn 2004-11-21 13:18:07 +00:00
parent eb44281ecb
commit 01cb15b9b2
6 changed files with 40 additions and 31 deletions

View file

@ -72,7 +72,10 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
}
FilesystemNode FilesystemNode::getParent() const {
FilesystemNode wrapper;
wrapper._realNode = _realNode->parent();
return wrapper;
AbstractFilesystemNode *node = _realNode->parent();
if (node == 0)
return *this;
else {
return AbstractFilesystemNode::wrap(node);
}
}

View file

@ -139,6 +139,17 @@ public:
{
return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
}
/* TODO:
bool exists();
bool isDirectory();
bool isFile();
bool isReadable();
bool isWriteable();
*/
};
class FilesystemNode : public AbstractFilesystemNode {

View file

@ -207,18 +207,15 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const
if (!_isDirectory)
error("parent() called on file node");
if (_lock == NULL)
if (_lock == NULL) {
/* Parent of the root is the root itself */
node = clone();
else
{
node = 0;
} else {
BPTR parent_lock = ParentDir(_lock);
if (parent_lock)
{
if (parent_lock) {
node = new ABoxFilesystemNode(parent_lock);
UnLock(parent_lock);
}
else
} else
node = new ABoxFilesystemNode();
}

View file

@ -136,13 +136,13 @@ const char *lastPathComponent(const Common::String &str) {
}
AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
PalmOSFilesystemNode *p = new PalmOSFilesystemNode();
PalmOSFilesystemNode *p = 0;
if (!_isPseudoRoot) {
const char *start = _path.c_str();
const char *end = lastPathComponent(_path);
p = new PalmOSFilesystemNode();
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;

View file

@ -185,22 +185,19 @@ FSList POSIXFilesystemNode::listDir(ListMode mode) const {
}
AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
POSIXFilesystemNode *p = new POSIXFilesystemNode();
if (_path == "/")
return 0;
// Root node is its own parent. Still we can't just return this
// as the GUI code will call delete on the old node.
if (_path != "/") {
POSIXFilesystemNode *p = new POSIXFilesystemNode();
const char *start = _path.c_str();
const char *end = lastPathComponent(_path);
p->_path = String(start, end - start);
p->_displayName = lastPathComponent(p->_path);
} else {
p->_path = _path;
p->_displayName = _displayName;
}
p->_isValid = true;
p->_isDirectory = true;
return p;
}

View file

@ -197,11 +197,12 @@ const char *lastPathComponent(const Common::String &str) {
AbstractFilesystemNode *WindowsFilesystemNode::parent() const {
assert(_isValid || _isPseudoRoot);
WindowsFilesystemNode *p = new WindowsFilesystemNode();
WindowsFilesystemNode *p = 0;
if (!_isPseudoRoot && _path.size() > 3) {
const char *start = _path.c_str();
const char *end = lastPathComponent(_path);
p = new WindowsFilesystemNode();
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;