[Scummvm-cvs-logs] SF.net SVN: scummvm:[33125] residual/trunk/engine/backend

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Sun Jul 20 15:56:13 CEST 2008


Revision: 33125
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33125&view=rev
Author:   aquadran
Date:     2008-07-20 13:56:00 +0000 (Sun, 20 Jul 2008)

Log Message:
-----------
added filesystem common code from scummvm (part 2)

Modified Paths:
--------------
    residual/trunk/engine/backend/driver.h
    residual/trunk/engine/backend/module.mk
    residual/trunk/engine/backend/sdl/driver_sdl.cpp
    residual/trunk/engine/backend/sdl/driver_sdl.h

Added Paths:
-----------
    residual/trunk/engine/backend/fs/
    residual/trunk/engine/backend/fs/abstract-fs.h
    residual/trunk/engine/backend/fs/amigaos4/
    residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.cpp
    residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.h
    residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs.cpp
    residual/trunk/engine/backend/fs/fs-factory.h
    residual/trunk/engine/backend/fs/posix/
    residual/trunk/engine/backend/fs/posix/posix-fs-factory.cpp
    residual/trunk/engine/backend/fs/posix/posix-fs-factory.h
    residual/trunk/engine/backend/fs/posix/posix-fs.cpp
    residual/trunk/engine/backend/fs/windows/
    residual/trunk/engine/backend/fs/windows/windows-fs-factory.cpp
    residual/trunk/engine/backend/fs/windows/windows-fs-factory.h
    residual/trunk/engine/backend/fs/windows/windows-fs.cpp

Modified: residual/trunk/engine/backend/driver.h
===================================================================
--- residual/trunk/engine/backend/driver.h	2008-07-20 13:37:50 UTC (rev 33124)
+++ residual/trunk/engine/backend/driver.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -42,6 +42,7 @@
 class Material;
 class Bitmap;
 class Timer;
+class FilesystemFactory;
 
 namespace Audio {
 	class MixerImpl;
@@ -294,6 +295,12 @@
 	//@{
 	/** Quit (exit) the application. */
 	virtual void quit() = 0;
+	/**
+	 * Returns the FilesystemFactory object, depending on the current architecture.
+	 *
+	 * @return FilesystemFactory* The specific factory for the current architecture.
+	 */
+	virtual FilesystemFactory *getFilesystemFactory() = 0;
 	//@}
 
 protected:


Property changes on: residual/trunk/engine/backend/fs
___________________________________________________________________
Added: svn:ignore
   + .deps
*.d
*.o


Added: residual/trunk/engine/backend/fs/abstract-fs.h
===================================================================
--- residual/trunk/engine/backend/fs/abstract-fs.h	                        (rev 0)
+++ residual/trunk/engine/backend/fs/abstract-fs.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,157 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef BACKENDS_ABSTRACT_FS_H
+#define BACKENDS_ABSTRACT_FS_H
+
+#include "common/array.h"
+#include "common/str.h"
+#include "common/fs.h"
+
+class AbstractFilesystemNode;
+
+typedef Common::Array<AbstractFilesystemNode *>	AbstractFSList;
+
+/**
+ * Abstract file system node. Private subclasses implement the actual
+ * functionality.
+ *
+ * Most of the methods correspond directly to methods in class FilesystemNode,
+ * so if they are not documented here, look there for more information about
+ * the semantics.
+ */
+class AbstractFilesystemNode {
+protected:
+	friend class FilesystemNode;
+	typedef Common::String String;
+	typedef FilesystemNode::ListMode ListMode;
+
+	/**
+	 * Returns the child node with the given name. If no child with this name
+	 * exists, returns 0. When called on a non-directory node, it should
+	 * handle this gracefully by returning 0.
+	 *
+	 * Example:
+	 *			Calling getChild() for a node with path "/foo/bar" using name="file.txt",
+	 *			would produce a new node with "/foo/bar/file.txt" as path.
+	 *
+	 * @note This function will append a separator char (\ or /) to the end of the
+	 * path if needed.
+	 *
+	 * @note Handling calls on non-dir nodes gracefully makes it possible to
+	 * switch to a lazy type detection scheme in the future.
+	 *
+	 * @param name String containing the name of the child to create a new node.
+	 */
+	virtual AbstractFilesystemNode *getChild(const String &name) const = 0;
+
+	/**
+	 * The parent node of this directory.
+	 * The parent of the root is the root itself.
+	 */
+	virtual AbstractFilesystemNode *getParent() const = 0;
+
+public:
+	/**
+	 * Destructor.
+	 */
+	virtual ~AbstractFilesystemNode() {}
+
+	/*
+	 * Indicates whether the object referred by this path exists in the filesystem or not.
+	 */
+	virtual bool exists() const = 0;
+
+	/**
+	 * Return a list of child nodes of this directory node. If called on a node
+	 * that does not represent a directory, false is returned.
+	 *
+	 * @param list List to put the contents of the directory in.
+	 * @param mode Mode to use while listing the directory.
+	 * @param hidden Whether to include hidden files or not in the results.
+	 *
+	 * @return true if succesful, false otherwise (e.g. when the directory does not exist).
+	 */
+	virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const = 0;
+
+	/**
+	 * Returns a human readable path string.
+	 *
+	 * @note By default, this method returns the value of getName().
+	 */
+	virtual String getDisplayName() const { return getName(); }
+
+	/**
+	 * Returns the last component of the path pointed by this FilesystemNode.
+	 *
+	 * Examples (POSIX):
+	 *			/foo/bar.txt would return /bar.txt
+	 *			/foo/bar/    would return /bar/
+	 *
+	 * @note This method is very architecture dependent, please check the concrete implementation for more information.
+	 */
+	virtual String getName() const = 0;
+
+	/**
+	 * Returns the 'path' of the current node, usable in fopen().
+	 */
+	virtual String getPath() const = 0;
+
+	/**
+	 * Indicates whether this path refers to a directory or not.
+	 */
+	virtual bool isDirectory() const = 0;
+
+	/**
+	 * Indicates whether the object referred by this path can be read from or not.
+	 *
+	 * If the path refers to a directory, readability implies being able to read
+	 * and list the directory entries.
+	 *
+	 * If the path refers to a file, readability implies being able to read the
+	 * contents of the file.
+	 *
+	 * @return bool true if the object can be read, false otherwise.
+	 */
+	virtual bool isReadable() const = 0;
+
+	/**
+	 * Indicates whether the object referred by this path can be written to or not.
+	 *
+	 * If the path refers to a directory, writability implies being able to modify
+	 * the directory entry (i.e. rename the directory, remove it or write files inside of it).
+	 *
+	 * If the path refers to a file, writability implies being able to write data
+	 * to the file.
+	 *
+	 * @return bool true if the object can be written to, false otherwise.
+	 */
+	virtual bool isWritable() const = 0;
+
+	/* TODO:
+	bool isFile();
+	*/
+};
+
+#endif //BACKENDS_ABSTRACT_FS_H


Property changes on: residual/trunk/engine/backend/fs/abstract-fs.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native


Property changes on: residual/trunk/engine/backend/fs/amigaos4
___________________________________________________________________
Added: svn:ignore
   + .deps
*.d
*.o


Added: residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.cpp
===================================================================
--- residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,42 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#if defined(__amigaos4__)
+#include "engine/backend/fs/amigaos4/amigaos4-fs-factory.h"
+#include "engine/backend/fs/amigaos4/amigaos4-fs.cpp"
+
+DECLARE_SINGLETON(AmigaOSFilesystemFactory);
+
+AbstractFilesystemNode *AmigaOSFilesystemFactory::makeRootFileNode() const {
+	return new AmigaOSFilesystemNode();
+}
+
+AbstractFilesystemNode *AmigaOSFilesystemFactory::makeCurrentDirectoryFileNode() const {
+	return new AmigaOSFilesystemNode();
+}
+
+AbstractFilesystemNode *AmigaOSFilesystemFactory::makeFileNodePath(const String &path) const {
+	return new AmigaOSFilesystemNode(path);
+}
+#endif


Property changes on: residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.h
===================================================================
--- residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.h	                        (rev 0)
+++ residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,51 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef AMIGAOS_FILESYSTEM_FACTORY_H
+#define AMIGAOS_FILESYSTEM_FACTORY_H
+
+#include "common/singleton.h"
+#include "engine/backend/fs/fs-factory.h"
+
+/**
+ * Creates AmigaOSFilesystemNode objects.
+ *
+ * Parts of this class are documented in the base interface class, FilesystemFactory.
+ */
+class AmigaOSFilesystemFactory : public FilesystemFactory, public Common::Singleton<AmigaOSFilesystemFactory> {
+public:
+	typedef Common::String String;
+
+	virtual AbstractFilesystemNode *makeRootFileNode() const;
+	virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
+	virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
+
+protected:
+	AmigaOSFilesystemFactory() {};
+
+private:
+	friend class Common::Singleton<SingletonBaseType>;
+};
+
+#endif /*AMIGAOS_FILESYSTEM_FACTORY_H*/


Property changes on: residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs-factory.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs.cpp
===================================================================
--- residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,568 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#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
+
+#include "common/util.h"
+#include "engine/backend/fs/abstract-fs.h"
+
+#define ENTER() /* debug(6, "Enter") */
+#define LEAVE() /* debug(6, "Leave") */
+
+const uint32 kExAllBufferSize = 40960; // TODO: is this okay for sure?
+
+/**
+ * Implementation of the ScummVM file system API.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
+ */
+class AmigaOSFilesystemNode : public AbstractFilesystemNode {
+protected:
+	BPTR _pFileLock;
+	String _sDisplayName;
+	String _sPath;
+	bool _bIsDirectory;
+	bool _bIsValid;
+
+	/**
+	 * Obtain the FileInfoBlock protection value for this FilesystemNode,
+	 * as defined in the <proto/dos.h> header.
+	 *
+	 * @return -1 if there were errors, 0 or a positive integer otherwise.
+	 */
+	virtual int getFibProtection() const;
+
+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();
+
+	virtual bool exists() const;
+	virtual String getDisplayName() const { return _sDisplayName; };
+	virtual String getName() const { return _sDisplayName; };
+	virtual String getPath() const { return _sPath; };
+	virtual bool isDirectory() const { return _bIsDirectory; };
+	virtual bool isReadable() const;
+	virtual bool isWritable() const;
+
+	virtual AbstractFilesystemNode *getChild(const String &n) const;
+	virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
+	virtual AbstractFilesystemNode *getParent() const;
+
+	/**
+	 * Creates a list with all the volumes present in the root node.
+	 */
+	virtual AbstractFSList listVolumes() const;
+};
+
+/**
+ * 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) {
+	int offset = str.size();
+
+	if (offset <= 0) {
+		debug(6, "Bad offset");
+		return 0;
+	}
+
+	const char *p = str.c_str();
+
+	while (offset > 0 && (p[offset-1] == '/' || p[offset-1] == ':'))
+		offset--;
+
+	while (offset > 0 && (p[offset-1] != '/' && p[offset-1] != ':'))
+		offset--;
+
+	return p + offset;
+}
+
+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();
+
+	//assert(offset > 0);
+
+	if (offset <= 0) {
+		debug(6, "Bad offset");
+		return;
+	}
+
+	_sPath = p;
+	_sDisplayName = lastPathComponent(_sPath);
+	_pFileLock = 0;
+	_bIsDirectory = false;
+
+	struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
+	if (!fib) {
+		debug(6, "FileInfoBlock is NULL");
+		LEAVE();
+		return;
+	}
+
+	// Check whether the node exists and if it is a directory
+	BPTR pLock = IDOS->Lock((STRPTR)_sPath.c_str(), SHARED_LOCK);
+	if (pLock) {
+		if (IDOS->Examine(pLock, fib) != DOSFALSE) {
+			if (FIB_IS_DRAWER(fib)) {
+				_bIsDirectory = true;
+				_pFileLock = IDOS->DupLock(pLock);
+				_bIsValid = (_pFileLock != 0);
+
+				// Add a trailing slash if it is needed
+				const char c = _sPath.lastChar();
+				if (c != '/' && c != ':')
+					_sPath += '/';
+			}
+			else {
+				//_bIsDirectory = false;
+				_bIsValid = true;
+			}
+		}
+
+		IDOS->UnLock(pLock);
+	}
+
+	IDOS->FreeDosObject(DOS_FIB, fib);
+	LEAVE();
+}
+
+AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName) {
+	ENTER();
+	int bufSize = MAXPATHLEN;
+	_pFileLock = 0;
+
+	while (true) {
+		char *n = new char[bufSize];
+		if (IDOS->NameFromLock(pLock, (STRPTR)n, bufSize) != DOSFALSE) {
+			_sPath = n;
+			_sDisplayName = pDisplayName ? pDisplayName : IDOS->FilePart((STRPTR)n);
+			delete[] n;
+			break;
+		}
+
+		if (IDOS->IoErr() != ERROR_LINE_TOO_LONG) {
+			_bIsValid = false;
+			debug(6, "IoErr() != ERROR_LINE_TOO_LONG");
+			LEAVE();
+			delete[] n;
+			return;
+		}
+
+		bufSize *= 2;
+		delete[] n;
+	}
+
+	_bIsValid =	false;
+	_bIsDirectory = false;
+
+	struct FileInfoBlock *fib = (struct	FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
+	if (!fib) {
+		debug(6, "FileInfoBlock is NULL");
+		LEAVE();
+		return;
+	}
+
+	if (IDOS->Examine(pLock, fib) != DOSFALSE) {
+		if (FIB_IS_DRAWER(fib)) {
+			_bIsDirectory = true;
+			_pFileLock = IDOS->DupLock(pLock);
+			_bIsValid = _pFileLock != 0;
+
+			const char c = _sPath.lastChar();
+			if (c != '/' && c != ':')
+				_sPath += '/';
+		}
+		else {
+			//_bIsDirectory = false;
+			_bIsValid = true;
+		}
+	}
+
+	IDOS->FreeDosObject(DOS_FIB, fib);
+	LEAVE();
+}
+
+// We need the custom copy constructor because of DupLock()
+AmigaOSFilesystemNode::AmigaOSFilesystemNode(const AmigaOSFilesystemNode& node) {
+	ENTER();
+	_sDisplayName = node._sDisplayName;
+	_bIsValid = node._bIsValid;
+	_bIsDirectory = node._bIsDirectory;
+	_sPath = node._sPath;
+	_pFileLock = IDOS->DupLock(node._pFileLock);
+	LEAVE();
+}
+
+AmigaOSFilesystemNode::~AmigaOSFilesystemNode() {
+	ENTER();
+	if (_pFileLock)
+		IDOS->UnLock(_pFileLock);
+	LEAVE();
+}
+
+bool AmigaOSFilesystemNode::exists() const {
+	ENTER();
+	if(_sPath.empty())
+		return false;
+
+	bool nodeExists = false;
+
+	struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
+	if (!fib) {
+		debug(6, "FileInfoBlock is NULL");
+		LEAVE();
+		return false;
+	}
+
+	BPTR pLock = IDOS->Lock((STRPTR)_sPath.c_str(), SHARED_LOCK);
+	if (pLock) {
+		if (IDOS->Examine(pLock, fib) != DOSFALSE)
+			nodeExists = true;
+		IDOS->UnLock(pLock);
+	}
+
+	IDOS->FreeDosObject(DOS_FIB, fib);
+	LEAVE();
+	return nodeExists;
+}
+
+AbstractFilesystemNode *AmigaOSFilesystemNode::getChild(const String &n) const {
+	ENTER();
+	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);
+
+	LEAVE();
+	return new AmigaOSFilesystemNode(newPath);
+}
+
+bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
+	ENTER();
+
+	//TODO: honor the hidden flag
+
+	if (!_bIsValid) {
+		debug(6, "Invalid node");
+		LEAVE();
+		return false; // Empty list
+	}
+
+	if (!_bIsDirectory) {
+		debug(6, "Not a directory");
+		LEAVE();
+		return false; // Empty list
+	}
+
+	if (_pFileLock == 0) {
+		debug(6, "Root node");
+		LEAVE();
+		myList = listVolumes();
+		return true;
+	}
+
+	struct ExAllControl *eac = (struct ExAllControl *)IDOS->AllocDosObject(DOS_EXALLCONTROL, 0);
+	if (eac) {
+		struct ExAllData *data = (struct ExAllData *)IExec->AllocVec(kExAllBufferSize, MEMF_ANY);
+		if (data) {
+			BOOL bExMore;
+			eac->eac_LastKey = 0;
+			do {
+				// Examine directory
+				bExMore = IDOS->ExAll(_pFileLock, data,	kExAllBufferSize, ED_TYPE, eac);
+
+				LONG error = IDOS->IoErr();
+				if (!bExMore && error != ERROR_NO_MORE_ENTRIES)
+					break; // Abnormal failure
+
+				if (eac->eac_Entries ==	0)
+					continue; // Normal failure, no entries
+
+				struct ExAllData *ead = data;
+				do {
+					if ((mode == FilesystemNode::kListAll) ||
+						(EAD_IS_DRAWER(ead) && (mode == FilesystemNode::kListDirectoriesOnly)) ||
+						(EAD_IS_FILE(ead) && (mode == FilesystemNode::kListFilesOnly))) {
+						String full_path = _sPath;
+						full_path += (char*)ead->ed_Name;
+
+						BPTR lock = IDOS->Lock((STRPTR)full_path.c_str(), SHARED_LOCK);
+						if (lock) {
+							AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name);
+							if (entry) {
+								//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())
+								    myList.push_back(entry);
+								else
+									delete entry;
+							}
+							IDOS->UnLock(lock);
+						}
+					}
+					ead = ead->ed_Next;
+				} while (ead);
+			} while (bExMore);
+
+			IExec->FreeVec(data);
+		}
+
+		IDOS->FreeDosObject(DOS_EXALLCONTROL, eac);
+	}
+
+	LEAVE();
+
+	return true;
+}
+
+int AmigaOSFilesystemNode::getFibProtection() const {
+	ENTER();
+
+	int fibProt = -1;
+	struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
+	if (!fib) {
+		debug(6, "FileInfoBlock is NULL");
+		LEAVE();
+		return fibProt;
+	}
+
+	BPTR pLock = IDOS->Lock((STRPTR)_sPath.c_str(), SHARED_LOCK);
+	if (pLock) {
+		if (IDOS->Examine(pLock, fib) != DOSFALSE) {
+			fibProt = fib->fib_Protection;
+		}
+		IDOS->UnLock(pLock);
+	}
+
+	IDOS->FreeDosObject(DOS_FIB, fib);
+	LEAVE();
+	return fibProt;
+}
+
+AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const {
+	ENTER();
+
+	if (!_bIsDirectory) {
+		debug(6, "Not a directory");
+		LEAVE();
+		return 0;
+	}
+
+	if (_pFileLock == 0) {
+		debug(6, "Root node");
+		LEAVE();
+		return new AmigaOSFilesystemNode(*this);
+	}
+
+	AmigaOSFilesystemNode *node;
+
+	BPTR parentDir = IDOS->ParentDir( _pFileLock );
+	if (parentDir) {
+		node = new AmigaOSFilesystemNode(parentDir);
+		IDOS->UnLock(parentDir);
+	}
+	else
+		node = new AmigaOSFilesystemNode();
+
+	LEAVE();
+
+	return node;
+}
+
+bool AmigaOSFilesystemNode::isReadable() const {
+	bool readable = false;
+	int fibProt = getFibProtection();
+
+	if (fibProt >= 0) {
+		/* The fib_Protection flag is low-active or inverted, thus the negation.
+		 *
+		 * For more information, consult the compiler/include/dos/dos.h
+		 * file from the AROS source (http://aros.sourceforge.net/).
+		 */
+		readable = !(fibProt & FIBF_READ);
+	}
+
+	return readable;
+}
+
+bool AmigaOSFilesystemNode::isWritable() const {
+	bool writable = false;
+	int fibProt = getFibProtection();
+
+	if (fibProt >= 0) {
+		/* The fib_Protection flag is low-active or inverted, thus the negation.
+		 *
+		 * For more information, consult the compiler/include/dos/dos.h
+		 * file from the AROS source (http://aros.sourceforge.net/).
+		 */
+		writable = !(fibProt & FIBF_WRITE);
+	}
+
+	return writable;
+}
+
+AbstractFSList AmigaOSFilesystemNode::listVolumes()	const {
+	ENTER();
+
+	AbstractFSList myList;
+
+	const uint32 kLockFlags = LDF_READ | LDF_VOLUMES;
+	char buffer[MAXPATHLEN];
+
+	struct DosList *dosList = IDOS->LockDosList(kLockFlags);
+	if (!dosList) {
+		debug(6, "Cannot lock the DOS list");
+		LEAVE();
+		return myList;
+	}
+
+	dosList = IDOS->NextDosEntry(dosList, LDF_VOLUMES);
+	while (dosList) {
+		if (dosList->dol_Type == DLT_VOLUME &&
+			dosList->dol_Name &&
+			dosList->dol_Task) {
+			//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);
+
+			strcat(buffer, ":");
+
+			BPTR volumeLock = IDOS->Lock((STRPTR)buffer, SHARED_LOCK);
+			if (volumeLock) {
+
+				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);
+				if (entry) {
+					//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())
+						myList.push_back(entry);
+					else
+						delete entry;
+				}
+
+				IDOS->UnLock(volumeLock);
+			}
+
+			delete[] volName;
+		}
+		dosList	= IDOS->NextDosEntry(dosList, LDF_VOLUMES);
+	}
+
+	IDOS->UnLockDosList(kLockFlags);
+
+	LEAVE();
+
+	return myList;
+}
+
+#endif //defined(__amigaos4__)


Property changes on: residual/trunk/engine/backend/fs/amigaos4/amigaos4-fs.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/fs-factory.h
===================================================================
--- residual/trunk/engine/backend/fs/fs-factory.h	                        (rev 0)
+++ residual/trunk/engine/backend/fs/fs-factory.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,71 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef FILESYSTEM_FACTORY_H
+#define FILESYSTEM_FACTORY_H
+
+#include "common/str.h"
+#include "engine/backend/fs/abstract-fs.h"
+
+/**
+ * Creates concrete FilesystemNode objects depending on the current architecture.
+ */
+class FilesystemFactory {
+public:
+	/**
+	 * Destructor.
+	 */
+	virtual ~FilesystemFactory() {}
+
+	/**
+	 * Returns a node representing the "current directory".
+	 * If your system does not support this concept, you can either try to
+	 * emulate it or simply return some "sensible" default directory node,
+	 * e.g. the same value as getRoot() returns.
+	 */
+	virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const = 0;
+
+	/**
+	 * Construct a node based on a path; the path is in the same format as it
+	 * would be for calls to fopen().
+	 *
+	 * Furthermore getNodeForPath(oldNode.path()) should create a new node
+	 * identical to oldNode. Hence, we can use the "path" value for persistent
+	 * storage e.g. in the config file.
+	 *
+	 * @param path The path string to create a FilesystemNode for.
+	 */
+	virtual AbstractFilesystemNode *makeFileNodePath(const Common::String &path) const = 0;
+
+	/**
+	 * Returns a special node representing the filesystem root.
+	 * The starting point for any file system browsing.
+	 *
+	 * On Unix, this will be simply the node for / (the root directory).
+	 * On Windows, it will be a special node which "contains" all drives (C:, D:, E:).
+	 */
+	virtual AbstractFilesystemNode *makeRootFileNode() const = 0;
+};
+
+#endif /*FILESYSTEM_FACTORY_H*/


Property changes on: residual/trunk/engine/backend/fs/fs-factory.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native


Property changes on: residual/trunk/engine/backend/fs/posix
___________________________________________________________________
Added: svn:ignore
   + .deps
*.d
*.o


Added: residual/trunk/engine/backend/fs/posix/posix-fs-factory.cpp
===================================================================
--- residual/trunk/engine/backend/fs/posix/posix-fs-factory.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/fs/posix/posix-fs-factory.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,44 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#if defined(UNIX)
+#include "engine/backend/fs/posix/posix-fs-factory.h"
+#include "engine/backend/fs/posix/posix-fs.cpp"
+
+DECLARE_SINGLETON(POSIXFilesystemFactory);
+
+AbstractFilesystemNode *POSIXFilesystemFactory::makeRootFileNode() const {
+	return new POSIXFilesystemNode();
+}
+
+AbstractFilesystemNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const {
+	char buf[MAXPATHLEN];
+	getcwd(buf, MAXPATHLEN);
+	return new POSIXFilesystemNode(buf, true);
+}
+
+AbstractFilesystemNode *POSIXFilesystemFactory::makeFileNodePath(const String &path) const {
+	return new POSIXFilesystemNode(path, true);
+}
+#endif


Property changes on: residual/trunk/engine/backend/fs/posix/posix-fs-factory.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/posix/posix-fs-factory.h
===================================================================
--- residual/trunk/engine/backend/fs/posix/posix-fs-factory.h	                        (rev 0)
+++ residual/trunk/engine/backend/fs/posix/posix-fs-factory.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,51 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef POSIX_FILESYSTEM_FACTORY_H
+#define POSIX_FILESYSTEM_FACTORY_H
+
+#include "common/singleton.h"
+#include "engine/backend/fs/fs-factory.h"
+
+/**
+ * Creates POSIXFilesystemNode objects.
+ *
+ * Parts of this class are documented in the base interface class, FilesystemFactory.
+ */
+class POSIXFilesystemFactory : public FilesystemFactory, public Common::Singleton<POSIXFilesystemFactory> {
+public:
+	typedef Common::String String;
+
+	virtual AbstractFilesystemNode *makeRootFileNode() const;
+	virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
+	virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
+
+protected:
+	POSIXFilesystemFactory() {};
+
+private:
+	friend class Common::Singleton<SingletonBaseType>;
+};
+
+#endif /*POSIX_FILESYSTEM_FACTORY_H*/


Property changes on: residual/trunk/engine/backend/fs/posix/posix-fs-factory.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/posix/posix-fs.cpp
===================================================================
--- residual/trunk/engine/backend/fs/posix/posix-fs.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/fs/posix/posix-fs.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,242 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#if defined(UNIX)
+
+#include "engine/backend/fs/abstract-fs.h"
+
+#ifdef MACOSX
+#include <sys/types.h>
+#endif
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <unistd.h>
+
+/**
+ * Implementation of the ScummVM file system API based on POSIX.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
+ */
+class POSIXFilesystemNode : public AbstractFilesystemNode {
+protected:
+	String _displayName;
+	String _path;
+	bool _isDirectory;
+	bool _isValid;
+
+public:
+	/**
+	 * Creates a POSIXFilesystemNode with the root node as path.
+	 */
+	POSIXFilesystemNode();
+
+	/**
+	 * Creates a POSIXFilesystemNode for a given path.
+	 *
+	 * @param path String with the path the new node should point to.
+	 * @param verify true if the isValid and isDirectory flags should be verified during the construction.
+	 */
+	POSIXFilesystemNode(const String &path, bool verify);
+
+	virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; }
+	virtual String getDisplayName() const { return _displayName; }
+	virtual String getName() const { return _displayName; }
+	virtual String getPath() const { return _path; }
+	virtual bool isDirectory() const { return _isDirectory; }
+	virtual bool isReadable() const { return access(_path.c_str(), R_OK) == 0; }
+	virtual bool isWritable() const { return access(_path.c_str(), W_OK) == 0; }
+
+	virtual AbstractFilesystemNode *getChild(const String &n) const;
+	virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
+	virtual AbstractFilesystemNode *getParent() const;
+
+private:
+	/**
+	 * Tests and sets the _isValid and _isDirectory flags, using the stat() function.
+	 */
+	virtual void setFlags();
+};
+
+/**
+ * Returns the last component of a given path.
+ *
+ * Examples:
+ *			/foo/bar.txt would return /bar.txt
+ *			/foo/bar/    would return /bar/
+ *
+ * @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) {
+	if(str.empty())
+		return "";
+
+	const char *start = str.c_str();
+	const char *cur = start + str.size() - 2;
+
+	while (cur >= start && *cur != '/') {
+		--cur;
+	}
+
+	return cur + 1;
+}
+
+void POSIXFilesystemNode::setFlags() {
+	struct stat st;
+
+	_isValid = (0 == stat(_path.c_str(), &st));
+	_isDirectory = _isValid ? S_ISDIR(st.st_mode) : false;
+}
+
+POSIXFilesystemNode::POSIXFilesystemNode() {
+	// The root dir.
+	_path = "/";
+	_displayName = _path;
+	_isValid = true;
+	_isDirectory = true;
+}
+
+POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) {
+	assert(p.size() > 0);
+
+	// Expand "~/" to the value of the HOME env variable
+	if (p.hasPrefix("~/")) {
+		const char *home = getenv("HOME");
+		if (home != NULL && strlen(home) < MAXPATHLEN) {
+			_path = home;
+			// Skip over the tilda.  We know that p contains at least
+			// two chars, so this is safe:
+			_path += p.c_str() + 1;
+		}
+	} else {
+		_path = p;
+	}
+
+	_displayName = lastPathComponent(_path);
+
+	if (verify) {
+		setFlags();
+	}
+}
+
+AbstractFilesystemNode *POSIXFilesystemNode::getChild(const String &n) const {
+	// FIXME: Pretty lame implementation! We do no error checking to speak
+	// of, do not check if this is a special node, etc.
+	assert(_isDirectory);
+
+	String newPath(_path);
+	if (_path.lastChar() != '/')
+		newPath += '/';
+	newPath += n;
+
+	return new POSIXFilesystemNode(newPath, true);
+}
+
+bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
+	assert(_isDirectory);
+
+	DIR *dirp = opendir(_path.c_str());
+	struct dirent *dp;
+
+	if (dirp == NULL)
+		return false;
+
+	// loop over dir entries using readdir
+	while ((dp = readdir(dirp)) != NULL) {
+		// Skip 'invisible' files if necessary
+		if (dp->d_name[0] == '.' && !hidden) {
+			continue;
+		}
+		// Skip '.' and '..' to avoid cycles
+		if ((dp->d_name[0] == '.' && dp->d_name[1] == 0) || (dp->d_name[0] == '.' && dp->d_name[1] == '.')) {
+			continue;
+		}
+
+		String newPath(_path);
+		if (newPath.lastChar() != '/')
+			newPath += '/';
+		newPath += dp->d_name;
+
+		POSIXFilesystemNode entry(newPath, false);
+
+#if defined(SYSTEM_NOT_SUPPORTING_D_TYPE)
+		/* TODO: d_type is not part of POSIX, so it might not be supported
+		 * on some of our targets. For those systems where it isn't supported,
+		 * add this #elif case, which tries to use stat() instead.
+		 *
+		 * The d_type method is used to avoid costly recurrent stat() calls in big
+		 * directories.
+		 */
+		entry.setFlags();
+#else
+		if (dp->d_type == DT_UNKNOWN) {
+			// Fall back to stat()
+			entry.setFlags();
+		} else {
+			entry._isValid = (dp->d_type == DT_DIR) || (dp->d_type == DT_REG) || (dp->d_type == DT_LNK);
+			if (dp->d_type == DT_LNK) {
+				struct stat st;
+				if (stat(entry._path.c_str(), &st) == 0)
+					entry._isDirectory = S_ISDIR(st.st_mode);
+				else
+					entry._isDirectory = false;
+			} else {
+				entry._isDirectory = (dp->d_type == DT_DIR);
+			}
+		}
+#endif
+
+		// Skip files that are invalid for some reason (e.g. because we couldn't
+		// properly stat them).
+		if (!entry._isValid)
+			continue;
+
+		// Honor the chosen mode
+		if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) ||
+			(mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
+			continue;
+
+		if (entry._isDirectory)
+			entry._path += "/";
+
+		myList.push_back(new POSIXFilesystemNode(entry));
+	}
+	closedir(dirp);
+
+	return true;
+}
+
+AbstractFilesystemNode *POSIXFilesystemNode::getParent() const {
+	if (_path == "/")
+		return 0;
+
+	const char *start = _path.c_str();
+	const char *end = lastPathComponent(_path);
+
+	return new POSIXFilesystemNode(String(start, end - start), true);
+}
+
+#endif //#if defined(UNIX)


Property changes on: residual/trunk/engine/backend/fs/posix/posix-fs.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native


Property changes on: residual/trunk/engine/backend/fs/windows
___________________________________________________________________
Added: svn:ignore
   + .deps
*.d
*.o


Added: residual/trunk/engine/backend/fs/windows/windows-fs-factory.cpp
===================================================================
--- residual/trunk/engine/backend/fs/windows/windows-fs-factory.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/fs/windows/windows-fs-factory.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,42 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#if defined(WIN32)
+#include "engine/backend/fs/windows/windows-fs-factory.h"
+#include "engine/backend/fs/windows/windows-fs.cpp"
+
+DECLARE_SINGLETON(WindowsFilesystemFactory);
+
+AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const {
+	return new WindowsFilesystemNode();
+}
+
+AbstractFilesystemNode *WindowsFilesystemFactory::makeCurrentDirectoryFileNode() const {
+	return new WindowsFilesystemNode("", true);
+}
+
+AbstractFilesystemNode *WindowsFilesystemFactory::makeFileNodePath(const String &path) const {
+	return new WindowsFilesystemNode(path, false);
+}
+#endif


Property changes on: residual/trunk/engine/backend/fs/windows/windows-fs-factory.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/windows/windows-fs-factory.h
===================================================================
--- residual/trunk/engine/backend/fs/windows/windows-fs-factory.h	                        (rev 0)
+++ residual/trunk/engine/backend/fs/windows/windows-fs-factory.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,51 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef WINDOWS_FILESYSTEM_FACTORY_H
+#define WINDOWS_FILESYSTEM_FACTORY_H
+
+#include "common/singleton.h"
+#include "engine/backend/fs/fs-factory.h"
+
+/**
+ * Creates WindowsFilesystemNode objects.
+ *
+ * Parts of this class are documented in the base interface class, FilesystemFactory.
+ */
+class WindowsFilesystemFactory : public FilesystemFactory, public Common::Singleton<WindowsFilesystemFactory> {
+public:
+	typedef Common::String String;
+
+	virtual AbstractFilesystemNode *makeRootFileNode() const;
+	virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
+	virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
+
+protected:
+	WindowsFilesystemFactory() {};
+
+private:
+	friend class Common::Singleton<SingletonBaseType>;
+};
+
+#endif /*WINDOWS_FILESYSTEM_FACTORY_H*/


Property changes on: residual/trunk/engine/backend/fs/windows/windows-fs-factory.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Added: residual/trunk/engine/backend/fs/windows/windows-fs.cpp
===================================================================
--- residual/trunk/engine/backend/fs/windows/windows-fs.cpp	                        (rev 0)
+++ residual/trunk/engine/backend/fs/windows/windows-fs.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -0,0 +1,344 @@
+/* Residual - Virtual machine to run LucasArts' 3D adventure games
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifdef WIN32
+
+#ifdef ARRAYSIZE
+#undef ARRAYSIZE
+#endif
+#ifdef _WIN32_WCE
+#include <windows.h>
+// winnt.h defines ARRAYSIZE, but we want our own one...
+#undef ARRAYSIZE
+#undef GetCurrentDirectory
+#endif
+#include "engine/backend/fs/abstract-fs.h"
+#include <io.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifndef _WIN32_WCE
+#include <windows.h>
+// winnt.h defines ARRAYSIZE, but we want our own one...
+#undef ARRAYSIZE
+#endif
+#include <tchar.h>
+
+// F_OK, R_OK and W_OK are not defined under MSVC, so we define them here
+// For more information on the modes used by MSVC, check:
+// http://msdn2.microsoft.com/en-us/library/1w06ktdy(VS.80).aspx
+#ifndef F_OK
+#define F_OK 0
+#endif
+
+#ifndef R_OK
+#define R_OK 4
+#endif
+
+#ifndef W_OK
+#define W_OK 2
+#endif
+
+/**
+ * Implementation of the ScummVM file system API based on Windows API.
+ *
+ * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
+ */
+class WindowsFilesystemNode : public AbstractFilesystemNode {
+protected:
+	String _displayName;
+	String _path;
+	bool _isDirectory;
+	bool _isPseudoRoot;
+	bool _isValid;
+
+public:
+	/**
+	 * Creates a WindowsFilesystemNode with the root node as path.
+	 *
+	 * In regular windows systems, a virtual root path is used "".
+	 * In windows CE, the "\" root is used instead.
+	 */
+	WindowsFilesystemNode();
+
+	/**
+	 * Creates a WindowsFilesystemNode for a given path.
+	 *
+	 * Examples:
+	 *			path=c:\foo\bar.txt, currentDir=false -> c:\foo\bar.txt
+	 *			path=c:\foo\bar.txt, currentDir=true -> current directory
+	 *			path=NULL, currentDir=true -> current directory
+	 *
+	 * @param path String with the path the new node should point to.
+	 * @param currentDir if true, the path parameter will be ignored and the resulting node will point to the current directory.
+	 */
+	WindowsFilesystemNode(const String &path, const bool currentDir);
+
+	virtual bool exists() const { return _access(_path.c_str(), F_OK) == 0; }
+	virtual String getDisplayName() const { return _displayName; }
+	virtual String getName() const { return _displayName; }
+	virtual String getPath() const { return _path; }
+	virtual bool isDirectory() const { return _isDirectory; }
+	virtual bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; }
+	virtual bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; }
+
+	virtual AbstractFilesystemNode *getChild(const String &n) const;
+	virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
+	virtual AbstractFilesystemNode *getParent() const;
+
+private:
+	/**
+	 * Adds a single WindowsFilesystemNode to a given list.
+	 * This method is used by getChildren() to populate the directory entries list.
+	 *
+	 * @param list List to put the file entry node in.
+	 * @param mode Mode to use while adding the file entry to the list.
+	 * @param base String with the directory being listed.
+	 * @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find.
+	 */
+	static void addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data);
+
+	/**
+	 * Converts a Unicode string to Ascii format.
+	 *
+	 * @param str String to convert from Unicode to Ascii.
+	 * @return str in Ascii format.
+	 */
+	static char *toAscii(TCHAR *str);
+
+	/**
+	 * Converts an Ascii string to Unicode format.
+	 *
+	 * @param str String to convert from Ascii to Unicode.
+	 * @return str in Unicode format.
+	 */
+	static const TCHAR* toUnicode(const char *str);
+};
+
+/**
+ * Returns the last component of a given path.
+ *
+ * Examples:
+ *			c:\foo\bar.txt would return "\bar.txt"
+ *			c:\foo\bar\    would return "\bar\"
+ *
+ * @param str Path to obtain the last component from.
+ * @return Pointer to the first char of the last component inside str.
+ */
+const char *lastPathComponent(const Common::String &str) {
+	if(str.empty())
+		return "";
+
+	const char *start = str.c_str();
+	const char *cur = start + str.size() - 2;
+
+	while (cur >= start && *cur != '\\') {
+		--cur;
+	}
+
+	return cur + 1;
+}
+
+void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) {
+	WindowsFilesystemNode entry;
+	char *asciiName = toAscii(find_data->cFileName);
+	bool isDirectory;
+
+	// Skip local directory (.) and parent (..)
+	if (!strcmp(asciiName, ".") || !strcmp(asciiName, ".."))
+		return;
+
+	isDirectory = (find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? true : false);
+
+	if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) ||
+		(isDirectory && mode == FilesystemNode::kListFilesOnly))
+		return;
+
+	entry._isDirectory = isDirectory;
+	entry._displayName = asciiName;
+	entry._path = base;
+	entry._path += asciiName;
+	if (entry._isDirectory)
+		entry._path += "\\";
+	entry._isValid = true;
+	entry._isPseudoRoot = false;
+
+	list.push_back(new WindowsFilesystemNode(entry));
+}
+
+char* WindowsFilesystemNode::toAscii(TCHAR *str) {
+#ifndef UNICODE
+	return (char*)str;
+#else
+	static char asciiString[MAX_PATH];
+	WideCharToMultiByte(CP_ACP, 0, str, _tcslen(str) + 1, asciiString, sizeof(asciiString), NULL, NULL);
+	return asciiString;
+#endif
+}
+
+const TCHAR* WindowsFilesystemNode::toUnicode(const char *str) {
+#ifndef UNICODE
+	return (const TCHAR *)str;
+#else
+	static TCHAR unicodeString[MAX_PATH];
+	MultiByteToWideChar(CP_ACP, 0, str, strlen(str) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR));
+	return unicodeString;
+#endif
+}
+
+WindowsFilesystemNode::WindowsFilesystemNode() {
+	_isDirectory = true;
+#ifndef _WIN32_WCE
+	// Create a virtual root directory for standard Windows system
+	_isValid = false;
+	_path = "";
+	_isPseudoRoot = true;
+#else
+	_displayName = "Root";
+	// No need to create a pseudo root directory on Windows CE
+	_isValid = true;
+	_path = "\\";
+	_isPseudoRoot = false;
+#endif
+}
+
+WindowsFilesystemNode::WindowsFilesystemNode(const String &p, const bool currentDir) {
+	if (currentDir) {
+		char path[MAX_PATH];
+		GetCurrentDirectory(MAX_PATH, path);
+		_path = path;
+	}
+	else {
+		assert(p.size() > 0);
+		_path = p;
+	}
+
+	_displayName = lastPathComponent(_path);
+
+	// Check whether it is a directory, and whether the file actually exists
+	DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
+
+	if (fileAttribs == INVALID_FILE_ATTRIBUTES) {
+		_isDirectory = false;
+		_isValid = false;
+	} else {
+		_isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
+		_isValid = true;
+		// Add a trailing slash, if necessary.
+		if (_path.lastChar() != '\\') {
+			_path += '\\';
+		}
+	}
+	_isPseudoRoot = false;
+}
+
+AbstractFilesystemNode *WindowsFilesystemNode::getChild(const String &n) const {
+	assert(_isDirectory);
+
+	String newPath(_path);
+	if (_path.lastChar() != '\\')
+		newPath += '\\';
+	newPath += n;
+
+	// Check whether the directory actually exists
+	DWORD fileAttribs = GetFileAttributes(toUnicode(newPath.c_str()));
+	if (fileAttribs == INVALID_FILE_ATTRIBUTES)
+		return 0;
+
+	return new WindowsFilesystemNode(newPath, false);
+}
+
+bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
+	assert(_isDirectory);
+
+	//TODO: honor the hidden flag
+
+	if (_isPseudoRoot) {
+#ifndef _WIN32_WCE
+		// Drives enumeration
+		TCHAR drive_buffer[100];
+		GetLogicalDriveStrings(sizeof(drive_buffer) / sizeof(TCHAR), drive_buffer);
+
+		for (TCHAR *current_drive = drive_buffer; *current_drive;
+			current_drive += _tcslen(current_drive) + 1) {
+				WindowsFilesystemNode entry;
+				char drive_name[2];
+
+				drive_name[0] = toAscii(current_drive)[0];
+				drive_name[1] = '\0';
+				entry._displayName = drive_name;
+				entry._isDirectory = true;
+				entry._isValid = true;
+				entry._isPseudoRoot = false;
+				entry._path = toAscii(current_drive);
+				myList.push_back(new WindowsFilesystemNode(entry));
+		}
+#endif
+	}
+	else {
+		// Files enumeration
+		WIN32_FIND_DATA desc;
+		HANDLE handle;
+		char searchPath[MAX_PATH + 10];
+
+		sprintf(searchPath, "%s*", _path.c_str());
+
+		handle = FindFirstFile(toUnicode(searchPath), &desc);
+
+		if (handle == INVALID_HANDLE_VALUE)
+			return false;
+
+		addFile(myList, mode, _path.c_str(), &desc);
+
+		while (FindNextFile(handle, &desc))
+			addFile(myList, mode, _path.c_str(), &desc);
+
+		FindClose(handle);
+	}
+
+	return true;
+}
+
+AbstractFilesystemNode *WindowsFilesystemNode::getParent() const {
+	assert(_isValid || _isPseudoRoot);
+
+	if (_isPseudoRoot)
+		return 0;
+
+	WindowsFilesystemNode *p = new WindowsFilesystemNode();
+	if (_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;
+		p->_displayName = lastPathComponent(p->_path);
+		p->_isPseudoRoot = false;
+	}
+
+	return p;
+}
+
+#endif //#ifdef WIN32


Property changes on: residual/trunk/engine/backend/fs/windows/windows-fs.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Revision Author URL Id
Added: svn:eol-style
   + native

Modified: residual/trunk/engine/backend/module.mk
===================================================================
--- residual/trunk/engine/backend/module.mk	2008-07-20 13:37:50 UTC (rev 33124)
+++ residual/trunk/engine/backend/module.mk	2008-07-20 13:56:00 UTC (rev 33125)
@@ -1,6 +1,9 @@
 MODULE := engine/backend
 
 MODULE_OBJS := \
+	fs/amigaos4/amigaos4-fs-factory.o \
+	fs/posix/posix-fs-factory.o \
+	fs/windows/windows-fs-factory.o \
 	default-timer.o
 
 # Include common rules

Modified: residual/trunk/engine/backend/sdl/driver_sdl.cpp
===================================================================
--- residual/trunk/engine/backend/sdl/driver_sdl.cpp	2008-07-20 13:37:50 UTC (rev 33124)
+++ residual/trunk/engine/backend/sdl/driver_sdl.cpp	2008-07-20 13:56:00 UTC (rev 33125)
@@ -38,6 +38,18 @@
 
 #define SAMPLES_PER_SEC 22050
 
+/*
+ * Include header files needed for the getFilesystemFactory() method.
+ */
+#if defined(__amigaos4__)
+	#include "engine/backend/fs/amigaos4/amigaos4-fs-factory.h"
+#elif defined(UNIX)
+	#include "engine/backend/fs/posix/posix-fs-factory.h"
+#elif defined(WIN32)
+	#include "engine/backend/fs/windows/windows-fs-factory.h"
+#endif
+
+
 // NOTE: This is not a complete driver, it needs to be subclassed
 //       to provide rendering functionality.
 
@@ -488,6 +500,20 @@
 		error("Unable to push exit event!");
 }
 
+FilesystemFactory *DriverSDL::getFilesystemFactory() {
+	#if defined(__amigaos4__)
+		return &AmigaOSFilesystemFactory::instance();	
+	#elif defined(UNIX)
+		return &POSIXFilesystemFactory::instance();
+	#elif defined(WIN32)
+		return &WindowsFilesystemFactory::instance();
+	#elif defined(__SYMBIAN32__)
+		// Do nothing since its handled by the Symbian SDL inheritance
+	#else
+		#error Unknown and unsupported backend in Driver_SDL::getFilesystemFactory
+	#endif
+}
+
 void DriverSDL::setupIcon() {
 	int w, h, ncols, nbytes, i;
 	unsigned int rgba[256], icon[32 * 32];

Modified: residual/trunk/engine/backend/sdl/driver_sdl.h
===================================================================
--- residual/trunk/engine/backend/sdl/driver_sdl.h	2008-07-20 13:37:50 UTC (rev 33124)
+++ residual/trunk/engine/backend/sdl/driver_sdl.h	2008-07-20 13:56:00 UTC (rev 33125)
@@ -76,6 +76,7 @@
 	Audio::Mixer *getMixer();
 
 	void quit();
+	FilesystemFactory *getFilesystemFactory();
 
 private:
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list