2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2005-05-10 00:58:08 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-05-10 00:58:08 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-05-10 00:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(__amigaos4__)
|
|
|
|
#ifdef __USE_INLINE__
|
|
|
|
#undef __USE_INLINE__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifndef USE_NEWLIB
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
#include "common/util.h"
|
2006-09-23 00:42:35 +00:00
|
|
|
#include "engines/engine.h"
|
2006-05-03 10:14:05 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-04-14 01:06:08 +00:00
|
|
|
#define ENTER() /* debug(6, "Enter") */
|
|
|
|
#define LEAVE() /* debug(6, "Leave") */
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
const uint32 kExAllBufferSize = 40960; // TODO: is this okay for sure?
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Implementation of the ScummVM file system API.
|
|
|
|
*
|
|
|
|
* Parts of this class are documented in the base interface class, AbstractFilesystemNode.
|
|
|
|
*/
|
2005-05-10 00:58:08 +00:00
|
|
|
class AmigaOSFilesystemNode : public AbstractFilesystemNode {
|
2007-05-03 02:39:33 +00:00
|
|
|
protected:
|
|
|
|
BPTR _pFileLock;
|
|
|
|
String _sDisplayName;
|
|
|
|
String _sPath;
|
|
|
|
bool _bIsDirectory;
|
|
|
|
bool _bIsValid;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a AmigaOSFilesystemNode with the root node as path.
|
|
|
|
*/
|
|
|
|
AmigaOSFilesystemNode();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a AmigaOSFilesystemNode for a given path.
|
|
|
|
*
|
|
|
|
* @param path String with the path the new node should point to.
|
|
|
|
*/
|
|
|
|
AmigaOSFilesystemNode(const String &p);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FIXME: document this constructor.
|
|
|
|
*/
|
|
|
|
AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
*
|
|
|
|
* @note Needed because it duplicates the file lock
|
|
|
|
*/
|
|
|
|
AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~AmigaOSFilesystemNode();
|
|
|
|
|
2007-10-30 21:31:39 +00:00
|
|
|
virtual bool exists() const;
|
2007-05-03 02:39:33 +00:00
|
|
|
virtual String getDisplayName() const { return _sDisplayName; };
|
|
|
|
virtual String getName() const { return _sDisplayName; };
|
|
|
|
virtual String getPath() const { return _sPath; };
|
|
|
|
virtual bool isDirectory() const { return _bIsDirectory; };
|
2007-06-04 22:02:35 +00:00
|
|
|
virtual bool isReadable() const { return true; } //FIXME: this is just a stub
|
|
|
|
virtual bool isWritable() const { return true; } //FIXME: this is just a stub
|
2007-05-03 02:39:33 +00:00
|
|
|
|
|
|
|
virtual AbstractFilesystemNode *getChild(const String &n) const;
|
2007-07-09 01:26:54 +00:00
|
|
|
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
|
2007-05-03 02:39:33 +00:00
|
|
|
virtual AbstractFilesystemNode *getParent() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a list with all the volumes present in the root node.
|
|
|
|
*/
|
|
|
|
virtual AbstractFSList listVolumes() const;
|
2005-05-10 00:58:08 +00:00
|
|
|
};
|
|
|
|
|
2007-09-22 20:47:41 +00:00
|
|
|
/**
|
|
|
|
* Returns the last component of a given path.
|
|
|
|
*
|
|
|
|
* @param str String containing the path.
|
|
|
|
* @return Pointer to the first char of the last component inside str.
|
|
|
|
*/
|
|
|
|
const char *lastPathComponent(const Common::String &str) {
|
2007-09-22 20:51:34 +00:00
|
|
|
int offset = str.size();
|
2007-10-07 00:28:38 +00:00
|
|
|
|
|
|
|
if (offset <= 0) {
|
|
|
|
debug(6, "Bad offset");
|
2007-10-07 20:42:46 +00:00
|
|
|
return 0;
|
2007-10-07 00:28:38 +00:00
|
|
|
}
|
|
|
|
|
2007-09-22 20:51:34 +00:00
|
|
|
const char *p = str.c_str();
|
2007-09-22 20:47:41 +00:00
|
|
|
|
2007-09-22 20:51:34 +00:00
|
|
|
while (offset > 0 && (p[offset-1] == '/' || p[offset-1] == ':'))
|
2007-09-22 20:47:41 +00:00
|
|
|
offset--;
|
|
|
|
|
2007-09-22 20:51:34 +00:00
|
|
|
while (offset > 0 && (p[offset-1] != '/' && p[offset-1] != ':'))
|
2007-09-22 20:47:41 +00:00
|
|
|
offset--;
|
|
|
|
|
2007-09-22 20:51:34 +00:00
|
|
|
return p + offset;
|
2007-09-22 20:47:41 +00:00
|
|
|
}
|
|
|
|
|
2005-05-10 00:58:08 +00:00
|
|
|
AmigaOSFilesystemNode::AmigaOSFilesystemNode() {
|
|
|
|
ENTER();
|
|
|
|
_sDisplayName = "Available Disks";
|
|
|
|
_bIsValid = true;
|
|
|
|
_bIsDirectory = true;
|
|
|
|
_sPath = "";
|
|
|
|
_pFileLock = 0;
|
|
|
|
LEAVE();
|
|
|
|
}
|
|
|
|
|
|
|
|
AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) {
|
|
|
|
ENTER();
|
|
|
|
|
|
|
|
int len = 0, offset = p.size();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-09-16 17:56:26 +00:00
|
|
|
//assert(offset > 0);
|
|
|
|
|
|
|
|
if (offset <= 0) {
|
|
|
|
debug(6, "Bad offset");
|
|
|
|
return;
|
|
|
|
}
|
2005-05-10 00:58:08 +00:00
|
|
|
|
|
|
|
_sPath = p;
|
2007-10-07 00:28:38 +00:00
|
|
|
_sDisplayName = lastPathComponent(_sPath);
|
2006-04-08 12:39:27 +00:00
|
|
|
_pFileLock = 0;
|
2006-10-08 12:50:53 +00:00
|
|
|
_bIsDirectory = false;
|
2006-04-08 12:39:27 +00:00
|
|
|
|
2005-05-10 00:58:08 +00:00
|
|
|
struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
|
|
|
|
if (!fib) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "FileInfoBlock is NULL");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-01 21:53:31 +00:00
|
|
|
// Check whether the node exists and if it is a directory
|
2006-04-14 01:06:08 +00:00
|
|
|
BPTR pLock = IDOS->Lock((STRPTR)_sPath.c_str(), SHARED_LOCK);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (pLock) {
|
|
|
|
if (IDOS->Examine(pLock, fib) != DOSFALSE) {
|
2006-05-01 21:53:31 +00:00
|
|
|
if (FIB_IS_DRAWER(fib)) {
|
2005-05-10 00:58:08 +00:00
|
|
|
_bIsDirectory = true;
|
|
|
|
_pFileLock = IDOS->DupLock(pLock);
|
|
|
|
_bIsValid = (_pFileLock != 0);
|
2006-05-01 21:53:31 +00:00
|
|
|
|
|
|
|
// Add a trailing slash if it is needed
|
|
|
|
const char c = _sPath.lastChar();
|
|
|
|
if (c != '/' && c != ':')
|
|
|
|
_sPath += '/';
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
2006-05-01 21:53:31 +00:00
|
|
|
else {
|
2006-10-08 12:50:53 +00:00
|
|
|
//_bIsDirectory = false;
|
2006-05-01 21:53:31 +00:00
|
|
|
_bIsValid = true;
|
|
|
|
}
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
2006-09-16 17:56:26 +00:00
|
|
|
|
|
|
|
IDOS->UnLock(pLock);
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IDOS->FreeDosObject(DOS_FIB, fib);
|
|
|
|
LEAVE();
|
|
|
|
}
|
|
|
|
|
|
|
|
AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName) {
|
|
|
|
ENTER();
|
2006-04-08 12:39:27 +00:00
|
|
|
int bufSize = MAXPATHLEN;
|
2005-05-10 00:58:08 +00:00
|
|
|
_pFileLock = 0;
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
while (true) {
|
2006-07-22 14:14:16 +00:00
|
|
|
char *n = new char[bufSize];
|
|
|
|
if (IDOS->NameFromLock(pLock, (STRPTR)n, bufSize) != DOSFALSE) {
|
|
|
|
_sPath = n;
|
|
|
|
_sDisplayName = pDisplayName ? pDisplayName : IDOS->FilePart((STRPTR)n);
|
|
|
|
delete [] n;
|
2005-05-10 00:58:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IDOS->IoErr() != ERROR_LINE_TOO_LONG) {
|
|
|
|
_bIsValid = false;
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "IoErr() != ERROR_LINE_TOO_LONG");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
2006-07-22 14:14:16 +00:00
|
|
|
delete [] n;
|
2005-05-10 00:58:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-05-03 02:39:33 +00:00
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
bufSize *= 2;
|
2006-07-22 14:14:16 +00:00
|
|
|
delete [] n;
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_bIsValid = false;
|
2006-10-08 12:50:53 +00:00
|
|
|
_bIsDirectory = false;
|
2005-05-10 00:58:08 +00:00
|
|
|
|
|
|
|
struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
|
|
|
|
if (!fib) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "FileInfoBlock is NULL");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IDOS->Examine(pLock, fib) != DOSFALSE) {
|
2006-05-01 21:53:31 +00:00
|
|
|
if (FIB_IS_DRAWER(fib)) {
|
2005-05-10 00:58:08 +00:00
|
|
|
_bIsDirectory = true;
|
|
|
|
_pFileLock = IDOS->DupLock(pLock);
|
2006-05-01 21:53:31 +00:00
|
|
|
_bIsValid = _pFileLock != 0;
|
|
|
|
|
|
|
|
const char c = _sPath.lastChar();
|
|
|
|
if (c != '/' && c != ':')
|
|
|
|
_sPath += '/';
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
2006-05-01 21:53:31 +00:00
|
|
|
else {
|
2006-10-08 12:50:53 +00:00
|
|
|
//_bIsDirectory = false;
|
2006-05-01 21:53:31 +00:00
|
|
|
_bIsValid = true;
|
|
|
|
}
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IDOS->FreeDosObject(DOS_FIB, fib);
|
|
|
|
LEAVE();
|
|
|
|
}
|
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
// We need the custom copy constructor because of DupLock()
|
|
|
|
AmigaOSFilesystemNode::AmigaOSFilesystemNode(const AmigaOSFilesystemNode& node) {
|
2005-05-10 00:58:08 +00:00
|
|
|
ENTER();
|
2006-04-08 12:39:27 +00:00
|
|
|
_sDisplayName = node._sDisplayName;
|
|
|
|
_bIsValid = node._bIsValid;
|
|
|
|
_bIsDirectory = node._bIsDirectory;
|
|
|
|
_sPath = node._sPath;
|
|
|
|
_pFileLock = IDOS->DupLock(node._pFileLock);
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
|
|
|
}
|
|
|
|
|
|
|
|
AmigaOSFilesystemNode::~AmigaOSFilesystemNode() {
|
|
|
|
ENTER();
|
|
|
|
if (_pFileLock)
|
|
|
|
IDOS->UnLock(_pFileLock);
|
|
|
|
LEAVE();
|
|
|
|
}
|
|
|
|
|
2007-10-30 21:31:39 +00:00
|
|
|
bool AmigaOSFilesystemNode::exists() const {
|
2007-10-30 21:57:41 +00:00
|
|
|
ENTER();
|
2007-10-30 21:31:39 +00:00
|
|
|
if(_sPath.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool nodeExists = false;
|
|
|
|
|
2007-10-30 21:35:26 +00:00
|
|
|
struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
|
|
|
|
if (!fib) {
|
|
|
|
debug(6, "FileInfoBlock is NULL");
|
|
|
|
LEAVE();
|
2007-10-30 21:37:00 +00:00
|
|
|
return false;
|
2007-10-30 21:35:26 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:31:39 +00:00
|
|
|
BPTR pLock = IDOS->Lock((STRPTR)_sPath.c_str(), SHARED_LOCK);
|
|
|
|
if (pLock) {
|
2007-10-30 21:57:41 +00:00
|
|
|
if (IDOS->Examine(pLock, fib) != DOSFALSE)
|
2007-10-30 21:31:39 +00:00
|
|
|
nodeExists = true;
|
|
|
|
IDOS->UnLock(pLock);
|
|
|
|
}
|
|
|
|
|
2007-10-30 21:57:41 +00:00
|
|
|
IDOS->FreeDosObject(DOS_FIB, fib);
|
2007-10-30 21:31:39 +00:00
|
|
|
LEAVE();
|
|
|
|
return nodeExists;
|
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
AbstractFilesystemNode *AmigaOSFilesystemNode::getChild(const String &n) const {
|
2007-10-30 21:57:41 +00:00
|
|
|
ENTER();
|
2007-05-03 02:39:33 +00:00
|
|
|
if (!_bIsDirectory) {
|
|
|
|
debug(6, "Not a directory");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String newPath(_sPath);
|
|
|
|
|
|
|
|
if (_sPath.lastChar() != '/')
|
|
|
|
newPath += '/';
|
|
|
|
|
|
|
|
newPath += n;
|
|
|
|
BPTR lock = IDOS->Lock(newPath.c_str(), SHARED_LOCK);
|
|
|
|
|
|
|
|
if (!lock) {
|
|
|
|
debug(6, "Bad path");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDOS->UnLock(lock);
|
|
|
|
|
2007-10-30 21:57:41 +00:00
|
|
|
LEAVE();
|
2007-05-03 02:39:33 +00:00
|
|
|
return new AmigaOSFilesystemNode(newPath);
|
|
|
|
}
|
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
|
2005-05-10 00:58:08 +00:00
|
|
|
ENTER();
|
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
//TODO: honor the hidden flag
|
|
|
|
|
2005-05-10 00:58:08 +00:00
|
|
|
if (!_bIsValid) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "Invalid node");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
2006-05-03 20:43:26 +00:00
|
|
|
return false; // Empty list
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_bIsDirectory) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "Not a directory");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
2006-05-03 20:43:26 +00:00
|
|
|
return false; // Empty list
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_pFileLock == 0) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "Root node");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
2006-05-03 20:43:26 +00:00
|
|
|
myList = listVolumes();
|
|
|
|
return true;
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
struct ExAllControl *eac = (struct ExAllControl *)IDOS->AllocDosObject(DOS_EXALLCONTROL, 0);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (eac) {
|
2006-04-08 12:39:27 +00:00
|
|
|
struct ExAllData *data = (struct ExAllData *)IExec->AllocVec(kExAllBufferSize, MEMF_ANY);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (data) {
|
2006-04-08 12:39:27 +00:00
|
|
|
BOOL bExMore;
|
2005-05-10 00:58:08 +00:00
|
|
|
eac->eac_LastKey = 0;
|
|
|
|
do {
|
2006-04-14 01:06:08 +00:00
|
|
|
// Examine directory
|
2006-04-08 12:39:27 +00:00
|
|
|
bExMore = IDOS->ExAll(_pFileLock, data, kExAllBufferSize, ED_TYPE, eac);
|
2005-05-10 00:58:08 +00:00
|
|
|
|
|
|
|
LONG error = IDOS->IoErr();
|
|
|
|
if (!bExMore && error != ERROR_NO_MORE_ENTRIES)
|
2006-04-14 01:06:08 +00:00
|
|
|
break; // Abnormal failure
|
2005-05-10 00:58:08 +00:00
|
|
|
|
|
|
|
if (eac->eac_Entries == 0)
|
2006-04-14 01:06:08 +00:00
|
|
|
continue; // Normal failure, no entries
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
struct ExAllData *ead = data;
|
2005-05-10 00:58:08 +00:00
|
|
|
do {
|
2006-05-03 10:14:05 +00:00
|
|
|
if ((mode == FilesystemNode::kListAll) ||
|
|
|
|
(EAD_IS_DRAWER(ead) && (mode == FilesystemNode::kListDirectoriesOnly)) ||
|
|
|
|
(EAD_IS_FILE(ead) && (mode == FilesystemNode::kListFilesOnly))) {
|
2006-04-08 12:39:27 +00:00
|
|
|
String full_path = _sPath;
|
2005-05-10 00:58:08 +00:00
|
|
|
full_path += (char*)ead->ed_Name;
|
2006-04-08 12:39:27 +00:00
|
|
|
|
2006-04-14 01:06:08 +00:00
|
|
|
BPTR lock = IDOS->Lock((STRPTR)full_path.c_str(), SHARED_LOCK);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (lock) {
|
2006-04-08 12:39:27 +00:00
|
|
|
AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (entry) {
|
2007-10-07 00:28:38 +00:00
|
|
|
//FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode
|
|
|
|
// specification, the following call had to be changed:
|
|
|
|
// if (entry->isValid())
|
|
|
|
// Please verify that the logic of the code remains coherent. Also, remember
|
|
|
|
// that the isReadable() and isWritable() methods are available.
|
|
|
|
if (entry->exists())
|
2006-05-03 11:13:21 +00:00
|
|
|
myList.push_back(entry);
|
2005-05-10 00:58:08 +00:00
|
|
|
else
|
|
|
|
delete entry;
|
|
|
|
}
|
|
|
|
IDOS->UnLock(lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ead = ead->ed_Next;
|
|
|
|
} while (ead);
|
|
|
|
} while (bExMore);
|
|
|
|
|
|
|
|
IExec->FreeVec(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
IDOS->FreeDosObject(DOS_EXALLCONTROL, eac);
|
|
|
|
}
|
2006-04-08 12:39:27 +00:00
|
|
|
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
2007-05-03 02:39:33 +00:00
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
return true;
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const {
|
2005-05-10 00:58:08 +00:00
|
|
|
ENTER();
|
|
|
|
|
|
|
|
if (!_bIsDirectory) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "Not a directory");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pFileLock == 0) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "Root node");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
2006-04-04 21:01:26 +00:00
|
|
|
return new AmigaOSFilesystemNode(*this);
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
AmigaOSFilesystemNode *node;
|
|
|
|
|
2006-01-27 15:51:41 +00:00
|
|
|
BPTR parentDir = IDOS->ParentDir( _pFileLock );
|
|
|
|
if (parentDir) {
|
|
|
|
node = new AmigaOSFilesystemNode(parentDir);
|
|
|
|
IDOS->UnLock(parentDir);
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
node = new AmigaOSFilesystemNode();
|
|
|
|
|
|
|
|
LEAVE();
|
2006-09-16 17:56:26 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
return node;
|
2006-04-30 22:52:10 +00:00
|
|
|
}
|
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
AbstractFSList AmigaOSFilesystemNode::listVolumes() const {
|
2005-05-10 00:58:08 +00:00
|
|
|
ENTER();
|
2006-04-14 01:06:08 +00:00
|
|
|
|
2006-05-03 11:13:21 +00:00
|
|
|
AbstractFSList myList;
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
const uint32 kLockFlags = LDF_READ | LDF_VOLUMES;
|
2006-09-16 17:56:26 +00:00
|
|
|
char buffer[MAXPATHLEN];
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
struct DosList *dosList = IDOS->LockDosList(kLockFlags);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (!dosList) {
|
2006-04-14 01:06:08 +00:00
|
|
|
debug(6, "Cannot lock the DOS list");
|
2005-05-10 00:58:08 +00:00
|
|
|
LEAVE();
|
|
|
|
return myList;
|
|
|
|
}
|
|
|
|
|
|
|
|
dosList = IDOS->NextDosEntry(dosList, LDF_VOLUMES);
|
|
|
|
while (dosList) {
|
|
|
|
if (dosList->dol_Type == DLT_VOLUME &&
|
|
|
|
dosList->dol_Name &&
|
|
|
|
dosList->dol_Task) {
|
2006-09-16 17:56:26 +00:00
|
|
|
//const char *volName = (const char *)BADDR(dosList->dol_Name)+1;
|
|
|
|
|
|
|
|
// Copy name to buffer
|
|
|
|
IDOS->CopyStringBSTRToC(dosList->dol_Name, buffer, MAXPATHLEN);
|
|
|
|
|
|
|
|
//const char *devName = (const char *)((struct Task *)dosList->dol_Task->mp_SigTask)->tc_Node.ln_Name;
|
|
|
|
|
|
|
|
// Volume name + '\0'
|
|
|
|
char *volName = new char [strlen(buffer) + 1];
|
|
|
|
|
|
|
|
strcpy(volName, buffer);
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-09-16 17:56:26 +00:00
|
|
|
strcat(buffer, ":");
|
2005-05-10 00:58:08 +00:00
|
|
|
|
2006-09-16 17:56:26 +00:00
|
|
|
BPTR volumeLock = IDOS->Lock((STRPTR)buffer, SHARED_LOCK);
|
2006-04-08 12:39:27 +00:00
|
|
|
if (volumeLock) {
|
2006-09-16 17:56:26 +00:00
|
|
|
|
|
|
|
char *devName = new char [MAXPATHLEN];
|
|
|
|
|
|
|
|
// Find device name
|
|
|
|
IDOS->DevNameFromLock(volumeLock, devName, MAXPATHLEN, DN_DEVICEONLY);
|
|
|
|
|
|
|
|
sprintf(buffer, "%s (%s)", volName, devName);
|
|
|
|
|
|
|
|
delete [] devName;
|
|
|
|
|
|
|
|
AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(volumeLock, buffer);
|
2005-05-10 00:58:08 +00:00
|
|
|
if (entry) {
|
2007-10-07 00:28:38 +00:00
|
|
|
//FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode
|
|
|
|
// specification, the following call had to be changed:
|
|
|
|
// if (entry->isValid())
|
|
|
|
// Please verify that the logic of the code remains coherent. Also, remember
|
|
|
|
// that the isReadable() and isWritable() methods are available.
|
|
|
|
if(entry->exists())
|
2006-05-03 11:13:21 +00:00
|
|
|
myList.push_back(entry);
|
2005-05-10 00:58:08 +00:00
|
|
|
else
|
|
|
|
delete entry;
|
|
|
|
}
|
2006-09-16 17:56:26 +00:00
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
IDOS->UnLock(volumeLock);
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
2006-09-16 17:56:26 +00:00
|
|
|
|
|
|
|
delete [] volName;
|
2005-05-10 00:58:08 +00:00
|
|
|
}
|
|
|
|
dosList = IDOS->NextDosEntry(dosList, LDF_VOLUMES);
|
|
|
|
}
|
|
|
|
|
2006-04-08 12:39:27 +00:00
|
|
|
IDOS->UnLockDosList(kLockFlags);
|
2005-05-10 00:58:08 +00:00
|
|
|
|
|
|
|
LEAVE();
|
2007-05-03 02:39:33 +00:00
|
|
|
|
2005-05-10 00:58:08 +00:00
|
|
|
return myList;
|
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
#endif //defined(__amigaos4__)
|