aboutsummaryrefslogtreecommitdiff
path: root/backends/fs
diff options
context:
space:
mode:
Diffstat (limited to 'backends/fs')
-rw-r--r--backends/fs/abstract-fs.h121
-rw-r--r--backends/fs/amigaos4/amigaos4-fs.cpp9
-rw-r--r--backends/fs/fs.cpp14
-rw-r--r--backends/fs/fs.h140
-rw-r--r--backends/fs/morphos/abox-fs.cpp7
-rw-r--r--backends/fs/palmos/palmos-fs.cpp4
-rw-r--r--backends/fs/posix/posix-fs.cpp7
-rw-r--r--backends/fs/ps2/ps2-fs.cpp6
-rw-r--r--backends/fs/symbian/symbian-fs.cpp7
-rw-r--r--backends/fs/windows/windows-fs.cpp5
10 files changed, 180 insertions, 140 deletions
diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h
new file mode 100644
index 0000000000..3d17590782
--- /dev/null
+++ b/backends/fs/abstract-fs.h
@@ -0,0 +1,121 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2002-2006 The ScummVM project
+ *
+ * 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/str.h"
+
+#include "backends/fs/fs.h"
+
+/**
+ * Abstract file system node. Private subclasses implement the actual
+ * functionality.
+ */
+class AbstractFilesystemNode {
+protected:
+ friend class FilesystemNode;
+ typedef Common::String String;
+ typedef FilesystemNode::ListMode ListMode;
+
+ /**
+ * The parent node of this directory.
+ * The parent of the root is the root itself.
+ */
+ virtual AbstractFilesystemNode *parent() const = 0;
+
+ /**
+ * The child node with the given name. If no child with this name
+ * exists, returns 0. Will never be called on a node which is not
+ * a directory node.
+ */
+ virtual AbstractFilesystemNode *child(const String &name) const = 0;
+
+ /**
+ * This method is a rather ugly hack which is used internally by the
+ * actual node implementions to wrap up raw nodes inside FilesystemNode
+ * objects. We probably want to get rid of this eventually and replace it
+ * with a cleaner / more elegant solution, but for now it works.
+ * @note This takes over ownership of node. Do not delete it yourself,
+ * else you'll get ugly crashes. You've been warned!
+ */
+ static FilesystemNode wrap(AbstractFilesystemNode *node);
+
+public:
+ virtual ~AbstractFilesystemNode() {}
+
+ /**
+ * Return a human readable string for this node, usable for display (e.g.
+ * in the GUI code). Do *not* rely on it being usable for anything else,
+ * like constructing paths!
+ * @return the display name
+ */
+ virtual String displayName() const = 0;
+
+ /**
+ * Is this node valid? Returns true if the file/directory pointed
+ * to by this node exists, false otherwise.
+ *
+ * @todo Maybe rename this to exists() ? Or maybe even distinguish between
+ * the two? E.g. a path may be non-existant but valid, while another might
+ * be completely invalid). But do we ever need to make that distinction?
+ */
+ virtual bool isValid() const = 0;
+
+ /**
+ * Is this node pointing to a directory?
+ * @todo Currently we assume that a valid node that is not a directory
+ * automatically is a file (ignoring things like symlinks). That might
+ * actually be OK... but we could still add an isFile method. Or even replace
+ * isValid and isDirectory by a getType() method that can return values like
+ * kDirNodeType, kFileNodeType, kInvalidNodeType.
+ */
+ virtual bool isDirectory() const = 0;
+
+ /**
+ * Return a string representation of the file which can be passed to fopen(),
+ * and is suitable for archiving (i.e. writing to the config file).
+ * This will usually be a 'path' (hence the name of the method), but can
+ * be anything that fulfilly the above criterions.
+ */
+ virtual String path() const = 0;
+
+ /**
+ * Return a list of child nodes of this directory node. If called
+ * on a node that does not represent a directory, an error is triggered.
+ * @todo Rename this to listChildren.
+ */
+ virtual FSList listDir(ListMode mode) const = 0;
+
+
+ /* TODO:
+ bool exists();
+
+ bool isDirectory();
+ bool isFile();
+
+ bool isReadable();
+ bool isWriteable();
+ */
+};
+
+
+#endif
diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp
index 92897ff0ca..77e96ea52b 100644
--- a/backends/fs/amigaos4/amigaos4-fs.cpp
+++ b/backends/fs/amigaos4/amigaos4-fs.cpp
@@ -37,6 +37,7 @@
#include "common/util.h"
#include "base/engine.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#define ENTER() /* debug(6, "Enter") */
@@ -68,7 +69,7 @@ class AmigaOSFilesystemNode : public AbstractFilesystemNode {
virtual bool isDirectory() const { return _bIsDirectory; };
virtual String path() const { return _sPath; };
- virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+ virtual FSList listDir(ListMode mode) const;
virtual FSList listVolumes(void) const;
virtual AbstractFilesystemNode *parent() const;
virtual AbstractFilesystemNode *child(const String &name) const;
@@ -263,9 +264,9 @@ FSList AmigaOSFilesystemNode::listDir(ListMode mode) const {
struct ExAllData *ead = data;
do {
- if ((mode == kListAll) ||
- (EAD_IS_DRAWER(ead) && (mode == kListDirectoriesOnly)) ||
- (EAD_IS_FILE(ead) && (mode == kListFilesOnly))) {
+ 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;
diff --git a/backends/fs/fs.cpp b/backends/fs/fs.cpp
index 4907e78ee6..a8c38786fc 100644
--- a/backends/fs/fs.cpp
+++ b/backends/fs/fs.cpp
@@ -21,6 +21,7 @@
#include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#include "common/util.h"
@@ -48,8 +49,7 @@ FilesystemNode::FilesystemNode() {
++(*_refCount);
}
-FilesystemNode::FilesystemNode(const FilesystemNode &node)
- : AbstractFilesystemNode() {
+FilesystemNode::FilesystemNode(const FilesystemNode &node) {
_realNode = node._realNode;
_refCount = node._refCount;
++(*_refCount);
@@ -131,3 +131,13 @@ Common::String FilesystemNode::path() const {
assert(_realNode);
return _realNode->path();
}
+
+
+bool FilesystemNode::operator< (const FilesystemNode& node) const
+{
+ if (isDirectory() && !node.isDirectory())
+ return true;
+ if (!isDirectory() && node.isDirectory())
+ return false;
+ return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
+}
diff --git a/backends/fs/fs.h b/backends/fs/fs.h
index bbc7d1e8d4..a2156463d8 100644
--- a/backends/fs/fs.h
+++ b/backends/fs/fs.h
@@ -19,8 +19,8 @@
* $Id$
*/
-#ifndef FS_H
-#define FS_H
+#ifndef BACKENDS_FS_H
+#define BACKENDS_FS_H
/*
* The API described in this header is meant to allow for file system browsing in a
@@ -56,6 +56,7 @@
#include "common/str.h"
class FilesystemNode;
+class AbstractFilesystemNode;
/**
@@ -66,119 +67,7 @@ class FilesystemNode;
class FSList : public Common::Array<FilesystemNode> {};
-/**
- * File system node.
- */
-class AbstractFilesystemNode {
-protected:
- friend class FilesystemNode;
- typedef Common::String String;
-
- /**
- * The parent node of this directory.
- * The parent of the root is the root itself.
- */
- virtual AbstractFilesystemNode *parent() const = 0;
-
- /**
- * The child node with the given name. If no child with this name
- * exists, returns 0. Will never be called on a node which is not
- * a directory node.
- */
- virtual AbstractFilesystemNode *child(const String &name) const = 0;
-
- /**
- * This method is a rather ugly hack which is used internally by the
- * actual node implementions to wrap up raw nodes inside FilesystemNode
- * objects. We probably want to get rid of this eventually and replace it
- * with a cleaner / more elegant solution, but for now it works.
- * @note This takes over ownership of node. Do not delete it yourself,
- * else you'll get ugly crashes. You've been warned!
- */
- static FilesystemNode wrap(AbstractFilesystemNode *node);
-
-public:
-
- /**
- * Flag to tell listDir() which kind of files to list.
- */
- typedef enum {
- kListFilesOnly = 1,
- kListDirectoriesOnly = 2,
- kListAll = 3
- } ListMode;
-
- virtual ~AbstractFilesystemNode() {}
-
- /**
- * Return a human readable string for this node, usable for display (e.g.
- * in the GUI code). Do *not* rely on it being usable for anything else,
- * like constructing paths!
- * @return the display name
- */
- virtual String displayName() const = 0;
-
- /**
- * Is this node valid? Returns true if the file/directory pointed
- * to by this node exists, false otherwise.
- *
- * @todo Maybe rename this to exists() ? Or maybe even distinguish between
- * the two? E.g. a path may be non-existant but valid, while another might
- * be completely invalid). But do we ever need to make that distinction?
- */
- virtual bool isValid() const = 0;
-
- /**
- * Is this node pointing to a directory?
- * @todo Currently we assume that a valid node that is not a directory
- * automatically is a file (ignoring things like symlinks). That might
- * actually be OK... but we could still add an isFile method. Or even replace
- * isValid and isDirectory by a getType() method that can return values like
- * kDirNodeType, kFileNodeType, kInvalidNodeType.
- */
- virtual bool isDirectory() const = 0;
-
- /**
- * Return a string representation of the file which can be passed to fopen(),
- * and is suitable for archiving (i.e. writing to the config file).
- * This will usually be a 'path' (hence the name of the method), but can
- * be anything that fulfilly the above criterions.
- */
- virtual String path() const = 0;
-
- /**
- * Return a list of child nodes of this directory node. If called
- * on a node that does not represent a directory, an error is triggered.
- * @todo Rename this to listChildren.
- */
- virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const = 0;
-
- /**
- * Compare the name of this node to the name of another. Directories
- * go before normal files.
- */
- virtual bool operator< (const AbstractFilesystemNode& node) const
- {
- if (isDirectory() && !node.isDirectory())
- return true;
- if (!isDirectory() && node.isDirectory())
- return false;
- return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
- }
-
-
- /* TODO:
- bool exists();
-
- bool isDirectory();
- bool isFile();
-
- bool isReadable();
- bool isWriteable();
- */
-};
-
-class FilesystemNode : public AbstractFilesystemNode {
+class FilesystemNode {
friend class AbstractFilesystemNode;
typedef Common::String String;
@@ -213,6 +102,16 @@ private:
public:
/**
+ * Flag to tell listDir() which kind of files to list.
+ */
+ enum ListMode {
+ kListFilesOnly = 1,
+ kListDirectoriesOnly = 2,
+ kListAll = 3
+ };
+
+
+ /**
* Create a new FilesystemNode refering to the specified path. This is
* the counterpart to the path() method.
*/
@@ -221,7 +120,7 @@ public:
FilesystemNode();
FilesystemNode(const FilesystemNode &node);
- ~FilesystemNode();
+ virtual ~FilesystemNode();
FilesystemNode &operator =(const FilesystemNode &node);
@@ -244,11 +143,14 @@ public:
virtual bool isDirectory() const;
virtual String path() const;
+ /**
+ * Compare the name of this node to the name of another. Directories
+ * go before normal files.
+ */
+ bool operator< (const FilesystemNode& node) const;
+
protected:
void decRefCount();
-
- virtual AbstractFilesystemNode *parent() const { return 0; }
- virtual AbstractFilesystemNode *child(const String &name) const { return 0; }
};
diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp
index c4cd89d438..d8eada1868 100644
--- a/backends/fs/morphos/abox-fs.cpp
+++ b/backends/fs/morphos/abox-fs.cpp
@@ -26,6 +26,7 @@
#include <stdio.h>
#include "base/engine.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
/*
@@ -50,7 +51,7 @@ class ABoxFilesystemNode : public AbstractFilesystemNode {
virtual bool isDirectory() const { return _isDirectory; }
virtual String path() const { return _path; }
- virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+ virtual FSList listDir(ListMode mode) const;
static FSList listRoot();
virtual AbstractFilesystemNode *parent() const;
virtual AbstractFilesystemNode *child(const String &name) const;
@@ -161,8 +162,8 @@ FSList ABoxFilesystemNode::listDir(ListMode mode) const
String full_path;
BPTR lock;
- if ((fib->fib_EntryType > 0 && (mode & kListDirectoriesOnly)) ||
- (fib->fib_EntryType < 0 && (mode & kListFilesOnly)))
+ if ((fib->fib_EntryType > 0 && (mode & FilesystemNode::kListDirectoriesOnly)) ||
+ (fib->fib_EntryType < 0 && (mode & FilesystemNode::kListFilesOnly)))
{
full_path = _path;
full_path += fib->fib_FileName;
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp
index 144165e903..c9afbeeb21 100644
--- a/backends/fs/palmos/palmos-fs.cpp
+++ b/backends/fs/palmos/palmos-fs.cpp
@@ -62,8 +62,8 @@ void PalmOSFilesystemNode::addFile(FSList &list, ListMode mode, const char *base
isDirectory = (find_data->attributes & vfsFileAttrDirectory);
- if ((!isDirectory && mode == kListDirectoriesOnly) ||
- (isDirectory && mode == kListFilesOnly))
+ if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) ||
+ (isDirectory && mode == FilesystemNode::kListFilesOnly))
return;
entry._isDirectory = isDirectory;
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index 9ad0d57967..6681a7fdf4 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -23,6 +23,7 @@
#include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#ifdef MACOSX
@@ -56,7 +57,7 @@ public:
virtual bool isDirectory() const { return _isDirectory; }
virtual String path() const { return _path; }
- virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+ virtual FSList listDir(ListMode mode) const;
virtual AbstractFilesystemNode *parent() const;
virtual AbstractFilesystemNode *child(const String &name) const;
};
@@ -185,8 +186,8 @@ FSList POSIXFilesystemNode::listDir(ListMode mode) const {
continue;
// Honor the chosen mode
- if ((mode == kListFilesOnly && entry._isDirectory) ||
- (mode == kListDirectoriesOnly && !entry._isDirectory))
+ if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) ||
+ (mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
continue;
if (entry._isDirectory)
diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp
index 7630dec653..b749f59796 100644
--- a/backends/fs/ps2/ps2-fs.cpp
+++ b/backends/fs/ps2/ps2-fs.cpp
@@ -19,6 +19,8 @@
* $Id$
*/
+#include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#include <kernel.h>
#include <stdio.h>
@@ -88,10 +90,10 @@ FSList Ps2FilesystemNode::listDir(ListMode mode) const {
sprintf(listDir, "%s/", _path.c_str() + 5);
switch(mode) {
- case kListFilesOnly:
+ case FilesystemNode::kListFilesOnly:
files = CDVD_GetDir(listDir, NULL, CDVD_GET_FILES_ONLY, tocEntries, MAX_LIST_ENTRIES, NULL);
break;
- case kListDirectoriesOnly:
+ case FilesystemNode::kListDirectoriesOnly:
files = CDVD_GetDir(listDir, NULL, CDVD_GET_DIRS_ONLY, tocEntries, MAX_LIST_ENTRIES, NULL);
break;
default:
diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp
index 062ab22856..78a2461a5b 100644
--- a/backends/fs/symbian/symbian-fs.cpp
+++ b/backends/fs/symbian/symbian-fs.cpp
@@ -24,6 +24,7 @@
#if defined (__SYMBIAN32__)
#include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#include <dirent.h>
@@ -51,7 +52,7 @@ public:
virtual bool isDirectory() const { return _isDirectory; }
virtual String path() const { return _path; }
- virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
+ virtual FSList listDir(ListMode mode) const;
virtual AbstractFilesystemNode *parent() const;
virtual AbstractFilesystemNode *child(const String &name) const;
};
@@ -166,8 +167,8 @@ FSList SymbianFilesystemNode::listDir(ListMode mode) const {
entry._isDirectory = fileentry.IsDir();
// Honor the chosen mode
- if ((mode == kListFilesOnly && entry._isDirectory) ||
- (mode == kListDirectoriesOnly && !entry._isDirectory))
+ if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) ||
+ (mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
continue;
if (entry._isDirectory)
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index aeeecd5d43..fb23c8e1f5 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -22,6 +22,7 @@
#ifdef WIN32
#include "common/stdafx.h"
+#include "backends/fs/abstract-fs.h"
#include "backends/fs/fs.h"
#include <stdio.h>
#include <stdlib.h>
@@ -103,8 +104,8 @@ void WindowsFilesystemNode::addFile(FSList &list, ListMode mode, const char *bas
isDirectory = (find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? true : false);
- if ((!isDirectory && mode == kListDirectoriesOnly) ||
- (isDirectory && mode == kListFilesOnly))
+ if ((!isDirectory && mode == FilesystemNode::kListDirectoriesOnly) ||
+ (isDirectory && mode == FilesystemNode::kListFilesOnly))
return;
entry._isDirectory = isDirectory;