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:
parent
eb44281ecb
commit
01cb15b9b2
6 changed files with 40 additions and 31 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -38,7 +38,7 @@ class ABoxFilesystemNode : public AbstractFilesystemNode {
|
|||
bool _isDirectory;
|
||||
bool _isValid;
|
||||
String _path;
|
||||
|
||||
|
||||
public:
|
||||
ABoxFilesystemNode();
|
||||
ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL);
|
||||
|
@ -140,7 +140,7 @@ ABoxFilesystemNode::~ABoxFilesystemNode()
|
|||
FSList ABoxFilesystemNode::listDir(ListMode mode) const
|
||||
{
|
||||
FSList myList;
|
||||
|
||||
|
||||
if (!_isValid)
|
||||
error("listDir() called on invalid node");
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
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;
|
||||
|
|
|
@ -185,22 +185,19 @@ FSList POSIXFilesystemNode::listDir(ListMode mode) const {
|
|||
}
|
||||
|
||||
AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
|
||||
if (_path == "/")
|
||||
return 0;
|
||||
|
||||
POSIXFilesystemNode *p = new POSIXFilesystemNode();
|
||||
const char *start = _path.c_str();
|
||||
const char *end = lastPathComponent(_path);
|
||||
|
||||
// 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 != "/") {
|
||||
const char *start = _path.c_str();
|
||||
const char *end = lastPathComponent(_path);
|
||||
p->_path = String(start, end - start);
|
||||
p->_displayName = lastPathComponent(p->_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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue