2005-05-09 18:58:19 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// Copyright (c) 1995-2010 by Bradford W. Mott and the Stella Team
|
2005-05-09 18:58:19 +00:00
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
2005-05-09 18:58:19 +00:00
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2009-05-13 13:55:40 +00:00
|
|
|
// $Id$
|
2005-05-09 18:58:19 +00:00
|
|
|
//
|
|
|
|
// Based on code from ScummVM - Scumm Interpreter
|
|
|
|
// Copyright (C) 2002-2004 The ScummVM project
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include "bspf.hxx"
|
2009-01-11 19:10:40 +00:00
|
|
|
#include "SharedPtr.hxx"
|
2007-09-03 18:37:24 +00:00
|
|
|
#include "FSNode.hxx"
|
2005-05-09 18:58:19 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
FilesystemNode::FilesystemNode()
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode)
|
|
|
|
: _realNode(realNode)
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
FilesystemNode::FilesystemNode(const string& p)
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
2009-01-16 14:57:53 +00:00
|
|
|
AbstractFilesystemNode* tmp = 0;
|
2009-01-11 19:10:40 +00:00
|
|
|
if (p.empty() || p == ".")
|
|
|
|
tmp = AbstractFilesystemNode::makeCurrentDirectoryFileNode();
|
2009-01-16 14:57:53 +00:00
|
|
|
else if (p == "~")
|
|
|
|
tmp = AbstractFilesystemNode::makeHomeDirectoryFileNode();
|
2009-01-11 19:10:40 +00:00
|
|
|
else
|
|
|
|
tmp = AbstractFilesystemNode::makeFileNodePath(p);
|
2005-05-09 18:58:19 +00:00
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
_realNode = Common::SharedPtr<AbstractFilesystemNode>(tmp);
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
bool FilesystemNode::operator<(const FilesystemNode& node) const
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
if (isDirectory() != node.isDirectory())
|
|
|
|
return isDirectory();
|
|
|
|
|
|
|
|
return BSPF_strcasecmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0;
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
bool FilesystemNode::exists() const
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->exists();
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
bool FilesystemNode::getChildren(FSList& fslist, ListMode mode, bool hidden) const
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
if (!_realNode || !_realNode->isDirectory())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AbstractFSList tmp;
|
|
|
|
|
|
|
|
if (!_realNode->getChildren(tmp, mode, hidden))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fslist.clear();
|
|
|
|
for (AbstractFSList::iterator i = tmp.begin(); i != tmp.end(); ++i)
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
fslist.push_back(FilesystemNode(*i));
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
2009-01-11 19:10:40 +00:00
|
|
|
|
|
|
|
return true;
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
string FilesystemNode::getDisplayName() const
|
2005-05-09 18:58:19 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
assert(_realNode);
|
|
|
|
return _realNode->getDisplayName();
|
|
|
|
}
|
2005-05-09 18:58:19 +00:00
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
string FilesystemNode::getName() const
|
|
|
|
{
|
|
|
|
assert(_realNode);
|
|
|
|
return _realNode->getName();
|
|
|
|
}
|
2005-05-09 18:58:19 +00:00
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::hasParent() const
|
|
|
|
{
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->getParent() != 0;
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
FilesystemNode FilesystemNode::getParent() const
|
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
if (_realNode == 0)
|
|
|
|
return *this;
|
2005-05-09 18:58:19 +00:00
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
AbstractFilesystemNode* node = _realNode->getParent();
|
|
|
|
if (node == 0)
|
2005-05-09 18:58:19 +00:00
|
|
|
return *this;
|
|
|
|
else
|
2009-01-11 19:10:40 +00:00
|
|
|
return FilesystemNode(node);
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
2006-03-19 22:06:20 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-01-11 19:10:40 +00:00
|
|
|
string FilesystemNode::getPath() const
|
2006-03-19 22:06:20 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
assert(_realNode);
|
|
|
|
return _realNode->getPath();
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:07:51 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
string FilesystemNode::getRelativePath() const
|
|
|
|
{
|
|
|
|
assert(_realNode);
|
|
|
|
return _realNode->getRelativePath();
|
|
|
|
}
|
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isDirectory() const
|
|
|
|
{
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->isDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isReadable() const
|
|
|
|
{
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->isReadable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isWritable() const
|
|
|
|
{
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->isWritable();
|
2006-03-19 22:06:20 +00:00
|
|
|
}
|