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
|
|
|
|
//============================================================================
|
|
|
|
|
2013-02-13 23:09:31 +00:00
|
|
|
#include <zlib.h>
|
|
|
|
|
2005-05-09 18:58:19 +00:00
|
|
|
#include "bspf.hxx"
|
2009-01-11 19:10:40 +00:00
|
|
|
#include "SharedPtr.hxx"
|
2013-02-10 21:47:47 +00:00
|
|
|
#include "FSNodeFactory.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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2013-02-10 21:47:47 +00:00
|
|
|
FilesystemNode::FilesystemNode(AbstractFSNode *realNode)
|
2009-01-11 19:10:40 +00:00
|
|
|
: _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
|
|
|
{
|
2013-02-10 21:47:47 +00:00
|
|
|
AbstractFSNode* tmp = 0;
|
|
|
|
|
|
|
|
// Is this potentially a ZIP archive?
|
|
|
|
if(BSPF_containsIgnoreCase(p, ".zip"))
|
|
|
|
tmp = FilesystemNodeFactory::create(p, FilesystemNodeFactory::ZIP);
|
|
|
|
else
|
|
|
|
tmp = FilesystemNodeFactory::create(p, FilesystemNodeFactory::SYSTEM);
|
|
|
|
|
|
|
|
_realNode = Common::SharedPtr<AbstractFSNode>(tmp);
|
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
|
|
|
{
|
2013-02-02 18:34:25 +00:00
|
|
|
return _realNode ? _realNode->exists() : false;
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2013-02-02 18:34:25 +00:00
|
|
|
return _realNode ? (_realNode->getParent() != 0) : false;
|
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
|
|
|
|
2013-02-10 21:47:47 +00:00
|
|
|
AbstractFSNode* node = _realNode->getParent();
|
2013-05-03 10:45:49 +00:00
|
|
|
return (node == 0) ? *this : 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
|
|
|
{
|
2011-12-22 21:29:24 +00:00
|
|
|
return _realNode->getPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2013-02-03 00:13:08 +00:00
|
|
|
string FilesystemNode::getShortPath() const
|
2011-12-22 21:29:24 +00:00
|
|
|
{
|
2013-02-03 00:13:08 +00:00
|
|
|
return _realNode->getShortPath();
|
2009-06-18 13:07:51 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isDirectory() const
|
|
|
|
{
|
2013-02-02 18:34:25 +00:00
|
|
|
return _realNode ? _realNode->isDirectory() : false;
|
2009-01-11 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 20:52:33 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isFile() const
|
|
|
|
{
|
2013-02-02 18:34:25 +00:00
|
|
|
return _realNode ? _realNode->isFile() : false;
|
2012-05-16 20:52:33 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 19:10:40 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isReadable() const
|
|
|
|
{
|
2013-02-02 18:34:25 +00:00
|
|
|
return _realNode ? _realNode->isReadable() : false;
|
2009-01-11 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isWritable() const
|
|
|
|
{
|
2013-02-02 18:34:25 +00:00
|
|
|
return _realNode ? _realNode->isWritable() : false;
|
|
|
|
}
|
2009-01-11 19:10:40 +00:00
|
|
|
|
2013-02-03 00:13:08 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::isAbsolute() const
|
|
|
|
{
|
|
|
|
return _realNode ? _realNode->isAbsolute() : false;
|
|
|
|
}
|
|
|
|
|
2013-02-02 18:34:25 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::makeDir()
|
|
|
|
{
|
|
|
|
return (_realNode && !_realNode->exists()) ? _realNode->makeDir() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::rename(const string& newfile)
|
|
|
|
{
|
|
|
|
return (_realNode && _realNode->exists()) ? _realNode->rename(newfile) : false;
|
2006-03-19 22:06:20 +00:00
|
|
|
}
|
2013-02-03 00:13:08 +00:00
|
|
|
|
2013-02-13 23:09:31 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool FilesystemNode::read(uInt8*& image, uInt32& size) const
|
|
|
|
{
|
|
|
|
// First let the private subclass attempt to open the file
|
|
|
|
if(_realNode->read(image, size))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Otherwise, assume the file is either gzip'ed or not compressed at all
|
|
|
|
gzFile f = gzopen(getPath().c_str(), "rb");
|
|
|
|
if(f)
|
|
|
|
{
|
|
|
|
image = new uInt8[512 * 1024];
|
|
|
|
size = gzread(f, image, 512 * 1024);
|
|
|
|
gzclose(f);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-03 00:13:08 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
string FilesystemNode::createAbsolutePath(
|
|
|
|
const string& p, const string& startpath, const string& ext)
|
|
|
|
{
|
|
|
|
FilesystemNode node(p);
|
|
|
|
string path = node.getShortPath();
|
|
|
|
|
|
|
|
// Is path already absolute, or does it start with the given startpath?
|
|
|
|
// If not, we prepend the given startpath
|
|
|
|
if(!BSPF_startsWithIgnoreCase(p, startpath+BSPF_PATH_SEPARATOR) &&
|
|
|
|
!node.isAbsolute())
|
|
|
|
path = startpath + BSPF_PATH_SEPARATOR + p;
|
|
|
|
|
|
|
|
// Does the path have a valid extension?
|
|
|
|
// If not, we append the given extension
|
|
|
|
string::size_type idx = path.find_last_of('.');
|
|
|
|
if(idx != string::npos)
|
|
|
|
{
|
|
|
|
if(!BSPF_equalsIgnoreCase(path.c_str() + idx + 1, ext))
|
|
|
|
path = path.replace(idx+1, ext.length(), ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
path += "." + ext;
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|