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
|
|
|
|
//
|
2013-01-04 19:49:01 +00:00
|
|
|
// Copyright (c) 1995-2013 by Bradford W. Mott, Stephen Anthony
|
2010-04-10 21:37:23 +00:00
|
|
|
// 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
|
|
|
{
|
2012-06-14 21:26:38 +00:00
|
|
|
AbstractFilesystemNode* tmp = AbstractFilesystemNode::makeFileNodePath(p);
|
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
|
|
|
}
|
|
|
|
|
2013-01-29 21:12:37 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::operator==(const FilesystemNode& node) const
|
|
|
|
{
|
|
|
|
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;
|
2012-04-15 21:39:15 +00:00
|
|
|
tmp.reserve(fslist.capacity());
|
2009-01-11 19:10:40 +00:00
|
|
|
|
|
|
|
if (!_realNode->getChildren(tmp, mode, hidden))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (AbstractFSList::iterator i = tmp.begin(); i != tmp.end(); ++i)
|
|
|
|
fslist.push_back(FilesystemNode(*i));
|
|
|
|
|
|
|
|
return true;
|
2005-05-09 18:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-12-22 22:11:09 +00:00
|
|
|
const 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
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-12-22 22:11:09 +00:00
|
|
|
const string& FilesystemNode::getName() const
|
2009-01-11 19:10:40 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2011-12-22 22:11:09 +00:00
|
|
|
const string& FilesystemNode::getPath() const
|
2006-03-19 22:06:20 +00:00
|
|
|
{
|
2009-01-11 19:10:40 +00:00
|
|
|
assert(_realNode);
|
2011-12-22 21:29:24 +00:00
|
|
|
return _realNode->getPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
string FilesystemNode::getRelativePath() const
|
|
|
|
{
|
|
|
|
assert(_realNode);
|
|
|
|
return _realNode->getRelativePath();
|
2009-06-18 13:07:51 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isDirectory() const
|
|
|
|
{
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->isDirectory();
|
|
|
|
}
|
|
|
|
|
2012-05-16 20:52:33 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isFile() const
|
|
|
|
{
|
|
|
|
if (_realNode == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _realNode->isFile();
|
|
|
|
}
|
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
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
|
|
|
}
|