From c459f054b46b8791ce206c2ee13d455a9c10fe4d Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 3 May 2007 02:39:33 +0000 Subject: [PATCH 01/26] Use abstract factories to initialize FilesystemNode objects. svn-id: r26739 --- backends/fs/AbstractFilesystemFactory.h | 48 ++++ backends/fs/FilesystemFactoryMaker.cpp | 113 ++++++++ backends/fs/abstract-fs.h | 102 ++++--- .../fs/amigaos4/AmigaOSFilesystemFactory.cpp | 23 ++ .../fs/amigaos4/AmigaOSFilesystemFactory.h | 38 +++ backends/fs/amigaos4/amigaos4-fs.cpp | 157 ++++++----- backends/fs/dc/RoninCDFilesystemFactory.cpp | 23 ++ backends/fs/dc/RoninCDFilesystemFactory.h | 38 +++ backends/fs/dc/dc-fs.cpp | 99 +++---- backends/fs/ds/DSFilesystemFactory.cpp | 36 +++ backends/fs/ds/DSFilesystemFactory.h | 38 +++ backends/fs/ds/ds-fs.cpp | 229 +++++---------- backends/fs/ds/ds-fs.h | 115 +++++--- backends/fs/gp32/GP32FilesystemFactory.cpp | 23 ++ backends/fs/gp32/GP32FilesystemFactory.h | 38 +++ backends/fs/gp32/gp32-fs.cpp | 125 +++++---- backends/fs/morphos/ABoxFilesystemFactory.cpp | 23 ++ backends/fs/morphos/ABoxFilesystemFactory.h | 38 +++ backends/fs/morphos/abox-fs.cpp | 265 +++++++++--------- .../fs/palmos/PalmOSFilesystemFactory.cpp | 23 ++ backends/fs/palmos/PalmOSFilesystemFactory.h | 38 +++ backends/fs/palmos/palmos-fs.cpp | 134 +++++---- backends/fs/posix/POSIXFilesystemFactory.cpp | 25 ++ backends/fs/posix/POSIXFilesystemFactory.h | 38 +++ backends/fs/posix/posix-fs.cpp | 133 +++++---- backends/fs/ps2/Ps2FilesystemFactory.cpp | 23 ++ backends/fs/ps2/Ps2FilesystemFactory.h | 38 +++ backends/fs/ps2/ps2-fs.cpp | 125 +++++---- backends/fs/psp/PSPFilesystemFactory.cpp | 23 ++ backends/fs/psp/PSPFilesystemFactory.h | 38 +++ backends/fs/psp/psp_fs.cpp | 105 +++---- .../fs/symbian/SymbianFilesystemFactory.cpp | 25 ++ .../fs/symbian/SymbianFilesystemFactory.h | 38 +++ backends/fs/symbian/symbian-fs.cpp | 115 ++++---- .../fs/windows/WindowsFilesystemFactory.cpp | 23 ++ .../fs/windows/WindowsFilesystemFactory.h | 38 +++ backends/fs/windows/windows-fs.cpp | 199 ++++++++----- common/fs.cpp | 23 +- common/fs.h | 90 +++--- 39 files changed, 1912 insertions(+), 953 deletions(-) create mode 100644 backends/fs/AbstractFilesystemFactory.h create mode 100644 backends/fs/FilesystemFactoryMaker.cpp create mode 100644 backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp create mode 100644 backends/fs/amigaos4/AmigaOSFilesystemFactory.h create mode 100644 backends/fs/dc/RoninCDFilesystemFactory.cpp create mode 100644 backends/fs/dc/RoninCDFilesystemFactory.h create mode 100644 backends/fs/ds/DSFilesystemFactory.cpp create mode 100644 backends/fs/ds/DSFilesystemFactory.h create mode 100644 backends/fs/gp32/GP32FilesystemFactory.cpp create mode 100644 backends/fs/gp32/GP32FilesystemFactory.h create mode 100644 backends/fs/morphos/ABoxFilesystemFactory.cpp create mode 100644 backends/fs/morphos/ABoxFilesystemFactory.h create mode 100644 backends/fs/palmos/PalmOSFilesystemFactory.cpp create mode 100644 backends/fs/palmos/PalmOSFilesystemFactory.h create mode 100644 backends/fs/posix/POSIXFilesystemFactory.cpp create mode 100644 backends/fs/posix/POSIXFilesystemFactory.h create mode 100644 backends/fs/ps2/Ps2FilesystemFactory.cpp create mode 100644 backends/fs/ps2/Ps2FilesystemFactory.h create mode 100644 backends/fs/psp/PSPFilesystemFactory.cpp create mode 100644 backends/fs/psp/PSPFilesystemFactory.h create mode 100644 backends/fs/symbian/SymbianFilesystemFactory.cpp create mode 100644 backends/fs/symbian/SymbianFilesystemFactory.h create mode 100644 backends/fs/windows/WindowsFilesystemFactory.cpp create mode 100644 backends/fs/windows/WindowsFilesystemFactory.h diff --git a/backends/fs/AbstractFilesystemFactory.h b/backends/fs/AbstractFilesystemFactory.h new file mode 100644 index 00000000000..4af8c6b6570 --- /dev/null +++ b/backends/fs/AbstractFilesystemFactory.h @@ -0,0 +1,48 @@ +#ifndef ABSTRACTFILESYSTEMFACTORY_H_ +#define ABSTRACTFILESYSTEMFACTORY_H_ + +#include "common/str.h" + +/** + * Creates concrete FilesystemNode objects depending on the current architecture. + */ +class AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Destructor. + */ + virtual ~AbstractFilesystemFactory() {}; + + /** + * 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 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 /*ABSTRACTFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/FilesystemFactoryMaker.cpp b/backends/fs/FilesystemFactoryMaker.cpp new file mode 100644 index 00000000000..66a1c8c0c49 --- /dev/null +++ b/backends/fs/FilesystemFactoryMaker.cpp @@ -0,0 +1,113 @@ +#include "backends/fs/AbstractFilesystemFactory.h" + +/* + * All the following includes choose, at compile time, which specific backend will be used + * during the execution of the ScummVM. + * + * It has to be done this way because not all the necessary libraries will be available in + * all build environments. Additionally, this results in smaller binaries. + */ +#if defined(__amigaos4__) + #include "backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp" +#endif + +#if defined(__DC__) + #include "backends/fs/dc/RoninCDFilesystemFactory.cpp" +#endif + +#if defined(__DS__) + #include "backends/fs/ds/DSFilesystemFactory.cpp" +#endif + +#if defined(__GP32__) + #include "backends/fs/gp32/GP32FilesystemFactory.cpp" +#endif + +#if defined(__MORPHOS__) + #include "backends/fs/morphos/ABoxFilesystemFactory.cpp" +#endif + +#if defined(PALMOS_MODE) + #include "backends/fs/palmos/PalmOSFilesystemFactory.cpp" +#endif + +#if defined(__PLAYSTATION2__) + #include "backends/fs/ps2/Ps2FilesystemFactory.cpp" +#endif + +#if defined(__PSP__) + #include "backends/fs/psp/PSPFilesystemFactory.cpp" +#endif + +#if defined(__SYMBIAN32__) + #include "backends/fs/symbian/SymbianFilesystemFactory.cpp" +#endif + +#if defined(UNIX) + #include "backends/fs/posix/POSIXFilesystemFactory.cpp" +#endif + +#if defined(WIN32) + #include "backends/fs/windows/WindowsFilesystemFactory.cpp" +#endif + +/** + * Creates concrete FilesystemFactory objects depending on the current architecture. + */ +class FilesystemFactoryMaker { +public: + + /** + * Returns the correct concrete factory depending on the current build architecture. + */ + static AbstractFilesystemFactory *makeFactory(); + +protected: + FilesystemFactoryMaker() {}; // avoid instances of this class +}; + +AbstractFilesystemFactory *FilesystemFactoryMaker::makeFactory(){ + #if defined(__amigaos4__) + return AmigaOSFilesystemFactory::instance(); + #endif + + #if defined(__DC__) + return RoninCDFilesystemFactory::instance(); + #endif + + #if defined(__DS__) + return DSFilesystemFactory::instance(); + #endif + + #if defined(__GP32__) + return GP32FilesystemFactory::instance(); + #endif + + #if defined(__MORPHOS__) + return ABoxFilesystemFactory::instance(); + #endif + + #if defined(PALMOS_MODE) + return PalmOSFilesystemFactory::instance(); + #endif + + #if defined(__PLAYSTATION2__) + return Ps2FilesystemFactory::instance(); + #endif + + #if defined(__PSP__) + return PSPFilesystemFactory::instance(); + #endif + + #if defined(__SYMBIAN32__) + return SymbianFilesystemFactory::instance(); + #endif + + #if defined(UNIX) + return POSIXFilesystemFactory::instance(); + #endif + + #if defined(WIN32) + return WindowsFilesystemFactory::instance(); + #endif +} diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index c85b2fe8bf8..86149dfffab 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -46,75 +46,72 @@ protected: 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 + * 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 *child(const String &name) const = 0; - + virtual AbstractFilesystemNode *getChild(const String &name) const = 0; /** - * Returns a special node representing the FS 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:). + * The parent node of this directory. + * The parent of the root is the root itself. */ - static AbstractFilesystemNode *getRoot(); - - /** - * 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. - */ - static AbstractFilesystemNode *getCurrentDirectory(); - - - /** - * 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. - * - * @todo: This is of course a place where non-portable code easily will sneak - * in, because the format of the path used here is not well-defined. - * So we really should reconsider this API and try to come up with - * something which is more portable but still flexible enough for our - * purposes. - */ - static AbstractFilesystemNode *getNodeForPath(const String &path); - + virtual AbstractFilesystemNode *getParent() const = 0; public: + /** + * Destructor. + */ virtual ~AbstractFilesystemNode() {} - virtual String name() 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. + * @return true if succesful, false otherwise (e.g. when the directory does not exist). + */ + virtual bool getChildren(AbstractFSList &list, ListMode mode) 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 a string with an architecture dependent path description. + */ + virtual String getName() const = 0; - // By default, we use the actual file name as 'display name'. - virtual String displayName() const { return name(); } - - virtual bool isValid() 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; /** - * Return the 'path' of the current node, usable in fopen(). See also - * the static getNodeForPath() method. + * Indicates whether this path is valid or not for usage. */ - virtual String path() const = 0; - virtual bool listDir(AbstractFSList &list, ListMode mode) const = 0; - + virtual bool isValid() const = 0; /* TODO: bool exists(); @@ -123,9 +120,8 @@ public: bool isFile(); bool isReadable(); - bool isWriteable(); + bool isWritable(); */ }; - #endif diff --git a/backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp b/backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp new file mode 100644 index 00000000000..2f264917883 --- /dev/null +++ b/backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/amigaos4/AmigaOSFilesystemFactory.h" +#include "backends/fs/amigaos4/amigaos4-fs.cpp" + +AmigaOSFilesystemFactory *AmigaOSFilesystemFactory::_instance = 0; + +AmigaOSFilesystemFactory *AmigaOSFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new AmigaOSFilesystemFactory(); + } + return _instance; +} + +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); +} diff --git a/backends/fs/amigaos4/AmigaOSFilesystemFactory.h b/backends/fs/amigaos4/AmigaOSFilesystemFactory.h new file mode 100644 index 00000000000..8eea9528310 --- /dev/null +++ b/backends/fs/amigaos4/AmigaOSFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef AMIGAOSFILESYSTEMFACTORY_H_ +#define AMIGAOSFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates AmigaOSFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class AmigaOSFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of AmigaOSFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of AmigaOSFilesytemFactory. + */ + static AmigaOSFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~AmigaOSFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + AmigaOSFilesystemFactory() {}; + +private: + static AmigaOSFilesystemFactory *_instance; +}; + +#endif /*AMIGAOSFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp index 3abf5672c80..8768519a76d 100644 --- a/backends/fs/amigaos4/amigaos4-fs.cpp +++ b/backends/fs/amigaos4/amigaos4-fs.cpp @@ -1,5 +1,5 @@ /* ScummVM - Scumm Interpreter - * Copyright (C) 2005-2006 The ScummVM project, contribution by Hans-Jörg Frieden and Juha Niemimäki + * Copyright (C) 2005-2006 The ScummVM project, contribution by Hans-J�rg Frieden and Juha Niemim�ki * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,58 +35,73 @@ #include #include "common/util.h" - #include "engines/engine.h" #include "backends/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; - bool _bIsDirectory; - bool _bIsValid; - String _sPath; +protected: + BPTR _pFileLock; + String _sDisplayName; + String _sPath; + bool _bIsDirectory; + bool _bIsValid; - public: - AmigaOSFilesystemNode(); - AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0); - AmigaOSFilesystemNode(const String &p); +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); - // Note: Copy constructor is needed because it duplicates the file lock - AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node); - - virtual ~AmigaOSFilesystemNode(); + /** + * Copy constructor. + * + * @note Needed because it duplicates the file lock + */ + AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node); + + /** + * Destructor. + */ + virtual ~AmigaOSFilesystemNode(); - virtual String displayName() const { return _sDisplayName; }; - virtual String name() const { return _sDisplayName; }; - virtual bool isValid() const { return _bIsValid; }; - virtual bool isDirectory() const { return _bIsDirectory; }; - virtual String path() const { return _sPath; }; - - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFSList listVolumes() const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual String getDisplayName() const { return _sDisplayName; }; + virtual String getName() const { return _sDisplayName; }; + virtual String getPath() const { return _sPath; }; + virtual bool isValid() const { return _bIsValid; }; + virtual bool isDirectory() const { return _bIsDirectory; }; + + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; + + /** + * Creates a list with all the volumes present in the root node. + */ + virtual AbstractFSList listVolumes() const; }; -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new AmigaOSFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new AmigaOSFilesystemNode(path); -} - AmigaOSFilesystemNode::AmigaOSFilesystemNode() { ENTER(); _sDisplayName = "Available Disks"; @@ -97,7 +112,6 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode() { LEAVE(); } - AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) { ENTER(); @@ -147,7 +161,6 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) { const char c = _sPath.lastChar(); if (c != '/' && c != ':') _sPath += '/'; - } else { //_bIsDirectory = false; @@ -167,7 +180,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayNam int bufSize = MAXPATHLEN; _pFileLock = 0; - while (1) { + while (true) { char *n = new char[bufSize]; if (IDOS->NameFromLock(pLock, (STRPTR)n, bufSize) != DOSFALSE) { _sPath = n; @@ -183,6 +196,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayNam delete [] n; return; } + bufSize *= 2; delete [] n; } @@ -235,7 +249,31 @@ AmigaOSFilesystemNode::~AmigaOSFilesystemNode() { LEAVE(); } -bool AmigaOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +AbstractFilesystemNode *AmigaOSFilesystemNode::getChild(const String &n) const { + 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); + + return new AmigaOSFilesystemNode(newPath); +} + +bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { ENTER(); if (!_bIsValid) { @@ -305,10 +343,11 @@ bool AmigaOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const } LEAVE(); + return true; } -AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const { +AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const { ENTER(); if (!_bIsDirectory) { @@ -334,33 +373,8 @@ AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const { node = new AmigaOSFilesystemNode(); LEAVE(); - return node; -} - -AbstractFilesystemNode *AmigaOSFilesystemNode::child(const String &n) const { - 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); - - return new AmigaOSFilesystemNode(newPath); + return node; } AbstractFSList AmigaOSFilesystemNode::listVolumes() const { @@ -428,7 +442,8 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const { IDOS->UnLockDosList(kLockFlags); LEAVE(); + return myList; } -#endif +#endif //defined(__amigaos4__) diff --git a/backends/fs/dc/RoninCDFilesystemFactory.cpp b/backends/fs/dc/RoninCDFilesystemFactory.cpp new file mode 100644 index 00000000000..19147453687 --- /dev/null +++ b/backends/fs/dc/RoninCDFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/dc/RoninCDFilesystemFactory.h" +#include "backends/fs/dc/dc-fs.cpp" + +RoninCDFilesystemFactory *RoninCDFilesystemFactory::_instance = 0; + +RoninCDFilesystemFactory *RoninCDFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new RoninCDFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *RoninCDFilesystemFactory::makeRootFileNode() const { + return new RoninCDFilesystemNode(); +} + +AbstractFilesystemNode *RoninCDFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new RoninCDFilesystemNode(); +} + +AbstractFilesystemNode *RoninCDFilesystemFactory::makeFileNodePath(const String &path) const { + return new RoninCDFilesystemNode(path, true); +} diff --git a/backends/fs/dc/RoninCDFilesystemFactory.h b/backends/fs/dc/RoninCDFilesystemFactory.h new file mode 100644 index 00000000000..a063ce1d6a9 --- /dev/null +++ b/backends/fs/dc/RoninCDFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef RONINCDFILESYSTEMFACTORY_H_ +#define RONINCDFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates RoninCDFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class RoninCDFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of RoninCDFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of RoninCDFilesytemFactory. + */ + static RoninCDFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~RoninCDFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + RoninCDFilesystemFactory() {}; + +private: + static RoninCDFilesystemFactory *_instance; +}; + +#endif /*RONINCDFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index e35d0923183..bdaaeaf6110 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -22,40 +22,59 @@ #if defined(__DC__) #include "common/stdafx.h" - #include "backends/fs/abstract-fs.h" #include #include #include -/* - * Implementation of the ScummVM file system API based on ronin. +/** + * Implementation of the ScummVM file system API based on POSIX. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class RoninCDFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; - String _path; public: + /** + * Creates a RoninCDFilesystemNode with the root node as path. + */ RoninCDFilesystemNode(); + + /** + * Creates a RoninCDFilesystemNode 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. + */ RoninCDFilesystemNode(const String &path, bool verify); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + 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 String path() const { return _path; } + virtual bool isValid() const { return _isValid; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; }; - +/** + * 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. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -67,22 +86,6 @@ static const char *lastPathComponent(const Common::String &str) { return cur + 1; } - -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - // Since there is no way to _set_ the current directory, - // it will always be /... - - return getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new RoninCDFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new RoninCDFilesystemNode(path, true); -} - RoninCDFilesystemNode::RoninCDFilesystemNode() { // The root dir. _path = "/"; @@ -115,10 +118,23 @@ RoninCDFilesystemNode::RoninCDFilesystemNode(const String &p, bool verify) { } } -bool RoninCDFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +AbstractFilesystemNode *RoninCDFilesystemNode::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); - DIR *dirp = opendir(_path.c_str()); + + String newPath(_path); + if (_path.lastChar() != '/') + newPath += '/'; + newPath += n; + return new RoninCDFilesystemNode(newPath, true); +} + +bool RoninCDFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { + assert(_isDirectory); + + DIR *dirp = opendir(_path.c_str()); struct dirent *dp; if (dirp == NULL) @@ -147,35 +163,22 @@ bool RoninCDFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const if (entry._isDirectory) entry._path += "/"; + myList.push_back(new RoninCDFilesystemNode(entry)); } closedir(dirp); + return true; } -AbstractFilesystemNode *RoninCDFilesystemNode::parent() const { +AbstractFilesystemNode *RoninCDFilesystemNode::getParent() const { if (_path == "/") return 0; const char *start = _path.c_str(); const char *end = lastPathComponent(_path); - RoninCDFilesystemNode *p = new RoninCDFilesystemNode(String(start, end - start), false); - - return p; -} - -AbstractFilesystemNode *RoninCDFilesystemNode::child(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; - RoninCDFilesystemNode *p = new RoninCDFilesystemNode(newPath, true); - - return p; + return new RoninCDFilesystemNode(String(start, end - start), false); } #endif // defined(__DC__) diff --git a/backends/fs/ds/DSFilesystemFactory.cpp b/backends/fs/ds/DSFilesystemFactory.cpp new file mode 100644 index 00000000000..809dc0e5cf6 --- /dev/null +++ b/backends/fs/ds/DSFilesystemFactory.cpp @@ -0,0 +1,36 @@ +#include "backends/fs/ds/DSFilesystemFactory.h" +#include "backends/fs/ds/ds-fs.cpp" +#include "dsmain.h" //for the isGBAMPAvailable() function + +DSFilesystemFactory *DSFilesystemFactory::_instance = 0; + +DSFilesystemFactory *DSFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new DSFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *DSFilesystemFactory::makeRootFileNode() const { + if (DS::isGBAMPAvailable()) { + return new DS::GBAMPFileSystemNode(); + } else { + return new DS::DSFileSystemNode(); + } +} + +AbstractFilesystemNode *DSFilesystemFactory::makeCurrentDirectoryFileNode() const { + if (DS::isGBAMPAvailable()) { + return new DS::GBAMPFileSystemNode(); + } else { + return new DS::DSFileSystemNode(); + } +} + +AbstractFilesystemNode *DSFilesystemFactory::makeFileNodePath(const String &path) const { + if (DS::isGBAMPAvailable()) { + return new DS::GBAMPFileSystemNode(path); + } else { + return new DS::DSFileSystemNode(path); + } +} diff --git a/backends/fs/ds/DSFilesystemFactory.h b/backends/fs/ds/DSFilesystemFactory.h new file mode 100644 index 00000000000..6eaef1cd1ed --- /dev/null +++ b/backends/fs/ds/DSFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef DSFILESYSTEMFACTORY_H_ +#define DSFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates DSFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class DSFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of DSFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of DSFilesytemFactory. + */ + static DSFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~DSFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + DSFilesystemFactory() {}; + +private: + static DSFilesystemFactory *_instance; +}; + +#endif /*DSFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index 40d160bbc8b..5243099fbe3 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -17,7 +17,6 @@ * */ - #include "stdafx.h" #include "str.h" #include "fs.h" @@ -27,14 +26,10 @@ #include "dsmain.h" #include "gba_nds_fat.h" - namespace DS { - - - ////////////////////////////////////////////////////////////// -// DSFileSystemNode - Flash ROM file system using Zip files +// DSFileSystemNode - Flash ROM file system using Zip files // ////////////////////////////////////////////////////////////// ZipFile* DSFileSystemNode::_zipFile = NULL; @@ -63,7 +58,6 @@ DSFileSystemNode::DSFileSystemNode(const String& path) { char disp[128]; char* pathStr = (char *) path.c_str(); - int lastSlash = 3; for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { if (path[r] == '\\') { @@ -78,13 +72,10 @@ DSFileSystemNode::DSFileSystemNode(const String& path) { // _isValid = true; // _isDirectory = false; - - if (!strncmp(pathStr, "ds:/", 4)) { pathStr += 4; } - if (*pathStr == '\0') { _isValid = true; _isDirectory = true; @@ -127,35 +118,10 @@ DSFileSystemNode::DSFileSystemNode(const String& path, bool isDir) { } DSFileSystemNode::DSFileSystemNode(const DSFileSystemNode* node) { - + //TODO: not implemented? } -AbstractFilesystemNode* DSFileSystemNode::parent() const { -// consolePrintf("parent\n"); - DSFileSystemNode *p; - - if (_path != "ds:/") { - char *path = (char *) _path.c_str(); - int lastSlash = 4; - - for (int r = 4; r < (int) strlen((char *) path); r++) { - if (path[r] == '\\') { - lastSlash = r; - } - } - - p = new DSFileSystemNode(String(path, lastSlash)); - ((DSFileSystemNode *) (p))->_isDirectory = true; - } else { - p = new DSFileSystemNode(); - } - - return p; - -} - - -AbstractFilesystemNode *DSFileSystemNode::child(const Common::String& n) const { +AbstractFilesystemNode *DSFileSystemNode::getChild(const Common::String& n) const { if (_path.lastChar() == '\\') { return new DSFileSystemNode(_path + n); } else { @@ -165,14 +131,10 @@ AbstractFilesystemNode *DSFileSystemNode::child(const Common::String& n) const { return NULL; } - -bool DSFileSystemNode::listDir(AbstractFSList &dirList, ListMode mode) const { +bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode) const { // consolePrintf("Listdir\n"); - - // consolePrintf("Directory\n"); - char temp[128]; strcpy(temp, _path.c_str()); @@ -187,14 +149,13 @@ bool DSFileSystemNode::listDir(AbstractFSList &dirList, ListMode mode) const { /* // This is the root dir, so add the RAM folder DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/ram"); dsfsn->_isDirectory = true; - dirList->push_back(wrap(dsfsn));*/ + dirList->push_back(wrap(dsfsn)); +*/ } } else { _zipFile->changeDirectory(temp); } - - if (_zipFile->restartFile()) { do { char n[128]; @@ -215,12 +176,32 @@ bool DSFileSystemNode::listDir(AbstractFSList &dirList, ListMode mode) const { return true; } +AbstractFilesystemNode* DSFileSystemNode::getParent() const { +// consolePrintf("parent\n"); + DSFileSystemNode *p; + if (_path != "ds:/") { + char *path = (char *) _path.c_str(); + int lastSlash = 4; + + for (int r = 4; r < (int) strlen((char *) path); r++) { + if (path[r] == '\\') { + lastSlash = r; + } + } + p = new DSFileSystemNode(String(path, lastSlash)); + ((DSFileSystemNode *) (p))->_isDirectory = true; + } else { + p = new DSFileSystemNode(); + } -///////////////////////////////////////////////////////////////////////// -// GBAMPFileSystemNode - File system using GBA Movie Player and CF card -///////////////////////////////////////////////////////////////////////// + return p; +} + +////////////////////////////////////////////////////////////////////////// +// GBAMPFileSystemNode - File system using GBA Movie Player and CF card // +////////////////////////////////////////////////////////////////////////// GBAMPFileSystemNode::GBAMPFileSystemNode() { _displayName = "mp:/"; @@ -287,35 +268,10 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path, bool isDirectory) { GBAMPFileSystemNode::GBAMPFileSystemNode(const GBAMPFileSystemNode* node) { - + //TODO: not implemented? } - -AbstractFilesystemNode* GBAMPFileSystemNode::parent() const { -// consolePrintf("parent\n"); - GBAMPFileSystemNode *p; - - if (_path != "mp:/") { - char *path = (char *) _path.c_str(); - int lastSlash = 4; - - for (int r = 4; r < (int) strlen((char *) path); r++) { - if (path[r] == '/') { - lastSlash = r; - } - } - - p = new GBAMPFileSystemNode(String(path, lastSlash)); - p->_isDirectory = true; - } else { - p = new GBAMPFileSystemNode(); - } - - return p; - -} - -AbstractFilesystemNode *GBAMPFileSystemNode::child(const Common::String& n) const { +AbstractFilesystemNode *GBAMPFileSystemNode::getChild(const Common::String& n) const { if (_path.lastChar() == '\\') { return new DSFileSystemNode(_path + n); } else { @@ -325,7 +281,7 @@ AbstractFilesystemNode *GBAMPFileSystemNode::child(const Common::String& n) cons return NULL; } -bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const { +bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode) const { // consolePrintf("Listdir\n"); enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 }; @@ -343,7 +299,6 @@ bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const pathTemp++; } - // consolePrintf("This dir: %s\n", path); FAT_chdir(path); @@ -366,8 +321,6 @@ bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const // dsfsn->_isDirectory = entryType == DIR; dirList.push_back((dsfsn)); } - - } else { // consolePrintf("Skipping %s\n", fname); } @@ -382,6 +335,28 @@ bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const return true; } +AbstractFilesystemNode* GBAMPFileSystemNode::getParent() const { +// consolePrintf("parent\n"); + GBAMPFileSystemNode *p; + + if (_path != "mp:/") { + char *path = (char *) _path.c_str(); + int lastSlash = 4; + + for (int r = 4; r < (int) strlen((char *) path); r++) { + if (path[r] == '/') { + lastSlash = r; + } + } + + p = new GBAMPFileSystemNode(String(path, lastSlash)); + p->_isDirectory = true; + } else { + p = new GBAMPFileSystemNode(); + } + + return p; +} // Stdio replacements #define MAX_FILE_HANDLES 32 @@ -390,9 +365,6 @@ bool inited = false; DS::fileHandle handle[MAX_FILE_HANDLES]; FILE* std_fopen(const char* name, const char* mode) { - - - if (!inited) { for (int r = 0; r < MAX_FILE_HANDLES; r++) { handle[r].used = false; @@ -400,9 +372,6 @@ FILE* std_fopen(const char* name, const char* mode) { inited = true; currentDir[0] = '\0'; } - - - char* realName = (char *) name; @@ -410,7 +379,7 @@ FILE* std_fopen(const char* name, const char* mode) { if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) { realName += 4; } - + if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) { realName += 4; } @@ -418,7 +387,6 @@ FILE* std_fopen(const char* name, const char* mode) { // consolePrintf("Open file:"); // consolePrintf("'%s', [%s]", realName, mode); - if (DS::isGBAMPAvailable()) { FAT_chdir("/"); @@ -440,10 +408,9 @@ FILE* std_fopen(const char* name, const char* mode) { return (FILE *) result; } - // Fail to open file for writing. It's in ROM! - + // Allocate a file handle int r = 0; while (handle[r].used) r++; @@ -456,7 +423,6 @@ FILE* std_fopen(const char* name, const char* mode) { handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, false); } - if (handle[r].sramFile) { handle[r].used = true; handle[r].pos = 0; @@ -510,6 +476,7 @@ FILE* std_fopen(const char* name, const char* mode) { return NULL; } } + void std_fclose(FILE* handle) { if (DS::isGBAMPAvailable()) { @@ -525,14 +492,9 @@ void std_fclose(FILE* handle) { } size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { - // consolePrintf("fread %d,%d %d ", size, numItems, ptr); - - if (DS::isGBAMPAvailable()) { - - int bytes = FAT_fread((void *) ptr, size, numItems, (FAT_FILE *) handle); if (!std_feof(handle)) { return numItems; @@ -557,27 +519,24 @@ size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { } - return item;*/ - - + return item; +*/ int items = 0; //for (int r = 0; r < numItems; r++) { if (!std_feof(handle)) { - - - /* for (int t = 0; t < size; t++) { if (feof(handle)) eof = true; *(((char *) (ptr)) + r * size + t) = getc(handle); }*/ int left = size * numItems; int bytesRead = -1; + while ((left > 0) && (!FAT_feof((FAT_FILE *) handle))) { int amount = left > 8192? 8192: left; // do { bytesRead = FAT_fread((void *) ptr, 1, amount, (FAT_FILE *) handle); - /* if (bytesRead == 0) { +/* if (bytesRead == 0) { consolePrintf("Pos:%d items:%d num:%d amount:%d read:%d\n", ftell(handle), items, numItems, amount, bytesRead); left++; @@ -589,27 +548,24 @@ size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { fread(ptr, 1024, 1, handle); swiWaitForVBlank(); //while (true); - }*/ - //} while (bytesRead == 0); + } + + } while (bytesRead == 0); +*/ left -= bytesRead; ptr = ((char *) (ptr)) + bytesRead; } items = numItems - (left / size); - - - - + // FAT_fread((void *) ptr, size, 1, ((int) (handle)) - 1); - // ptr = ((char *) (ptr)) + size; - +// ptr = ((char *) (ptr)) + size; } - //} +// } // consolePrintf("...done %d \n", items) return items; - } if (handle->sramFile) { @@ -627,7 +583,6 @@ size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { return bytes / size; } - if (handle->pos + size * numItems > handle->size) { numItems = (handle->size - handle->pos) / size; if (numItems < 0) numItems = 0; @@ -636,10 +591,8 @@ size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { // consolePrintf("read %d ", size * numItems); memcpy((void *) ptr, handle->data + handle->pos, size * numItems); - handle->pos += size * numItems; - return numItems; } @@ -654,7 +607,6 @@ size_t std_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle) { //consolePrintf("fwrite size=%d\n", size * numItems); if (DS::isGBAMPAvailable()) { - FAT_fwrite(((char *) (ptr)), size, numItems, (FAT_FILE *) handle); return numItems; @@ -672,7 +624,6 @@ size_t std_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle) { return numItems; } - if (handle->sramFile) { handle->sramFile->write(ptr, size); return size; @@ -701,6 +652,7 @@ bool std_feof(FILE* handle) { } void std_fflush(FILE* handle) { + //FIXME: not implemented? // consolePrintf("fflush "); } @@ -708,7 +660,6 @@ char* std_fgets(char* str, int size, FILE* file) { // consolePrintf("fgets file=%d ", file); if (DS::isGBAMPAvailable()) { - char* s = str; while ((*s++ = std_getc(file)) >= 32) { // consolePrintf("%d ", *s); @@ -720,7 +671,6 @@ char* std_fgets(char* str, int size, FILE* file) { return str; } - if (file->sramFile) { file->pos--; int p = -1; @@ -740,7 +690,6 @@ char* std_fgets(char* str, int size, FILE* file) { } long int std_ftell(FILE* handle) { - if (DS::isGBAMPAvailable()) { return FAT_ftell((FAT_FILE *) handle); } @@ -755,39 +704,30 @@ int std_fseek(FILE* handle, long int offset, int whence) { return FAT_fseek((FAT_FILE *) handle, offset, whence); } - switch (whence) { - case SEEK_CUR: { + case SEEK_CUR: handle->pos += offset; break; - } - - case SEEK_SET: { + case SEEK_SET: handle->pos = offset; break; - } - - case SEEK_END: { + case SEEK_END: handle->pos = handle->size + offset; break; - } - - default: { + default: handle->pos = offset; break; - } - } return 0; } void std_clearerr(FILE* handle) { + //FIXME: not implemented? // consolePrintf("clearerr "); } int std_getc(FILE* handle) { - if (DS::isGBAMPAvailable()) { char c; FAT_fread(&c, 1, 1, (FAT_FILE *) handle); @@ -849,24 +789,3 @@ int std_ferror(FILE* handle) { } } // namespace DS - -// These functions are added to AbstractFileSystemNode and are therefore outside -// the DS namespace. - -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { -// consolePrintf("New node"); - - if (DS::isGBAMPAvailable()) { - return new DS::GBAMPFileSystemNode(); - } else { - return new DS::DSFileSystemNode(); - } -} - -AbstractFilesystemNode* AbstractFilesystemNode::getNodeForPath(const String& path) { - if (DS::isGBAMPAvailable()) { - return new DS::GBAMPFileSystemNode(path); - } else { - return new DS::DSFileSystemNode(path); - } -} diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index 2830ff61ae7..8b5cc5bdd0e 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -20,8 +20,6 @@ #ifndef _DS_FS_H #define _DS_FS_H - - //#include #include "fs.h" #include "zipreader.h" @@ -29,81 +27,131 @@ #include "scummconsole.h" #include "gba_nds_fat.h" #include "backends/fs/abstract-fs.h" -//#include "backends/fs/fs.h" namespace DS { /** + * Implementation of the ScummVM file system API. * This class is used when a Flash cart is in use. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ class DSFileSystemNode : public AbstractFilesystemNode { protected: - static ZipFile* _zipFile; - typedef class Common::String String; + static ZipFile* _zipFile; + String _displayName; + String _path; bool _isDirectory; bool _isValid; - String _path; int _refCountVal; public: + /** + * Creates a DSFilesystemNode with the root node as path. + */ DSFileSystemNode(); + + /** + * Creates a DSFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ DSFileSystemNode(const String &path); - DSFileSystemNode(const DSFileSystemNode *node); + + /** + * Creates a DSFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + * @param path true if path is a directory, false otherwise. + */ DSFileSystemNode(const String& path, bool isDir); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } - virtual bool isDirectory() const { return _isDirectory; } - virtual String path() const { return _path; } + /** + * Copy constructor. + */ + DSFileSystemNode(const DSFileSystemNode *node); - virtual bool listDir(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; - virtual AbstractFilesystemNode *parent() const; + 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 isValid() const { return _isValid; } + + /** + * Returns a copy of this node. + */ virtual AbstractFilesystemNode *clone() const { return new DSFileSystemNode(this); } - virtual AbstractFilesystemNode *child(const Common::String& name) const; + virtual AbstractFilesystemNode *getChild(const Common::String& name) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; + virtual AbstractFilesystemNode *getParent() const; + + /** + * Returns the zip file this node points to. + * TODO: check this documentation. + */ static ZipFile* getZip() { return _zipFile; } }; - -/** + /** + * Implementation of the ScummVM file system API. * This class is used when the GBAMP (GBA Movie Player) is used with a CompactFlash card. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ class GBAMPFileSystemNode : public AbstractFilesystemNode { protected: typedef class Common::String String; String _displayName; + String _path; bool _isDirectory; bool _isValid; - String _path; - int _refCountVal; public: + /** + * Creates a GBAMPFilesystemNode with the root node as path. + */ GBAMPFileSystemNode(); + + /** + * Creates a GBAMPFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ GBAMPFileSystemNode(const String &path); + + /** + * Creates a DSFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + * @param path true if path is a directory, false otherwise. + */ GBAMPFileSystemNode(const String &path, bool isDirectory); + + /** + * Copy constructor. + */ GBAMPFileSystemNode(const GBAMPFileSystemNode *node); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - - virtual bool isValid() const { return _isValid; } + 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 String path() const { return _path; } - virtual bool listDir(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *clone() const { return new GBAMPFileSystemNode(this); } - virtual AbstractFilesystemNode *child(const Common::String& name) const; + virtual bool isValid() const { return _isValid; } + /** + * Returns a copy of this node. + */ + virtual AbstractFilesystemNode *clone() const { return new GBAMPFileSystemNode(this); } + virtual AbstractFilesystemNode *getChild(const Common::String& name) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; + virtual AbstractFilesystemNode *getParent() const; }; - - - struct fileHandle { int pos; bool used; @@ -113,7 +161,6 @@ struct fileHandle { DSSaveFile* sramFile; }; - #undef stderr #undef stdout #undef stdin @@ -137,6 +184,6 @@ void std_clearerr(FILE* handle); void std_cwd(char* dir); void std_fflush(FILE* handle); -} +} //namespace DS -#endif +#endif //_DS_FS_H diff --git a/backends/fs/gp32/GP32FilesystemFactory.cpp b/backends/fs/gp32/GP32FilesystemFactory.cpp new file mode 100644 index 00000000000..fa98079a8d0 --- /dev/null +++ b/backends/fs/gp32/GP32FilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/gp32/GP32FilesystemFactory.h" +#include "backends/fs/gp32/gp32-fs.cpp" + +GP32FilesystemFactory *GP32FilesystemFactory::_instance = 0; + +GP32FilesystemFactory *GP32FilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new GP32FilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *GP32FilesystemFactory::makeRootFileNode() const { + return new GP32FilesystemNode(); +} + +AbstractFilesystemNode *GP32FilesystemFactory::makeCurrentDirectoryFileNode() const { + return new GP32FilesystemNode(); +} + +AbstractFilesystemNode *GP32FilesystemFactory::makeFileNodePath(const String &path) const { + return new GP32FilesystemNode(path); +} diff --git a/backends/fs/gp32/GP32FilesystemFactory.h b/backends/fs/gp32/GP32FilesystemFactory.h new file mode 100644 index 00000000000..d31642acd22 --- /dev/null +++ b/backends/fs/gp32/GP32FilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef GP32FILESYSTEMFACTORY_H_ +#define GP32FILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates GP32FilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class GP32FilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of GP32FilesystemFactory using the Singleton pattern. + * + * @return A unique instance of GP32FilesytemFactory. + */ + static GP32FilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~GP32FilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + GP32FilesystemFactory() {}; + +private: + static GP32FilesystemFactory *_instance; +}; + +#endif /*GP32FILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/gp32/gp32-fs.cpp b/backends/fs/gp32/gp32-fs.cpp index c80e5a4f8fb..4fe6cfabde3 100644 --- a/backends/fs/gp32/gp32-fs.cpp +++ b/backends/fs/gp32/gp32-fs.cpp @@ -24,38 +24,78 @@ */ #include "stdafx.h" - #include "backends/fs/abstract-fs.h" +#define MAX_PATH_SIZE 256 + +/** + * Implementation of the ScummVM file system API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. + */ class GP32FilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isRoot; - String _path; public: + /** + * Creates a GP32FilesystemNode with the root node as path. + */ GP32FilesystemNode(); + + /** + * Creates a GP32FilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ GP32FilesystemNode(const String &path); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - // FIXME: isValid should return false if this Node can't be used! - // client code can rely on the return value. - virtual bool isValid() const { return true; } + 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 String path() const { return _path; } + // FIXME: isValid should return false if this Node can't be used! + // so client code can rely on the return value. + virtual bool isValid() const { return true; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; }; -#define MAX_PATH_SIZE 256 - const char gpRootPath[] = "gp:\\"; //char gpCurrentPath[MAX_PATH_SIZE] = "gp:\\"; // must end with '\' +/** + * Returns the last component of a given path. + * + * Examples: + * gp:\foo\bar.txt would return "\bar.txt" + * gp:\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. + */ +static const char *lastPathComponent(const Common::String &str) { + const char *start = str.c_str(); + const char *cur = start + str.size() - 2; + + while (cur >= start && *cur != '\\') { + --cur; + } + + return cur + 1; +} + +/** + * FIXME: document this function. + * + * @param path + * @param convPath + */ int gpMakePath(const char *path, char *convPath) { // copy root or current directory const char *p; @@ -106,18 +146,6 @@ int gpMakePath(const char *path, char *convPath) { return 0; } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new GP32FilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new GP32FilesystemNode(path); -} - GP32FilesystemNode::GP32FilesystemNode() { _isDirectory = true; _isRoot = true; @@ -132,8 +160,8 @@ GP32FilesystemNode::GP32FilesystemNode(const String &path) { gpMakePath(path.c_str(), convPath); _path = convPath; - pos = convPath; + while (*pos) if (*pos++ == '\\') dsplName = pos; @@ -150,14 +178,25 @@ GP32FilesystemNode::GP32FilesystemNode(const String &path) { _isDirectory = true; } -bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +AbstractFilesystemNode *GP32FilesystemNode::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 GP32FilesystemNode(newPath); +} + +bool GP32FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { assert(_isDirectory); GPDIRENTRY dirEntry; GPFILEATTR attr; - GP32FilesystemNode entry; - uint32 read; if (mode == FilesystemNode::kListAll) @@ -168,9 +207,11 @@ bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { int startIdx = 0; // current file String listDir(_path); //listDir += "/"; + while (GpDirEnumList(listDir.c_str(), startIdx++, 1, &dirEntry, &read) == SM_OK) { if (dirEntry.name[0] == '.') continue; + entry._displayName = dirEntry.name; entry._path = _path; entry._path += dirEntry.name; @@ -194,18 +235,7 @@ bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { return true; } -static const char *lastPathComponent(const Common::String &str) { - const char *start = str.c_str(); - const char *cur = start + str.size() - 2; - - while (cur >= start && *cur != '\\') { - --cur; - } - - return cur + 1; -} - -AbstractFilesystemNode *GP32FilesystemNode::parent() const { +AbstractFilesystemNode *GP32FilesystemNode::getParent() const { if(_isRoot) return 0; @@ -218,16 +248,3 @@ AbstractFilesystemNode *GP32FilesystemNode::parent() const { return p; } - -AbstractFilesystemNode *GP32FilesystemNode::child(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; - GP32FilesystemNode *p = new GP32FilesystemNode(newPath); - - return p; -} diff --git a/backends/fs/morphos/ABoxFilesystemFactory.cpp b/backends/fs/morphos/ABoxFilesystemFactory.cpp new file mode 100644 index 00000000000..02d954ee74f --- /dev/null +++ b/backends/fs/morphos/ABoxFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/morphos/ABoxFilesystemFactory.h" +#include "backends/fs/morphos/abox-fs.cpp" + +ABoxFilesystemFactory *ABoxFilesystemFactory::_instance = 0; + +ABoxFilesystemFactory *ABoxFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new ABoxFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *ABoxFilesystemFactory::makeRootFileNode() const { + return new ABoxFilesystemNode(); +} + +AbstractFilesystemNode *ABoxFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new ABoxFilesystemNode(); +} + +AbstractFilesystemNode *ABoxFilesystemFactory::makeFileNodePath(const String &path) const { + return new ABoxFilesystemNode(path); +} diff --git a/backends/fs/morphos/ABoxFilesystemFactory.h b/backends/fs/morphos/ABoxFilesystemFactory.h new file mode 100644 index 00000000000..c8fc0b3c193 --- /dev/null +++ b/backends/fs/morphos/ABoxFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef ABOXFILESYSTEMFACTORY_H_ +#define ABOXFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates ABoxFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class ABoxFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of ABoxFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of ABoxFilesytemFactory. + */ + static ABoxFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~ABoxFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + ABoxFilesystemFactory() {}; + +private: + static ABoxFilesystemFactory *_instance; +}; + +#endif /*ABOXFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp index e88eb19c00d..d4cc303219f 100644 --- a/backends/fs/morphos/abox-fs.cpp +++ b/backends/fs/morphos/abox-fs.cpp @@ -32,52 +32,63 @@ #include "base/engine.h" #include "backends/fs/abstract-fs.h" -/* +/** * Implementation of the ScummVM file system API based on the MorphOS A-Box API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class ABoxFilesystemNode : public AbstractFilesystemNode { - protected: - BPTR _lock; - String _displayName; - bool _isDirectory; - bool _isValid; - String _path; +protected: + BPTR _lock; + String _displayName; + String _path; + bool _isDirectory; + bool _isValid; - public: - ABoxFilesystemNode(); - ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL); - ABoxFilesystemNode(const String &p); - ABoxFilesystemNode(const ABoxFilesystemNode &node); +public: + /** + * Creates a ABoxFilesystemNode with the root node as path. + */ + ABoxFilesystemNode(); + + /** + * Creates a ABoxFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ + ABoxFilesystemNode(const String &p); + + /** + * FIXME: document this constructor. + */ + ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL); + + /** + * Copy constructor. + */ + ABoxFilesystemNode(const ABoxFilesystemNode &node); - ~ABoxFilesystemNode(); + /** + * Destructor. + */ + ~ABoxFilesystemNode(); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; }; - virtual bool isValid() const { return _isValid; } - virtual bool isDirectory() const { return _isDirectory; } - virtual String path() const { return _path; } - - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - static AbstractFSList listRoot(); - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &name) const; + 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 isValid() const { return _isValid; } + + virtual AbstractFilesystemNode *getChild(const String &name) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; + + /** + * Return the list of child nodes for the root node. + */ + static AbstractFSList getRootChildren(); }; - -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new ABoxFilesystemNode(path); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() -{ - return new ABoxFilesystemNode(); -} - ABoxFilesystemNode::ABoxFilesystemNode() { _displayName = "Mounted Volumes"; @@ -87,6 +98,62 @@ ABoxFilesystemNode::ABoxFilesystemNode() _lock = NULL; } +ABoxFilesystemNode::ABoxFilesystemNode(const String &p) { + int len = 0, offset = p.size(); + + assert(offset > 0); + + _path = p; + + // Extract last component from path + const char *str = p.c_str(); + while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) + offset--; + while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { + len++; + offset--; + } + _displayName = String(str + offset, len); + _lock = NULL; + _isDirectory = false; + + struct FileInfoBlock *fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, NULL); + if (!fib) + { + debug(6, "FileInfoBlock is NULL"); + return; + } + + // Check whether the node exists and if it is a directory + BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK); + if (pLock) + { + if (Examine(pLock, fib) != DOSFALSE) { + if (fib->fib_EntryType > 0) + { + _isDirectory = true; + _lock = DupLock(pLock); + _isValid = (_lock != 0); + + // Add a trailing slash if it is needed + const char c = _path.lastChar(); + if (c != '/' && c != ':') + _path += '/'; + + } + else + { + _isDirectory = false; + _isValid = true; + } + } + + UnLock(pLock); + } + + FreeDosObject(DOS_FIB, fib); +} + ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name) { int bufsize = 256; @@ -135,63 +202,7 @@ ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name) _isValid = true; } } - FreeDosObject(DOS_FIB, fib); -} - -ABoxFilesystemNode::ABoxFilesystemNode(const String &p) { - int len = 0, offset = p.size(); - - assert(offset > 0); - - _path = p; - - // Extract last component from path - const char *str = p.c_str(); - while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) - offset--; - while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { - len++; - offset--; - } - _displayName = String(str + offset, len); - _lock = NULL; - _isDirectory = false; - - struct FileInfoBlock *fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, NULL); - if (!fib) - { - debug(6, "FileInfoBlock is NULL"); - return; - } - - // Check whether the node exists and if it is a directory - - BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK); - if (pLock) - { - if (Examine(pLock, fib) != DOSFALSE) { - if (fib->fib_EntryType > 0) - { - _isDirectory = true; - _lock = DupLock(pLock); - _isValid = (_lock != 0); - - // Add a trailing slash if it is needed - const char c = _path.lastChar(); - if (c != '/' && c != ':') - _path += '/'; - - } - else - { - _isDirectory = false; - _isValid = true; - } - } - UnLock(pLock); - } - FreeDosObject(DOS_FIB, fib); } @@ -213,7 +224,27 @@ ABoxFilesystemNode::~ABoxFilesystemNode() } } -bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const +AbstractFilesystemNode *ABoxFilesystemNode::getChild(const String &name) const { + assert(_isDirectory); + String newPath(_path); + + if (_path.lastChar() != '/') + newPath += '/'; + newPath += name; + + BPTR lock = Lock(newPath.c_str(), SHARED_LOCK); + + if (!lock) + { + return 0; + } + + UnLock(lock); + + return new ABoxFilesystemNode(newPath); +} + +bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode) const { if (!_isValid) { @@ -229,7 +260,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const if (_lock == NULL) { /* This is the root node */ - myList = listRoot(); + list = getRootChildren(); return true; } @@ -263,7 +294,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const if (entry) { if (entry->isValid()) - myList.push_back(entry); + list.push_back(entry); else delete entry; } @@ -281,7 +312,7 @@ bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } -AbstractFilesystemNode *ABoxFilesystemNode::parent() const +AbstractFilesystemNode *ABoxFilesystemNode::getParent() const { AbstractFilesystemNode *node = NULL; @@ -306,29 +337,9 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const return node; } -AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const { - assert(_isDirectory); - String newPath(_path); - - if (_path.lastChar() != '/') - newPath += '/'; - newPath += name; - - BPTR lock = Lock(newPath.c_str(), SHARED_LOCK); - - if (!lock) - { - return 0; - } - - UnLock(lock); - - return new ABoxFilesystemNode(newPath); -} - -AbstractFSList ABoxFilesystemNode::listRoot() +AbstractFSList ABoxFilesystemNode::getRootChildren() { - AbstractFSList myList; + AbstractFSList list; DosList *dosList; CONST ULONG lockDosListFlags = LDF_READ | LDF_VOLUMES; char name[256]; @@ -336,15 +347,15 @@ AbstractFSList ABoxFilesystemNode::listRoot() dosList = LockDosList(lockDosListFlags); if (dosList == NULL) { - return myList; + return list; } dosList = NextDosEntry(dosList, LDF_VOLUMES); while (dosList) { - if (dosList->dol_Type == DLT_VOLUME && // Should always be true, but ... - dosList->dol_Name && // Same here - dosList->dol_Task // Will be NULL if volume is removed from drive but still in use by some program + if (dosList->dol_Type == DLT_VOLUME && // Should always be true, but ... + dosList->dol_Name && // Same here + dosList->dol_Task // Will be NULL if volume is removed from drive but still in use by some program ) { ABoxFilesystemNode *entry; @@ -362,7 +373,7 @@ AbstractFSList ABoxFilesystemNode::listRoot() if (entry) { if (entry->isValid()) - myList.push_back(entry); + list.push_back(entry); else delete entry; } @@ -374,9 +385,7 @@ AbstractFSList ABoxFilesystemNode::listRoot() UnLockDosList(lockDosListFlags); - return myList; + return list; } #endif // defined(__MORPHOS__) - - diff --git a/backends/fs/palmos/PalmOSFilesystemFactory.cpp b/backends/fs/palmos/PalmOSFilesystemFactory.cpp new file mode 100644 index 00000000000..15240d23976 --- /dev/null +++ b/backends/fs/palmos/PalmOSFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/palmos/PalmOSFilesystemFactory.h" +#include "backends/fs/palmos/palmos-fs.cpp" + +PalmOSFilesystemFactory *PalmOSFilesystemFactory::_instance = 0; + +PalmOSFilesystemFactory *PalmOSFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new PalmOSFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const { + return new PalmOSFilesystemNode(); +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new PalmOSFilesystemNode(); +} + +AbstractFilesystemNode *PalmOSFilesystemFactory::makeFileNodePath(const String &path) const { + return new PalmOSFilesystemNode(path); +} diff --git a/backends/fs/palmos/PalmOSFilesystemFactory.h b/backends/fs/palmos/PalmOSFilesystemFactory.h new file mode 100644 index 00000000000..dd1f31b3c8c --- /dev/null +++ b/backends/fs/palmos/PalmOSFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef PALMOSFILESYSTEMFACTORY_H_ +#define PALMOSFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates PalmOSFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class PalmOSFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of PalmOSFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of PalmOSFilesytemFactory. + */ + static PalmOSFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~PalmOSFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + PalmOSFilesystemFactory() {}; + +private: + static PalmOSFilesystemFactory *_instance; +}; + +#endif /*PALMOSFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 4dfdb2f0685..52fe741d26e 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -27,36 +27,65 @@ #include #include -/* +/** * Implementation of the ScummVM file system API based on PalmOS VFS API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class PalmOSFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; bool _isPseudoRoot; - String _path; public: + /** + * Creates a PalmOSFilesystemNode with the root node as path. + */ PalmOSFilesystemNode(); + + /** + * Creates a POSIXFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ PalmOSFilesystemNode(const String &p); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + 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 String path() const { return _path; } + virtual bool isValid() const { return _isValid; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; private: - static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); + /** + * 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, FileInfoType* find_data); }; +/** + * 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. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -92,19 +121,6 @@ void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const ch list.push_back(new PalmOSFilesystemNode(entry)); } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new PalmOSFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new PalmOSFilesystemNode(path); -} - - PalmOSFilesystemNode::PalmOSFilesystemNode() { _isDirectory = true; _displayName = "Root"; @@ -119,13 +135,13 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { UInt32 attr; FileRef handle; - Err e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (!e) { - e = VFSFileGetAttributes(handle, &attr); + Err error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + if (!error) { + error = VFSFileGetAttributes(handle, &attr); VFSFileClose(handle); } - if (e) { + if (error) { _isValid = false; _isDirectory = false; @@ -136,8 +152,31 @@ PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { _isPseudoRoot = false; } -bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { - Err e; +AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const { + assert(_isDirectory); + + String newPath(_path); + if (_path.lastChar() != '/') + newPath += '/'; + newPath += n; + + FileRef handle; + UInt32 attr; + Err error = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); + if (error) + return 0; + + error = VFSFileGetAttributes(handle, &attr); + VFSFileClose(handle); + + if (error || !(attr & vfsFileAttrDirectory)) + return 0; + + return new PalmOSFilesystemNode(newPath); +} + +bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { + Err error; Char nameP[256]; FileInfoType desc; FileRef handle; @@ -145,14 +184,14 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const desc.nameP = nameP; desc.nameBufLen = 256; - e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); + error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (e) + if (error) return false; while(dirIterator != expIteratorStop) { - e = VFSDirEntryEnumerate(handle, &dirIterator, &desc); - if (!e) { + error = VFSDirEntryEnumerate(handle, &dirIterator, &desc); + if (!error) { addFile(myList, mode, _path.c_str(), &desc); } } @@ -162,8 +201,7 @@ bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } - -AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { +AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { PalmOSFilesystemNode *p = 0; if (!_isPseudoRoot) { @@ -177,31 +215,7 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { p->_displayName = lastPathComponent(p->_path); p->_isPseudoRoot =(p->_path == "/"); } - return p; -} - - -AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &n) const { - assert(_isDirectory); - String newPath(_path); - - if (_path.lastChar() != '/') - newPath += '/'; - newPath += n; - - FileRef handle; - UInt32 attr; - Err e = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); - if (e) - return 0; - e = VFSFileGetAttributes(handle, &attr); - VFSFileClose(handle); - - if (e || !(attr & vfsFileAttrDirectory)) - return 0; - - PalmOSFilesystemNode *p = new PalmOSFilesystemNode(newPath); return p; } diff --git a/backends/fs/posix/POSIXFilesystemFactory.cpp b/backends/fs/posix/POSIXFilesystemFactory.cpp new file mode 100644 index 00000000000..9a13c37c301 --- /dev/null +++ b/backends/fs/posix/POSIXFilesystemFactory.cpp @@ -0,0 +1,25 @@ +#include "backends/fs/posix/POSIXFilesystemFactory.h" +#include "backends/fs/posix/posix-fs.cpp" + +POSIXFilesystemFactory *POSIXFilesystemFactory::_instance = 0; + +POSIXFilesystemFactory *POSIXFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new POSIXFilesystemFactory(); + } + return _instance; +} + +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); +} diff --git a/backends/fs/posix/POSIXFilesystemFactory.h b/backends/fs/posix/POSIXFilesystemFactory.h new file mode 100644 index 00000000000..b4714604457 --- /dev/null +++ b/backends/fs/posix/POSIXFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef POSIXFILESYSTEMFACTORY_H_ +#define POSIXFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates POSIXFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class POSIXFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of POSIXFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of POSIXFilesytemFactory. + */ + static POSIXFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~POSIXFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + POSIXFilesystemFactory() {}; + +private: + static POSIXFilesystemFactory *_instance; +}; + +#endif /*POSIXFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 14ed0d39b9d..4ab0c4f207c 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -22,7 +22,6 @@ #if defined(UNIX) #include "common/stdafx.h" - #include "backends/fs/abstract-fs.h" #ifdef MACOSX @@ -34,33 +33,59 @@ #include #include -/* +/** * 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; - String _path; 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 String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + + 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 String path() const { return _path; } - - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual bool isValid() const { return _isValid; } + + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) 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. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -72,18 +97,10 @@ static const char *lastPathComponent(const Common::String &str) { return cur + 1; } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - char buf[MAXPATHLEN]; - getcwd(buf, MAXPATHLEN); - return new POSIXFilesystemNode(buf, true); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new POSIXFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new POSIXFilesystemNode(path, true); +void POSIXFilesystemNode::setFlags() { + struct stat st; + _isValid = (0 == stat(_path.c_str(), &st)); + _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; } POSIXFilesystemNode::POSIXFilesystemNode() { @@ -124,22 +141,33 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) { _isDirectory = true; if (verify) { - struct stat st; - _isValid = (0 == stat(_path.c_str(), &st)); - _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; + setFlags(); } } -bool POSIXFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +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); - DIR *dirp = opendir(_path.c_str()); + + String newPath(_path); + if (_path.lastChar() != '/') + newPath += '/'; + newPath += n; + + return new POSIXFilesystemNode(newPath, true); +} +bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { + assert(_isDirectory); + + DIR *dirp = opendir(_path.c_str()); struct dirent *dp; if (dirp == NULL) return false; - // ... loop over dir entries using readdir + // loop over dir entries using readdir while ((dp = readdir(dirp)) != NULL) { // Skip 'invisible' files if (dp->d_name[0] == '.') @@ -153,18 +181,18 @@ bool POSIXFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { 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. - struct stat st; - entry._isValid = (0 == stat(entry._path.c_str(), &st)); - entry._isDirectory = entry._isValid ? S_ISDIR(st.st_mode) : false; + /* 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() - struct stat st; - entry._isValid = (0 == stat(entry._path.c_str(), &st)); - entry._isDirectory = entry._isValid ? S_ISDIR(st.st_mode) : false; + 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) { @@ -191,35 +219,22 @@ bool POSIXFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { if (entry._isDirectory) entry._path += "/"; + myList.push_back(new POSIXFilesystemNode(entry)); } closedir(dirp); + return true; } -AbstractFilesystemNode *POSIXFilesystemNode::parent() const { +AbstractFilesystemNode *POSIXFilesystemNode::getParent() const { if (_path == "/") return 0; const char *start = _path.c_str(); const char *end = lastPathComponent(_path); - POSIXFilesystemNode *p = new POSIXFilesystemNode(String(start, end - start), false); - - return p; + return new POSIXFilesystemNode(String(start, end - start), false); } -AbstractFilesystemNode *POSIXFilesystemNode::child(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; - POSIXFilesystemNode *p = new POSIXFilesystemNode(newPath, true); - - return p; -} - -#endif // defined(UNIX) +#endif //#if defined(UNIX) diff --git a/backends/fs/ps2/Ps2FilesystemFactory.cpp b/backends/fs/ps2/Ps2FilesystemFactory.cpp new file mode 100644 index 00000000000..c07387eae10 --- /dev/null +++ b/backends/fs/ps2/Ps2FilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/ps2/Ps2FilesystemFactory.h" +#include "backends/fs/ps2/ps2-fs.cpp" + +Ps2FilesystemFactory *Ps2FilesystemFactory::_instance = 0; + +Ps2FilesystemFactory *Ps2FilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new Ps2FilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *Ps2FilesystemFactory::makeRootFileNode() const { + return new Ps2FilesystemNode(); +} + +AbstractFilesystemNode *Ps2FilesystemFactory::makeCurrentDirectoryFileNode() const { + return new Ps2FilesystemNode(); +} + +AbstractFilesystemNode *Ps2FilesystemFactory::makeFileNodePath(const String &path) const { + return new Ps2FilesystemNode(path); +} diff --git a/backends/fs/ps2/Ps2FilesystemFactory.h b/backends/fs/ps2/Ps2FilesystemFactory.h new file mode 100644 index 00000000000..e394865e805 --- /dev/null +++ b/backends/fs/ps2/Ps2FilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef PS2FILESYSTEMFACTORY_H_ +#define PS2FILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates PS2FilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class Ps2FilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of Ps2FilesystemFactory using the Singleton pattern. + * + * @return A unique instance of Ps2FilesytemFactory. + */ + static Ps2FilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~Ps2FilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + Ps2FilesystemFactory() {}; + +private: + static Ps2FilesystemFactory *_instance; +}; + +#endif /*PS2FILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp index 18d6df5bb30..0661175c573 100644 --- a/backends/fs/ps2/ps2-fs.cpp +++ b/backends/fs/ps2/ps2-fs.cpp @@ -29,44 +29,49 @@ extern AsyncFio fio; extern OSystem_PS2 *g_systemPs2; +/** + * Implementation of the ScummVM file system API based on the Ps2SDK. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. + */ class Ps2FilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isRoot; - String _path; public: - Ps2FilesystemNode(void); - Ps2FilesystemNode(const Ps2FilesystemNode *node); + /** + * Creates a PS2FilesystemNode with the root node as path. + */ + Ps2FilesystemNode(); + + /** + * Creates a PS2FilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ Ps2FilesystemNode(const String &path); + + /** + * Copy constructor. + */ + Ps2FilesystemNode(const Ps2FilesystemNode *node); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return !_isRoot; } + 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 String path() const { return _path; } + virtual bool isValid() const { return !_isRoot; } - //virtual FSList listDir(ListMode) const; - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); } - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; }; -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot(void) { - return new Ps2FilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new Ps2FilesystemNode(path); -} - -Ps2FilesystemNode::Ps2FilesystemNode(void) { +Ps2FilesystemNode::Ps2FilesystemNode() { _isDirectory = true; _isRoot = true; _displayName = "PlayStation 2"; @@ -105,7 +110,41 @@ Ps2FilesystemNode::Ps2FilesystemNode(const Ps2FilesystemNode *node) { _isRoot = node->_isRoot; } -bool Ps2FilesystemNode::listDir(AbstractFSList &list, ListMode mode) const { +AbstractFilesystemNode *Ps2FilesystemNode::getChild(const String &n) const { + if (!_isDirectory) + return NULL; + + char listDir[256]; + sprintf(listDir, "%s/", _path.c_str()); + int fd = fio.dopen(listDir); + + if (fd >= 0) { + iox_dirent_t dirent; + + while (fio.dread(fd, &dirent) > 0) { + if (strcmp(n.c_str(), dirent.name) == 0) { + Ps2FilesystemNode *dirEntry = new Ps2FilesystemNode(); + + dirEntry->_isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR); + dirEntry->_isRoot = false; + + dirEntry->_path = _path; + dirEntry->_path += "/"; + dirEntry->_path += dirent.name; + + dirEntry->_displayName = dirent.name; + + fio.dclose(fd); + return dirEntry; + } + } + fio.dclose(fd); + } + + return NULL; +} + +bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode) const { if (!_isDirectory) return false; @@ -132,6 +171,7 @@ bool Ps2FilesystemNode::listDir(AbstractFSList &list, ListMode mode) const { } else { char listDir[256]; int fd; + if (_path.lastChar() == '/') fd = fio.dopen(_path.c_str()); else { @@ -170,7 +210,7 @@ bool Ps2FilesystemNode::listDir(AbstractFSList &list, ListMode mode) const { } } -AbstractFilesystemNode *Ps2FilesystemNode::parent() const { +AbstractFilesystemNode *Ps2FilesystemNode::getParent() const { if (_isRoot) return new Ps2FilesystemNode(this); @@ -188,36 +228,3 @@ AbstractFilesystemNode *Ps2FilesystemNode::parent() const { else return new Ps2FilesystemNode(); } - -AbstractFilesystemNode *Ps2FilesystemNode::child(const String &n) const { - if (!_isDirectory) - return NULL; - - char listDir[256]; - sprintf(listDir, "%s/", _path.c_str()); - int fd = fio.dopen(listDir); - - if (fd >= 0) { - iox_dirent_t dirent; - - while (fio.dread(fd, &dirent) > 0) { - if (strcmp(n.c_str(), dirent.name) == 0) { - Ps2FilesystemNode *dirEntry = new Ps2FilesystemNode(); - - dirEntry->_isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR); - dirEntry->_isRoot = false; - - dirEntry->_path = _path; - dirEntry->_path += "/"; - dirEntry->_path += dirent.name; - - dirEntry->_displayName = dirent.name; - - fio.dclose(fd); - return dirEntry; - } - } - fio.dclose(fd); - } - return NULL; -} diff --git a/backends/fs/psp/PSPFilesystemFactory.cpp b/backends/fs/psp/PSPFilesystemFactory.cpp new file mode 100644 index 00000000000..5a3802c10a7 --- /dev/null +++ b/backends/fs/psp/PSPFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/psp/PSPFilesystemFactory.h" +#include "backends/fs/psp/psp_fs.cpp" + +PSPFilesystemFactory *PSPFilesystemFactory::_instance = 0; + +PSPFilesystemFactory *PSPFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new PSPFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *PSPFilesystemFactory::makeRootFileNode() const { + return new PSPFilesystemNode(); +} + +AbstractFilesystemNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new PSPFilesystemNode(); +} + +AbstractFilesystemNode *PSPFilesystemFactory::makeFileNodePath(const String &path) const { + return new PSPFilesystemNode(path, true); +} diff --git a/backends/fs/psp/PSPFilesystemFactory.h b/backends/fs/psp/PSPFilesystemFactory.h new file mode 100644 index 00000000000..70358c90ed4 --- /dev/null +++ b/backends/fs/psp/PSPFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef PSPFILESYSTEMFACTORY_H_ +#define PSPFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates PSPFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class PSPFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of PSPFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of PSPFilesytemFactory. + */ + static PSPFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~PSPFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + PSPFilesystemFactory() {}; + +private: + static PSPFilesystemFactory *_instance; +}; + +#endif /*PSPFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/psp/psp_fs.cpp b/backends/fs/psp/psp_fs.cpp index 211a9bb8e6f..a695eb66dc9 100644 --- a/backends/fs/psp/psp_fs.cpp +++ b/backends/fs/psp/psp_fs.cpp @@ -23,8 +23,8 @@ */ #ifdef __PSP__ -#include "engines/engine.h" +#include "engines/engine.h" #include "backends/fs/abstract-fs.h" #include @@ -32,39 +32,62 @@ #define ROOT_PATH "ms0:/" - -/* +/** * Implementation of the ScummVM file system API based on PSPSDK API. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class PSPFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; - String _path; public: + /** + * Creates a PSPFilesystemNode with the root node as path. + */ PSPFilesystemNode(); + + /** + * Creates a PSPFilesystemNode 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. + */ PSPFilesystemNode(const Common::String &p, bool verify); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + 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 String path() const { return _path; } + virtual bool isValid() const { return _isValid; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; }; -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - return AbstractFilesystemNode::getRoot(); -} +/** + * 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. + */ +static const char *lastPathComponent(const Common::String &str) { + const char *start = str.c_str(); + const char *cur = start + str.size() - 2; -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new PSPFilesystemNode(); + while (cur >= start && *cur != '/') { + --cur; + } + + return cur + 1; } PSPFilesystemNode::PSPFilesystemNode() { @@ -89,12 +112,20 @@ PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) { } } -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new PSPFilesystemNode(path, true); +AbstractFilesystemNode *PSPFilesystemNode::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 PSPFilesystemNode(newPath, true); } - -bool PSPFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { assert(_isDirectory); int dfd = sceIoDopen(_path.c_str()); @@ -133,18 +164,7 @@ bool PSPFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { } } -static const char *lastPathComponent(const Common::String &str) { - const char *start = str.c_str(); - const char *cur = start + str.size() - 2; - - while (cur >= start && *cur != '/') { - --cur; - } - - return cur + 1; -} - -AbstractFilesystemNode *PSPFilesystemNode::parent() const { +AbstractFilesystemNode *PSPFilesystemNode::getParent() const { assert(_isValid); if (_path == ROOT_PATH) @@ -153,22 +173,7 @@ AbstractFilesystemNode *PSPFilesystemNode::parent() const { const char *start = _path.c_str(); const char *end = lastPathComponent(_path); - PSPFilesystemNode *p = new PSPFilesystemNode(String(start, end - start), false); - - return p; + return new PSPFilesystemNode(String(start, end - start), false); } -AbstractFilesystemNode *PSPFilesystemNode::child(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; - PSPFilesystemNode *p = new PSPFilesystemNode(newPath, true); - - return p; -} - -#endif // PSP +#endif //#ifdef __PSP__ diff --git a/backends/fs/symbian/SymbianFilesystemFactory.cpp b/backends/fs/symbian/SymbianFilesystemFactory.cpp new file mode 100644 index 00000000000..07da19629c3 --- /dev/null +++ b/backends/fs/symbian/SymbianFilesystemFactory.cpp @@ -0,0 +1,25 @@ +#include "backends/fs/symbian/SymbianFilesystemFactory.h" +#include "backends/fs/symbian/symbian-fs.cpp" + +SymbianFilesystemFactory *SymbianFilesystemFactory::_instance = 0; + +SymbianFilesystemFactory *SymbianFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new SymbianFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *SymbianFilesystemFactory::makeRootFileNode() const { + return new SymbianFilesystemNode(true); +} + +AbstractFilesystemNode *SymbianFilesystemFactory::makeCurrentDirectoryFileNode() const { + char path[MAXPATHLEN]; + getcwd(path, MAXPATHLEN); + return new SymbianFilesystemNode(path); +} + +AbstractFilesystemNode *SymbianFilesystemFactory::makeFileNodePath(const String &path) const { + return new SymbianFilesystemNode(path); +} diff --git a/backends/fs/symbian/SymbianFilesystemFactory.h b/backends/fs/symbian/SymbianFilesystemFactory.h new file mode 100644 index 00000000000..b1d4b81250b --- /dev/null +++ b/backends/fs/symbian/SymbianFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef SYMBIANFILESYSTEMFACTORY_H_ +#define SYMBIANFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates SymbianFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class SymbianFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of SymbianFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of SymbianFilesytemFactory. + */ + static SymbianFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~SymbianFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + SymbianFilesystemFactory() {}; + +private: + static SymbianFilesystemFactory *_instance; +}; + +#endif /*SYMBIANFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp index dd18d8b5e53..e243872c8d7 100644 --- a/backends/fs/symbian/symbian-fs.cpp +++ b/backends/fs/symbian/symbian-fs.cpp @@ -31,33 +31,55 @@ #include #include -/* +/** * Implementation of the ScummVM file system API based on POSIX. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - class SymbianFilesystemNode : public AbstractFilesystemNode { protected: String _displayName; + String _path; bool _isDirectory; bool _isValid; - String _path; bool _isPseudoRoot; public: + /** + * Creates a SymbianFilesystemNode with the root node as path. + * + * @param aIsRoot true if the node will be a pseudo root, false otherwise. + */ SymbianFilesystemNode(bool aIsRoot); + + /** + * Creates a SymbianFilesystemNode for a given path. + * + * @param path String with the path the new node should point to. + */ SymbianFilesystemNode(const String &path); - virtual String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + + 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 String path() const { return _path; } + virtual bool isValid() const { return _isValid; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; }; - +/** + * 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. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -69,6 +91,11 @@ static const char *lastPathComponent(const Common::String &str) { return cur + 1; } +/** + * Fixes the path by changing all slashes to backslashes. + * + * @param path String with the path to be fixed. + */ static void fixFilePath(Common::String& path) { TInt len = path.size(); @@ -79,20 +106,6 @@ static void fixFilePath(Common::String& path) { } } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - char path[MAXPATHLEN]; - getcwd(path, MAXPATHLEN); - return new SymbianFilesystemNode(path); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new SymbianFilesystemNode(true); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new SymbianFilesystemNode(path); -} - SymbianFilesystemNode::SymbianFilesystemNode(bool aIsRoot) { _path = ""; _isValid = true; @@ -128,7 +141,26 @@ SymbianFilesystemNode::SymbianFilesystemNode(const String &path) { } } -bool SymbianFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +AbstractFilesystemNode *SymbianFilesystemNode::getChild(const String &n) const { + assert(_isDirectory); + String newPath(_path); + + if (_path.lastChar() != '\\') + newPath += '\\'; + newPath += n; + + TPtrC8 ptr((const unsigned char*) newPath.c_str(), newPath.size()); + TFileName fname; + fname.Copy(ptr); + TBool isFolder = EFalse; + BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), fname, isFolder); + if(!isFolder) + return 0; + + return new SymbianFilesystemNode(newPath); +} + +bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { assert(_isDirectory); if (_isPseudoRoot) { @@ -199,18 +231,18 @@ bool SymbianFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const } CleanupStack::PopAndDestroy(dirPtr); } - } + return true; } -AbstractFilesystemNode *SymbianFilesystemNode::parent() const { +AbstractFilesystemNode *SymbianFilesystemNode::getParent() const { SymbianFilesystemNode *p =NULL; // Root node is its own parent. Still we can't just return this // as the GUI code will call delete on the old node. if (!_isPseudoRoot && _path.size() > 3) { - p=new SymbianFilesystemNode(false); + p = new SymbianFilesystemNode(false); const char *start = _path.c_str(); const char *end = lastPathComponent(_path); @@ -221,29 +253,10 @@ AbstractFilesystemNode *SymbianFilesystemNode::parent() const { } else { - p=new SymbianFilesystemNode(true); + p = new SymbianFilesystemNode(true); } + return p; } -AbstractFilesystemNode *SymbianFilesystemNode::child(const String &n) const { - assert(_isDirectory); - String newPath(_path); - - if (_path.lastChar() != '\\') - newPath += '\\'; - newPath += n; - - TPtrC8 ptr((const unsigned char*) newPath.c_str(), newPath.size()); - TFileName fname; - fname.Copy(ptr); - TBool isFolder = EFalse; - BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), fname, isFolder); - if(!isFolder) - return 0; - - SymbianFilesystemNode *p = new SymbianFilesystemNode(newPath); - return p; -} - -#endif // defined(__SYMBIAN32__) +#endif //#if defined (__SYMBIAN32__) diff --git a/backends/fs/windows/WindowsFilesystemFactory.cpp b/backends/fs/windows/WindowsFilesystemFactory.cpp new file mode 100644 index 00000000000..a360fd1c7ab --- /dev/null +++ b/backends/fs/windows/WindowsFilesystemFactory.cpp @@ -0,0 +1,23 @@ +#include "backends/fs/windows/WindowsFilesystemFactory.h" +#include "backends/fs/windows/windows-fs.cpp" + +WindowsFilesystemFactory *WindowsFilesystemFactory::_instance = 0; + +WindowsFilesystemFactory *WindowsFilesystemFactory::instance(){ + if(_instance == 0){ + _instance = new WindowsFilesystemFactory(); + } + return _instance; +} + +AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const { + return new WindowsFilesystemNode(); +} + +AbstractFilesystemNode *WindowsFilesystemFactory::makeCurrentDirectoryFileNode() const { + return new WindowsFilesystemNode(NULL, true); +} + +AbstractFilesystemNode *WindowsFilesystemFactory::makeFileNodePath(const String &path) const { + return new WindowsFilesystemNode(path, false); +} diff --git a/backends/fs/windows/WindowsFilesystemFactory.h b/backends/fs/windows/WindowsFilesystemFactory.h new file mode 100644 index 00000000000..0d965089c4b --- /dev/null +++ b/backends/fs/windows/WindowsFilesystemFactory.h @@ -0,0 +1,38 @@ +#ifndef WINDOWSFILESYSTEMFACTORY_H_ +#define WINDOWSFILESYSTEMFACTORY_H_ + +#include "backends/fs/AbstractFilesystemFactory.h" + +/** + * Creates WindowsFilesystemNode objects. + * + * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. + */ +class WindowsFilesystemFactory : public AbstractFilesystemFactory { +public: + typedef Common::String String; + + /** + * Creates an instance of WindowsFilesystemFactory using the Singleton pattern. + * + * @return A unique instance of WindowsFilesytemFactory. + */ + static WindowsFilesystemFactory *instance(); + + /** + * Destructor. + */ + virtual ~WindowsFilesystemFactory() {}; + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + WindowsFilesystemFactory() {}; + +private: + static WindowsFilesystemFactory *_instance; +}; + +#endif /*WINDOWSFILESYSTEMFACTORY_H_*/ diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp index 32c1ab42e50..af19384e39e 100644 --- a/backends/fs/windows/windows-fs.cpp +++ b/backends/fs/windows/windows-fs.cpp @@ -33,39 +33,90 @@ #endif #include -/* +/** * 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; - bool _isDirectory; - bool _isValid; - bool _isPseudoRoot; 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(); - WindowsFilesystemNode(const String &path); + + /** + * 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 String displayName() const { return _displayName; } - virtual String name() const { return _displayName; } - virtual bool isValid() const { return _isValid; } + 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 String path() const { return _path; } + virtual bool isValid() const { return _isValid; } - virtual bool listDir(AbstractFSList &list, ListMode mode) const; - virtual AbstractFilesystemNode *parent() const; - virtual AbstractFilesystemNode *child(const String &n) const; + virtual AbstractFilesystemNode *getChild(const String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual AbstractFilesystemNode *getParent() const; private: - static char *toAscii(TCHAR *x); - static const TCHAR* toUnicode(const char *x); - static void addFile (AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data); + /** + * 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. + */ static const char *lastPathComponent(const Common::String &str) { const char *start = str.c_str(); const char *cur = start + str.size() - 2; @@ -77,27 +128,6 @@ static const char *lastPathComponent(const Common::String &str) { return cur + 1; } -char* WindowsFilesystemNode::toAscii(TCHAR *x) { - -#ifndef UNICODE - return (char*)x; -#else - static char asciiString[MAX_PATH]; - WideCharToMultiByte(CP_ACP, 0, x, _tcslen(x) + 1, asciiString, sizeof(asciiString), NULL, NULL); - return asciiString; -#endif -} - -const TCHAR* WindowsFilesystemNode::toUnicode(const char *x) { -#ifndef UNICODE - return (const TCHAR *)x; -#else - static TCHAR unicodeString[MAX_PATH]; - MultiByteToWideChar(CP_ACP, 0, x, strlen(x) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR)); - return unicodeString; -#endif -} - void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) { WindowsFilesystemNode entry; char *asciiName = toAscii(find_data->cFileName); @@ -125,25 +155,24 @@ void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const c list.push_back(new WindowsFilesystemNode(entry)); } -AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { - char path[MAX_PATH]; - GetCurrentDirectory(MAX_PATH, path); - - // Add a trailing slash, if necessary. - if (path[0] != 0) { - if (path[strlen(path) - 1] != '\\') - strcat(path, "\\"); - } - - return new WindowsFilesystemNode(path); +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 } -AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { - return new WindowsFilesystemNode(); -} - -AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { - return new WindowsFilesystemNode(path); +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() { @@ -162,10 +191,23 @@ WindowsFilesystemNode::WindowsFilesystemNode() { #endif } -WindowsFilesystemNode::WindowsFilesystemNode(const String &p) { - assert(p.size() > 0); +WindowsFilesystemNode::WindowsFilesystemNode(const String &p, const bool currentDir) { + if (currentDir) { + char path[MAX_PATH]; + GetCurrentDirectory(MAX_PATH, path); - _path = p; + // Add a trailing slash, if necessary. + if (path[0] != 0) { + if (path[strlen(path) - 1] != '\\') + strcat(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 @@ -181,7 +223,23 @@ WindowsFilesystemNode::WindowsFilesystemNode(const String &p) { _isPseudoRoot = false; } -bool WindowsFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { +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) const { assert(_isDirectory); if (_isPseudoRoot) { @@ -227,10 +285,12 @@ bool WindowsFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const return true; } -AbstractFilesystemNode *WindowsFilesystemNode::parent() const { +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(); @@ -243,23 +303,8 @@ AbstractFilesystemNode *WindowsFilesystemNode::parent() const { p->_displayName = lastPathComponent(p->_path); p->_isPseudoRoot = false; } + return p; } -AbstractFilesystemNode *WindowsFilesystemNode::child(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; - - WindowsFilesystemNode *p = new WindowsFilesystemNode(newPath); - return p; -} - -#endif // WIN32 +#endif //#ifdef WIN32 diff --git a/common/fs.cpp b/common/fs.cpp index 10087cd91c7..cdc3e5f799f 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -23,7 +23,7 @@ #include "backends/fs/abstract-fs.h" #include "common/util.h" - +#include "backends/fs/FilesystemFactoryMaker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { _realNode = realNode; @@ -43,10 +43,12 @@ FilesystemNode::FilesystemNode(const FilesystemNode &node) { } FilesystemNode::FilesystemNode(const Common::String &p) { + AbstractFilesystemFactory *factory = FilesystemFactoryMaker::makeFactory(); + if (p.empty() || p == ".") - _realNode = AbstractFilesystemNode::getCurrentDirectory(); + _realNode = factory->makeCurrentDirectoryFileNode(); else - _realNode = AbstractFilesystemNode::getNodeForPath(p); + _realNode = factory->makeFileNodePath(p); _refCount = new int(1); } @@ -65,7 +67,7 @@ void FilesystemNode::decRefCount() { } } -FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) { +FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { if (node._refCount) ++(*node._refCount); @@ -87,7 +89,7 @@ FilesystemNode FilesystemNode::getParent() const { if (_realNode == 0) return *this; - AbstractFilesystemNode *node = _realNode->parent(); + AbstractFilesystemNode *node = _realNode->getParent(); if (node == 0) { return *this; } else { @@ -100,7 +102,7 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return *this; assert(_realNode->isDirectory()); - AbstractFilesystemNode *node = _realNode->child(n); + AbstractFilesystemNode *node = _realNode->getChild(n); return FilesystemNode(node); } @@ -110,7 +112,7 @@ bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { AbstractFSList tmp; - if (!_realNode->listDir(tmp, mode)) + if (!_realNode->getChildren(tmp, mode)) return false; fslist.clear(); @@ -129,20 +131,19 @@ bool FilesystemNode::isDirectory() const { Common::String FilesystemNode::displayName() const { assert(_realNode); - return _realNode->displayName(); + return _realNode->getDisplayName(); } Common::String FilesystemNode::name() const { assert(_realNode); - return _realNode->name(); + return _realNode->getName(); } Common::String FilesystemNode::path() const { assert(_realNode); - return _realNode->path(); + return _realNode->getPath(); } - bool FilesystemNode::operator< (const FilesystemNode& node) const { if (isDirectory() && !node.isDirectory()) diff --git a/common/fs.h b/common/fs.h index 2d906431caf..6a89bfcdaf7 100644 --- a/common/fs.h +++ b/common/fs.h @@ -30,7 +30,6 @@ class FilesystemNode; class AbstractFilesystemNode; - /** * List of multiple file system nodes. E.g. the contents of a given directory. * This is subclass instead of just a typedef so that we can use forward @@ -38,9 +37,8 @@ class AbstractFilesystemNode; */ class FSList : public Common::Array {}; - /** - * FilesystemNode provides an abstraction for file pathes, allowing for portable + * FilesystemNode provides an abstraction for file paths, allowing for portable * file system browsing. To this ends, multiple or single roots have to be supported * (compare Unix with a single root, Windows with multiple roots C:, D:, ...). * @@ -64,8 +62,8 @@ class FSList : public Common::Array {}; */ class FilesystemNode { private: - AbstractFilesystemNode *_realNode; int *_refCount; + AbstractFilesystemNode *_realNode; FilesystemNode(AbstractFilesystemNode *realNode); @@ -110,43 +108,13 @@ public: /** * Copy operator. */ - FilesystemNode &operator =(const FilesystemNode &node); - + FilesystemNode &operator= (const FilesystemNode &node); + /** - * Checks if the FilesystemNode is valid for any usage + * Compare the name of this node to the name of another. Directories + * go before normal files. */ - bool isValid() const; - - /** - * Get the parent node of this node. If this node has no parent node, - * then it returns a duplicate of this node. - */ - FilesystemNode getParent() const; - - /** - * Fetch a child node of this node, with the given name. Only valid for - * directory nodes (an assertion is triggered otherwise). If no no child - * node with the given name exists, an invalid node is returned. - */ - FilesystemNode getChild(const Common::String &name) const; - - /** - * Return a list of child nodes of this directory node. If called on a node - * that does not represent a directory, false is returned. - * @return true if succesful, false otherwise (e.g. when the directory does not exist). - * @todo Rename this to listChildren or getChildren. - */ - virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; - - /** - * 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; + bool operator< (const FilesystemNode& node) const; /** * Return a human readable string for this node, usable for display (e.g. @@ -180,15 +148,51 @@ public: virtual Common::String path() const; /** - * Compare the name of this node to the name of another. Directories - * go before normal files. + * Fetch a child node of this node, with the given name. Only valid for + * directory nodes (an assertion is triggered otherwise). + * If no child node with the given name exists, an invalid node is returned. */ - bool operator< (const FilesystemNode& node) const; + FilesystemNode getChild(const Common::String &name) const; + + /** + * Return a list of child nodes of this directory node. If called on a node + * that does not represent a directory, false is returned. + * + * @return true if succesful, false otherwise (e.g. when the directory does not exist). + * @todo Rename this to listChildren or getChildren. + */ + virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + + /** + * Get the parent node of this node. If this node has no parent node, + * then it returns a duplicate of this node. + */ + FilesystemNode getParent() const; + + /** + * Indicates whether this path refers to a directory or not. + * + * @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; + + /** + * Indicates whether this path is valid or not for usage. + */ + bool isValid() const; protected: + /** + * Decreases the reference count to the FilesystemNode, and if necessary, + * deletes the corresponding underlying references. + */ void decRefCount(); }; //} // End of namespace Common -#endif +#endif //COMMON_FS_H From 86324f00bc561c03b281170125ef2fde14cae132 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 12 May 2007 18:17:40 +0000 Subject: [PATCH 02/26] Renamed files and minor tweaks. Thanks LordHoto :) svn-id: r26810 --- ...esystemFactory.h => abstract-fs-factory.h} | 6 ++--- backends/fs/abstract-fs.h | 1 - ...temFactory.cpp => amigaos4-fs-factory.cpp} | 2 +- ...esystemFactory.h => amigaos4-fs-factory.h} | 13 ++++------ ...stemFactory.cpp => ronincd-fs-factory.cpp} | 2 +- ...lesystemFactory.h => ronincd-fs-factory.h} | 13 ++++------ ...ilesystemFactory.cpp => ds-fs-factory.cpp} | 2 +- ...{DSFilesystemFactory.h => ds-fs-factory.h} | 13 ++++------ ...mFactoryMaker.cpp => fs-factory-maker.cpp} | 24 +++++++++---------- ...esystemFactory.cpp => gp32-fs-factory.cpp} | 2 +- ...2FilesystemFactory.h => gp32-fs-factory.h} | 13 ++++------ ...esystemFactory.cpp => abox-fs-factory.cpp} | 2 +- ...xFilesystemFactory.h => abox-fs-factory.h} | 13 ++++------ ...ystemFactory.cpp => palmos-fs-factory.cpp} | 2 +- ...ilesystemFactory.h => palmos-fs-factory.h} | 13 ++++------ ...systemFactory.cpp => posix-fs-factory.cpp} | 2 +- ...FilesystemFactory.h => posix-fs-factory.h} | 13 ++++------ ...lesystemFactory.cpp => ps2-fs-factory.cpp} | 2 +- ...s2FilesystemFactory.h => ps2-fs-factory.h} | 13 ++++------ ...lesystemFactory.cpp => psp-fs-factory.cpp} | 2 +- ...SPFilesystemFactory.h => psp-fs-factory.h} | 13 ++++------ ...stemFactory.cpp => symbian-fs-factory.cpp} | 2 +- ...lesystemFactory.h => symbian-fs-factory.h} | 13 ++++------ ...stemFactory.cpp => windows-fs-factory.cpp} | 2 +- ...lesystemFactory.h => windows-fs-factory.h} | 13 ++++------ common/fs.cpp | 2 +- 26 files changed, 71 insertions(+), 127 deletions(-) rename backends/fs/{AbstractFilesystemFactory.h => abstract-fs-factory.h} (92%) rename backends/fs/amigaos4/{AmigaOSFilesystemFactory.cpp => amigaos4-fs-factory.cpp} (91%) rename backends/fs/amigaos4/{AmigaOSFilesystemFactory.h => amigaos4-fs-factory.h} (77%) rename backends/fs/dc/{RoninCDFilesystemFactory.cpp => ronincd-fs-factory.cpp} (92%) rename backends/fs/dc/{RoninCDFilesystemFactory.h => ronincd-fs-factory.h} (77%) rename backends/fs/ds/{DSFilesystemFactory.cpp => ds-fs-factory.cpp} (95%) rename backends/fs/ds/{DSFilesystemFactory.h => ds-fs-factory.h} (77%) rename backends/fs/{FilesystemFactoryMaker.cpp => fs-factory-maker.cpp} (74%) rename backends/fs/gp32/{GP32FilesystemFactory.cpp => gp32-fs-factory.cpp} (92%) rename backends/fs/gp32/{GP32FilesystemFactory.h => gp32-fs-factory.h} (77%) rename backends/fs/morphos/{ABoxFilesystemFactory.cpp => abox-fs-factory.cpp} (91%) rename backends/fs/morphos/{ABoxFilesystemFactory.h => abox-fs-factory.h} (77%) rename backends/fs/palmos/{PalmOSFilesystemFactory.cpp => palmos-fs-factory.cpp} (91%) rename backends/fs/palmos/{PalmOSFilesystemFactory.h => palmos-fs-factory.h} (77%) rename backends/fs/posix/{POSIXFilesystemFactory.cpp => posix-fs-factory.cpp} (92%) rename backends/fs/posix/{POSIXFilesystemFactory.h => posix-fs-factory.h} (77%) rename backends/fs/ps2/{Ps2FilesystemFactory.cpp => ps2-fs-factory.cpp} (92%) rename backends/fs/ps2/{Ps2FilesystemFactory.h => ps2-fs-factory.h} (77%) rename backends/fs/psp/{PSPFilesystemFactory.cpp => psp-fs-factory.cpp} (92%) rename backends/fs/psp/{PSPFilesystemFactory.h => psp-fs-factory.h} (77%) rename backends/fs/symbian/{SymbianFilesystemFactory.cpp => symbian-fs-factory.cpp} (92%) rename backends/fs/symbian/{SymbianFilesystemFactory.h => symbian-fs-factory.h} (77%) rename backends/fs/windows/{WindowsFilesystemFactory.cpp => windows-fs-factory.cpp} (92%) rename backends/fs/windows/{WindowsFilesystemFactory.h => windows-fs-factory.h} (77%) diff --git a/backends/fs/AbstractFilesystemFactory.h b/backends/fs/abstract-fs-factory.h similarity index 92% rename from backends/fs/AbstractFilesystemFactory.h rename to backends/fs/abstract-fs-factory.h index 4af8c6b6570..41bfaaa34bc 100644 --- a/backends/fs/AbstractFilesystemFactory.h +++ b/backends/fs/abstract-fs-factory.h @@ -1,5 +1,5 @@ -#ifndef ABSTRACTFILESYSTEMFACTORY_H_ -#define ABSTRACTFILESYSTEMFACTORY_H_ +#ifndef ABSTRACT_FILESYSTEM_FACTORY_H +#define ABSTRACT_FILESYSTEM_FACTORY_H #include "common/str.h" @@ -45,4 +45,4 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const = 0; }; -#endif /*ABSTRACTFILESYSTEMFACTORY_H_*/ +#endif /*ABSTRACT_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 86149dfffab..8297bf69e2c 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -24,7 +24,6 @@ #include "common/array.h" #include "common/str.h" - #include "common/fs.h" class AbstractFilesystemNode; diff --git a/backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp b/backends/fs/amigaos4/amigaos4-fs-factory.cpp similarity index 91% rename from backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp rename to backends/fs/amigaos4/amigaos4-fs-factory.cpp index 2f264917883..abb0790c18a 100644 --- a/backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp +++ b/backends/fs/amigaos4/amigaos4-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/amigaos4/AmigaOSFilesystemFactory.h" +#include "backends/fs/amigaos4/amigaos4-fs-factory.h" #include "backends/fs/amigaos4/amigaos4-fs.cpp" AmigaOSFilesystemFactory *AmigaOSFilesystemFactory::_instance = 0; diff --git a/backends/fs/amigaos4/AmigaOSFilesystemFactory.h b/backends/fs/amigaos4/amigaos4-fs-factory.h similarity index 77% rename from backends/fs/amigaos4/AmigaOSFilesystemFactory.h rename to backends/fs/amigaos4/amigaos4-fs-factory.h index 8eea9528310..4b34cc19543 100644 --- a/backends/fs/amigaos4/AmigaOSFilesystemFactory.h +++ b/backends/fs/amigaos4/amigaos4-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef AMIGAOSFILESYSTEMFACTORY_H_ -#define AMIGAOSFILESYSTEMFACTORY_H_ +#ifndef AMIGAOS_FILESYSTEM_FACTORY_H +#define AMIGAOS_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates AmigaOSFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of AmigaOSFilesytemFactory. */ static AmigaOSFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~AmigaOSFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static AmigaOSFilesystemFactory *_instance; }; -#endif /*AMIGAOSFILESYSTEMFACTORY_H_*/ +#endif /*AMIGAOS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/dc/RoninCDFilesystemFactory.cpp b/backends/fs/dc/ronincd-fs-factory.cpp similarity index 92% rename from backends/fs/dc/RoninCDFilesystemFactory.cpp rename to backends/fs/dc/ronincd-fs-factory.cpp index 19147453687..92b2c5f7bb5 100644 --- a/backends/fs/dc/RoninCDFilesystemFactory.cpp +++ b/backends/fs/dc/ronincd-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/dc/RoninCDFilesystemFactory.h" +#include "backends/fs/dc/ronincd-fs-factory.h" #include "backends/fs/dc/dc-fs.cpp" RoninCDFilesystemFactory *RoninCDFilesystemFactory::_instance = 0; diff --git a/backends/fs/dc/RoninCDFilesystemFactory.h b/backends/fs/dc/ronincd-fs-factory.h similarity index 77% rename from backends/fs/dc/RoninCDFilesystemFactory.h rename to backends/fs/dc/ronincd-fs-factory.h index a063ce1d6a9..02cfe66c825 100644 --- a/backends/fs/dc/RoninCDFilesystemFactory.h +++ b/backends/fs/dc/ronincd-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef RONINCDFILESYSTEMFACTORY_H_ -#define RONINCDFILESYSTEMFACTORY_H_ +#ifndef RONINCD_FILESYSTEM_FACTORY_H +#define RONINCD_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates RoninCDFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of RoninCDFilesytemFactory. */ static RoninCDFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~RoninCDFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static RoninCDFilesystemFactory *_instance; }; -#endif /*RONINCDFILESYSTEMFACTORY_H_*/ +#endif /*RONINCD_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/ds/DSFilesystemFactory.cpp b/backends/fs/ds/ds-fs-factory.cpp similarity index 95% rename from backends/fs/ds/DSFilesystemFactory.cpp rename to backends/fs/ds/ds-fs-factory.cpp index 809dc0e5cf6..1855fbc40d6 100644 --- a/backends/fs/ds/DSFilesystemFactory.cpp +++ b/backends/fs/ds/ds-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/ds/DSFilesystemFactory.h" +#include "backends/fs/ds/ds-fs-factory.h" #include "backends/fs/ds/ds-fs.cpp" #include "dsmain.h" //for the isGBAMPAvailable() function diff --git a/backends/fs/ds/DSFilesystemFactory.h b/backends/fs/ds/ds-fs-factory.h similarity index 77% rename from backends/fs/ds/DSFilesystemFactory.h rename to backends/fs/ds/ds-fs-factory.h index 6eaef1cd1ed..5e96edc390c 100644 --- a/backends/fs/ds/DSFilesystemFactory.h +++ b/backends/fs/ds/ds-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef DSFILESYSTEMFACTORY_H_ -#define DSFILESYSTEMFACTORY_H_ +#ifndef DS_FILESYSTEM_FACTORY_H +#define DS_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates DSFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of DSFilesytemFactory. */ static DSFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~DSFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static DSFilesystemFactory *_instance; }; -#endif /*DSFILESYSTEMFACTORY_H_*/ +#endif /*DS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/FilesystemFactoryMaker.cpp b/backends/fs/fs-factory-maker.cpp similarity index 74% rename from backends/fs/FilesystemFactoryMaker.cpp rename to backends/fs/fs-factory-maker.cpp index 66a1c8c0c49..636a39b5e3f 100644 --- a/backends/fs/FilesystemFactoryMaker.cpp +++ b/backends/fs/fs-factory-maker.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /* * All the following includes choose, at compile time, which specific backend will be used @@ -8,47 +8,47 @@ * all build environments. Additionally, this results in smaller binaries. */ #if defined(__amigaos4__) - #include "backends/fs/amigaos4/AmigaOSFilesystemFactory.cpp" + #include "backends/fs/amigaos4/amigaos4-fs-factory.cpp" #endif #if defined(__DC__) - #include "backends/fs/dc/RoninCDFilesystemFactory.cpp" + #include "backends/fs/dc/ronincd-fs-factory.cpp" #endif #if defined(__DS__) - #include "backends/fs/ds/DSFilesystemFactory.cpp" + #include "backends/fs/ds/ds-fs-factory.cpp" #endif #if defined(__GP32__) - #include "backends/fs/gp32/GP32FilesystemFactory.cpp" + #include "backends/fs/gp32/gp32-fs-factory.cpp" #endif #if defined(__MORPHOS__) - #include "backends/fs/morphos/ABoxFilesystemFactory.cpp" + #include "backends/fs/morphos/abox-fs-factory.cpp" #endif #if defined(PALMOS_MODE) - #include "backends/fs/palmos/PalmOSFilesystemFactory.cpp" + #include "backends/fs/palmos/palmos-fs-factory.cpp" #endif #if defined(__PLAYSTATION2__) - #include "backends/fs/ps2/Ps2FilesystemFactory.cpp" + #include "backends/fs/ps2/ps2-fs-factory.cpp" #endif #if defined(__PSP__) - #include "backends/fs/psp/PSPFilesystemFactory.cpp" + #include "backends/fs/psp/psp-fs-factory.cpp" #endif #if defined(__SYMBIAN32__) - #include "backends/fs/symbian/SymbianFilesystemFactory.cpp" + #include "backends/fs/symbian/symbian-fs-factory.cpp" #endif #if defined(UNIX) - #include "backends/fs/posix/POSIXFilesystemFactory.cpp" + #include "backends/fs/posix/posix-fs-factory.cpp" #endif #if defined(WIN32) - #include "backends/fs/windows/WindowsFilesystemFactory.cpp" + #include "backends/fs/windows/windows-fs-factory.cpp" #endif /** diff --git a/backends/fs/gp32/GP32FilesystemFactory.cpp b/backends/fs/gp32/gp32-fs-factory.cpp similarity index 92% rename from backends/fs/gp32/GP32FilesystemFactory.cpp rename to backends/fs/gp32/gp32-fs-factory.cpp index fa98079a8d0..fc19bdf1cfd 100644 --- a/backends/fs/gp32/GP32FilesystemFactory.cpp +++ b/backends/fs/gp32/gp32-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/gp32/GP32FilesystemFactory.h" +#include "backends/fs/gp32/gp32-fs-factory.h" #include "backends/fs/gp32/gp32-fs.cpp" GP32FilesystemFactory *GP32FilesystemFactory::_instance = 0; diff --git a/backends/fs/gp32/GP32FilesystemFactory.h b/backends/fs/gp32/gp32-fs-factory.h similarity index 77% rename from backends/fs/gp32/GP32FilesystemFactory.h rename to backends/fs/gp32/gp32-fs-factory.h index d31642acd22..1b34597d845 100644 --- a/backends/fs/gp32/GP32FilesystemFactory.h +++ b/backends/fs/gp32/gp32-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef GP32FILESYSTEMFACTORY_H_ -#define GP32FILESYSTEMFACTORY_H_ +#ifndef GP32_FILESYSTEM_FACTORY_H +#define GP32_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates GP32FilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of GP32FilesytemFactory. */ static GP32FilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~GP32FilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static GP32FilesystemFactory *_instance; }; -#endif /*GP32FILESYSTEMFACTORY_H_*/ +#endif /*GP32_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/morphos/ABoxFilesystemFactory.cpp b/backends/fs/morphos/abox-fs-factory.cpp similarity index 91% rename from backends/fs/morphos/ABoxFilesystemFactory.cpp rename to backends/fs/morphos/abox-fs-factory.cpp index 02d954ee74f..4689a6a42f8 100644 --- a/backends/fs/morphos/ABoxFilesystemFactory.cpp +++ b/backends/fs/morphos/abox-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/morphos/ABoxFilesystemFactory.h" +#include "backends/fs/morphos/abox-fs-factory.h" #include "backends/fs/morphos/abox-fs.cpp" ABoxFilesystemFactory *ABoxFilesystemFactory::_instance = 0; diff --git a/backends/fs/morphos/ABoxFilesystemFactory.h b/backends/fs/morphos/abox-fs-factory.h similarity index 77% rename from backends/fs/morphos/ABoxFilesystemFactory.h rename to backends/fs/morphos/abox-fs-factory.h index c8fc0b3c193..f6cf7774c5f 100644 --- a/backends/fs/morphos/ABoxFilesystemFactory.h +++ b/backends/fs/morphos/abox-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef ABOXFILESYSTEMFACTORY_H_ -#define ABOXFILESYSTEMFACTORY_H_ +#ifndef ABOX_FILESYSTEM_FACTORY_H +#define ABOX_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates ABoxFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of ABoxFilesytemFactory. */ static ABoxFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~ABoxFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static ABoxFilesystemFactory *_instance; }; -#endif /*ABOXFILESYSTEMFACTORY_H_*/ +#endif /*ABOX_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/palmos/PalmOSFilesystemFactory.cpp b/backends/fs/palmos/palmos-fs-factory.cpp similarity index 91% rename from backends/fs/palmos/PalmOSFilesystemFactory.cpp rename to backends/fs/palmos/palmos-fs-factory.cpp index 15240d23976..6be7021f774 100644 --- a/backends/fs/palmos/PalmOSFilesystemFactory.cpp +++ b/backends/fs/palmos/palmos-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/palmos/PalmOSFilesystemFactory.h" +#include "backends/fs/palmos/palmos-fs-factory.h" #include "backends/fs/palmos/palmos-fs.cpp" PalmOSFilesystemFactory *PalmOSFilesystemFactory::_instance = 0; diff --git a/backends/fs/palmos/PalmOSFilesystemFactory.h b/backends/fs/palmos/palmos-fs-factory.h similarity index 77% rename from backends/fs/palmos/PalmOSFilesystemFactory.h rename to backends/fs/palmos/palmos-fs-factory.h index dd1f31b3c8c..618a1965d9a 100644 --- a/backends/fs/palmos/PalmOSFilesystemFactory.h +++ b/backends/fs/palmos/palmos-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef PALMOSFILESYSTEMFACTORY_H_ -#define PALMOSFILESYSTEMFACTORY_H_ +#ifndef PALMOS_FILESYSTEM_FACTORY_H +#define PALMOS_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates PalmOSFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of PalmOSFilesytemFactory. */ static PalmOSFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~PalmOSFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static PalmOSFilesystemFactory *_instance; }; -#endif /*PALMOSFILESYSTEMFACTORY_H_*/ +#endif /*PALMOS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/posix/POSIXFilesystemFactory.cpp b/backends/fs/posix/posix-fs-factory.cpp similarity index 92% rename from backends/fs/posix/POSIXFilesystemFactory.cpp rename to backends/fs/posix/posix-fs-factory.cpp index 9a13c37c301..b302bb31e8d 100644 --- a/backends/fs/posix/POSIXFilesystemFactory.cpp +++ b/backends/fs/posix/posix-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/posix/POSIXFilesystemFactory.h" +#include "backends/fs/posix/posix-fs-factory.h" #include "backends/fs/posix/posix-fs.cpp" POSIXFilesystemFactory *POSIXFilesystemFactory::_instance = 0; diff --git a/backends/fs/posix/POSIXFilesystemFactory.h b/backends/fs/posix/posix-fs-factory.h similarity index 77% rename from backends/fs/posix/POSIXFilesystemFactory.h rename to backends/fs/posix/posix-fs-factory.h index b4714604457..5195491b955 100644 --- a/backends/fs/posix/POSIXFilesystemFactory.h +++ b/backends/fs/posix/posix-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef POSIXFILESYSTEMFACTORY_H_ -#define POSIXFILESYSTEMFACTORY_H_ +#ifndef POSIX_FILESYSTEM_FACTORY_H +#define POSIX_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates POSIXFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of POSIXFilesytemFactory. */ static POSIXFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~POSIXFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static POSIXFilesystemFactory *_instance; }; -#endif /*POSIXFILESYSTEMFACTORY_H_*/ +#endif /*POSIX_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/ps2/Ps2FilesystemFactory.cpp b/backends/fs/ps2/ps2-fs-factory.cpp similarity index 92% rename from backends/fs/ps2/Ps2FilesystemFactory.cpp rename to backends/fs/ps2/ps2-fs-factory.cpp index c07387eae10..726eb87c6fc 100644 --- a/backends/fs/ps2/Ps2FilesystemFactory.cpp +++ b/backends/fs/ps2/ps2-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/ps2/Ps2FilesystemFactory.h" +#include "backends/fs/ps2/ps2-fs-factory.h" #include "backends/fs/ps2/ps2-fs.cpp" Ps2FilesystemFactory *Ps2FilesystemFactory::_instance = 0; diff --git a/backends/fs/ps2/Ps2FilesystemFactory.h b/backends/fs/ps2/ps2-fs-factory.h similarity index 77% rename from backends/fs/ps2/Ps2FilesystemFactory.h rename to backends/fs/ps2/ps2-fs-factory.h index e394865e805..de7ada6ba38 100644 --- a/backends/fs/ps2/Ps2FilesystemFactory.h +++ b/backends/fs/ps2/ps2-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef PS2FILESYSTEMFACTORY_H_ -#define PS2FILESYSTEMFACTORY_H_ +#ifndef PS2_FILESYSTEM_FACTORY_H +#define PS2_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates PS2FilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of Ps2FilesytemFactory. */ static Ps2FilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~Ps2FilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static Ps2FilesystemFactory *_instance; }; -#endif /*PS2FILESYSTEMFACTORY_H_*/ +#endif /*PS2_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/psp/PSPFilesystemFactory.cpp b/backends/fs/psp/psp-fs-factory.cpp similarity index 92% rename from backends/fs/psp/PSPFilesystemFactory.cpp rename to backends/fs/psp/psp-fs-factory.cpp index 5a3802c10a7..2a0307d3f40 100644 --- a/backends/fs/psp/PSPFilesystemFactory.cpp +++ b/backends/fs/psp/psp-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/psp/PSPFilesystemFactory.h" +#include "backends/fs/psp/psp-fs-factory.h" #include "backends/fs/psp/psp_fs.cpp" PSPFilesystemFactory *PSPFilesystemFactory::_instance = 0; diff --git a/backends/fs/psp/PSPFilesystemFactory.h b/backends/fs/psp/psp-fs-factory.h similarity index 77% rename from backends/fs/psp/PSPFilesystemFactory.h rename to backends/fs/psp/psp-fs-factory.h index 70358c90ed4..05388fa6975 100644 --- a/backends/fs/psp/PSPFilesystemFactory.h +++ b/backends/fs/psp/psp-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef PSPFILESYSTEMFACTORY_H_ -#define PSPFILESYSTEMFACTORY_H_ +#ifndef PSP_FILESYSTEM_FACTORY_H +#define PSP_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates PSPFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of PSPFilesytemFactory. */ static PSPFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~PSPFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static PSPFilesystemFactory *_instance; }; -#endif /*PSPFILESYSTEMFACTORY_H_*/ +#endif /*PSP_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/symbian/SymbianFilesystemFactory.cpp b/backends/fs/symbian/symbian-fs-factory.cpp similarity index 92% rename from backends/fs/symbian/SymbianFilesystemFactory.cpp rename to backends/fs/symbian/symbian-fs-factory.cpp index 07da19629c3..f3eb5521594 100644 --- a/backends/fs/symbian/SymbianFilesystemFactory.cpp +++ b/backends/fs/symbian/symbian-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/symbian/SymbianFilesystemFactory.h" +#include "backends/fs/symbian/symbian-fs-factory.h" #include "backends/fs/symbian/symbian-fs.cpp" SymbianFilesystemFactory *SymbianFilesystemFactory::_instance = 0; diff --git a/backends/fs/symbian/SymbianFilesystemFactory.h b/backends/fs/symbian/symbian-fs-factory.h similarity index 77% rename from backends/fs/symbian/SymbianFilesystemFactory.h rename to backends/fs/symbian/symbian-fs-factory.h index b1d4b81250b..4bbac728cb6 100644 --- a/backends/fs/symbian/SymbianFilesystemFactory.h +++ b/backends/fs/symbian/symbian-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef SYMBIANFILESYSTEMFACTORY_H_ -#define SYMBIANFILESYSTEMFACTORY_H_ +#ifndef SYMBIAN_FILESYSTEM_FACTORY_H +#define SYMBIAN_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates SymbianFilesystemNode objects. @@ -18,11 +18,6 @@ public: * @return A unique instance of SymbianFilesytemFactory. */ static SymbianFilesystemFactory *instance(); - - /** - * Destructor. - */ - virtual ~SymbianFilesystemFactory() {}; virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -35,4 +30,4 @@ private: static SymbianFilesystemFactory *_instance; }; -#endif /*SYMBIANFILESYSTEMFACTORY_H_*/ +#endif /*SYMBIAN_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/windows/WindowsFilesystemFactory.cpp b/backends/fs/windows/windows-fs-factory.cpp similarity index 92% rename from backends/fs/windows/WindowsFilesystemFactory.cpp rename to backends/fs/windows/windows-fs-factory.cpp index a360fd1c7ab..fb77b4ca077 100644 --- a/backends/fs/windows/WindowsFilesystemFactory.cpp +++ b/backends/fs/windows/windows-fs-factory.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/windows/WindowsFilesystemFactory.h" +#include "backends/fs/windows/windows-fs-factory.h" #include "backends/fs/windows/windows-fs.cpp" WindowsFilesystemFactory *WindowsFilesystemFactory::_instance = 0; diff --git a/backends/fs/windows/WindowsFilesystemFactory.h b/backends/fs/windows/windows-fs-factory.h similarity index 77% rename from backends/fs/windows/WindowsFilesystemFactory.h rename to backends/fs/windows/windows-fs-factory.h index 0d965089c4b..a7abf390aea 100644 --- a/backends/fs/windows/WindowsFilesystemFactory.h +++ b/backends/fs/windows/windows-fs-factory.h @@ -1,7 +1,7 @@ -#ifndef WINDOWSFILESYSTEMFACTORY_H_ -#define WINDOWSFILESYSTEMFACTORY_H_ +#ifndef WINDOWS_FILESYSTEM_FACTORY_H +#define WINDOWS_FILESYSTEM_FACTORY_H -#include "backends/fs/AbstractFilesystemFactory.h" +#include "backends/fs/abstract-fs-factory.h" /** * Creates WindowsFilesystemNode objects. @@ -19,11 +19,6 @@ public: */ static WindowsFilesystemFactory *instance(); - /** - * Destructor. - */ - virtual ~WindowsFilesystemFactory() {}; - virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; @@ -35,4 +30,4 @@ private: static WindowsFilesystemFactory *_instance; }; -#endif /*WINDOWSFILESYSTEMFACTORY_H_*/ +#endif /*WINDOWS_FILESYSTEM_FACTORY_H*/ diff --git a/common/fs.cpp b/common/fs.cpp index cdc3e5f799f..07fafa9aa80 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -23,7 +23,7 @@ #include "backends/fs/abstract-fs.h" #include "common/util.h" -#include "backends/fs/FilesystemFactoryMaker.cpp" +#include "backends/fs/fs-factory-maker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { _realNode = realNode; From d1f56d93f934150f4b579c2e90564e2bf035f113 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 12 May 2007 20:00:52 +0000 Subject: [PATCH 03/26] Use common/singleton.h in the concrete fs factories. svn-id: r26814 --- backends/fs/amigaos4/amigaos4-fs-factory.cpp | 9 +------- backends/fs/amigaos4/amigaos4-fs-factory.h | 11 ++-------- backends/fs/dc/ronincd-fs-factory.cpp | 9 +------- backends/fs/dc/ronincd-fs-factory.h | 11 ++-------- backends/fs/ds/ds-fs-factory.cpp | 9 +------- backends/fs/ds/ds-fs-factory.h | 11 ++-------- backends/fs/fs-factory-maker.cpp | 22 ++++++++++---------- backends/fs/gp32/gp32-fs-factory.cpp | 9 +------- backends/fs/gp32/gp32-fs-factory.h | 11 ++-------- backends/fs/morphos/abox-fs-factory.cpp | 9 +------- backends/fs/morphos/abox-fs-factory.h | 11 ++-------- backends/fs/palmos/palmos-fs-factory.cpp | 9 +------- backends/fs/palmos/palmos-fs-factory.h | 11 ++-------- backends/fs/posix/posix-fs-factory.cpp | 9 +------- backends/fs/posix/posix-fs-factory.h | 12 +++-------- backends/fs/ps2/ps2-fs-factory.cpp | 9 +------- backends/fs/ps2/ps2-fs-factory.h | 11 ++-------- backends/fs/psp/psp-fs-factory.cpp | 9 +------- backends/fs/psp/psp-fs-factory.h | 11 ++-------- backends/fs/symbian/symbian-fs-factory.cpp | 9 +------- backends/fs/symbian/symbian-fs-factory.h | 11 ++-------- backends/fs/windows/windows-fs-factory.cpp | 9 +------- backends/fs/windows/windows-fs-factory.h | 11 ++-------- common/fs.cpp | 3 +-- 24 files changed, 46 insertions(+), 200 deletions(-) diff --git a/backends/fs/amigaos4/amigaos4-fs-factory.cpp b/backends/fs/amigaos4/amigaos4-fs-factory.cpp index abb0790c18a..becbd490038 100644 --- a/backends/fs/amigaos4/amigaos4-fs-factory.cpp +++ b/backends/fs/amigaos4/amigaos4-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/amigaos4/amigaos4-fs-factory.h" #include "backends/fs/amigaos4/amigaos4-fs.cpp" -AmigaOSFilesystemFactory *AmigaOSFilesystemFactory::_instance = 0; - -AmigaOSFilesystemFactory *AmigaOSFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new AmigaOSFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(AmigaOSFilesystemFactory); AbstractFilesystemNode *AmigaOSFilesystemFactory::makeRootFileNode() const { return new AmigaOSFilesystemNode(); diff --git a/backends/fs/amigaos4/amigaos4-fs-factory.h b/backends/fs/amigaos4/amigaos4-fs-factory.h index 4b34cc19543..861f28b7947 100644 --- a/backends/fs/amigaos4/amigaos4-fs-factory.h +++ b/backends/fs/amigaos4/amigaos4-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class AmigaOSFilesystemFactory : public AbstractFilesystemFactory { +class AmigaOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of AmigaOSFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of AmigaOSFilesytemFactory. - */ - static AmigaOSFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: AmigaOSFilesystemFactory() {}; private: - static AmigaOSFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*AMIGAOS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/dc/ronincd-fs-factory.cpp b/backends/fs/dc/ronincd-fs-factory.cpp index 92b2c5f7bb5..0229a44c453 100644 --- a/backends/fs/dc/ronincd-fs-factory.cpp +++ b/backends/fs/dc/ronincd-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/dc/ronincd-fs-factory.h" #include "backends/fs/dc/dc-fs.cpp" -RoninCDFilesystemFactory *RoninCDFilesystemFactory::_instance = 0; - -RoninCDFilesystemFactory *RoninCDFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new RoninCDFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(RoninCDFilesystemFactory); AbstractFilesystemNode *RoninCDFilesystemFactory::makeRootFileNode() const { return new RoninCDFilesystemNode(); diff --git a/backends/fs/dc/ronincd-fs-factory.h b/backends/fs/dc/ronincd-fs-factory.h index 02cfe66c825..12590e8fa41 100644 --- a/backends/fs/dc/ronincd-fs-factory.h +++ b/backends/fs/dc/ronincd-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class RoninCDFilesystemFactory : public AbstractFilesystemFactory { +class RoninCDFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of RoninCDFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of RoninCDFilesytemFactory. - */ - static RoninCDFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: RoninCDFilesystemFactory() {}; private: - static RoninCDFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*RONINCD_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/ds/ds-fs-factory.cpp b/backends/fs/ds/ds-fs-factory.cpp index 1855fbc40d6..7e64b374115 100644 --- a/backends/fs/ds/ds-fs-factory.cpp +++ b/backends/fs/ds/ds-fs-factory.cpp @@ -2,14 +2,7 @@ #include "backends/fs/ds/ds-fs.cpp" #include "dsmain.h" //for the isGBAMPAvailable() function -DSFilesystemFactory *DSFilesystemFactory::_instance = 0; - -DSFilesystemFactory *DSFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new DSFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(DSFilesystemFactory); AbstractFilesystemNode *DSFilesystemFactory::makeRootFileNode() const { if (DS::isGBAMPAvailable()) { diff --git a/backends/fs/ds/ds-fs-factory.h b/backends/fs/ds/ds-fs-factory.h index 5e96edc390c..5bc847a7b21 100644 --- a/backends/fs/ds/ds-fs-factory.h +++ b/backends/fs/ds/ds-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class DSFilesystemFactory : public AbstractFilesystemFactory { +class DSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of DSFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of DSFilesytemFactory. - */ - static DSFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: DSFilesystemFactory() {}; private: - static DSFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*DS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/fs-factory-maker.cpp b/backends/fs/fs-factory-maker.cpp index 636a39b5e3f..bae3d1a30a3 100644 --- a/backends/fs/fs-factory-maker.cpp +++ b/backends/fs/fs-factory-maker.cpp @@ -68,46 +68,46 @@ protected: AbstractFilesystemFactory *FilesystemFactoryMaker::makeFactory(){ #if defined(__amigaos4__) - return AmigaOSFilesystemFactory::instance(); + return &AmigaOSFilesystemFactory::instance(); #endif #if defined(__DC__) - return RoninCDFilesystemFactory::instance(); + return &RoninCDFilesystemFactory::instance(); #endif #if defined(__DS__) - return DSFilesystemFactory::instance(); + return &DSFilesystemFactory::instance(); #endif #if defined(__GP32__) - return GP32FilesystemFactory::instance(); + return &GP32FilesystemFactory::instance(); #endif #if defined(__MORPHOS__) - return ABoxFilesystemFactory::instance(); + return &ABoxFilesystemFactory::instance(); #endif #if defined(PALMOS_MODE) - return PalmOSFilesystemFactory::instance(); + return &PalmOSFilesystemFactory::instance(); #endif #if defined(__PLAYSTATION2__) - return Ps2FilesystemFactory::instance(); + return &Ps2FilesystemFactory::instance(); #endif #if defined(__PSP__) - return PSPFilesystemFactory::instance(); + return &PSPFilesystemFactory::instance(); #endif #if defined(__SYMBIAN32__) - return SymbianFilesystemFactory::instance(); + return &SymbianFilesystemFactory::instance(); #endif #if defined(UNIX) - return POSIXFilesystemFactory::instance(); + return &POSIXFilesystemFactory::instance(); #endif #if defined(WIN32) - return WindowsFilesystemFactory::instance(); + return &WindowsFilesystemFactory::instance(); #endif } diff --git a/backends/fs/gp32/gp32-fs-factory.cpp b/backends/fs/gp32/gp32-fs-factory.cpp index fc19bdf1cfd..6328836c0e0 100644 --- a/backends/fs/gp32/gp32-fs-factory.cpp +++ b/backends/fs/gp32/gp32-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/gp32/gp32-fs-factory.h" #include "backends/fs/gp32/gp32-fs.cpp" -GP32FilesystemFactory *GP32FilesystemFactory::_instance = 0; - -GP32FilesystemFactory *GP32FilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new GP32FilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(GP32FilesystemFactory); AbstractFilesystemNode *GP32FilesystemFactory::makeRootFileNode() const { return new GP32FilesystemNode(); diff --git a/backends/fs/gp32/gp32-fs-factory.h b/backends/fs/gp32/gp32-fs-factory.h index 1b34597d845..22c502d69fa 100644 --- a/backends/fs/gp32/gp32-fs-factory.h +++ b/backends/fs/gp32/gp32-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class GP32FilesystemFactory : public AbstractFilesystemFactory { +class GP32FilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of GP32FilesystemFactory using the Singleton pattern. - * - * @return A unique instance of GP32FilesytemFactory. - */ - static GP32FilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: GP32FilesystemFactory() {}; private: - static GP32FilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*GP32_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/morphos/abox-fs-factory.cpp b/backends/fs/morphos/abox-fs-factory.cpp index 4689a6a42f8..9de810c3619 100644 --- a/backends/fs/morphos/abox-fs-factory.cpp +++ b/backends/fs/morphos/abox-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/morphos/abox-fs-factory.h" #include "backends/fs/morphos/abox-fs.cpp" -ABoxFilesystemFactory *ABoxFilesystemFactory::_instance = 0; - -ABoxFilesystemFactory *ABoxFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new ABoxFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(ABoxFilesystemFactory); AbstractFilesystemNode *ABoxFilesystemFactory::makeRootFileNode() const { return new ABoxFilesystemNode(); diff --git a/backends/fs/morphos/abox-fs-factory.h b/backends/fs/morphos/abox-fs-factory.h index f6cf7774c5f..b0d1dfb3409 100644 --- a/backends/fs/morphos/abox-fs-factory.h +++ b/backends/fs/morphos/abox-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class ABoxFilesystemFactory : public AbstractFilesystemFactory { +class ABoxFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of ABoxFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of ABoxFilesytemFactory. - */ - static ABoxFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: ABoxFilesystemFactory() {}; private: - static ABoxFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*ABOX_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/palmos/palmos-fs-factory.cpp b/backends/fs/palmos/palmos-fs-factory.cpp index 6be7021f774..1b0db0f0420 100644 --- a/backends/fs/palmos/palmos-fs-factory.cpp +++ b/backends/fs/palmos/palmos-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/palmos/palmos-fs-factory.h" #include "backends/fs/palmos/palmos-fs.cpp" -PalmOSFilesystemFactory *PalmOSFilesystemFactory::_instance = 0; - -PalmOSFilesystemFactory *PalmOSFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new PalmOSFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(PalmOSFilesystemFactory); AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const { return new PalmOSFilesystemNode(); diff --git a/backends/fs/palmos/palmos-fs-factory.h b/backends/fs/palmos/palmos-fs-factory.h index 618a1965d9a..4bb94ab4c17 100644 --- a/backends/fs/palmos/palmos-fs-factory.h +++ b/backends/fs/palmos/palmos-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class PalmOSFilesystemFactory : public AbstractFilesystemFactory { +class PalmOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of PalmOSFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of PalmOSFilesytemFactory. - */ - static PalmOSFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: PalmOSFilesystemFactory() {}; private: - static PalmOSFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*PALMOS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/posix/posix-fs-factory.cpp b/backends/fs/posix/posix-fs-factory.cpp index b302bb31e8d..bed3dc5f8fd 100644 --- a/backends/fs/posix/posix-fs-factory.cpp +++ b/backends/fs/posix/posix-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/posix/posix-fs-factory.h" #include "backends/fs/posix/posix-fs.cpp" -POSIXFilesystemFactory *POSIXFilesystemFactory::_instance = 0; - -POSIXFilesystemFactory *POSIXFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new POSIXFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(POSIXFilesystemFactory); AbstractFilesystemNode *POSIXFilesystemFactory::makeRootFileNode() const { return new POSIXFilesystemNode(); diff --git a/backends/fs/posix/posix-fs-factory.h b/backends/fs/posix/posix-fs-factory.h index 5195491b955..93f0ac115b8 100644 --- a/backends/fs/posix/posix-fs-factory.h +++ b/backends/fs/posix/posix-fs-factory.h @@ -1,6 +1,7 @@ #ifndef POSIX_FILESYSTEM_FACTORY_H #define POSIX_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** @@ -8,16 +9,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class POSIXFilesystemFactory : public AbstractFilesystemFactory { +class POSIXFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of POSIXFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of POSIXFilesytemFactory. - */ - static POSIXFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +21,7 @@ protected: POSIXFilesystemFactory() {}; private: - static POSIXFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*POSIX_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/ps2/ps2-fs-factory.cpp b/backends/fs/ps2/ps2-fs-factory.cpp index 726eb87c6fc..5f109745018 100644 --- a/backends/fs/ps2/ps2-fs-factory.cpp +++ b/backends/fs/ps2/ps2-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/ps2/ps2-fs-factory.h" #include "backends/fs/ps2/ps2-fs.cpp" -Ps2FilesystemFactory *Ps2FilesystemFactory::_instance = 0; - -Ps2FilesystemFactory *Ps2FilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new Ps2FilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(Ps2FilesystemFactory); AbstractFilesystemNode *Ps2FilesystemFactory::makeRootFileNode() const { return new Ps2FilesystemNode(); diff --git a/backends/fs/ps2/ps2-fs-factory.h b/backends/fs/ps2/ps2-fs-factory.h index de7ada6ba38..2dceb5a6dc1 100644 --- a/backends/fs/ps2/ps2-fs-factory.h +++ b/backends/fs/ps2/ps2-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class Ps2FilesystemFactory : public AbstractFilesystemFactory { +class Ps2FilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of Ps2FilesystemFactory using the Singleton pattern. - * - * @return A unique instance of Ps2FilesytemFactory. - */ - static Ps2FilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: Ps2FilesystemFactory() {}; private: - static Ps2FilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*PS2_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/psp/psp-fs-factory.cpp b/backends/fs/psp/psp-fs-factory.cpp index 2a0307d3f40..6fc829baf14 100644 --- a/backends/fs/psp/psp-fs-factory.cpp +++ b/backends/fs/psp/psp-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/psp/psp-fs-factory.h" #include "backends/fs/psp/psp_fs.cpp" -PSPFilesystemFactory *PSPFilesystemFactory::_instance = 0; - -PSPFilesystemFactory *PSPFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new PSPFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(PSPFilesystemFactory); AbstractFilesystemNode *PSPFilesystemFactory::makeRootFileNode() const { return new PSPFilesystemNode(); diff --git a/backends/fs/psp/psp-fs-factory.h b/backends/fs/psp/psp-fs-factory.h index 05388fa6975..e751afbe1a6 100644 --- a/backends/fs/psp/psp-fs-factory.h +++ b/backends/fs/psp/psp-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class PSPFilesystemFactory : public AbstractFilesystemFactory { +class PSPFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of PSPFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of PSPFilesytemFactory. - */ - static PSPFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: PSPFilesystemFactory() {}; private: - static PSPFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*PSP_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/symbian/symbian-fs-factory.cpp b/backends/fs/symbian/symbian-fs-factory.cpp index f3eb5521594..87b1f0f05d2 100644 --- a/backends/fs/symbian/symbian-fs-factory.cpp +++ b/backends/fs/symbian/symbian-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/symbian/symbian-fs-factory.h" #include "backends/fs/symbian/symbian-fs.cpp" -SymbianFilesystemFactory *SymbianFilesystemFactory::_instance = 0; - -SymbianFilesystemFactory *SymbianFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new SymbianFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(SymbianFilesystemFactory); AbstractFilesystemNode *SymbianFilesystemFactory::makeRootFileNode() const { return new SymbianFilesystemNode(true); diff --git a/backends/fs/symbian/symbian-fs-factory.h b/backends/fs/symbian/symbian-fs-factory.h index 4bbac728cb6..4acca7924cd 100644 --- a/backends/fs/symbian/symbian-fs-factory.h +++ b/backends/fs/symbian/symbian-fs-factory.h @@ -8,16 +8,9 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class SymbianFilesystemFactory : public AbstractFilesystemFactory { +class SymbianFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - - /** - * Creates an instance of SymbianFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of SymbianFilesytemFactory. - */ - static SymbianFilesystemFactory *instance(); virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; @@ -27,7 +20,7 @@ protected: SymbianFilesystemFactory() {}; private: - static SymbianFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*SYMBIAN_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/windows/windows-fs-factory.cpp b/backends/fs/windows/windows-fs-factory.cpp index fb77b4ca077..76b62e5deb4 100644 --- a/backends/fs/windows/windows-fs-factory.cpp +++ b/backends/fs/windows/windows-fs-factory.cpp @@ -1,14 +1,7 @@ #include "backends/fs/windows/windows-fs-factory.h" #include "backends/fs/windows/windows-fs.cpp" -WindowsFilesystemFactory *WindowsFilesystemFactory::_instance = 0; - -WindowsFilesystemFactory *WindowsFilesystemFactory::instance(){ - if(_instance == 0){ - _instance = new WindowsFilesystemFactory(); - } - return _instance; -} +DECLARE_SINGLETON(WindowsFilesystemFactory); AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const { return new WindowsFilesystemNode(); diff --git a/backends/fs/windows/windows-fs-factory.h b/backends/fs/windows/windows-fs-factory.h index a7abf390aea..b260eab65ad 100644 --- a/backends/fs/windows/windows-fs-factory.h +++ b/backends/fs/windows/windows-fs-factory.h @@ -8,17 +8,10 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. */ -class WindowsFilesystemFactory : public AbstractFilesystemFactory { +class WindowsFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { public: typedef Common::String String; - /** - * Creates an instance of WindowsFilesystemFactory using the Singleton pattern. - * - * @return A unique instance of WindowsFilesytemFactory. - */ - static WindowsFilesystemFactory *instance(); - virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; @@ -27,7 +20,7 @@ protected: WindowsFilesystemFactory() {}; private: - static WindowsFilesystemFactory *_instance; + friend class Common::Singleton; }; #endif /*WINDOWS_FILESYSTEM_FACTORY_H*/ diff --git a/common/fs.cpp b/common/fs.cpp index 07fafa9aa80..e9c673abb24 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -20,9 +20,8 @@ */ #include "common/stdafx.h" - -#include "backends/fs/abstract-fs.h" #include "common/util.h" +#include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory-maker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { From 6c69d531d262e14fa02b6e1adb42baaa5c74dbe6 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 31 May 2007 21:42:01 +0000 Subject: [PATCH 04/26] Removed the now obsolete singleton declaration macro from the FSNode factories. svn-id: r27031 --- backends/fs/amigaos4/amigaos4-fs-factory.cpp | 2 -- backends/fs/dc/ronincd-fs-factory.cpp | 2 -- backends/fs/ds/ds-fs-factory.cpp | 2 -- backends/fs/gp32/gp32-fs-factory.cpp | 2 -- backends/fs/morphos/abox-fs-factory.cpp | 2 -- backends/fs/palmos/palmos-fs-factory.cpp | 2 -- backends/fs/ps2/ps2-fs-factory.cpp | 2 -- backends/fs/psp/psp-fs-factory.cpp | 2 -- backends/fs/symbian/symbian-fs-factory.cpp | 2 -- backends/fs/windows/windows-fs-factory.cpp | 2 -- 10 files changed, 20 deletions(-) diff --git a/backends/fs/amigaos4/amigaos4-fs-factory.cpp b/backends/fs/amigaos4/amigaos4-fs-factory.cpp index becbd490038..9fe081e7e5c 100644 --- a/backends/fs/amigaos4/amigaos4-fs-factory.cpp +++ b/backends/fs/amigaos4/amigaos4-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/amigaos4/amigaos4-fs-factory.h" #include "backends/fs/amigaos4/amigaos4-fs.cpp" -DECLARE_SINGLETON(AmigaOSFilesystemFactory); - AbstractFilesystemNode *AmigaOSFilesystemFactory::makeRootFileNode() const { return new AmigaOSFilesystemNode(); } diff --git a/backends/fs/dc/ronincd-fs-factory.cpp b/backends/fs/dc/ronincd-fs-factory.cpp index 0229a44c453..43fbdd1e390 100644 --- a/backends/fs/dc/ronincd-fs-factory.cpp +++ b/backends/fs/dc/ronincd-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/dc/ronincd-fs-factory.h" #include "backends/fs/dc/dc-fs.cpp" -DECLARE_SINGLETON(RoninCDFilesystemFactory); - AbstractFilesystemNode *RoninCDFilesystemFactory::makeRootFileNode() const { return new RoninCDFilesystemNode(); } diff --git a/backends/fs/ds/ds-fs-factory.cpp b/backends/fs/ds/ds-fs-factory.cpp index 7e64b374115..830d4d2359a 100644 --- a/backends/fs/ds/ds-fs-factory.cpp +++ b/backends/fs/ds/ds-fs-factory.cpp @@ -2,8 +2,6 @@ #include "backends/fs/ds/ds-fs.cpp" #include "dsmain.h" //for the isGBAMPAvailable() function -DECLARE_SINGLETON(DSFilesystemFactory); - AbstractFilesystemNode *DSFilesystemFactory::makeRootFileNode() const { if (DS::isGBAMPAvailable()) { return new DS::GBAMPFileSystemNode(); diff --git a/backends/fs/gp32/gp32-fs-factory.cpp b/backends/fs/gp32/gp32-fs-factory.cpp index 6328836c0e0..6c8e940ce14 100644 --- a/backends/fs/gp32/gp32-fs-factory.cpp +++ b/backends/fs/gp32/gp32-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/gp32/gp32-fs-factory.h" #include "backends/fs/gp32/gp32-fs.cpp" -DECLARE_SINGLETON(GP32FilesystemFactory); - AbstractFilesystemNode *GP32FilesystemFactory::makeRootFileNode() const { return new GP32FilesystemNode(); } diff --git a/backends/fs/morphos/abox-fs-factory.cpp b/backends/fs/morphos/abox-fs-factory.cpp index 9de810c3619..cfa165a8616 100644 --- a/backends/fs/morphos/abox-fs-factory.cpp +++ b/backends/fs/morphos/abox-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/morphos/abox-fs-factory.h" #include "backends/fs/morphos/abox-fs.cpp" -DECLARE_SINGLETON(ABoxFilesystemFactory); - AbstractFilesystemNode *ABoxFilesystemFactory::makeRootFileNode() const { return new ABoxFilesystemNode(); } diff --git a/backends/fs/palmos/palmos-fs-factory.cpp b/backends/fs/palmos/palmos-fs-factory.cpp index 1b0db0f0420..c54f2dd6559 100644 --- a/backends/fs/palmos/palmos-fs-factory.cpp +++ b/backends/fs/palmos/palmos-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/palmos/palmos-fs-factory.h" #include "backends/fs/palmos/palmos-fs.cpp" -DECLARE_SINGLETON(PalmOSFilesystemFactory); - AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const { return new PalmOSFilesystemNode(); } diff --git a/backends/fs/ps2/ps2-fs-factory.cpp b/backends/fs/ps2/ps2-fs-factory.cpp index 5f109745018..8278d103afb 100644 --- a/backends/fs/ps2/ps2-fs-factory.cpp +++ b/backends/fs/ps2/ps2-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/ps2/ps2-fs-factory.h" #include "backends/fs/ps2/ps2-fs.cpp" -DECLARE_SINGLETON(Ps2FilesystemFactory); - AbstractFilesystemNode *Ps2FilesystemFactory::makeRootFileNode() const { return new Ps2FilesystemNode(); } diff --git a/backends/fs/psp/psp-fs-factory.cpp b/backends/fs/psp/psp-fs-factory.cpp index 6fc829baf14..58b0877f8fb 100644 --- a/backends/fs/psp/psp-fs-factory.cpp +++ b/backends/fs/psp/psp-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/psp/psp-fs-factory.h" #include "backends/fs/psp/psp_fs.cpp" -DECLARE_SINGLETON(PSPFilesystemFactory); - AbstractFilesystemNode *PSPFilesystemFactory::makeRootFileNode() const { return new PSPFilesystemNode(); } diff --git a/backends/fs/symbian/symbian-fs-factory.cpp b/backends/fs/symbian/symbian-fs-factory.cpp index 87b1f0f05d2..b715d0e3ad9 100644 --- a/backends/fs/symbian/symbian-fs-factory.cpp +++ b/backends/fs/symbian/symbian-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/symbian/symbian-fs-factory.h" #include "backends/fs/symbian/symbian-fs.cpp" -DECLARE_SINGLETON(SymbianFilesystemFactory); - AbstractFilesystemNode *SymbianFilesystemFactory::makeRootFileNode() const { return new SymbianFilesystemNode(true); } diff --git a/backends/fs/windows/windows-fs-factory.cpp b/backends/fs/windows/windows-fs-factory.cpp index 76b62e5deb4..60252642097 100644 --- a/backends/fs/windows/windows-fs-factory.cpp +++ b/backends/fs/windows/windows-fs-factory.cpp @@ -1,8 +1,6 @@ #include "backends/fs/windows/windows-fs-factory.h" #include "backends/fs/windows/windows-fs.cpp" -DECLARE_SINGLETON(WindowsFilesystemFactory); - AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const { return new WindowsFilesystemNode(); } From 3e7c5b027e2131cde30d994ccdb27c77f0118ffe Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 4 Jun 2007 03:46:56 +0000 Subject: [PATCH 05/26] Added a missing include in non-POSIX factories. For the POSIX and Windows architectures, added exists(), isReadable() and isWritable() svn-id: r27073 --- backends/fs/abstract-fs.h | 22 ++++++++++++++++------ backends/fs/amigaos4/amigaos4-fs-factory.h | 1 + backends/fs/dc/ronincd-fs-factory.h | 1 + backends/fs/ds/ds-fs-factory.h | 1 + backends/fs/gp32/gp32-fs-factory.h | 1 + backends/fs/morphos/abox-fs-factory.h | 1 + backends/fs/palmos/palmos-fs-factory.h | 1 + backends/fs/posix/posix-fs.cpp | 8 +++++--- backends/fs/ps2/ps2-fs-factory.h | 1 + backends/fs/psp/psp-fs-factory.h | 1 + backends/fs/symbian/symbian-fs-factory.h | 1 + backends/fs/windows/windows-fs-factory.h | 1 + backends/fs/windows/windows-fs.cpp | 13 ++++++++++--- 13 files changed, 41 insertions(+), 12 deletions(-) diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 19d8aaa37d7..aaae65eed35 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -78,12 +78,18 @@ public: */ virtual ~AbstractFilesystemNode() {} + /* + * Indicates whether 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. + * * @return true if succesful, false otherwise (e.g. when the directory does not exist). */ virtual bool getChildren(AbstractFSList &list, ListMode mode) const = 0; @@ -110,19 +116,23 @@ public: */ virtual bool isDirectory() const = 0; + /** + * Indicates whether this path can be read from or not. + */ + virtual bool isReadable() const = 0; + + /** + * Indicates whether this path can be written to or not. + */ + virtual bool isWritable() const = 0; + /** * Indicates whether this path is valid or not for usage. */ virtual bool isValid() const = 0; /* TODO: - bool exists(); - - bool isDirectory(); bool isFile(); - - bool isReadable(); - bool isWritable(); */ }; diff --git a/backends/fs/amigaos4/amigaos4-fs-factory.h b/backends/fs/amigaos4/amigaos4-fs-factory.h index 861f28b7947..ed8af246483 100644 --- a/backends/fs/amigaos4/amigaos4-fs-factory.h +++ b/backends/fs/amigaos4/amigaos4-fs-factory.h @@ -1,6 +1,7 @@ #ifndef AMIGAOS_FILESYSTEM_FACTORY_H #define AMIGAOS_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/dc/ronincd-fs-factory.h b/backends/fs/dc/ronincd-fs-factory.h index 12590e8fa41..426ef7ef2c0 100644 --- a/backends/fs/dc/ronincd-fs-factory.h +++ b/backends/fs/dc/ronincd-fs-factory.h @@ -1,6 +1,7 @@ #ifndef RONINCD_FILESYSTEM_FACTORY_H #define RONINCD_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/ds/ds-fs-factory.h b/backends/fs/ds/ds-fs-factory.h index 5bc847a7b21..a2e96aa548a 100644 --- a/backends/fs/ds/ds-fs-factory.h +++ b/backends/fs/ds/ds-fs-factory.h @@ -1,6 +1,7 @@ #ifndef DS_FILESYSTEM_FACTORY_H #define DS_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/gp32/gp32-fs-factory.h b/backends/fs/gp32/gp32-fs-factory.h index 22c502d69fa..fc15b52bc6b 100644 --- a/backends/fs/gp32/gp32-fs-factory.h +++ b/backends/fs/gp32/gp32-fs-factory.h @@ -1,6 +1,7 @@ #ifndef GP32_FILESYSTEM_FACTORY_H #define GP32_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/morphos/abox-fs-factory.h b/backends/fs/morphos/abox-fs-factory.h index b0d1dfb3409..35f4472b8b3 100644 --- a/backends/fs/morphos/abox-fs-factory.h +++ b/backends/fs/morphos/abox-fs-factory.h @@ -1,6 +1,7 @@ #ifndef ABOX_FILESYSTEM_FACTORY_H #define ABOX_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/palmos/palmos-fs-factory.h b/backends/fs/palmos/palmos-fs-factory.h index 4bb94ab4c17..cfe246e8068 100644 --- a/backends/fs/palmos/palmos-fs-factory.h +++ b/backends/fs/palmos/palmos-fs-factory.h @@ -1,6 +1,7 @@ #ifndef PALMOS_FILESYSTEM_FACTORY_H #define PALMOS_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 966bfe34e63..712a8ce68de 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -62,10 +62,13 @@ public: */ 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 bool isValid() const { return _isValid; } virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -102,8 +105,9 @@ static const char *lastPathComponent(const Common::String &str) { void POSIXFilesystemNode::setFlags() { struct stat st; + _isValid = (0 == stat(_path.c_str(), &st)); - _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; + _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; } POSIXFilesystemNode::POSIXFilesystemNode() { @@ -140,8 +144,6 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) { _path = p; _displayName = lastPathComponent(_path); - _isValid = true; - _isDirectory = true; if (verify) { setFlags(); diff --git a/backends/fs/ps2/ps2-fs-factory.h b/backends/fs/ps2/ps2-fs-factory.h index 2dceb5a6dc1..6f0da114c57 100644 --- a/backends/fs/ps2/ps2-fs-factory.h +++ b/backends/fs/ps2/ps2-fs-factory.h @@ -1,6 +1,7 @@ #ifndef PS2_FILESYSTEM_FACTORY_H #define PS2_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/psp/psp-fs-factory.h b/backends/fs/psp/psp-fs-factory.h index e751afbe1a6..b1a44b90c4e 100644 --- a/backends/fs/psp/psp-fs-factory.h +++ b/backends/fs/psp/psp-fs-factory.h @@ -1,6 +1,7 @@ #ifndef PSP_FILESYSTEM_FACTORY_H #define PSP_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/symbian/symbian-fs-factory.h b/backends/fs/symbian/symbian-fs-factory.h index 4acca7924cd..69749cbd7ec 100644 --- a/backends/fs/symbian/symbian-fs-factory.h +++ b/backends/fs/symbian/symbian-fs-factory.h @@ -1,6 +1,7 @@ #ifndef SYMBIAN_FILESYSTEM_FACTORY_H #define SYMBIAN_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/windows/windows-fs-factory.h b/backends/fs/windows/windows-fs-factory.h index b260eab65ad..7d17802b522 100644 --- a/backends/fs/windows/windows-fs-factory.h +++ b/backends/fs/windows/windows-fs-factory.h @@ -1,6 +1,7 @@ #ifndef WINDOWS_FILESYSTEM_FACTORY_H #define WINDOWS_FILESYSTEM_FACTORY_H +#include "common/singleton.h" #include "backends/fs/abstract-fs-factory.h" /** diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp index 88d04e1643c..9cd6aa40a03 100644 --- a/backends/fs/windows/windows-fs.cpp +++ b/backends/fs/windows/windows-fs.cpp @@ -29,6 +29,7 @@ #endif #include "common/stdafx.h" #include "backends/fs/abstract-fs.h" +#include #include #include #ifndef _WIN32_WCE @@ -70,11 +71,14 @@ public: * @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 bool isValid() const { return _isValid; } virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -217,11 +221,11 @@ WindowsFilesystemNode::WindowsFilesystemNode(const String &p, const bool current DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str())); if (fileAttribs == INVALID_FILE_ATTRIBUTES) { - _isValid = false; _isDirectory = false; + _isValid = false; } else { - _isValid = true; _isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0); + _isValid = true; } _isPseudoRoot = false; } @@ -276,9 +280,12 @@ bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) c 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); From fedfe66831ebed2822fe74c86ed59b6d69326f3d Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 4 Jun 2007 22:02:35 +0000 Subject: [PATCH 06/26] Added stubs for the exists(), isReadable() and isWritable() methods for all architectures. svn-id: r27087 --- backends/fs/abstract-fs.h | 10 +++++----- backends/fs/amigaos4/amigaos4-fs.cpp | 5 ++++- backends/fs/dc/dc-fs.cpp | 3 +++ backends/fs/ds/ds-fs.h | 3 +++ backends/fs/gp32/gp32-fs.cpp | 2 ++ backends/fs/morphos/abox-fs.cpp | 3 +++ backends/fs/palmos/palmos-fs.cpp | 3 +++ backends/fs/posix/posix-fs.cpp | 2 +- backends/fs/ps2/ps2-fs.cpp | 3 +++ backends/fs/psp/psp_fs.cpp | 3 +++ backends/fs/symbian/symbian-fs.cpp | 3 +++ backends/fs/windows/windows-fs.cpp | 2 +- 12 files changed, 34 insertions(+), 8 deletions(-) diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index aaae65eed35..519337a486d 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -121,15 +121,15 @@ public: */ virtual bool isReadable() const = 0; - /** - * Indicates whether this path can be written to or not. - */ - virtual bool isWritable() const = 0; - /** * Indicates whether this path is valid or not for usage. */ virtual bool isValid() const = 0; + + /** + * Indicates whether this path can be written to or not. + */ + virtual bool isWritable() const = 0; /* TODO: bool isFile(); diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp index d28604ab18d..88af467ae5a 100644 --- a/backends/fs/amigaos4/amigaos4-fs.cpp +++ b/backends/fs/amigaos4/amigaos4-fs.cpp @@ -89,11 +89,14 @@ public: */ virtual ~AmigaOSFilesystemNode(); + virtual bool exists() const { return true; } //FIXME: this is just a stub virtual String getDisplayName() const { return _sDisplayName; }; virtual String getName() const { return _sDisplayName; }; virtual String getPath() const { return _sPath; }; - virtual bool isValid() const { return _bIsValid; }; virtual bool isDirectory() const { return _bIsDirectory; }; + virtual bool isReadable() const { return true; } //FIXME: this is just a stub + virtual bool isValid() const { return _bIsValid; }; + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index 1b2d123c24d..070c9b075bc 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -57,11 +57,14 @@ public: */ RoninCDFilesystemNode(const String &path, bool verify); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index eeee18f322a..e3014d0d2e7 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -77,11 +77,14 @@ public: */ DSFileSystemNode(const DSFileSystemNode *node); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub /** * Returns a copy of this node. diff --git a/backends/fs/gp32/gp32-fs.cpp b/backends/fs/gp32/gp32-fs.cpp index ad92365a838..92968b5976b 100644 --- a/backends/fs/gp32/gp32-fs.cpp +++ b/backends/fs/gp32/gp32-fs.cpp @@ -59,7 +59,9 @@ public: virtual bool isDirectory() const { return _isDirectory; } // FIXME: isValid should return false if this Node can't be used! // so client code can rely on the return value. + virtual bool isReadable() const { return true; } //FIXME: this is just a stub virtual bool isValid() const { return true; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp index 24803544148..8f46f9a9a88 100644 --- a/backends/fs/morphos/abox-fs.cpp +++ b/backends/fs/morphos/abox-fs.cpp @@ -76,11 +76,14 @@ public: */ ~ABoxFilesystemNode(); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &name) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index 7abc28bf331..eae35811961 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -56,11 +56,14 @@ public: */ PalmOSFilesystemNode(const String &p); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 712a8ce68de..2e222f34f80 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -68,8 +68,8 @@ public: 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 bool isValid() const { return _isValid; } + 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) const; diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp index 237f8a9efeb..9d8e360f649 100644 --- a/backends/fs/ps2/ps2-fs.cpp +++ b/backends/fs/ps2/ps2-fs.cpp @@ -62,11 +62,14 @@ public: */ Ps2FilesystemNode(const Ps2FilesystemNode *node); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return !_isRoot; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); } virtual AbstractFilesystemNode *getChild(const String &n) const; diff --git a/backends/fs/psp/psp_fs.cpp b/backends/fs/psp/psp_fs.cpp index 079df64dcb7..5b0faf38474 100644 --- a/backends/fs/psp/psp_fs.cpp +++ b/backends/fs/psp/psp_fs.cpp @@ -58,11 +58,14 @@ public: */ PSPFilesystemNode(const Common::String &p, bool verify); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp index a235933947b..5c3dd74f5c6 100644 --- a/backends/fs/symbian/symbian-fs.cpp +++ b/backends/fs/symbian/symbian-fs.cpp @@ -59,11 +59,14 @@ public: */ SymbianFilesystemNode(const String &path); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode) const; diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp index 9cd6aa40a03..5a9e1c65b68 100644 --- a/backends/fs/windows/windows-fs.cpp +++ b/backends/fs/windows/windows-fs.cpp @@ -78,8 +78,8 @@ public: 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 bool isValid() const { return _isValid; } + 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) const; From 716bcd0b2bcd4d04489bc2fc23a948fad3e2c02a Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 4 Jun 2007 22:16:17 +0000 Subject: [PATCH 07/26] Expose new fs backend methods in the FilesystemNode class. svn-id: r27089 --- common/fs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/fs.h b/common/fs.h index 5e441a212f6..c78980a813c 100644 --- a/common/fs.h +++ b/common/fs.h @@ -127,6 +127,11 @@ public: */ virtual Common::String displayName() const; + /* + * Indicates whether the object refered by this path exists in the filesystem or not. + */ + virtual bool exists() const; + /** * Return a string representation of the name of the file. This is can be * used e.g. by detection code that relies on matching the name of a given @@ -183,10 +188,20 @@ public: */ virtual bool isDirectory() const; + /** + * Indicates whether this path can be read from or not. + */ + virtual bool isReadable() const; + /** * Indicates whether this path is valid or not for usage. */ bool isValid() const; + + /** + * Indicates whether this path can be written to or not. + */ + virtual bool isWritable() const; protected: /** From 3b96c7fad54ff7f5000667be494e50e7ca11e69a Mon Sep 17 00:00:00 2001 From: David Corrales Date: Tue, 5 Jun 2007 21:02:35 +0000 Subject: [PATCH 08/26] Renamed methods in the FilesystemNode class to match the AbstractFSNode implementations. Also exposed the new methods (exists, isReadable and isWritable) in FilesystemNode. svn-id: r27113 --- backends/fs/abstract-fs.h | 2 +- backends/plugins/dc/dc-provider.cpp | 6 +- backends/plugins/posix/posix-provider.cpp | 6 +- backends/plugins/sdl/sdl-provider.cpp | 6 +- backends/plugins/win32/win32-provider.cpp | 6 +- base/commandLine.cpp | 2 +- common/advancedDetector.cpp | 6 +- common/file.cpp | 14 +-- common/fs.cpp | 118 +++++++++++++--------- common/fs.h | 64 ++++++------ common/md5.cpp | 2 +- engines/agi/agi_v3.cpp | 6 +- engines/agi/detection.cpp | 2 +- engines/kyra/resource.cpp | 10 +- engines/queen/queen.cpp | 2 +- engines/scumm/detection.cpp | 10 +- engines/sky/sky.cpp | 6 +- engines/sword1/sword1.cpp | 6 +- engines/sword2/sword2.cpp | 8 +- gui/browser.cpp | 10 +- gui/launcher.cpp | 16 +-- gui/massadd.cpp | 6 +- gui/options.cpp | 10 +- gui/themebrowser.cpp | 6 +- 24 files changed, 174 insertions(+), 156 deletions(-) diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 519337a486d..bb7669739f1 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -79,7 +79,7 @@ public: virtual ~AbstractFilesystemNode() {} /* - * Indicates whether this path exists in the filesystem or not. + * Indicates whether the object refered by this path exists in the filesystem or not. */ virtual bool exists() const = 0; diff --git a/backends/plugins/dc/dc-provider.cpp b/backends/plugins/dc/dc-provider.cpp index 166852655b7..db0242f7d80 100644 --- a/backends/plugins/dc/dc-provider.cpp +++ b/backends/plugins/dc/dc-provider.cpp @@ -114,14 +114,14 @@ PluginList DCPluginProvider::getPlugins() { // Scan for all plugins in this directory FilesystemNode dir(PLUGIN_DIRECTORY); FSList files; - if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); } for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { - Common::String name(i->name()); + Common::String name(i->getName()); if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { - pl.push_back(new DCPlugin(i->path())); + pl.push_back(new DCPlugin(i->getPath())); } } diff --git a/backends/plugins/posix/posix-provider.cpp b/backends/plugins/posix/posix-provider.cpp index ce319840a44..03ee1c204f8 100644 --- a/backends/plugins/posix/posix-provider.cpp +++ b/backends/plugins/posix/posix-provider.cpp @@ -107,14 +107,14 @@ PluginList POSIXPluginProvider::getPlugins() { // Scan for all plugins in this directory FilesystemNode dir(PLUGIN_DIRECTORY); FSList files; - if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); } for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { - Common::String name(i->name()); + Common::String name(i->getName()); if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { - pl.push_back(new POSIXPlugin(i->path())); + pl.push_back(new POSIXPlugin(i->getPath())); } } diff --git a/backends/plugins/sdl/sdl-provider.cpp b/backends/plugins/sdl/sdl-provider.cpp index 0f67c9a691c..cb09af20ca8 100644 --- a/backends/plugins/sdl/sdl-provider.cpp +++ b/backends/plugins/sdl/sdl-provider.cpp @@ -107,14 +107,14 @@ PluginList SDLPluginProvider::getPlugins() { // Scan for all plugins in this directory FilesystemNode dir(PLUGIN_DIRECTORY); FSList files; - if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); } for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { - Common::String name(i->name()); + Common::String name(i->getName()); if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { - pl.push_back(new SDLPlugin(i->path())); + pl.push_back(new SDLPlugin(i->getPath())); } } diff --git a/backends/plugins/win32/win32-provider.cpp b/backends/plugins/win32/win32-provider.cpp index eeea3b805c6..b340c23709d 100644 --- a/backends/plugins/win32/win32-provider.cpp +++ b/backends/plugins/win32/win32-provider.cpp @@ -110,14 +110,14 @@ PluginList Win32PluginProvider::getPlugins() { // Scan for all plugins in this directory FilesystemNode dir(PLUGIN_DIRECTORY); FSList files; - if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); } for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { - Common::String name(i->name()); + Common::String name(i->getName()); if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { - pl.push_back(new Win32Plugin(i->path())); + pl.push_back(new Win32Plugin(i->getPath())); } } diff --git a/base/commandLine.cpp b/base/commandLine.cpp index b273e50f811..3d826e2fa09 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -562,7 +562,7 @@ static void runDetectorTest() { FilesystemNode dir(path); FSList files; - if (!dir.listDir(files, FilesystemNode::kListAll)) { + if (!dir.getChildren(files, FilesystemNode::kListAll)) { printf(" ... invalid path, skipping\n"); continue; } diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 24e884a1640..d6b622451af 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -227,7 +227,7 @@ PluginError detectGameForEngineCreation( FSList fslist; FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { return kInvalidPathError; } @@ -285,7 +285,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p // Get the information of the existing files for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { if (file->isDirectory()) continue; - tstr = file->name(); + tstr = file->getName(); tstr.toLowercase(); // Strip any trailing dot @@ -304,7 +304,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p debug(3, "> %s: %s", tstr.c_str(), md5str); - if (testFile.open(file->path())) { + if (testFile.open(file->getPath())) { filesSize[tstr] = (int32)testFile.size(); testFile.close(); } diff --git a/common/file.cpp b/common/file.cpp index 2eba1bcb3de..c04c579535f 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -226,7 +226,7 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, co return; FSList fslist; - if (!dir.listDir(fslist, FilesystemNode::kListAll)) { + if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { // Failed listing the contents of this node, so it is either not a // directory, or just doesn't exist at all. return; @@ -237,7 +237,7 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, co // Do not add directories multiple times, unless this time they are added // with a bigger depth. - const String &directory(dir.path()); + const String &directory(dir.getPath()); if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level) return; (*_defaultDirectories)[directory] = level; @@ -247,13 +247,13 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, co for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { if (file->isDirectory()) { - addDefaultDirectoryRecursive(file->path(), level - 1, prefix + file->name() + "/"); + addDefaultDirectoryRecursive(file->getPath(), level - 1, prefix + file->getName() + "/"); } else { String lfn(prefix); - lfn += file->name(); + lfn += file->getName(); lfn.toLowercase(); if (!_filesMap->contains(lfn)) { - (*_filesMap)[lfn] = file->path(); + (*_filesMap)[lfn] = file->getPath(); } } } @@ -372,7 +372,7 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { return false; } - String filename(node.name()); + String filename(node.getName()); if (_handle) { error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); @@ -383,7 +383,7 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb"; - _handle = fopen(node.path().c_str(), modeStr); + _handle = fopen(node.getPath().c_str(), modeStr); if (_handle == NULL) { if (mode == kFileReadMode) diff --git a/common/fs.cpp b/common/fs.cpp index ef106c24886..fdc485a06fe 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -27,16 +27,16 @@ #include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory-maker.cpp" -FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { - _realNode = realNode; - _refCount = new int(1); -} - FilesystemNode::FilesystemNode() { _realNode = 0; _refCount = 0; } +FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { + _realNode = realNode; + _refCount = new int(1); +} + FilesystemNode::FilesystemNode(const FilesystemNode &node) { _realNode = node._realNode; _refCount = node._refCount; @@ -58,17 +58,6 @@ FilesystemNode::~FilesystemNode() { decRefCount(); } -void FilesystemNode::decRefCount() { - if (_refCount) { - assert(*_refCount > 0); - --(*_refCount); - if (*_refCount == 0) { - delete _refCount; - delete _realNode; - } - } -} - FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { if (node._refCount) ++(*node._refCount); @@ -81,24 +70,32 @@ FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { return *this; } -bool FilesystemNode::isValid() const { - if (_realNode == 0) +bool FilesystemNode::operator< (const FilesystemNode& node) const +{ + if (isDirectory() && !node.isDirectory()) + return true; + if (!isDirectory() && node.isDirectory()) return false; - return _realNode->isValid(); + return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0; } -FilesystemNode FilesystemNode::getParent() const { - if (_realNode == 0) - return *this; - - AbstractFilesystemNode *node = _realNode->getParent(); - if (node == 0) { - return *this; - } else { - return FilesystemNode(node); +void FilesystemNode::decRefCount() { + if (_refCount) { + assert(*_refCount > 0); + --(*_refCount); + if (*_refCount == 0) { + delete _refCount; + delete _realNode; + } } } +bool FilesystemNode::exists() const { + if (_realNode == 0) + return false; + return _realNode->exists(); +} + FilesystemNode FilesystemNode::getChild(const Common::String &n) const { if (_realNode == 0) return *this; @@ -108,7 +105,7 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return FilesystemNode(node); } -bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { +bool FilesystemNode::getChildren(FSList &fslist, ListMode mode) const { if (!_realNode || !_realNode->isDirectory()) return false; @@ -125,32 +122,53 @@ bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { return true; } +Common::String FilesystemNode::getDisplayName() const { + assert(_realNode); + return _realNode->getDisplayName(); +} + +Common::String FilesystemNode::getName() const { + assert(_realNode); + return _realNode->getName(); +} + +FilesystemNode FilesystemNode::getParent() const { + if (_realNode == 0) + return *this; + + AbstractFilesystemNode *node = _realNode->getParent(); + if (node == 0) { + return *this; + } else { + return FilesystemNode(node); + } +} + +Common::String FilesystemNode::getPath() const { + assert(_realNode); + return _realNode->getPath(); +} + bool FilesystemNode::isDirectory() const { if (_realNode == 0) return false; return _realNode->isDirectory(); } -Common::String FilesystemNode::displayName() const { - assert(_realNode); - return _realNode->getDisplayName(); -} - -Common::String FilesystemNode::name() const { - assert(_realNode); - return _realNode->getName(); -} - -Common::String FilesystemNode::path() const { - assert(_realNode); - return _realNode->getPath(); -} - -bool FilesystemNode::operator< (const FilesystemNode& node) const -{ - if (isDirectory() && !node.isDirectory()) - return true; - if (!isDirectory() && node.isDirectory()) +bool FilesystemNode::isReadable() const { + if (_realNode == 0) return false; - return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0; + return _realNode->isReadable(); +} + +bool FilesystemNode::isValid() const { + if (_realNode == 0) + return false; + return _realNode->isValid(); +} + +bool FilesystemNode::isWritable() const { + if (_realNode == 0) + return false; + return _realNode->isWritable(); } diff --git a/common/fs.h b/common/fs.h index c78980a813c..6b0a587e1b8 100644 --- a/common/fs.h +++ b/common/fs.h @@ -119,42 +119,11 @@ public: */ bool operator< (const FilesystemNode& node) const; - /** - * 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 Common::String displayName() const; - /* * Indicates whether the object refered by this path exists in the filesystem or not. */ virtual bool exists() const; - /** - * Return a string representation of the name of the file. This is can be - * used e.g. by detection code that relies on matching the name of a given - * file. But it is *not* suitable for use with fopen / File::open, nor - * should it be archived. - * - * @return the file name - */ - virtual Common::String name() const; - - /** - * 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 fulfills the above criterions. - * - * @note Do not assume that this string contains (back)slashes or any - * other kind of 'path separators'. - * - * @return the 'path' represented by this filesystem node - */ - virtual Common::String path() const; - /** * Fetch a child node of this node, with the given name. Only valid for * directory nodes (an assertion is triggered otherwise). @@ -169,7 +138,38 @@ public: * @return true if succesful, false otherwise (e.g. when the directory does not exist). * @todo Rename this to listChildren or getChildren. */ - virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + + /** + * 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 Common::String getDisplayName() const; + + /** + * Return a string representation of the name of the file. This is can be + * used e.g. by detection code that relies on matching the name of a given + * file. But it is *not* suitable for use with fopen / File::open, nor + * should it be archived. + * + * @return the file name + */ + virtual Common::String getName() const; + + /** + * 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 fulfills the above criterions. + * + * @note Do not assume that this string contains (back)slashes or any + * other kind of 'path separators'. + * + * @return the 'path' represented by this filesystem node + */ + virtual Common::String getPath() const; /** * Get the parent node of this node. If this node has no parent node, diff --git a/common/md5.cpp b/common/md5.cpp index a48ecb49486..35fbe0b9ab2 100644 --- a/common/md5.cpp +++ b/common/md5.cpp @@ -254,7 +254,7 @@ bool md5_file(const FilesystemNode &file, uint8 digest[16], uint32 length) { return false; } - return md5_file(file.path().c_str(), digest, length); + return md5_file(file.getPath().c_str(), digest, length); } bool md5_file(const char *name, uint8 digest[16], uint32 length) { diff --git a/engines/agi/agi_v3.cpp b/engines/agi/agi_v3.cpp index 3e90dc11f18..33f670e7799 100644 --- a/engines/agi/agi_v3.cpp +++ b/engines/agi/agi_v3.cpp @@ -52,14 +52,14 @@ int AgiLoader_v3::detectGame() { FSList fslist; FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { - warning("AgiEngine: invalid game path '%s'", dir.path().c_str()); + if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { + warning("AgiEngine: invalid game path '%s'", dir.getPath().c_str()); return errInvalidAGIFile; } for (FSList::const_iterator file = fslist.begin(); file != fslist.end() && !found; ++file) { - Common::String f = file->name(); + Common::String f = file->getName(); f.toLowercase(); if (f.hasSuffix("vol.0")) { diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index 9f6f0e71569..b7f8c127304 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -1885,7 +1885,7 @@ Common::ADGameDescList fallbackDetector(const FSList *fslist) { // First grab all filenames for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { if (file->isDirectory()) continue; - tstr = file->name(); + tstr = file->getName(); tstr.toLowercase(); allFiles[tstr] = true; diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp index 7c15cee2f9a..319845c22c1 100644 --- a/engines/kyra/resource.cpp +++ b/engines/kyra/resource.cpp @@ -82,8 +82,8 @@ Resource::Resource(KyraEngine *vm) { FSList fslist; FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) - error("invalid game path '%s'", dir.path().c_str()); + if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) + error("invalid game path '%s'", dir.getPath().c_str()); if (_vm->game() == GI_KYRA1 && _vm->gameFlags().isTalkie) { static const char *list[] = { @@ -96,7 +96,7 @@ Resource::Resource(KyraEngine *vm) { Common::for_each(_pakfiles.begin(), _pakfiles.end(), Common::bind2nd(Common::mem_fun(&ResourceFile::protect), true)); } else { for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { - Common::String filename = file->name(); + Common::String filename = file->getName(); filename.toUppercase(); // No real PAK file! @@ -104,8 +104,8 @@ Resource::Resource(KyraEngine *vm) { continue; if (filename.hasSuffix("PAK") || filename.hasSuffix("APK")) { - if (!loadPakFile(file->name())) - error("couldn't open pakfile '%s'", file->name().c_str()); + if (!loadPakFile(file->getName())) + error("couldn't open pakfile '%s'", file->getName().c_str()); } } diff --git a/engines/queen/queen.cpp b/engines/queen/queen.cpp index bbb186d0aef..c1e909ffdb7 100644 --- a/engines/queen/queen.cpp +++ b/engines/queen/queen.cpp @@ -73,7 +73,7 @@ GameList Engine_QUEEN_detectGames(const FSList &fslist) { if (file->isDirectory()) { continue; } - if (file->name().equalsIgnoreCase("queen.1") || file->name().equalsIgnoreCase("queen.1c")) { + if (file->getName().equalsIgnoreCase("queen.1") || file->getName().equalsIgnoreCase("queen.1c")) { Common::File dataFile; if (!dataFile.open(*file)) { continue; diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp index f60908d3ed5..217b257e5eb 100644 --- a/engines/scumm/detection.cpp +++ b/engines/scumm/detection.cpp @@ -205,7 +205,7 @@ static bool testGame(const GameSettings *g, const DescMap &fileMD5Map, const Com // the first match is used. static bool searchFSNode(const FSList &fslist, const Common::String &name, FilesystemNode &result) { for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { - if (!scumm_stricmp(file->name().c_str(), name.c_str())) { + if (!scumm_stricmp(file->getName().c_str(), name.c_str())) { result = *file; return true; } @@ -231,7 +231,7 @@ static Common::Language detectLanguage(const FSList &fslist, byte id) { FSList tmpList; if (searchFSNode(fslist, "RESOURCE", resDir) && resDir.isDirectory() - && resDir.listDir(tmpList, FilesystemNode::kListFilesOnly) + && resDir.getChildren(tmpList, FilesystemNode::kListFilesOnly) && searchFSNode(tmpList, filename, langFile)) { tmp.open(langFile); } @@ -328,7 +328,7 @@ static void detectGames(const FSList &fslist, Common::List &resu DetectorDesc d; d.node = *file; d.md5Entry = 0; - fileMD5Map[file->name()] = d; + fileMD5Map[file->getName()] = d; } } @@ -455,7 +455,7 @@ static bool testGame(const GameSettings *g, const DescMap &fileMD5Map, const Com Common::File tmp; if (!tmp.open(d.node)) { - warning("SCUMM detectGames: failed to open '%s' for read access", d.node.path().c_str()); + warning("SCUMM detectGames: failed to open '%s' for read access", d.node.getPath().c_str()); return false; } @@ -784,7 +784,7 @@ PluginError Engine_SCUMM_create(OSystem *syst, Engine **engine) { // Fetch the list of files in the current directory FSList fslist; FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { return kInvalidPathError; } diff --git a/engines/sky/sky.cpp b/engines/sky/sky.cpp index 84038990aa5..d8e642d717f 100644 --- a/engines/sky/sky.cpp +++ b/engines/sky/sky.cpp @@ -124,11 +124,11 @@ GameList Engine_SKY_detectGames(const FSList &fslist) { // Iterate over all files in the given directory for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { if (!file->isDirectory()) { - const char *fileName = file->name().c_str(); + const char *fileName = file->getName().c_str(); if (0 == scumm_stricmp("sky.dsk", fileName)) { Common::File dataDisk; - if (dataDisk.open(file->path())) { + if (dataDisk.open(file->getPath())) { hasSkyDsk = true; dataDiskSize = dataDisk.size(); } @@ -136,7 +136,7 @@ GameList Engine_SKY_detectGames(const FSList &fslist) { if (0 == scumm_stricmp("sky.dnr", fileName)) { Common::File dinner; - if (dinner.open(file->path())) { + if (dinner.open(file->getPath())) { hasSkyDnr = true; dinnerTableEntries = dinner.readUint32LE(); } diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index 97e518421c1..db978cd33e7 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -107,15 +107,15 @@ GameDescriptor Engine_SWORD1_findGameID(const char *gameid) { void Sword1CheckDirectory(const FSList &fslist, bool *filesFound) { for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { if (!file->isDirectory()) { - const char *fileName = file->name().c_str(); + const char *fileName = file->getName().c_str(); for (int cnt = 0; cnt < NUM_FILES_TO_CHECK; cnt++) if (scumm_stricmp(fileName, g_filesToCheck[cnt]) == 0) filesFound[cnt] = true; } else { for (int cnt = 0; cnt < ARRAYSIZE(g_dirNames); cnt++) - if (scumm_stricmp(file->name().c_str(), g_dirNames[cnt]) == 0) { + if (scumm_stricmp(file->getName().c_str(), g_dirNames[cnt]) == 0) { FSList fslist2; - if (file->listDir(fslist2, FilesystemNode::kListFilesOnly)) + if (file->getChildren(fslist2, FilesystemNode::kListFilesOnly)) Sword1CheckDirectory(fslist2, filesFound); } } diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 280beb7c228..be240e5956d 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -101,7 +101,7 @@ GameList Engine_SWORD2_detectGames(const FSList &fslist) { // Iterate over all files in the given directory for (file = fslist.begin(); file != fslist.end(); ++file) { if (!file->isDirectory()) { - const char *fileName = file->name().c_str(); + const char *fileName = file->getName().c_str(); if (0 == scumm_stricmp(g->detectname, fileName)) { // Match found, add to list of candidates, then abort inner loop. @@ -118,11 +118,11 @@ GameList Engine_SWORD2_detectGames(const FSList &fslist) { // present e.g. if the user copied the data straight from CD. for (file = fslist.begin(); file != fslist.end(); ++file) { if (file->isDirectory()) { - const char *fileName = file->name().c_str(); + const char *fileName = file->getName().c_str(); if (0 == scumm_stricmp("clusters", fileName)) { FSList recList; - if (file->listDir(recList, FilesystemNode::kListAll)) { + if (file->getChildren(recList, FilesystemNode::kListAll)) { GameList recGames(Engine_SWORD2_detectGames(recList)); if (!recGames.empty()) { detectedGames.push_back(recGames); @@ -144,7 +144,7 @@ PluginError Engine_SWORD2_create(OSystem *syst, Engine **engine) { FSList fslist; FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListAll)) { + if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { return kInvalidPathError; } diff --git a/gui/browser.cpp b/gui/browser.cpp index b9cae7d9231..ebe4aef0c47 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -222,15 +222,15 @@ void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data void BrowserDialog::updateListing() { // Update the path display - _currentPath->setLabel(_node.path()); + _currentPath->setLabel(_node.getPath()); // We memorize the last visited path. - ConfMan.set("browser_lastpath", _node.path()); + ConfMan.set("browser_lastpath", _node.getPath()); // Read in the data from the file system FilesystemNode::ListMode listMode = _isDirBrowser ? FilesystemNode::kListDirectoriesOnly : FilesystemNode::kListAll; - if (!_node.listDir(_nodeContent, listMode)) { + if (!_node.getChildren(_nodeContent, listMode)) { _nodeContent.clear(); } else { Common::sort(_nodeContent.begin(), _nodeContent.end()); @@ -240,9 +240,9 @@ void BrowserDialog::updateListing() { Common::StringList list; for (FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) { if (!_isDirBrowser && i->isDirectory()) - list.push_back(i->displayName() + "/"); + list.push_back(i->getDisplayName() + "/"); else - list.push_back(i->displayName()); + list.push_back(i->getDisplayName()); } _fileList->setList(list); _fileList->scrollTo(0); diff --git a/gui/launcher.cpp b/gui/launcher.cpp index eba5498318c..4a92de1101d 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -405,9 +405,9 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat if (browser.runModal() > 0) { // User made this choice... FilesystemNode file(browser.getResult()); - _soundFont->setLabel(file.path()); + _soundFont->setLabel(file.getPath()); - if (!file.path().empty() && (file.path() != "None")) + if (!file.getPath().empty() && (file.getPath() != "None")) _soundFontClearButton->setEnabled(true); else _soundFontClearButton->setEnabled(false); @@ -428,7 +428,7 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat // done with optional specific gameid to pluginmgr detectgames? // FSList files = dir.listDir(FilesystemNode::kListFilesOnly); - _gamePathWidget->setLabel(dir.path()); + _gamePathWidget->setLabel(dir.getPath()); draw(); } draw(); @@ -441,7 +441,7 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat if (browser.runModal() > 0) { // User made his choice... FilesystemNode dir(browser.getResult()); - _extraPathWidget->setLabel(dir.path()); + _extraPathWidget->setLabel(dir.getPath()); draw(); } draw(); @@ -453,7 +453,7 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat if (browser.runModal() > 0) { // User made his choice... FilesystemNode dir(browser.getResult()); - _savePathWidget->setLabel(dir.path()); + _savePathWidget->setLabel(dir.getPath()); draw(); } draw(); @@ -654,9 +654,9 @@ void LauncherDialog::addGame() { // User made his choice... FilesystemNode dir(_browser->getResult()); FSList files; - if (!dir.listDir(files, FilesystemNode::kListAll)) { + if (!dir.getChildren(files, FilesystemNode::kListAll)) { error("browser returned a node that is not a directory: '%s'", - dir.path().c_str()); + dir.getPath().c_str()); } // ...so let's determine a list of candidates, games that @@ -686,7 +686,7 @@ void LauncherDialog::addGame() { GameDescriptor result = candidates[idx]; // TODO: Change the detectors to set "path" ! - result["path"] = dir.path(); + result["path"] = dir.getPath(); Common::String domain = addGameToConf(result); diff --git a/gui/massadd.cpp b/gui/massadd.cpp index de54cada26e..c12e60ea8b9 100644 --- a/gui/massadd.cpp +++ b/gui/massadd.cpp @@ -127,9 +127,9 @@ void MassAddDialog::handleTickle() { FilesystemNode dir = _scanStack.pop(); FSList files; - if (!dir.listDir(files, FilesystemNode::kListAll)) { + if (!dir.getChildren(files, FilesystemNode::kListAll)) { error("browser returned a node that is not a directory: '%s'", - dir.path().c_str()); + dir.getPath().c_str()); } // Run the detector on the dir @@ -141,7 +141,7 @@ void MassAddDialog::handleTickle() { // e.g. ask the user which one to pick (make sure to display the // path, too). GameDescriptor result = candidates[0]; - result["path"] = dir.path(); + result["path"] = dir.getPath(); _games.push_back(result); } diff --git a/gui/options.cpp b/gui/options.cpp index 76a40f5f50f..4d6cadfdefc 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -821,7 +821,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 if (browser.runModal() > 0) { // User made his choice... FilesystemNode dir(browser.getResult()); - _savePath->setLabel(dir.path()); + _savePath->setLabel(dir.getPath()); draw(); // TODO - we should check if the directory is writeable before accepting it } @@ -832,7 +832,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 if (browser.runModal() > 0) { // User made his choice... FilesystemNode dir(browser.getResult()); - _themePath->setLabel(dir.path()); + _themePath->setLabel(dir.getPath()); draw(); } break; @@ -842,7 +842,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 if (browser.runModal() > 0) { // User made his choice... FilesystemNode dir(browser.getResult()); - _extraPath->setLabel(dir.path()); + _extraPath->setLabel(dir.getPath()); draw(); } break; @@ -852,9 +852,9 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 if (browser.runModal() > 0) { // User made his choice... FilesystemNode file(browser.getResult()); - _soundFont->setLabel(file.path()); + _soundFont->setLabel(file.getPath()); - if (!file.path().empty() && (file.path() != "None")) + if (!file.getPath().empty() && (file.getPath() != "None")) _soundFontClearButton->setEnabled(true); else _soundFontClearButton->setEnabled(false); diff --git a/gui/themebrowser.cpp b/gui/themebrowser.cpp index 8f72127a75b..4d8c4398721 100644 --- a/gui/themebrowser.cpp +++ b/gui/themebrowser.cpp @@ -148,12 +148,12 @@ void ThemeBrowser::addDir(ThList &list, const Common::String &dir, int level) { return; FSList fslist; - if (!node.listDir(fslist, FilesystemNode::kListAll)) + if (!node.getChildren(fslist, FilesystemNode::kListAll)) return; for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) { if (i->isDirectory()) { - addDir(list, i->path(), level-1); + addDir(list, i->getPath(), level-1); } else { Entry th; if (isTheme(*i, th)) { @@ -176,7 +176,7 @@ bool ThemeBrowser::isTheme(const FilesystemNode &node, Entry &out) { Common::ConfigFile cfg; Common::String type; - out.file = node.name(); + out.file = node.getName(); for (int i = out.file.size()-1; out.file[i] != '.' && i > 0; --i) { out.file.deleteLastChar(); } From e7aa6b996b54cec0a3dc2cb91feb4f1529cc27e5 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 14 Jun 2007 18:40:27 +0000 Subject: [PATCH 09/26] Fixed a TODO about checking that the savegames path is writable. svn-id: r27403 --- gui/options.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gui/options.cpp b/gui/options.cpp index 4d6cadfdefc..76bec036adb 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -27,6 +27,7 @@ #include "gui/themebrowser.h" #include "gui/chooser.h" #include "gui/eval.h" +#include "gui/message.h" #include "gui/newgui.h" #include "gui/options.h" #include "gui/PopUpWidget.h" @@ -821,9 +822,15 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 if (browser.runModal() > 0) { // User made his choice... FilesystemNode dir(browser.getResult()); - _savePath->setLabel(dir.getPath()); + if(dir.isWritable()) + { + _savePath->setLabel(dir.getPath()); + } else { + MessageDialog error("The chosen directory cannot be written to. Please select another one."); + error.runModal(); + return; + } draw(); - // TODO - we should check if the directory is writeable before accepting it } break; } From b405220ff2990b01b93c03a664ae9247b2fc422c Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 16 Jun 2007 17:20:46 +0000 Subject: [PATCH 10/26] Fixed several TODO's concerning path validation. svn-id: r27472 --- base/commandLine.cpp | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 3d826e2fa09..1fe54d629da 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -32,6 +32,7 @@ #include "common/config-manager.h" #include "common/system.h" +#include "common/fs.h" #include "sound/mididrv.h" #include "sound/mixer.h" @@ -48,10 +49,6 @@ #define DETECTOR_TESTING_HACK -#ifdef DETECTOR_TESTING_HACK -#include "common/fs.h" -#endif - namespace Base { static const char USAGE_STRING[] = @@ -313,7 +310,7 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, char **ar for (int i = 1; i < argc; ++i) { s = argv[i]; s2 = (i < argc-1) ? argv[i+1] : 0; - + if (s[0] != '-') { // The argument doesn't start with a dash, so it's not an option. // Hence it must be the target name. We currently enforce that @@ -390,7 +387,12 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, char **ar END_OPTION DO_OPTION('p', "path") - // TODO: Verify whether the path is valid + FilesystemNode path(option); + if(!path.exists()) { + usage("Non-existent game path '%s'", option); + } else if(!path.isReadable()) { + usage("Non-readable game path '%s'", option); + } END_OPTION DO_OPTION('q', "language") @@ -428,7 +430,12 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, char **ar END_OPTION DO_LONG_OPTION("soundfont") - // TODO: Verify whether the path is valid + FilesystemNode path(option); + if(!path.exists()) { + usage("Non-existent soundfont path '%s'", option); + } else if(!path.isReadable()) { + usage("Non-readable soundfont path '%s'", option); + } END_OPTION DO_LONG_OPTION_BOOL("disable-sdl-parachute") @@ -453,7 +460,12 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, char **ar END_OPTION DO_LONG_OPTION("savepath") - // TODO: Verify whether the path is valid + FilesystemNode path(option); + if(!path.exists()) { + usage("Non-existent savegames path '%s'", option); + } else if(!path.isWritable()) { + usage("Non-writable savegames path '%s'", option); + } END_OPTION DO_LONG_OPTION_INT("talkspeed") @@ -466,7 +478,12 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, char **ar END_OPTION DO_LONG_OPTION("themepath") - // TODO: Verify whether the path is valid + FilesystemNode path(option); + if(!path.exists()) { + usage("Non-existent theme path '%s'", option); + } else if(!path.isReadable()) { + usage("Non-readable theme path '%s'", option); + } END_OPTION DO_LONG_OPTION("target-md5") @@ -657,13 +674,18 @@ bool processSettings(Common::String &command, Common::StringMap &settings) { if (!settings.contains("savepath")) { const char *dir = getenv("SCUMMVM_SAVEPATH"); if (dir && *dir && strlen(dir) < MAXPATHLEN) { - // TODO: Verify whether the path is valid - settings["savepath"] = dir; + FilesystemNode saveDir(dir); + if(!saveDir.exists()) { + warning("Non-existent SCUMMVM_SAVEPATH save path. It will be ignored."); + } else if(!saveDir.isWritable()) { + warning("Non-writable SCUMMVM_SAVEPATH save path. It will be ignored."); + } else { + settings["savepath"] = dir; + } } } #endif - // Finally, store the command line settings into the config manager. for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) { Common::String key(x->_key); From f7ea7e666da6e484577d0341fb0331dff75c69f7 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 16 Jun 2007 17:31:36 +0000 Subject: [PATCH 11/26] Removed the isValid operation from the FilesystemNode class in favor of the much richer combinations possible with the new operations (exists, isReadable and isWritable). The work on the Common::File class is far from complete. Only the necessary was updated. svn-id: r27473 --- backends/fs/abstract-fs.h | 5 ----- backends/fs/posix/posix-fs.cpp | 1 - common/file.cpp | 14 ++++++++++---- common/fs.cpp | 6 ------ common/fs.h | 5 ----- common/md5.cpp | 9 ++++++--- gui/themebrowser.cpp | 2 +- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index bb7669739f1..fed2b9b4c50 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -121,11 +121,6 @@ public: */ virtual bool isReadable() const = 0; - /** - * Indicates whether this path is valid or not for usage. - */ - virtual bool isValid() const = 0; - /** * Indicates whether this path can be written to or not. */ diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 2e222f34f80..fb5c9dc5d78 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -68,7 +68,6 @@ public: 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 isValid() const { return _isValid; } virtual bool isWritable() const { return access(_path.c_str(), W_OK) == 0; } virtual AbstractFilesystemNode *getChild(const String &n) const; diff --git a/common/file.cpp b/common/file.cpp index c04c579535f..0df575ac823 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -364,13 +364,19 @@ bool File::open(const String &filename, AccessMode mode) { bool File::open(const FilesystemNode &node, AccessMode mode) { assert(mode == kFileReadMode || mode == kFileWriteMode); - if (!node.isValid()) { - warning("File::open: Trying to open an invalid FilesystemNode object"); + if (!node.exists()) { + warning("File::open: Trying to open a FilesystemNode which does not exist"); return false; } else if (node.isDirectory()) { warning("File::open: Trying to open a FilesystemNode which is a directory"); return false; - } + } /*else if (!node.isReadable() && mode == kFileReadMode) { + warning("File::open: Trying to open an unreadable FilesystemNode object for reading"); + return false; + } else if (!node.isWritable() && mode == kFileWriteMode) { + warning("File::open: Trying to open an unwritable FilesystemNode object for writing"); + return false; + }*/ String filename(node.getName()); @@ -409,7 +415,7 @@ bool File::exists(const String &filename) { // FIXME: can't use isValid() here since at the time of writing // FilesystemNode is to be unable to find for example files // added in extrapath - if (file.isDirectory()) + if (file.isDirectory() && !file.exists()) return false; // Next, try to locate the file by *opening* it in read mode. This has diff --git a/common/fs.cpp b/common/fs.cpp index fdc485a06fe..fc091262d77 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -161,12 +161,6 @@ bool FilesystemNode::isReadable() const { return _realNode->isReadable(); } -bool FilesystemNode::isValid() const { - if (_realNode == 0) - return false; - return _realNode->isValid(); -} - bool FilesystemNode::isWritable() const { if (_realNode == 0) return false; diff --git a/common/fs.h b/common/fs.h index 6b0a587e1b8..328bebb15b7 100644 --- a/common/fs.h +++ b/common/fs.h @@ -193,11 +193,6 @@ public: */ virtual bool isReadable() const; - /** - * Indicates whether this path is valid or not for usage. - */ - bool isValid() const; - /** * Indicates whether this path can be written to or not. */ diff --git a/common/md5.cpp b/common/md5.cpp index 35fbe0b9ab2..32acdc5b8cc 100644 --- a/common/md5.cpp +++ b/common/md5.cpp @@ -246,11 +246,14 @@ void md5_finish(md5_context *ctx, uint8 digest[16]) { } bool md5_file(const FilesystemNode &file, uint8 digest[16], uint32 length) { - if (!file.isValid()) { - warning("md5_file: using an invalid FilesystemNode"); + if(!file.exists()) { + warning("md5_file: using an inexistent FilesystemNode"); + return false; + } else if (!file.isReadable()) { + warning("md5_file: using an unreadable FilesystemNode"); return false; } else if (file.isDirectory()) { - warning("md5_file: using a diretory FilesystemNode"); + warning("md5_file: using a directory FilesystemNode"); return false; } diff --git a/gui/themebrowser.cpp b/gui/themebrowser.cpp index 4d8c4398721..75fe5404c43 100644 --- a/gui/themebrowser.cpp +++ b/gui/themebrowser.cpp @@ -144,7 +144,7 @@ void ThemeBrowser::addDir(ThList &list, const Common::String &dir, int level) { FilesystemNode node(dir); - if (!node.isValid()) + if (!node.exists() || !node.isReadable()) return; FSList fslist; From fe4ee4740d76b0aee2032814095f1d2b81dbde14 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 16 Jun 2007 17:41:31 +0000 Subject: [PATCH 12/26] Small bugfix. Wrong logical operator. svn-id: r27474 --- common/file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/file.cpp b/common/file.cpp index 0df575ac823..238c3a4bb33 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -415,7 +415,7 @@ bool File::exists(const String &filename) { // FIXME: can't use isValid() here since at the time of writing // FilesystemNode is to be unable to find for example files // added in extrapath - if (file.isDirectory() && !file.exists()) + if (file.isDirectory() || !file.exists()) return false; // Next, try to locate the file by *opening* it in read mode. This has From 8ebf479bc5db8cf4996cc0820269aaf04139b940 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 17 Jun 2007 17:17:38 +0000 Subject: [PATCH 13/26] Added a new parameter to the getChildren function, which allows including hidden files in the results. svn-id: r27514 --- backends/fs/abstract-fs.h | 3 ++- backends/fs/posix/posix-fs.cpp | 8 ++++---- common/fs.cpp | 4 ++-- common/fs.h | 5 ++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index fed2b9b4c50..371c38a495b 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -89,10 +89,11 @@ public: * * @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) const = 0; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const = 0; /** * Returns a human readable path string. diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index fb5c9dc5d78..c9768304020 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -71,7 +71,7 @@ public: 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) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; private: @@ -162,7 +162,7 @@ AbstractFilesystemNode *POSIXFilesystemNode::getChild(const String &n) const { return new POSIXFilesystemNode(newPath, true); } -bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { assert(_isDirectory); DIR *dirp = opendir(_path.c_str()); @@ -173,8 +173,8 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) con // loop over dir entries using readdir while ((dp = readdir(dirp)) != NULL) { - // Skip 'invisible' files - if (dp->d_name[0] == '.') + // Skip 'invisible' files if necessary + if (dp->d_name[0] == '.' && !hidden) continue; String newPath(_path); diff --git a/common/fs.cpp b/common/fs.cpp index fc091262d77..6eaa35e67fc 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -105,13 +105,13 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return FilesystemNode(node); } -bool FilesystemNode::getChildren(FSList &fslist, ListMode mode) const { +bool FilesystemNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const { if (!_realNode || !_realNode->isDirectory()) return false; AbstractFSList tmp; - if (!_realNode->getChildren(tmp, mode)) + if (!_realNode->getChildren(tmp, mode, hidden)) return false; fslist.clear(); diff --git a/common/fs.h b/common/fs.h index 328bebb15b7..7291fb75fcc 100644 --- a/common/fs.h +++ b/common/fs.h @@ -67,7 +67,6 @@ class FilesystemNode { private: int *_refCount; AbstractFilesystemNode *_realNode; - FilesystemNode(AbstractFilesystemNode *realNode); public: @@ -136,14 +135,14 @@ public: * that does not represent a directory, false is returned. * * @return true if succesful, false otherwise (e.g. when the directory does not exist). - * @todo Rename this to listChildren or getChildren. */ - virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = false) const; /** * 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 Common::String getDisplayName() const; From 0ac96302fe9c04df79cb01a77d19535b45fe2db0 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 20 Jun 2007 00:28:04 +0000 Subject: [PATCH 14/26] Initial implementation of the lookupFile() function. It's meant to search recursively for given filename within a set of directories. svn-id: r27551 --- backends/fs/posix/posix-fs.cpp | 7 ++- common/fs.cpp | 82 ++++++++++++++++++++++++++++++++++ common/fs.h | 37 +++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index c9768304020..385bab833cf 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -174,8 +174,13 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, boo // loop over dir entries using readdir while ((dp = readdir(dirp)) != NULL) { // Skip 'invisible' files if necessary - if (dp->d_name[0] == '.' && !hidden) + 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() != '/') diff --git a/common/fs.cpp b/common/fs.cpp index 6eaa35e67fc..28f3e11f0b7 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -27,6 +27,43 @@ #include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory-maker.cpp" +/* + * Simple DOS-style pattern matching function (understands * and ? like used in DOS). + * Taken from exult/files/listfiles.cc + */ +static bool matchString(const char *str, const char *pat) { + const char *p = 0; + const char *q = 0; + + for (;;) { + switch (*pat) { + case '*': + p = ++pat; + q = str; + break; + + default: + if (*pat != *str) { + if (p) { + pat = p; + str = ++q; + if(!*str) + return !*pat; + break; + } + else + return false; + } + // fallthrough + case '?': + if(!*str) + return !*pat; + pat++; + str++; + } + } +} + FilesystemNode::FilesystemNode() { _realNode = 0; _refCount = 0; @@ -166,3 +203,48 @@ bool FilesystemNode::isWritable() const { return false; return _realNode->isWritable(); } + +bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const +{ + for(FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) + { + if(entry->isDirectory()) { + lookupFileRec(results, *entry, filename, hidden, exhaustive); + } + } + + //TODO: we would return true even if no matches were found, if the initial results list isn't empty + return ((results.size() > 0) ? true : false); +} + +bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const +{ + lookupFileRec(results, dir, filename, hidden, exhaustive); + + //TODO: we would return true even if no matches were found, if the initial results list isn't empty + return ((results.size() > 0) ? true : false); +} + +void FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const +{ + FSList entries; + dir.getChildren(entries, FilesystemNode::kListAll, hidden); + + for(FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) + { + if(entry->isDirectory()) { + lookupFileRec(results, *entry, filename, hidden, exhaustive); + } else { + //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, + // so it might be a good idea to include it inside the backend class. This would enforce its + // implementation by all ports. + if(matchString(lastPathComponent(entry->getPath()), filename.c_str())) { + results.push_back(*entry); + + if(!exhaustive) { + break; + } + } + } + } +} diff --git a/common/fs.h b/common/fs.h index 7291fb75fcc..6a2f049be1c 100644 --- a/common/fs.h +++ b/common/fs.h @@ -196,6 +196,32 @@ public: * Indicates whether this path can be written to or not. */ virtual bool isWritable() const; + + /** + * Searches recursively for a filename inside the given directories. + * + * @param results List to put the matches in. + * @param fslist List of directories to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. Default: false + * @param exhaustive Whether to continue searching after one match has been found. Default: false + * + * @return true if matches could be found, false otherwise. + */ + virtual bool lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const; + + /** + * Searches recursively for a filename inside the given directory. + * + * @param results List to put the matches in. + * @param FilesystemNode Directory to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. Default: false + * @param exhaustive Whether to continue searching after one match has been found. Default: false + * + * @return true if matches could be found, false otherwise. + */ + virtual bool lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; protected: /** @@ -203,6 +229,17 @@ protected: * deletes the corresponding underlying references. */ void decRefCount(); + + /** + * Searches recursively for a filename inside the given directory. + * + * @param results List to put the matches in. + * @param FilesystemNode Directory to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. + */ + void lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; }; //} // End of namespace Common From 256e4d9521b79160d1f9ed670656097a96dc5a34 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 8 Jul 2007 07:19:50 +0000 Subject: [PATCH 15/26] Initial patch to the listSavefiles method. Now only the existing savegames are marked as available. svn-id: r27957 --- backends/saves/default/default-saves.cpp | 25 +++++++++++++++++++----- backends/saves/default/default-saves.h | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index 1898a23f2a4..8c9b0ffd2a2 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -28,6 +28,7 @@ #include "common/stdafx.h" #include "common/savefile.h" #include "common/util.h" +#include "common/fs.h" #include "backends/saves/default/default-saves.h" #include "backends/saves/compressed/compressed-saves.h" @@ -179,11 +180,25 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) return wrapInSaveFile(sf); } -void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) { - // TODO: Implement this properly, at least on systems that support - // opendir/readdir. - // Even better, replace this with a better design... - memset(marks, true, num * sizeof(bool)); +void DefaultSaveFileManager::listSavefiles(const char *prefix , bool *marks, int num) { + FilesystemNode savePath(getSavePath()); + FSList savefiles; + Common::String search(prefix); + search += '*'; //match all files that start with the given prefix + search.c_str(); //FIXME: subtle bug? removing this line will break things. Looks like the string isn't getting updated. + + memset(marks, false, num * sizeof(bool)); //assume no savegames for this title + + if(savePath.lookupFile(savefiles, savePath, search, false, true)) { + char slot[2]; + for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) { + //TODO: check if this is the behavior for all engines + //Obtain the last 2 digits of the filename, since they correspond to the save slot + slot[0] = file->getName()[file->getName().size()-2]; + slot[1] = file->getName()[file->getName().size()-1]; + marks[atoi(slot)] = true; //mark this slot as valid + } + } } #endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER) diff --git a/backends/saves/default/default-saves.h b/backends/saves/default/default-saves.h index 3aea1495a4b..a3e2037a5c2 100644 --- a/backends/saves/default/default-saves.h +++ b/backends/saves/default/default-saves.h @@ -33,7 +33,7 @@ class DefaultSaveFileManager : public Common::SaveFileManager { public: virtual Common::OutSaveFile *openForSaving(const char *filename); virtual Common::InSaveFile *openForLoading(const char *filename); - virtual void listSavefiles(const char * /* prefix */, bool *marks, int num); + virtual void listSavefiles(const char *prefix, bool *marks, int num); }; #endif From 779f702b695977b5d8c0e03b8a24bd9c107b7cfe Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 8 Jul 2007 17:44:26 +0000 Subject: [PATCH 16/26] Fixed a very strange bug with strings. Also added a couple sanity checks. svn-id: r27973 --- backends/saves/default/default-saves.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index b58dd87d93e..8cda56ded9e 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -184,12 +184,11 @@ void DefaultSaveFileManager::listSavefiles(const char *prefix , bool *marks, int FilesystemNode savePath(getSavePath()); FSList savefiles; Common::String search(prefix); - search += '*'; //match all files that start with the given prefix - search.c_str(); //FIXME: subtle bug? removing this line will break things. Looks like the string isn't getting updated. + search = search + '*'; //match all files that start with the given prefix. += causes a strange bug. assert(marks); memset(marks, false, num * sizeof(bool)); //assume no savegames for this title - + if(savePath.lookupFile(savefiles, savePath, search, false, true)) { char slot[2]; int slotNum; From 8a36379d55afbfd5e322c1e216a11447a4de8a51 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 9 Jul 2007 01:16:13 +0000 Subject: [PATCH 17/26] Fixed a couple compilation issues in the windows build. svn-id: r27983 --- backends/fs/windows/windows-fs-factory.cpp | 2 +- backends/fs/windows/windows-fs.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backends/fs/windows/windows-fs-factory.cpp b/backends/fs/windows/windows-fs-factory.cpp index 76b62e5deb4..3d7a3cc6724 100644 --- a/backends/fs/windows/windows-fs-factory.cpp +++ b/backends/fs/windows/windows-fs-factory.cpp @@ -8,7 +8,7 @@ AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const { } AbstractFilesystemNode *WindowsFilesystemFactory::makeCurrentDirectoryFileNode() const { - return new WindowsFilesystemNode(NULL, true); + return new WindowsFilesystemNode("", true); } AbstractFilesystemNode *WindowsFilesystemFactory::makeFileNodePath(const String &path) const { diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp index 5a9e1c65b68..995264f1101 100644 --- a/backends/fs/windows/windows-fs.cpp +++ b/backends/fs/windows/windows-fs.cpp @@ -82,7 +82,7 @@ public: 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) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; private: @@ -246,9 +246,11 @@ AbstractFilesystemNode *WindowsFilesystemNode::getChild(const String &n) const { return new WindowsFilesystemNode(newPath, false); } -bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { assert(_isDirectory); + //TODO: honor the hidden flag + if (_isPseudoRoot) { #ifndef _WIN32_WCE // Drives enumeration From 1a965aad9568b296545890b7bb61e0de7b052e26 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 9 Jul 2007 01:26:54 +0000 Subject: [PATCH 18/26] Update the interfaces for the getChildren method to include the hidden flag. Also added some missing method stubs to the gamecard dc port. svn-id: r27984 --- backends/fs/amigaos4/amigaos4-fs.cpp | 6 ++++-- backends/fs/dc/dc-fs.cpp | 6 ++++-- backends/fs/ds/ds-fs.cpp | 8 ++++++-- backends/fs/ds/ds-fs.h | 7 +++++-- backends/fs/gp32/gp32-fs.cpp | 7 +++++-- backends/fs/morphos/abox-fs.cpp | 6 ++++-- backends/fs/palmos/palmos-fs.cpp | 6 ++++-- backends/fs/ps2/ps2-fs.cpp | 6 ++++-- backends/fs/psp/psp_fs.cpp | 6 ++++-- backends/fs/symbian/symbian-fs.cpp | 6 ++++-- 10 files changed, 44 insertions(+), 20 deletions(-) diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp index 88af467ae5a..3eefd6507e8 100644 --- a/backends/fs/amigaos4/amigaos4-fs.cpp +++ b/backends/fs/amigaos4/amigaos4-fs.cpp @@ -99,7 +99,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; /** @@ -279,9 +279,11 @@ AbstractFilesystemNode *AmigaOSFilesystemNode::getChild(const String &n) const { return new AmigaOSFilesystemNode(newPath); } -bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { ENTER(); + //TODO: honor the hidden flag + if (!_bIsValid) { debug(6, "Invalid node"); LEAVE(); diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index 070c9b075bc..e1228c7ff27 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -67,7 +67,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; }; @@ -137,9 +137,11 @@ AbstractFilesystemNode *RoninCDFilesystemNode::getChild(const String &n) const { return new RoninCDFilesystemNode(newPath, true); } -bool RoninCDFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool RoninCDFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { assert(_isDirectory); + //TODO: honor the hidden flag + DIR *dirp = opendir(_path.c_str()); struct dirent *dp; diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index c0138459a96..11d373ea1ec 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -133,10 +133,12 @@ AbstractFilesystemNode *DSFileSystemNode::getChild(const Common::String& n) cons return NULL; } -bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode) const { +bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode, bool hidden) const { // consolePrintf("Listdir\n"); // consolePrintf("Directory\n"); + //TODO: honor the hidden flag + char temp[128]; strcpy(temp, _path.c_str()); @@ -283,9 +285,11 @@ AbstractFilesystemNode *GBAMPFileSystemNode::getChild(const Common::String& n) c return NULL; } -bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode) const { +bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode, bool hidden) const { // consolePrintf("Listdir\n"); + //TODO: honor the hidden flag + enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 }; char temp[128], fname[128], *path, *pathTemp; diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index e3014d0d2e7..ead0acc05e8 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -91,7 +91,7 @@ public: */ virtual AbstractFilesystemNode *clone() const { return new DSFileSystemNode(this); } virtual AbstractFilesystemNode *getChild(const Common::String& name) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; /** @@ -143,18 +143,21 @@ public: */ GBAMPFileSystemNode(const GBAMPFileSystemNode *node); + virtual bool exists() const { return true; } //FIXME: this is just a stub 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 true; } //FIXME: this is just a stub virtual bool isValid() const { return _isValid; } + virtual bool isWritable() const { return true; } //FIXME: this is just a stub /** * Returns a copy of this node. */ virtual AbstractFilesystemNode *clone() const { return new GBAMPFileSystemNode(this); } virtual AbstractFilesystemNode *getChild(const Common::String& name) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; }; diff --git a/backends/fs/gp32/gp32-fs.cpp b/backends/fs/gp32/gp32-fs.cpp index 92968b5976b..9b839867bca 100644 --- a/backends/fs/gp32/gp32-fs.cpp +++ b/backends/fs/gp32/gp32-fs.cpp @@ -53,6 +53,7 @@ public: */ GP32FilesystemNode(const String &path); + virtual bool exists() const { return true; } //FIXME: this is just a stub virtual String getDisplayName() const { return _displayName; } virtual String getName() const { return _displayName; } virtual String getPath() const { return _path; } @@ -64,7 +65,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; }; @@ -193,9 +194,11 @@ AbstractFilesystemNode *GP32FilesystemNode::getChild(const String &n) const { return new GP32FilesystemNode(newPath); } -bool GP32FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool GP32FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { assert(_isDirectory); + //TODO: honor the hidden flag + GPDIRENTRY dirEntry; GPFILEATTR attr; GP32FilesystemNode entry; diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp index 8f46f9a9a88..ef50a11e4e5 100644 --- a/backends/fs/morphos/abox-fs.cpp +++ b/backends/fs/morphos/abox-fs.cpp @@ -86,7 +86,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &name) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; /** @@ -250,8 +250,10 @@ AbstractFilesystemNode *ABoxFilesystemNode::getChild(const String &name) const { return new ABoxFilesystemNode(newPath); } -bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode) const +bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const { + //TODO: honor the hidden flag + if (!_isValid) { debug(6, "listDir() called on invalid node"); diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index eae35811961..1e954be2f68 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -66,7 +66,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; private: @@ -181,7 +181,9 @@ AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const { return new PalmOSFilesystemNode(newPath); } -bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { + //TODO: honor the hidden flag + Err error; Char nameP[256]; FileInfoType desc; diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp index 9d8e360f649..727e1a894fd 100644 --- a/backends/fs/ps2/ps2-fs.cpp +++ b/backends/fs/ps2/ps2-fs.cpp @@ -73,7 +73,7 @@ public: virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); } virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; }; @@ -150,7 +150,9 @@ AbstractFilesystemNode *Ps2FilesystemNode::getChild(const String &n) const { return NULL; } -bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode) const { +bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const { + //TODO: honor the hidden flag + if (!_isDirectory) return false; diff --git a/backends/fs/psp/psp_fs.cpp b/backends/fs/psp/psp_fs.cpp index 5b0faf38474..019b13e9e69 100644 --- a/backends/fs/psp/psp_fs.cpp +++ b/backends/fs/psp/psp_fs.cpp @@ -68,7 +68,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; }; @@ -128,9 +128,11 @@ AbstractFilesystemNode *PSPFilesystemNode::getChild(const String &n) const { return new PSPFilesystemNode(newPath, true); } -bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { assert(_isDirectory); + //TODO: honor the hidden flag + int dfd = sceIoDopen(_path.c_str()); if (dfd > 0) { SceIoDirent dir; diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp index 5c3dd74f5c6..60693eefb5c 100644 --- a/backends/fs/symbian/symbian-fs.cpp +++ b/backends/fs/symbian/symbian-fs.cpp @@ -69,7 +69,7 @@ public: virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; virtual AbstractFilesystemNode *getParent() const; }; @@ -163,9 +163,11 @@ AbstractFilesystemNode *SymbianFilesystemNode::getChild(const String &n) const { return new SymbianFilesystemNode(newPath); } -bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode) const { +bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { assert(_isDirectory); + //TODO: honor the hidden flag + if (_isPseudoRoot) { // Drives enumeration RFs fs = CEikonEnv::Static()->FsSession(); From c1961f1f76e91595624a2e49e48b0fab5f412f27 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 9 Jul 2007 02:57:47 +0000 Subject: [PATCH 19/26] Kirben's fix to Simon the Sorcerer floppy version crash. svn-id: r27986 --- engines/agos/gfx.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engines/agos/gfx.cpp b/engines/agos/gfx.cpp index 2b530fdcd69..15937db0da2 100644 --- a/engines/agos/gfx.cpp +++ b/engines/agos/gfx.cpp @@ -666,6 +666,9 @@ void AGOSEngine_Simon1::drawImage(VC10_state *state) { } else if (getGameType() == GType_SIMON1 && (getFeatures() & GF_DEMO)) { // The DOS Floppy demo was based off Waxworks engine if (_windowNum == 4 || (_windowNum >= 10 && _windowNum <= 27)) { + state->surf2_addr = getBackGround(); + state->surf2_pitch = _screenWidth; + state->surf_addr = _window4BackScn; state->surf_pitch = _videoWindows[18] * 16; From 720c974fafaca16b6e86f28ffc14c8c3aa574e15 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 12 Jul 2007 17:58:15 +0000 Subject: [PATCH 20/26] Changed SaveFileManager::listSavegames() function to be engine agnostic. It now returns a list will the full paths of existing files that match a given regex. Additionally, modified the 5 engines which use the default manager (Agos, Queen, Saga, Scumm and Touche) to parse the filename list and mark the available saves bool array correctly. svn-id: r28046 --- backends/saves/default/default-saves.cpp | 22 ++++++-------------- backends/saves/default/default-saves.h | 3 ++- common/savefile.h | 10 ++++----- engines/agos/saveload.cpp | 21 +++++++++++++++++-- engines/queen/queen.cpp | 25 +++++++++++++++++++---- engines/saga/saveload.cpp | 24 +++++++++++++++++++--- engines/scumm/dialogs.cpp | 12 +++++------ engines/scumm/saveload.cpp | 22 ++++++++++++++++++-- engines/touche/saveload.cpp | 2 +- engines/touche/ui.cpp | 26 +++++++++++++++++++++++- 10 files changed, 126 insertions(+), 41 deletions(-) diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index 8cda56ded9e..2219d1c9dc9 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -180,29 +180,19 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) return wrapInSaveFile(sf); } -void DefaultSaveFileManager::listSavefiles(const char *prefix , bool *marks, int num) { +Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) { FilesystemNode savePath(getSavePath()); FSList savefiles; - Common::String search(prefix); - search = search + '*'; //match all files that start with the given prefix. += causes a strange bug. + Common::StringList results; + Common::String search(regex); - assert(marks); - memset(marks, false, num * sizeof(bool)); //assume no savegames for this title - if(savePath.lookupFile(savefiles, savePath, search, false, true)) { - char slot[2]; - int slotNum; for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) { - //TODO: check if this is the behavior for all engines - //Obtain the last 2 digits of the filename, since they correspond to the save slot - slot[0] = file->getName()[file->getName().size()-2]; - slot[1] = file->getName()[file->getName().size()-1]; - - slotNum = atoi(slot); - if(slotNum >= 0 && slotNum < num) - marks[slotNum] = true; //mark this slot as valid + results.push_back(file->getPath()); } } + + return results; } #endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER) diff --git a/backends/saves/default/default-saves.h b/backends/saves/default/default-saves.h index a3e2037a5c2..4b525cabc82 100644 --- a/backends/saves/default/default-saves.h +++ b/backends/saves/default/default-saves.h @@ -28,12 +28,13 @@ #include "common/stdafx.h" #include "common/savefile.h" +#include "common/str.h" class DefaultSaveFileManager : public Common::SaveFileManager { public: virtual Common::OutSaveFile *openForSaving(const char *filename); virtual Common::InSaveFile *openForLoading(const char *filename); - virtual void listSavefiles(const char *prefix, bool *marks, int num); + virtual Common::StringList listSavefiles(const char *regex); }; #endif diff --git a/common/savefile.h b/common/savefile.h index 612d6ae210d..fec6fc697b2 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -30,6 +30,7 @@ #include "common/noncopyable.h" #include "common/scummsys.h" #include "common/stream.h" +#include "common/str.h" namespace Common { @@ -94,12 +95,11 @@ public: virtual InSaveFile *openForLoading(const char *filename) = 0; /** - * Request a list of available savegames with a given prefix. - * TODO: Document this better! - * TODO: Or even replace it with a better API. For example, one that - * returns a list of strings for all present file names. + * Request a list of available savegames with a given regex. + * @param regex Regular expression to match. Wildcards like * or ? are available. + * returns a list of strings for all present file names. */ - virtual void listSavefiles(const char *prefix , bool *marks, int num) = 0; + virtual Common::StringList listSavefiles(const char *regex) = 0; /** * Get the path to the save game directory. diff --git a/engines/agos/saveload.cpp b/engines/agos/saveload.cpp index 32b767073a9..61c640d7c52 100644 --- a/engines/agos/saveload.cpp +++ b/engines/agos/saveload.cpp @@ -38,13 +38,29 @@ namespace AGOS { int AGOSEngine::countSaveGames() { Common::InSaveFile *f; + Common::StringList filenames; uint i = 1; + char slot[3]; + int slotNum; bool marks[256]; char *prefix = genSaveName(998); - prefix[strlen(prefix)-3] = '\0'; - _saveFileMan->listSavefiles(prefix, marks, 256); + prefix[strlen(prefix)-3] = '*'; + prefix[strlen(prefix)-2] = '\0'; + memset(marks, false, 256 * sizeof(bool)); //assume no savegames for this title + filenames = _saveFileMan->listSavefiles(prefix); + for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ + //Obtain the last 3 digits of the filename, since they correspond to the save slot + slot[0] = file->c_str()[file->size()-3]; + slot[1] = file->c_str()[file->size()-2]; + slot[2] = file->c_str()[file->size()-1]; + + slotNum = atoi(slot); + if(slotNum >= 0 && slotNum < 256) + marks[slotNum] = true; //mark this slot as valid + } + while (i < 256) { if (marks[i] && (f = _saveFileMan->openForLoading(genSaveName(i)))) { @@ -53,6 +69,7 @@ int AGOSEngine::countSaveGames() { } else break; } + return i; } diff --git a/engines/queen/queen.cpp b/engines/queen/queen.cpp index c1e909ffdb7..7ba89b7af9e 100644 --- a/engines/queen/queen.cpp +++ b/engines/queen/queen.cpp @@ -317,11 +317,28 @@ void QueenEngine::makeGameStateName(uint16 slot, char *buf) { } void QueenEngine::findGameStateDescriptions(char descriptions[100][32]) { - char filename[20]; - makeGameStateName(0, filename); - filename[strlen(filename) - 2] = 0; + char prefix[20]; + makeGameStateName(0, prefix); + prefix[strlen(prefix) - 2] = '*'; + prefix[strlen(prefix) - 1] = 0; bool marks[SAVESTATE_MAX_NUM]; - _saveFileMan->listSavefiles(filename, marks, SAVESTATE_MAX_NUM); + char slot[2]; + int slotNum; + Common::StringList filenames; + + memset(marks, false, SAVESTATE_MAX_NUM * sizeof(bool)); //assume no savegames for this title + filenames = _saveFileMan->listSavefiles(prefix); + + for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ + //Obtain the last 2 digits of the filename, since they correspond to the save slot + slot[0] = file->c_str()[file->size()-2]; + slot[1] = file->c_str()[file->size()-1]; + + slotNum = atoi(slot); + if(slotNum >= 0 && slotNum < SAVESTATE_MAX_NUM) + marks[slotNum] = true; //mark this slot as valid + } + for (int i = 0; i < SAVESTATE_MAX_NUM; ++i) { if (marks[i]) { GameStateHeader header; diff --git a/engines/saga/saveload.cpp b/engines/saga/saveload.cpp index c93ace81b37..bb3164a79c3 100644 --- a/engines/saga/saveload.cpp +++ b/engines/saga/saveload.cpp @@ -112,14 +112,32 @@ uint SagaEngine::getNewSaveSlotNumber() { } void SagaEngine::fillSaveList() { + assert(_saveMarks); + int i; Common::InSaveFile *in; + Common::StringList filenames; + char slot[2]; + int slotNum; char *name; name = calcSaveFileName(MAX_SAVES); - name[strlen(name) - 2] = 0; - _saveFileMan->listSavefiles(name, _saveMarks, MAX_SAVES); - + name[strlen(name) - 2] = '*'; + name[strlen(name) - 1] = 0; + + memset(_saveMarks, false, MAX_SAVES * sizeof(bool)); //assume no savegames for this title + filenames = _saveFileMan->listSavefiles(name); + + for(Common::StringList::iterator file = filenames.begin(); file != filenames.end(); file++){ + //Obtain the last 2 digits of the filename, since they correspond to the save slot + slot[0] = file->c_str()[file->size()-2]; + slot[1] = file->c_str()[file->size()-1]; + + slotNum = atoi(slot); + if(slotNum >= 0 && slotNum < MAX_SAVES) + _saveMarks[slotNum] = true; //mark this slot as valid + } + _saveFilesMaxCount = 0; for (i = 0; i < MAX_SAVES; i++) { if (_saveMarks[i]) { diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp index 16fe72531b8..85a72cb090d 100644 --- a/engines/scumm/dialogs.cpp +++ b/engines/scumm/dialogs.cpp @@ -427,10 +427,10 @@ void SaveLoadChooser::updateInfos() { #pragma mark - Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) { - // Get savegame names - Common::StringList l; + // Get savegame descriptions + Common::StringList descriptions; char name[32]; - uint i = saveMode ? 1 : 0; + uint i = saveMode ? 1 : 0; //the autosave is on slot #0 bool avail_saves[81]; scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves)); @@ -439,10 +439,10 @@ Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) { scumm->getSavegameName(i, name); else name[0] = 0; - l.push_back(name); + descriptions.push_back(name); } - - return l; + + return descriptions; } MainMenuDialog::MainMenuDialog(ScummEngine *scumm) diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp index 9d0d0ad6547..3f638946c4e 100644 --- a/engines/scumm/saveload.cpp +++ b/engines/scumm/saveload.cpp @@ -384,10 +384,28 @@ void ScummEngine::makeSavegameName(char *out, int slot, bool temporary) { } void ScummEngine::listSavegames(bool *marks, int num) { + assert(marks); + char prefix[256]; + char slot[2]; + int slotNum; + Common::StringList filenames; + makeSavegameName(prefix, 99, false); - prefix[strlen(prefix)-2] = 0; - _saveFileMan->listSavefiles(prefix, marks, num); + prefix[strlen(prefix)-2] = '*'; + prefix[strlen(prefix)-1] = 0; + memset(marks, false, num * sizeof(bool)); //assume no savegames for this title + filenames = _saveFileMan->listSavefiles(prefix); + + for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ + //Obtain the last 2 digits of the filename, since they correspond to the save slot + slot[0] = file->c_str()[file->size()-2]; + slot[1] = file->c_str()[file->size()-1]; + + slotNum = atoi(slot); + if(slotNum >= 0 && slotNum < num) + marks[slotNum] = true; //mark this slot as valid + } } bool ScummEngine::getSavegameName(int slot, char *desc) { diff --git a/engines/touche/saveload.cpp b/engines/touche/saveload.cpp index b219001c49f..c37c06aacb3 100644 --- a/engines/touche/saveload.cpp +++ b/engines/touche/saveload.cpp @@ -398,7 +398,7 @@ void ToucheEngine::readGameStateDescription(int num, char *description, int len) void ToucheEngine::generateGameStateFileName(int num, char *dst, int len, bool prefixOnly) const { if (prefixOnly) { - snprintf(dst, len, "%s.", _targetName.c_str()); + snprintf(dst, len, "%s.*", _targetName.c_str()); } else { snprintf(dst, len, "%s.%d", _targetName.c_str(), num); } diff --git a/engines/touche/ui.cpp b/engines/touche/ui.cpp index 15dc64aaf2d..4d7100d4d0c 100644 --- a/engines/touche/ui.cpp +++ b/engines/touche/ui.cpp @@ -370,9 +370,33 @@ void ToucheEngine::handleOptions(int forceDisplay) { setupMenu(menuData.mode, &menuData); curMode = menuData.mode; if (menuData.mode == kMenuLoadStateMode || menuData.mode == kMenuSaveStateMode) { + assert(menuData.saveLoadMarks); + char gameStateFileName[16]; generateGameStateFileName(999, gameStateFileName, 15, true); - _saveFileMan->listSavefiles(gameStateFileName, menuData.saveLoadMarks, 100); + char slot[2]; + int slotNum; + Common::StringList filenames; + + memset(menuData.saveLoadMarks, false, 100 * sizeof(bool)); //assume no savegames for this title + filenames = _saveFileMan->listSavefiles(gameStateFileName); + + for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ + //Obtain the last 1 or 2 digits of the filename, since they correspond to the save slot + //This engine can save games either with one or two digits, hence the additional if statement + slot[0] = file->c_str()[file->size()-2]; + slot[1] = file->c_str()[file->size()-1]; + + if(!atoi(&slot[0])){ + slotNum = atoi(&slot[1]); + } else { + slotNum = atoi(slot); + } + + if(slotNum >= 0 && slotNum < 100) + menuData.saveLoadMarks[slotNum] = true; //mark this slot as valid + } + for (int i = 0; i < 100; ++i) { menuData.saveLoadDescriptionsTable[i][0] = 0; if (menuData.saveLoadMarks[i]) { From 21f352b2df2b45b9bcff6a0c21d57a1e480d4802 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 18 Jul 2007 20:51:26 +0000 Subject: [PATCH 21/26] Added error codes to the SaveFileManager via the SFMError enum. Also, solved TODO's in the default-saves implementation. svn-id: r28140 --- backends/saves/default/default-saves.cpp | 59 +++++++++++++++++++----- common/savefile.h | 44 +++++++++++++++++- 2 files changed, 90 insertions(+), 13 deletions(-) diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index 2219d1c9dc9..f41455be3f7 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -29,6 +29,7 @@ #include "common/savefile.h" #include "common/util.h" #include "common/fs.h" +#include "common/str.h" #include "backends/saves/default/default-saves.h" #include "backends/saves/compressed/compressed-saves.h" @@ -120,36 +121,69 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) // Ensure that the savepath exists and is writeable. If not, generate // an appropriate error const char *savePath = getSavePath(); + #if defined(UNIX) || defined(__SYMBIAN32__) struct stat sb; + clearError(); // Check whether the dir exists if (stat(savePath, &sb) == -1) { // The dir does not exist, or stat failed for some other reason. // If the problem was that the path pointed to nothing, try - // to create the dir. - if (errno == ENOENT) { + // to create the dir (ENOENT case). + switch (errno) { + case EACCES: + setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied")); + break; + case ELOOP: + setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path")); + break; + case ENAMETOOLONG: + setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long")); + break; + case ENOENT: if (mkdir(savePath, 0755) != 0) { // mkdir could fail for various reasons: The parent dir doesn't exist, // or is not writeable, the path could be completly bogus, etc. warning("mkdir for '%s' failed!", savePath); perror("mkdir"); - // TODO: Specify an error code here so that callers can - // determine what exactly went wrong. + + switch (errno) { + case EACCES: + setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied")); + break; + case EMLINK: + setError(SFM_DIR_LINKMAX, Common::String("The link count of the parent directory would exceed {LINK_MAX}")); + break; + case ELOOP: + setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path")); + break; + case ENAMETOOLONG: + setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long")); + break; + case ENOENT: + setError(SFM_DIR_NOENT, Common::String("A component of the path path does not exist, or the path is an empty string")); + break; + case ENOTDIR: + setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory")); + break; + case EROFS: + setError(SFM_DIR_ROFS, Common::String("The parent directory resides on a read-only file system")); + break; + } + return 0; } - } else { - // Unknown error, abort. - // TODO: Specify an error code here so that callers can - // determine what exactly went wrong. - return 0; - } + break; + case ENOTDIR: + setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory")); + break; + } } else { // So stat() succeeded. But is the path actually pointing to a // directory? if (!S_ISDIR(sb.st_mode)) { - // TODO: Specify an error code here so that callers can - // determine what exactly went wrong. + setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory")); return 0; } } @@ -164,6 +198,7 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) delete sf; sf = 0; } + return wrapOutSaveFile(sf); } diff --git a/common/savefile.h b/common/savefile.h index fec6fc697b2..7c97ea50587 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -77,9 +77,51 @@ public: */ class SaveFileManager : NonCopyable { +public: + enum SFMError { + SFM_NO_ERROR, //Default state, indicates no error has been recorded + SFM_DIR_ACCESS, //stat(), mkdir()::EACCES: Search or write permission denied + SFM_DIR_LINKMAX, //mkdir()::EMLINK: The link count of the parent directory would exceed {LINK_MAX} + SFM_DIR_LOOP, //stat(), mkdir()::ELOOP: Too many symbolic links encountered while traversing the path + SFM_DIR_NAMETOOLONG, //stat(), mkdir()::ENAMETOOLONG: The path name is too long + SFM_DIR_NOENT, //stat(), mkdir()::ENOENT: A component of the path path does not exist, or the path is an empty string + SFM_DIR_NOTDIR, //stat(), mkdir()::ENOTDIR: A component of the path prefix is not a directory + SFM_DIR_ROFS //mkdir()::EROFS: The parent directory resides on a read-only file system + }; + +protected: + SFMError _error; + String _errorDesc; + public: virtual ~SaveFileManager() {} - + + /** + * Clears the last set error code and string. + */ + virtual void clearError() { _error = SFM_NO_ERROR; _errorDesc = ""; } + + /** + * Returns the last ocurred error code. If none ocurred, returns SFM_NO_ERROR. + * + * @return A SFMError indicating the type of the last error. + */ + virtual SFMError getError() { return _error; } + + /** + * Returns the last ocurred error description. If none ocurred, returns 0. + * + * @return A string describing the last error. + */ + virtual String getErrorDesc() { return _errorDesc; } + + /** + * Sets the last ocurred error. + * @param error Code identifying the last error. + * @param errorDesc String describing the last error. + */ + virtual void setError(SFMError error, String errorDesc) { _error = error; _errorDesc = errorDesc; } + /** * Open the file with name filename in the given directory for saving. * @param filename the filename From b95b3fe4f39dee9f46a522c05791628d085b2704 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 19 Jul 2007 20:21:47 +0000 Subject: [PATCH 22/26] Fixed a subtle bug when browsing directories in the main game chooser. svn-id: r28149 --- backends/fs/posix/posix-fs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 385bab833cf..3708acd2a81 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -243,7 +243,7 @@ AbstractFilesystemNode *POSIXFilesystemNode::getParent() const { const char *start = _path.c_str(); const char *end = lastPathComponent(_path); - return new POSIXFilesystemNode(String(start, end - start), false); + return new POSIXFilesystemNode(String(start, end - start), true); } #endif //#if defined(UNIX) From f42108e63399f4329bb1cadfd2e21d808aea8a89 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Fri, 20 Jul 2007 19:42:38 +0000 Subject: [PATCH 23/26] Added a remove() function to the Common::File class. Also changed the exists() function to account for new capabilities in the FSNode layer. svn-id: r28150 --- common/file.cpp | 40 ++++++++++++++++++++++++++++++++++------ common/file.h | 3 +++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/common/file.cpp b/common/file.cpp index 238c3a4bb33..30ac870f057 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -29,6 +29,10 @@ #include "common/util.h" #include "common/hash-str.h" +#if defined(UNIX) || defined(__SYMBIAN32__) +#include +#endif + #ifdef MACOSX #include "CoreFoundation/CoreFoundation.h" #endif @@ -408,16 +412,40 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { return true; } +bool File::remove(const String &filename){ + if (remove(filename.c_str()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + +bool File::remove(const FilesystemNode &node){ + if (remove(node.getPath()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + bool File::exists(const String &filename) { // First try to find the file it via a FilesystemNode (in case an absolute // path was passed). But we only use this to filter out directories. FilesystemNode file(filename); - // FIXME: can't use isValid() here since at the time of writing - // FilesystemNode is to be unable to find for example files - // added in extrapath - if (file.isDirectory() || !file.exists()) - return false; - + + return (!file.isDirectory() && file.exists()); + + //***DEPRECATED COMMENTS BELOW, LEFT FOR DISCUSSION*** // Next, try to locate the file by *opening* it in read mode. This has // multiple effects: // 1) It takes _filesMap and _defaultDirectories into consideration -> good diff --git a/common/file.h b/common/file.h index 3d816a61049..4d519be475d 100644 --- a/common/file.h +++ b/common/file.h @@ -86,6 +86,9 @@ public: virtual void close(); + virtual bool remove(const String &filename); + virtual bool remove(const FilesystemNode &node); + /** * Checks if the object opened a file successfully. * From 9752c75f407c8bd82006222433fcc3618b9e82bb Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 29 Jul 2007 01:36:59 +0000 Subject: [PATCH 24/26] Add a removeSavefile() to the default savefile manager based on the new Common::File::remove(). svn-id: r28282 --- backends/saves/default/default-saves.cpp | 12 +++++++++--- backends/saves/default/default-saves.h | 1 + common/savefile.h | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index f41455be3f7..299c528e46d 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -29,7 +29,7 @@ #include "common/savefile.h" #include "common/util.h" #include "common/fs.h" -#include "common/str.h" +#include "common/file.h" #include "backends/saves/default/default-saves.h" #include "backends/saves/compressed/compressed-saves.h" @@ -180,10 +180,10 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) break; } } else { - // So stat() succeeded. But is the path actually pointing to a - // directory? + // So stat() succeeded. But is the path actually pointing to a directory? if (!S_ISDIR(sb.st_mode)) { setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory")); + return 0; } } @@ -215,6 +215,12 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) return wrapInSaveFile(sf); } +bool DefaultSaveFileManager::removeSavefile(const char *filename) { + Common::File file; + FilesystemNode savePath(filename); + return file.remove(savePath); +} + Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) { FilesystemNode savePath(getSavePath()); FSList savefiles; diff --git a/backends/saves/default/default-saves.h b/backends/saves/default/default-saves.h index 4b525cabc82..2baddd13359 100644 --- a/backends/saves/default/default-saves.h +++ b/backends/saves/default/default-saves.h @@ -34,6 +34,7 @@ class DefaultSaveFileManager : public Common::SaveFileManager { public: virtual Common::OutSaveFile *openForSaving(const char *filename); virtual Common::InSaveFile *openForLoading(const char *filename); + virtual bool removeSavefile(const char *filename); virtual Common::StringList listSavefiles(const char *regex); }; diff --git a/common/savefile.h b/common/savefile.h index 7c97ea50587..3e1b9ffaaae 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -136,6 +136,13 @@ public: */ virtual InSaveFile *openForLoading(const char *filename) = 0; + /** + * Removes the given savefile from the filesystem. + * @param filename Filename path pointing to the savefile. + * @return true if no error ocurred. false otherwise. + */ + virtual bool removeSavefile(const char *filename) = 0; + /** * Request a list of available savegames with a given regex. * @param regex Regular expression to match. Wildcards like * or ? are available. From 1400d28bfb37fc94f3c44dec0a4d0cef65fb8fb7 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 1 Aug 2007 22:07:50 +0000 Subject: [PATCH 25/26] Initial commit of the new BaseFile implementation. It provides a common ground for file objects across platforms and divides responsibilities between the Common::File class and a base file implementation. Also rearranged the factories into a new directory for clarity. Note 1: The posix-file.h and cpp files are for testing only. Only the ds, ps2 and symbian architecture will use special BaseFile based objects. Note 2: The current code does not yet make use of this new structure, since the Common::File remains intact. svn-id: r28395 --- .../{fs => factories}/abstract-fs-factory.h | 12 +- .../amigaos4/amigaos4-fs-factory.cpp | 7 +- .../amigaos4/amigaos4-fs-factory.h | 3 +- .../dc/ronincd-fs-factory.cpp | 7 +- .../{fs => factories}/dc/ronincd-fs-factory.h | 3 +- .../{fs => factories}/ds/ds-fs-factory.cpp | 7 +- backends/{fs => factories}/ds/ds-fs-factory.h | 3 +- .../{fs => factories}/fs-factory-maker.cpp | 28 +-- .../gp32/gp32-fs-factory.cpp | 7 +- .../{fs => factories}/gp32/gp32-fs-factory.h | 3 +- .../morphos/abox-fs-factory.cpp | 7 +- .../morphos/abox-fs-factory.h | 3 +- .../palmos/palmos-fs-factory.cpp | 7 +- .../palmos/palmos-fs-factory.h | 3 +- .../posix/posix-fs-factory.cpp | 8 +- .../posix/posix-fs-factory.h | 3 +- .../{fs => factories}/ps2/ps2-fs-factory.cpp | 7 +- .../{fs => factories}/ps2/ps2-fs-factory.h | 3 +- .../{fs => factories}/psp/psp-fs-factory.cpp | 7 +- .../{fs => factories}/psp/psp-fs-factory.h | 3 +- .../symbian/symbian-fs-factory.cpp | 7 +- .../symbian/symbian-fs-factory.h | 3 +- .../windows/windows-fs-factory.cpp | 7 +- .../windows/windows-fs-factory.h | 3 +- backends/file/base-file.cpp | 226 ++++++++++++++++++ backends/file/base-file.h | 180 ++++++++++++++ backends/file/ds/ds-file.cpp | 0 backends/file/ds/ds-file.h | 46 ++++ backends/file/posix/posix-file.cpp | 41 ++++ backends/file/posix/posix-file.h | 50 ++++ backends/file/ps2/ps2-file.cpp | 0 backends/file/ps2/ps2-file.h | 24 ++ backends/file/symbian/symbian-file.cpp | 0 backends/file/symbian/symbian-file.h | 29 +++ backends/fs/abstract-fs.h | 4 +- common/file.h | 7 +- common/fs.cpp | 2 +- 37 files changed, 718 insertions(+), 42 deletions(-) rename backends/{fs => factories}/abstract-fs-factory.h (84%) rename backends/{fs => factories}/amigaos4/amigaos4-fs-factory.cpp (70%) rename backends/{fs => factories}/amigaos4/amigaos4-fs-factory.h (89%) rename backends/{fs => factories}/dc/ronincd-fs-factory.cpp (72%) rename backends/{fs => factories}/dc/ronincd-fs-factory.h (89%) rename backends/{fs => factories}/ds/ds-fs-factory.cpp (82%) rename backends/{fs => factories}/ds/ds-fs-factory.h (88%) rename backends/{fs => factories}/fs-factory-maker.cpp (66%) rename backends/{fs => factories}/gp32/gp32-fs-factory.cpp (72%) rename backends/{fs => factories}/gp32/gp32-fs-factory.h (89%) rename backends/{fs => factories}/morphos/abox-fs-factory.cpp (72%) rename backends/{fs => factories}/morphos/abox-fs-factory.h (89%) rename backends/{fs => factories}/palmos/palmos-fs-factory.cpp (72%) rename backends/{fs => factories}/palmos/palmos-fs-factory.h (89%) rename backends/{fs => factories}/posix/posix-fs-factory.cpp (69%) rename backends/{fs => factories}/posix/posix-fs-factory.h (89%) rename backends/{fs => factories}/ps2/ps2-fs-factory.cpp (71%) rename backends/{fs => factories}/ps2/ps2-fs-factory.h (88%) rename backends/{fs => factories}/psp/psp-fs-factory.cpp (72%) rename backends/{fs => factories}/psp/psp-fs-factory.h (88%) rename backends/{fs => factories}/symbian/symbian-fs-factory.cpp (73%) rename backends/{fs => factories}/symbian/symbian-fs-factory.h (89%) rename backends/{fs => factories}/windows/windows-fs-factory.cpp (72%) rename backends/{fs => factories}/windows/windows-fs-factory.h (89%) create mode 100644 backends/file/base-file.cpp create mode 100644 backends/file/base-file.h create mode 100644 backends/file/ds/ds-file.cpp create mode 100644 backends/file/ds/ds-file.h create mode 100644 backends/file/posix/posix-file.cpp create mode 100644 backends/file/posix/posix-file.h create mode 100644 backends/file/ps2/ps2-file.cpp create mode 100644 backends/file/ps2/ps2-file.h create mode 100644 backends/file/symbian/symbian-file.cpp create mode 100644 backends/file/symbian/symbian-file.h diff --git a/backends/fs/abstract-fs-factory.h b/backends/factories/abstract-fs-factory.h similarity index 84% rename from backends/fs/abstract-fs-factory.h rename to backends/factories/abstract-fs-factory.h index 41bfaaa34bc..b06ad632282 100644 --- a/backends/fs/abstract-fs-factory.h +++ b/backends/factories/abstract-fs-factory.h @@ -2,6 +2,8 @@ #define ABSTRACT_FILESYSTEM_FACTORY_H #include "common/str.h" +#include "backends/fs/abstract-fs.h" +#include "backends/file/base-file.h" /** * Creates concrete FilesystemNode objects depending on the current architecture. @@ -9,11 +11,11 @@ class AbstractFilesystemFactory { public: typedef Common::String String; - + /** * Destructor. */ - virtual ~AbstractFilesystemFactory() {}; + virtual ~AbstractFilesystemFactory() {} /** * Returns a node representing the "current directory". @@ -43,6 +45,12 @@ public: * On Windows, it will be a special node which "contains" all drives (C:, D:, E:). */ virtual AbstractFilesystemNode *makeRootFileNode() const = 0; + + /** + * Creates a base file usable by the Common::File wrapper to implement several + * methods. + */ + virtual BaseFile *makeBaseFile() const = 0; }; #endif /*ABSTRACT_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/amigaos4/amigaos4-fs-factory.cpp b/backends/factories/amigaos4/amigaos4-fs-factory.cpp similarity index 70% rename from backends/fs/amigaos4/amigaos4-fs-factory.cpp rename to backends/factories/amigaos4/amigaos4-fs-factory.cpp index becbd490038..2d73c4dbdce 100644 --- a/backends/fs/amigaos4/amigaos4-fs-factory.cpp +++ b/backends/factories/amigaos4/amigaos4-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/amigaos4/amigaos4-fs-factory.h" +#include "backends/factories/amigaos4/amigaos4-fs-factory.h" #include "backends/fs/amigaos4/amigaos4-fs.cpp" +#include "backends/file/amigaos4/amigaos4-file.h" DECLARE_SINGLETON(AmigaOSFilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *AmigaOSFilesystemFactory::makeCurrentDirectoryFileNode() AbstractFilesystemNode *AmigaOSFilesystemFactory::makeFileNodePath(const String &path) const { return new AmigaOSFilesystemNode(path); } + +BaseFile *AmigaOSFilesystemFactory::makeBaseFile() const { + return new AmigaOSFile(); +} diff --git a/backends/fs/amigaos4/amigaos4-fs-factory.h b/backends/factories/amigaos4/amigaos4-fs-factory.h similarity index 89% rename from backends/fs/amigaos4/amigaos4-fs-factory.h rename to backends/factories/amigaos4/amigaos4-fs-factory.h index ed8af246483..86f77ca6fac 100644 --- a/backends/fs/amigaos4/amigaos4-fs-factory.h +++ b/backends/factories/amigaos4/amigaos4-fs-factory.h @@ -2,7 +2,7 @@ #define AMIGAOS_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates AmigaOSFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: AmigaOSFilesystemFactory() {}; diff --git a/backends/fs/dc/ronincd-fs-factory.cpp b/backends/factories/dc/ronincd-fs-factory.cpp similarity index 72% rename from backends/fs/dc/ronincd-fs-factory.cpp rename to backends/factories/dc/ronincd-fs-factory.cpp index 0229a44c453..c28d735aec8 100644 --- a/backends/fs/dc/ronincd-fs-factory.cpp +++ b/backends/factories/dc/ronincd-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/dc/ronincd-fs-factory.h" +#include "backends/factories/dc/ronincd-fs-factory.h" #include "backends/fs/dc/dc-fs.cpp" +#include "backends/file/base-file.h" DECLARE_SINGLETON(RoninCDFilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *RoninCDFilesystemFactory::makeCurrentDirectoryFileNode() AbstractFilesystemNode *RoninCDFilesystemFactory::makeFileNodePath(const String &path) const { return new RoninCDFilesystemNode(path, true); } + +BaseFile *RoninCDFilesystemFactory::makeBaseFile() const { + return new BaseFile(); +} diff --git a/backends/fs/dc/ronincd-fs-factory.h b/backends/factories/dc/ronincd-fs-factory.h similarity index 89% rename from backends/fs/dc/ronincd-fs-factory.h rename to backends/factories/dc/ronincd-fs-factory.h index 426ef7ef2c0..5aa6f7a91f9 100644 --- a/backends/fs/dc/ronincd-fs-factory.h +++ b/backends/factories/dc/ronincd-fs-factory.h @@ -2,7 +2,7 @@ #define RONINCD_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates RoninCDFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: RoninCDFilesystemFactory() {}; diff --git a/backends/fs/ds/ds-fs-factory.cpp b/backends/factories/ds/ds-fs-factory.cpp similarity index 82% rename from backends/fs/ds/ds-fs-factory.cpp rename to backends/factories/ds/ds-fs-factory.cpp index 7e64b374115..94bf8e75d06 100644 --- a/backends/fs/ds/ds-fs-factory.cpp +++ b/backends/factories/ds/ds-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/ds/ds-fs-factory.h" +#include "backends/factories/ds/ds-fs-factory.h" #include "backends/fs/ds/ds-fs.cpp" +#include "backends/file/ds/ds-file.h" #include "dsmain.h" //for the isGBAMPAvailable() function DECLARE_SINGLETON(DSFilesystemFactory); @@ -27,3 +28,7 @@ AbstractFilesystemNode *DSFilesystemFactory::makeFileNodePath(const String &path return new DS::DSFileSystemNode(path); } } + +BaseFile *DSFilesystemFactory::makeBaseFile() const { + return new DSFile(); +} diff --git a/backends/fs/ds/ds-fs-factory.h b/backends/factories/ds/ds-fs-factory.h similarity index 88% rename from backends/fs/ds/ds-fs-factory.h rename to backends/factories/ds/ds-fs-factory.h index a2e96aa548a..eecd4066822 100644 --- a/backends/fs/ds/ds-fs-factory.h +++ b/backends/factories/ds/ds-fs-factory.h @@ -2,7 +2,7 @@ #define DS_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates DSFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: DSFilesystemFactory() {}; diff --git a/backends/fs/fs-factory-maker.cpp b/backends/factories/fs-factory-maker.cpp similarity index 66% rename from backends/fs/fs-factory-maker.cpp rename to backends/factories/fs-factory-maker.cpp index bae3d1a30a3..8bef982f378 100644 --- a/backends/fs/fs-factory-maker.cpp +++ b/backends/factories/fs-factory-maker.cpp @@ -1,4 +1,4 @@ -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /* * All the following includes choose, at compile time, which specific backend will be used @@ -8,57 +8,57 @@ * all build environments. Additionally, this results in smaller binaries. */ #if defined(__amigaos4__) - #include "backends/fs/amigaos4/amigaos4-fs-factory.cpp" + #include "backends/factories/amigaos4/amigaos4-fs-factory.cpp" #endif #if defined(__DC__) - #include "backends/fs/dc/ronincd-fs-factory.cpp" + #include "backends/factories/dc/ronincd-fs-factory.cpp" #endif #if defined(__DS__) - #include "backends/fs/ds/ds-fs-factory.cpp" + #include "backends/factories/ds/ds-fs-factory.cpp" #endif #if defined(__GP32__) - #include "backends/fs/gp32/gp32-fs-factory.cpp" + #include "backends/factories/gp32/gp32-fs-factory.cpp" #endif #if defined(__MORPHOS__) - #include "backends/fs/morphos/abox-fs-factory.cpp" + #include "backends/factories/morphos/abox-fs-factory.cpp" #endif #if defined(PALMOS_MODE) - #include "backends/fs/palmos/palmos-fs-factory.cpp" + #include "backends/factories/palmos/palmos-fs-factory.cpp" #endif #if defined(__PLAYSTATION2__) - #include "backends/fs/ps2/ps2-fs-factory.cpp" + #include "backends/factories/ps2/ps2-fs-factory.cpp" #endif #if defined(__PSP__) - #include "backends/fs/psp/psp-fs-factory.cpp" + #include "backends/factories/psp/psp-fs-factory.cpp" #endif #if defined(__SYMBIAN32__) - #include "backends/fs/symbian/symbian-fs-factory.cpp" + #include "backends/factories/symbian/symbian-fs-factory.cpp" #endif #if defined(UNIX) - #include "backends/fs/posix/posix-fs-factory.cpp" + #include "backends/factories/posix/posix-fs-factory.cpp" #endif #if defined(WIN32) - #include "backends/fs/windows/windows-fs-factory.cpp" + #include "backends/factories/windows/windows-fs-factory.cpp" #endif /** - * Creates concrete FilesystemFactory objects depending on the current architecture. + * Creates concrete FilesystemFactory and FileFactory objects depending on the current architecture. */ class FilesystemFactoryMaker { public: /** - * Returns the correct concrete factory depending on the current build architecture. + * Returns the correct concrete filesystem factory depending on the current build architecture. */ static AbstractFilesystemFactory *makeFactory(); diff --git a/backends/fs/gp32/gp32-fs-factory.cpp b/backends/factories/gp32/gp32-fs-factory.cpp similarity index 72% rename from backends/fs/gp32/gp32-fs-factory.cpp rename to backends/factories/gp32/gp32-fs-factory.cpp index 6328836c0e0..bffbffa21da 100644 --- a/backends/fs/gp32/gp32-fs-factory.cpp +++ b/backends/factories/gp32/gp32-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/gp32/gp32-fs-factory.h" +#include "backends/factories/gp32/gp32-fs-factory.h" #include "backends/fs/gp32/gp32-fs.cpp" +#include "backends/file/base-file.h" DECLARE_SINGLETON(GP32FilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *GP32FilesystemFactory::makeCurrentDirectoryFileNode() co AbstractFilesystemNode *GP32FilesystemFactory::makeFileNodePath(const String &path) const { return new GP32FilesystemNode(path); } + +BaseFile *GP32FilesystemFactory::makeBaseFile() const { + return new BaseFile(); +} diff --git a/backends/fs/gp32/gp32-fs-factory.h b/backends/factories/gp32/gp32-fs-factory.h similarity index 89% rename from backends/fs/gp32/gp32-fs-factory.h rename to backends/factories/gp32/gp32-fs-factory.h index fc15b52bc6b..b5e5df3b6b2 100644 --- a/backends/fs/gp32/gp32-fs-factory.h +++ b/backends/factories/gp32/gp32-fs-factory.h @@ -2,7 +2,7 @@ #define GP32_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates GP32FilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: GP32FilesystemFactory() {}; diff --git a/backends/fs/morphos/abox-fs-factory.cpp b/backends/factories/morphos/abox-fs-factory.cpp similarity index 72% rename from backends/fs/morphos/abox-fs-factory.cpp rename to backends/factories/morphos/abox-fs-factory.cpp index 9de810c3619..5659baf6f9c 100644 --- a/backends/fs/morphos/abox-fs-factory.cpp +++ b/backends/factories/morphos/abox-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/morphos/abox-fs-factory.h" +#include "backends/factories/morphos/abox-fs-factory.h" #include "backends/fs/morphos/abox-fs.cpp" +#include "backends/file/base-file.h" DECLARE_SINGLETON(ABoxFilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *ABoxFilesystemFactory::makeCurrentDirectoryFileNode() co AbstractFilesystemNode *ABoxFilesystemFactory::makeFileNodePath(const String &path) const { return new ABoxFilesystemNode(path); } + +BaseFile *ABoxFilesystemFactory::makeBaseFile() const { + return new BaseFile(); +} diff --git a/backends/fs/morphos/abox-fs-factory.h b/backends/factories/morphos/abox-fs-factory.h similarity index 89% rename from backends/fs/morphos/abox-fs-factory.h rename to backends/factories/morphos/abox-fs-factory.h index 35f4472b8b3..ff282b5bb9a 100644 --- a/backends/fs/morphos/abox-fs-factory.h +++ b/backends/factories/morphos/abox-fs-factory.h @@ -2,7 +2,7 @@ #define ABOX_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates ABoxFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: ABoxFilesystemFactory() {}; diff --git a/backends/fs/palmos/palmos-fs-factory.cpp b/backends/factories/palmos/palmos-fs-factory.cpp similarity index 72% rename from backends/fs/palmos/palmos-fs-factory.cpp rename to backends/factories/palmos/palmos-fs-factory.cpp index 1b0db0f0420..275118b5188 100644 --- a/backends/fs/palmos/palmos-fs-factory.cpp +++ b/backends/factories/palmos/palmos-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/palmos/palmos-fs-factory.h" +#include "backends/factories/palmos/palmos-fs-factory.h" #include "backends/fs/palmos/palmos-fs.cpp" +#include "backends/file/base-file.h" DECLARE_SINGLETON(PalmOSFilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() AbstractFilesystemNode *PalmOSFilesystemFactory::makeFileNodePath(const String &path) const { return new PalmOSFilesystemNode(path); } + +BaseFile *PalmOSFilesystemFactory::makeBaseFile() const { + return new BaseFile(); +} diff --git a/backends/fs/palmos/palmos-fs-factory.h b/backends/factories/palmos/palmos-fs-factory.h similarity index 89% rename from backends/fs/palmos/palmos-fs-factory.h rename to backends/factories/palmos/palmos-fs-factory.h index cfe246e8068..65af4e2fe6c 100644 --- a/backends/fs/palmos/palmos-fs-factory.h +++ b/backends/factories/palmos/palmos-fs-factory.h @@ -2,7 +2,7 @@ #define PALMOS_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates PalmOSFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: PalmOSFilesystemFactory() {}; diff --git a/backends/fs/posix/posix-fs-factory.cpp b/backends/factories/posix/posix-fs-factory.cpp similarity index 69% rename from backends/fs/posix/posix-fs-factory.cpp rename to backends/factories/posix/posix-fs-factory.cpp index bed3dc5f8fd..9b77e315572 100644 --- a/backends/fs/posix/posix-fs-factory.cpp +++ b/backends/factories/posix/posix-fs-factory.cpp @@ -1,5 +1,7 @@ -#include "backends/fs/posix/posix-fs-factory.h" +#include "backends/factories/posix/posix-fs-factory.h" #include "backends/fs/posix/posix-fs.cpp" +#include "backends/file/posix/posix-file.cpp" +//#include "backends/file/base-file.cpp" DECLARE_SINGLETON(POSIXFilesystemFactory); @@ -16,3 +18,7 @@ AbstractFilesystemNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() c AbstractFilesystemNode *POSIXFilesystemFactory::makeFileNodePath(const String &path) const { return new POSIXFilesystemNode(path, true); } + +BaseFile *POSIXFilesystemFactory::makeBaseFile() const { + return new POSIXFile(); +} diff --git a/backends/fs/posix/posix-fs-factory.h b/backends/factories/posix/posix-fs-factory.h similarity index 89% rename from backends/fs/posix/posix-fs-factory.h rename to backends/factories/posix/posix-fs-factory.h index 93f0ac115b8..aef411c92bc 100644 --- a/backends/fs/posix/posix-fs-factory.h +++ b/backends/factories/posix/posix-fs-factory.h @@ -2,7 +2,7 @@ #define POSIX_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates POSIXFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: POSIXFilesystemFactory() {}; diff --git a/backends/fs/ps2/ps2-fs-factory.cpp b/backends/factories/ps2/ps2-fs-factory.cpp similarity index 71% rename from backends/fs/ps2/ps2-fs-factory.cpp rename to backends/factories/ps2/ps2-fs-factory.cpp index 5f109745018..cd6f2937945 100644 --- a/backends/fs/ps2/ps2-fs-factory.cpp +++ b/backends/factories/ps2/ps2-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/ps2/ps2-fs-factory.h" +#include "backends/factories/ps2/ps2-fs-factory.h" #include "backends/fs/ps2/ps2-fs.cpp" +#include "backends/file/ps2/ps2-file.h" DECLARE_SINGLETON(Ps2FilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *Ps2FilesystemFactory::makeCurrentDirectoryFileNode() con AbstractFilesystemNode *Ps2FilesystemFactory::makeFileNodePath(const String &path) const { return new Ps2FilesystemNode(path); } + +BaseFile *Ps2FilesystemFactory::makeBaseFile() const { + return new Ps2File(); +} diff --git a/backends/fs/ps2/ps2-fs-factory.h b/backends/factories/ps2/ps2-fs-factory.h similarity index 88% rename from backends/fs/ps2/ps2-fs-factory.h rename to backends/factories/ps2/ps2-fs-factory.h index 6f0da114c57..e1ddee9677f 100644 --- a/backends/fs/ps2/ps2-fs-factory.h +++ b/backends/factories/ps2/ps2-fs-factory.h @@ -2,7 +2,7 @@ #define PS2_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates PS2FilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: Ps2FilesystemFactory() {}; diff --git a/backends/fs/psp/psp-fs-factory.cpp b/backends/factories/psp/psp-fs-factory.cpp similarity index 72% rename from backends/fs/psp/psp-fs-factory.cpp rename to backends/factories/psp/psp-fs-factory.cpp index 6fc829baf14..9c9bef21e7b 100644 --- a/backends/fs/psp/psp-fs-factory.cpp +++ b/backends/factories/psp/psp-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/psp/psp-fs-factory.h" +#include "backends/factories/psp/psp-fs-factory.h" #include "backends/fs/psp/psp_fs.cpp" +#include "backends/file/base-file.h" DECLARE_SINGLETON(PSPFilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() con AbstractFilesystemNode *PSPFilesystemFactory::makeFileNodePath(const String &path) const { return new PSPFilesystemNode(path, true); } + +BaseFile *PSPFilesystemFactory::makeBaseFile() const { + return new BaseFile(); +} diff --git a/backends/fs/psp/psp-fs-factory.h b/backends/factories/psp/psp-fs-factory.h similarity index 88% rename from backends/fs/psp/psp-fs-factory.h rename to backends/factories/psp/psp-fs-factory.h index b1a44b90c4e..0d30efd5ad0 100644 --- a/backends/fs/psp/psp-fs-factory.h +++ b/backends/factories/psp/psp-fs-factory.h @@ -2,7 +2,7 @@ #define PSP_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates PSPFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: PSPFilesystemFactory() {}; diff --git a/backends/fs/symbian/symbian-fs-factory.cpp b/backends/factories/symbian/symbian-fs-factory.cpp similarity index 73% rename from backends/fs/symbian/symbian-fs-factory.cpp rename to backends/factories/symbian/symbian-fs-factory.cpp index 87b1f0f05d2..a21b40a0954 100644 --- a/backends/fs/symbian/symbian-fs-factory.cpp +++ b/backends/factories/symbian/symbian-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/symbian/symbian-fs-factory.h" +#include "backends/factories/symbian/symbian-fs-factory.h" #include "backends/fs/symbian/symbian-fs.cpp" +#include "backends/file/symbian/symbian-file.h" DECLARE_SINGLETON(SymbianFilesystemFactory); @@ -16,3 +17,7 @@ AbstractFilesystemNode *SymbianFilesystemFactory::makeCurrentDirectoryFileNode() AbstractFilesystemNode *SymbianFilesystemFactory::makeFileNodePath(const String &path) const { return new SymbianFilesystemNode(path); } + +BaseFile *SymbianFilesystemFactory::makeBaseFile() const { + return new SymbianFile(); +} diff --git a/backends/fs/symbian/symbian-fs-factory.h b/backends/factories/symbian/symbian-fs-factory.h similarity index 89% rename from backends/fs/symbian/symbian-fs-factory.h rename to backends/factories/symbian/symbian-fs-factory.h index 69749cbd7ec..49f92410ce8 100644 --- a/backends/fs/symbian/symbian-fs-factory.h +++ b/backends/factories/symbian/symbian-fs-factory.h @@ -2,7 +2,7 @@ #define SYMBIAN_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates SymbianFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: SymbianFilesystemFactory() {}; diff --git a/backends/fs/windows/windows-fs-factory.cpp b/backends/factories/windows/windows-fs-factory.cpp similarity index 72% rename from backends/fs/windows/windows-fs-factory.cpp rename to backends/factories/windows/windows-fs-factory.cpp index 3d7a3cc6724..55c48c3b9cd 100644 --- a/backends/fs/windows/windows-fs-factory.cpp +++ b/backends/factories/windows/windows-fs-factory.cpp @@ -1,5 +1,6 @@ -#include "backends/fs/windows/windows-fs-factory.h" +#include "backends/factories/windows/windows-fs-factory.h" #include "backends/fs/windows/windows-fs.cpp" +#include "backends/file/base-file.h" DECLARE_SINGLETON(WindowsFilesystemFactory); @@ -14,3 +15,7 @@ AbstractFilesystemNode *WindowsFilesystemFactory::makeCurrentDirectoryFileNode() AbstractFilesystemNode *WindowsFilesystemFactory::makeFileNodePath(const String &path) const { return new WindowsFilesystemNode(path, false); } + +BaseFile *WindowsFilesystemFactory::makeBaseFile() const { + return new BaseFile(); +} diff --git a/backends/fs/windows/windows-fs-factory.h b/backends/factories/windows/windows-fs-factory.h similarity index 89% rename from backends/fs/windows/windows-fs-factory.h rename to backends/factories/windows/windows-fs-factory.h index 7d17802b522..1f85d8f1c34 100644 --- a/backends/fs/windows/windows-fs-factory.h +++ b/backends/factories/windows/windows-fs-factory.h @@ -2,7 +2,7 @@ #define WINDOWS_FILESYSTEM_FACTORY_H #include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" +#include "backends/factories/abstract-fs-factory.h" /** * Creates WindowsFilesystemNode objects. @@ -16,6 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + virtual BaseFile *makeBaseFile() const; protected: WindowsFilesystemFactory() {}; diff --git a/backends/file/base-file.cpp b/backends/file/base-file.cpp new file mode 100644 index 00000000000..3174f5828c2 --- /dev/null +++ b/backends/file/base-file.cpp @@ -0,0 +1,226 @@ +/* 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. + * + * 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: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/branches/gsoc2007-fsnode/common/file.cpp $ + * $Id: file.cpp 28150 2007-07-20 19:42:38Z david_corrales $ + * + */ + +#include "backends/file/base-file.h" +#include "common/fs.h" +#include "common/hashmap.h" +#include "common/util.h" +#include "common/hash-str.h" + +#if defined(UNIX) || defined(__SYMBIAN32__) +#include +#endif + +#ifdef MACOSX +#include "CoreFoundation/CoreFoundation.h" +#endif + +BaseFile::BaseFile() { + _handle = 0; + _ioFailed = false; +} + +//#define DEBUG_FILE_REFCOUNT + +BaseFile::~BaseFile() { +#ifdef DEBUG_FILE_REFCOUNT + warning("File::~File on file '%s'", _name.c_str()); +#endif + close(); +} + +bool BaseFile::open(const String &filename, AccessMode mode) { + assert(mode == kFileReadMode || mode == kFileWriteMode); + + if (filename.empty()) { + error("File::open: No filename was specified"); + } + + if (_handle) { + error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); + } + + _name.clear(); + clearIOFailed(); + + const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb"; + _handle = _fopen(filename.c_str(), modeStr); + + if (_handle == NULL) { + if (mode == kFileReadMode) + debug(2, "File %s not found", filename.c_str()); + else + debug(2, "File %s not opened", filename.c_str()); + return false; + } + + _name = filename; + +#ifdef DEBUG_FILE_REFCOUNT + warning("File::open on file '%s'", _name.c_str()); +#endif + + return true; +} + +bool BaseFile::remove(const String &filename){ + if (remove(filename.c_str()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + +void BaseFile::close() { + if (_handle) + _fclose((FILE *)_handle); + _handle = NULL; +} + +bool BaseFile::isOpen() const { + return _handle != NULL; +} + +bool BaseFile::ioFailed() const { + return _ioFailed != 0; +} + +void BaseFile::clearIOFailed() { + _ioFailed = false; +} + +bool BaseFile::eof() const { + if (_handle == NULL) { + error("File::eof: File is not open!"); + return false; + } + + return _feof((FILE *)_handle) != 0; +} + +uint32 BaseFile::pos() const { + if (_handle == NULL) { + error("File::pos: File is not open!"); + return 0; + } + + return _ftell((FILE *)_handle); +} + +uint32 BaseFile::size() const { + if (_handle == NULL) { + error("File::size: File is not open!"); + return 0; + } + + uint32 oldPos = _ftell((FILE *)_handle); + _fseek((FILE *)_handle, 0, SEEK_END); + uint32 length = _ftell((FILE *)_handle); + _fseek((FILE *)_handle, oldPos, SEEK_SET); + + return length; +} + +void BaseFile::seek(int32 offs, int whence) { + if (_handle == NULL) { + error("File::seek: File is not open!"); + return; + } + + if (_fseek((FILE *)_handle, offs, whence) != 0) + _clearerr((FILE *)_handle); +} + +uint32 BaseFile::read(void *ptr, uint32 len) { + byte *ptr2 = (byte *)ptr; + uint32 real_len; + + if (_handle == NULL) { + error("File::read: File is not open!"); + return 0; + } + + if (len == 0) + return 0; + + real_len = _fread(ptr2, 1, len, (FILE *)_handle); + if (real_len < len) { + _ioFailed = true; + } + + return real_len; +} + +/*uint32 File::write(const void *ptr, uint32 len) { + if (_handle == NULL) { + error("File::write: File is not open!"); + return 0; + } + + if (len == 0) + return 0; + + if ((uint32)_fwrite(ptr, 1, len, (FILE *)_handle) != len) { + _ioFailed = true; + } + + return len; +}*/ + +void BaseFile::_clearerr(FILE *stream) { + clearerr(stream); +} + +int BaseFile::_fclose(FILE *stream) { + return fclose(stream); +} + +int BaseFile::_feof(FILE *stream) const { + return feof(stream); +} +FILE *BaseFile::_fopen(const char * filename, const char * mode) { + return fopen(filename, mode); +} + +int BaseFile::_fread(void *buffer, size_t obj_size, size_t num, FILE *stream) { + return fread(buffer, obj_size, num, stream); +} + +int BaseFile::_fseek(FILE * stream, long int offset, int origin) const { + return fseek(stream, offset, origin); +} + +long BaseFile::_ftell(FILE *stream) const { + return ftell(stream); +} + +int BaseFile::_fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream) { + return fwrite(ptr, obj_size, count, stream); +} diff --git a/backends/file/base-file.h b/backends/file/base-file.h new file mode 100644 index 00000000000..f383a1a453a --- /dev/null +++ b/backends/file/base-file.h @@ -0,0 +1,180 @@ +/* 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. + * + * 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_BASE_FILE_H +#define BACKENDS_BASE_FILE_H + +#include "common/stdafx.h" +#include "common/scummsys.h" +#include "common/str.h" +#include "common/stream.h" + +using namespace Common; + +/** + * Implements several file related functions used by the Common::File wrapper. + */ +class BaseFile : public Common::SeekableReadStream { +protected: + /** File handle to the actual file; 0 if no file is open. */ + void *_handle; + + /** Status flag which tells about recent I/O failures. */ + bool _ioFailed; + + /** The name of this file, for debugging. */ + String _name; + + /** + * The following functions are meant to be redefined by subclasses if needed. E.g. ps2-file.h or ds-file.h + * They behave as the C++ standard I/O methods so refer to the standard documentation for usage. + * + * This design was inspired on the Template pattern. + */ + void _clearerr(FILE *stream); + int _fclose(FILE *stream); + int _feof(FILE *stream) const; + FILE *_fopen(const char * filename, const char * mode); + int _fread(void *buffer, size_t obj_size, size_t num, FILE *stream); + int _fseek(FILE * stream, long int offset, int origin) const; + long _ftell(FILE *stream) const; + int _fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream); + +private: + // Disallow copying BaseFile objects. There is not strict reason for this, + // except that so far we never had real need for such a feature, and + // code that accidentally copied File objects tended to break in strange + // ways. + BaseFile(const BaseFile &f); + BaseFile &operator =(const BaseFile &f); + +public: + enum AccessMode { + kFileReadMode = 1, + kFileWriteMode = 2 + }; + + BaseFile(); + virtual ~BaseFile(); + + /** + * Clears the flag for the last ocurred IO failure. + */ + void clearIOFailed(); + + /** + * Closes the file handle. + */ + virtual void close(); + + /** + * Checks for end of file. + * + * @return: true if the end of file is reached, false otherwise. + */ + bool eof() const; + + /** + * Checks for the end of the stream. In this case it's equivalent to eof(). + * + * @return: true if the end of the stream is reached, false otherwise. + */ + bool eos() const { return eof(); } + + /** + * Checks whether the last IO operation failed. + * + * @return: true if the last IO operation failed, false otherwise. + */ + bool ioFailed() const; + + /** + * Obtain the filename of the opened file. + * + * @return: the filename of the opened file. + */ + const char *name() const { return _name.c_str(); } + + /** + * Checks if the object opened a file successfully. + * + * @return: true if any file is opened, false otherwise. + */ + bool isOpen() const; + + /** + * Opens a given file. + * + * @param filename Path of the file to be opened. + * @param mode Mode to open to file. Read or write. + */ + virtual bool open(const String &filename, AccessMode mode = kFileReadMode); + + /** + * Obtain the position of the seek pointer. + * + * @return The position of the seek pointer within the file. + */ + uint32 pos() const; + + /** + * Read a chunk of data from the file. + * + * @param dataPtr Buffer to the place the read contents. + * @param dataSize Amount of bytes to read from the file. + * @return Amount of read bytes. + */ + uint32 read(void *dataPtr, uint32 dataSize); + + /** + * Remove a given file from the filesystem. + * + * @param filename Path to the file to be removed. + * @return true if the file was removed succesfully, false otherwise. + */ + virtual bool remove(const String &filename); + + /** + * Move the seek pointer within the file. + * + * @param offs Amount of bytes to move the pointer within the file. + * @param whence Starting point of the seek cursor. + */ + void seek(int32 offs, int whence = SEEK_SET); + + /** + * Obtain the size of the file. + * + * @return The size of the file in bytes. + */ + uint32 size() const; + + //TODO: Remove the write functions? Also remove the enum then + /** + * Write a chunk of data to the file. + */ + //uint32 write(const void *dataPtr, uint32 dataSize); +}; + +#endif //BACKENDS_BASE_FILE_H diff --git a/backends/file/ds/ds-file.cpp b/backends/file/ds/ds-file.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/backends/file/ds/ds-file.h b/backends/file/ds/ds-file.h new file mode 100644 index 00000000000..e133def5480 --- /dev/null +++ b/backends/file/ds/ds-file.h @@ -0,0 +1,46 @@ +#ifdef __DS__ + + // These functions replease the standard library functions of the same name. + // As this header is included after the standard one, I have the chance to #define + // all of these to my own code. + // + // A #define is the only way, as redefinig the functions would cause linker errors. + + // These functions need to be #undef'ed, as their original definition + // in devkitarm is done with #includes (ugh!) + #undef feof + #undef clearerr + //#undef getc + //#undef ferror + + + //void std_fprintf(FILE* handle, const char* fmt, ...); // used in common/util.cpp + //void std_fflush(FILE* handle); // used in common/util.cpp + + //char* std_fgets(char* str, int size, FILE* file); // not used + //int std_getc(FILE* handle); // not used + //char* std_getcwd(char* dir, int dunno); // not used + //void std_cwd(char* dir); // not used + //int std_ferror(FILE* handle); // not used + + // Only functions used in the ScummVM source have been defined here! + #define fopen(name, mode) DS::std_fopen(name, mode) + #define fclose(handle) DS::std_fclose(handle) + #define fread(ptr, size, items, file) DS::std_fread(ptr, size, items, file) + #define fwrite(ptr, size, items, file) DS::std_fwrite(ptr, size, items, file) + #define feof(handle) DS::std_feof(handle) + #define ftell(handle) DS::std_ftell(handle) + #define fseek(handle, offset, whence) DS::std_fseek(handle, offset, whence) + #define clearerr(handle) DS::std_clearerr(handle) + + //#define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__) + + //#define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); } + //#define fflush(file) DS::std_fflush(file) // used in common/util.cpp + + //#define fgets(str, size, file) DS::std_fgets(str, size, file) // not used + //#define getc(handle) DS::std_getc(handle) // not used + //#define getcwd(dir, dunno) DS::std_getcwd(dir, dunno) // not used + //#define ferror(handle) DS::std_ferror(handle) // not used + +#endif \ No newline at end of file diff --git a/backends/file/posix/posix-file.cpp b/backends/file/posix/posix-file.cpp new file mode 100644 index 00000000000..84c82fa5c55 --- /dev/null +++ b/backends/file/posix/posix-file.cpp @@ -0,0 +1,41 @@ +#include "backends/file/posix/posix-file.h" + +POSIXFile::POSIXFile() : BaseFile() { + // +} + +POSIXFile::~POSIXFile() { + close(); +} + +void POSIXFile::_clearerr(FILE *stream) { + clearerr(stream); +} + +int POSIXFile::_fclose(FILE *stream) { + return fclose(stream); +} + +int POSIXFile::_feof(FILE *stream) const { + return feof(stream); +} +FILE *POSIXFile::_fopen(const char * filename, const char * mode) { + printf("Opened a file!\n"); + return fopen(filename, mode); +} + +int POSIXFile::_fread(void *buffer, size_t obj_size, size_t num, FILE *stream) { + return fread(buffer, obj_size, num, stream); +} + +int POSIXFile::_fseek(FILE * stream, long int offset, int origin) const { + return fseek(stream, offset, origin); +} + +long POSIXFile::_ftell(FILE *stream) const { + return ftell(stream); +} + +int POSIXFile::_fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream) { + return fwrite(ptr, obj_size, count, stream); +} diff --git a/backends/file/posix/posix-file.h b/backends/file/posix/posix-file.h new file mode 100644 index 00000000000..00ce307df53 --- /dev/null +++ b/backends/file/posix/posix-file.h @@ -0,0 +1,50 @@ +/* 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. + * + * 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_POSIX_FILE_H +#define BACKENDS_POSIX_FILE_H + +#include "backends/file/base-file.cpp" + +/** + * Implements several POSIX specific file related functions used by the Common::File wrapper. + * + * Parts of this class are documented in the base file class, BaseFile. + */ +class POSIXFile : public BaseFile { +public: + POSIXFile(); + ~POSIXFile(); +protected: + void _clearerr(FILE *stream); + int _fclose(FILE *stream); + int _feof(FILE *stream) const; + FILE *_fopen(const char * filename, const char * mode); + int _fread(void *buffer, size_t obj_size, size_t num, FILE *stream); + int _fseek(FILE * stream, long int offset, int origin) const; + long _ftell(FILE *stream) const; + int _fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream); +}; + +#endif //BACKENDS_POSIX_FILE_H diff --git a/backends/file/ps2/ps2-file.cpp b/backends/file/ps2/ps2-file.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/backends/file/ps2/ps2-file.h b/backends/file/ps2/ps2-file.h new file mode 100644 index 00000000000..e7acfd801f8 --- /dev/null +++ b/backends/file/ps2/ps2-file.h @@ -0,0 +1,24 @@ +#ifdef __PLAYSTATION2__ + // for those replaced fopen/fread/etc functions + typedef unsigned long uint64; + typedef signed long int64; + #include "backends/platform/ps2/fileio.h" + + #define fopen(a, b) ps2_fopen(a, b) + #define fclose(a) ps2_fclose(a) + #define fseek(a, b, c) ps2_fseek(a, b, c) + #define ftell(a) ps2_ftell(a) + #define feof(a) ps2_feof(a) + #define fread(a, b, c, d) ps2_fread(a, b, c, d) + #define fwrite(a, b, c, d) ps2_fwrite(a, b, c, d) + + //#define fprintf ps2_fprintf // used in common/util.cpp + //#define fflush(a) ps2_fflush(a) // used in common/util.cpp + + //#define fgetc(a) ps2_fgetc(a) // not used + //#define fgets(a, b, c) ps2_fgets(a, b, c) // not used + //#define fputc(a, b) ps2_fputc(a, b) // not used + //#define fputs(a, b) ps2_fputs(a, b) // not used + + //#define fsize(a) ps2_fsize(a) // not used -- and it is not a standard function either +#endif \ No newline at end of file diff --git a/backends/file/symbian/symbian-file.cpp b/backends/file/symbian/symbian-file.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/backends/file/symbian/symbian-file.h b/backends/file/symbian/symbian-file.h new file mode 100644 index 00000000000..7807a9355ab --- /dev/null +++ b/backends/file/symbian/symbian-file.h @@ -0,0 +1,29 @@ +#ifdef __SYMBIAN32__ + #undef feof + #undef clearerr + + #define FILE void + + FILE* symbian_fopen(const char* name, const char* mode); + void symbian_fclose(FILE* handle); + size_t symbian_fread(const void* ptr, size_t size, size_t numItems, FILE* handle); + size_t symbian_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle); + bool symbian_feof(FILE* handle); + long int symbian_ftell(FILE* handle); + int symbian_fseek(FILE* handle, long int offset, int whence); + void symbian_clearerr(FILE* handle); + + // Only functions used in the ScummVM source have been defined here! + #define fopen(name, mode) symbian_fopen(name, mode) + #define fclose(handle) symbian_fclose(handle) + #define fread(ptr, size, items, file) symbian_fread(ptr, size, items, file) + #define fwrite(ptr, size, items, file) symbian_fwrite(ptr, size, items, file) + #define feof(handle) symbian_feof(handle) + #define ftell(handle) symbian_ftell(handle) + #define fseek(handle, offset, whence) symbian_fseek(handle, offset, whence) + #define clearerr(handle) symbian_clearerr(handle) +#endif + +#if defined(UNIX) || defined(__SYMBIAN32__) +#include +#endif \ No newline at end of file diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 371c38a495b..85fcbcdebbe 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -46,7 +46,7 @@ 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 @@ -77,7 +77,7 @@ public: * Destructor. */ virtual ~AbstractFilesystemNode() {} - + /* * Indicates whether the object refered by this path exists in the filesystem or not. */ diff --git a/common/file.h b/common/file.h index 4d519be475d..d2eae1f28c7 100644 --- a/common/file.h +++ b/common/file.h @@ -30,6 +30,8 @@ #include "common/scummsys.h" #include "common/str.h" #include "common/stream.h" +#include "backends/file/base-file.h" +//#include "backends/factories/fs-factory-maker.cpp" class FilesystemNode; @@ -37,6 +39,9 @@ namespace Common { class File : public SeekableReadStream, public WriteStream { protected: + /** File handle to the actual file; 0 if no file is open. */ + //BaseFile *_test; + /** File handle to the actual file; 0 if no file is open. */ void *_handle; @@ -52,7 +57,7 @@ private: // code that accidentally copied File objects tended to break in strange // ways. File(const File &f); - File &operator =(const File &f); + File &operator =(const File &f); public: enum AccessMode { diff --git a/common/fs.cpp b/common/fs.cpp index 28f3e11f0b7..40d9e4de148 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -25,7 +25,7 @@ #include "common/stdafx.h" #include "common/util.h" #include "backends/fs/abstract-fs.h" -#include "backends/fs/fs-factory-maker.cpp" +#include "backends/factories/fs-factory-maker.cpp" /* * Simple DOS-style pattern matching function (understands * and ? like used in DOS). From 1dc13a641dd82825334e81bb3eb3b4ebd69d2552 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 18 Aug 2007 05:24:18 +0000 Subject: [PATCH 26/26] Merged some of the changes from the trunk patch back in to the GSoC fsnode branch. svn-id: r28649 --- backends/factories/abstract-fs-factory.h | 26 +++- .../amigaos4/amigaos4-fs-factory.cpp | 24 ++++ .../factories/amigaos4/amigaos4-fs-factory.h | 24 ++++ backends/factories/dc/ronincd-fs-factory.cpp | 24 ++++ backends/factories/dc/ronincd-fs-factory.h | 24 ++++ backends/factories/ds/ds-fs-factory.cpp | 24 ++++ backends/factories/ds/ds-fs-factory.h | 24 ++++ backends/factories/fs-factory-maker.cpp | 128 +++++------------- backends/factories/fs-factory-maker.h | 76 +++++++++++ backends/factories/gp32/gp32-fs-factory.cpp | 24 ++++ .../factories/morphos/abox-fs-factory.cpp | 24 ++++ backends/factories/morphos/abox-fs-factory.h | 24 ++++ .../factories/palmos/palmos-fs-factory.cpp | 24 ++++ backends/factories/posix/posix-fs-factory.cpp | 28 +++- backends/factories/posix/posix-fs-factory.h | 2 +- backends/factories/ps2/ps2-fs-factory.cpp | 24 ++++ backends/factories/ps2/ps2-fs-factory.h | 24 ++++ backends/factories/psp/psp-fs-factory.cpp | 24 ++++ backends/factories/psp/psp-fs-factory.h | 24 ++++ .../factories/symbian/symbian-fs-factory.cpp | 24 ++++ .../factories/symbian/symbian-fs-factory.h | 24 ++++ .../factories/windows/windows-fs-factory.cpp | 24 ++++ .../factories/windows/windows-fs-factory.h | 24 ++++ backends/file/base-file.cpp | 4 + backends/file/base-file.h | 8 +- backends/file/posix/posix-file.cpp | 4 + backends/file/posix/posix-file.h | 4 + backends/fs/abstract-fs.h | 36 ++++- backends/fs/dc/dc-fs.cpp | 2 +- backends/fs/posix/posix-fs.cpp | 37 ++--- common/file.cpp | 4 - common/file.h | 5 +- common/fs.cpp | 57 +++++--- common/fs.h | 65 ++++++--- 34 files changed, 748 insertions(+), 170 deletions(-) create mode 100644 backends/factories/fs-factory-maker.h diff --git a/backends/factories/abstract-fs-factory.h b/backends/factories/abstract-fs-factory.h index b06ad632282..4238baf5c2c 100644 --- a/backends/factories/abstract-fs-factory.h +++ b/backends/factories/abstract-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 ABSTRACT_FILESYSTEM_FACTORY_H #define ABSTRACT_FILESYSTEM_FACTORY_H @@ -50,7 +74,7 @@ public: * Creates a base file usable by the Common::File wrapper to implement several * methods. */ - virtual BaseFile *makeBaseFile() const = 0; + virtual Common::BaseFile *makeBaseFile() const = 0; }; #endif /*ABSTRACT_FILESYSTEM_FACTORY_H*/ diff --git a/backends/factories/amigaos4/amigaos4-fs-factory.cpp b/backends/factories/amigaos4/amigaos4-fs-factory.cpp index 2d73c4dbdce..15847e37fc7 100644 --- a/backends/factories/amigaos4/amigaos4-fs-factory.cpp +++ b/backends/factories/amigaos4/amigaos4-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/amigaos4/amigaos4-fs-factory.h" #include "backends/fs/amigaos4/amigaos4-fs.cpp" #include "backends/file/amigaos4/amigaos4-file.h" diff --git a/backends/factories/amigaos4/amigaos4-fs-factory.h b/backends/factories/amigaos4/amigaos4-fs-factory.h index 86f77ca6fac..62433031664 100644 --- a/backends/factories/amigaos4/amigaos4-fs-factory.h +++ b/backends/factories/amigaos4/amigaos4-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 diff --git a/backends/factories/dc/ronincd-fs-factory.cpp b/backends/factories/dc/ronincd-fs-factory.cpp index c28d735aec8..f87aa0b9d5f 100644 --- a/backends/factories/dc/ronincd-fs-factory.cpp +++ b/backends/factories/dc/ronincd-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/dc/ronincd-fs-factory.h" #include "backends/fs/dc/dc-fs.cpp" #include "backends/file/base-file.h" diff --git a/backends/factories/dc/ronincd-fs-factory.h b/backends/factories/dc/ronincd-fs-factory.h index 5aa6f7a91f9..f41c3e81f07 100644 --- a/backends/factories/dc/ronincd-fs-factory.h +++ b/backends/factories/dc/ronincd-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 RONINCD_FILESYSTEM_FACTORY_H #define RONINCD_FILESYSTEM_FACTORY_H diff --git a/backends/factories/ds/ds-fs-factory.cpp b/backends/factories/ds/ds-fs-factory.cpp index 94bf8e75d06..fab45c92e9e 100644 --- a/backends/factories/ds/ds-fs-factory.cpp +++ b/backends/factories/ds/ds-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/ds/ds-fs-factory.h" #include "backends/fs/ds/ds-fs.cpp" #include "backends/file/ds/ds-file.h" diff --git a/backends/factories/ds/ds-fs-factory.h b/backends/factories/ds/ds-fs-factory.h index eecd4066822..c076f1cb997 100644 --- a/backends/factories/ds/ds-fs-factory.h +++ b/backends/factories/ds/ds-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 DS_FILESYSTEM_FACTORY_H #define DS_FILESYSTEM_FACTORY_H diff --git a/backends/factories/fs-factory-maker.cpp b/backends/factories/fs-factory-maker.cpp index 8bef982f378..10567268876 100644 --- a/backends/factories/fs-factory-maker.cpp +++ b/backends/factories/fs-factory-maker.cpp @@ -1,113 +1,51 @@ -#include "backends/factories/abstract-fs-factory.h" - -/* - * All the following includes choose, at compile time, which specific backend will be used - * during the execution of the ScummVM. - * - * It has to be done this way because not all the necessary libraries will be available in - * all build environments. Additionally, this results in smaller binaries. +/* 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. + * + * 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 "backends/factories/amigaos4/amigaos4-fs-factory.cpp" -#endif - -#if defined(__DC__) - #include "backends/factories/dc/ronincd-fs-factory.cpp" -#endif -#if defined(__DS__) - #include "backends/factories/ds/ds-fs-factory.cpp" -#endif - -#if defined(__GP32__) - #include "backends/factories/gp32/gp32-fs-factory.cpp" -#endif - -#if defined(__MORPHOS__) - #include "backends/factories/morphos/abox-fs-factory.cpp" -#endif - -#if defined(PALMOS_MODE) - #include "backends/factories/palmos/palmos-fs-factory.cpp" -#endif - -#if defined(__PLAYSTATION2__) - #include "backends/factories/ps2/ps2-fs-factory.cpp" -#endif - -#if defined(__PSP__) - #include "backends/factories/psp/psp-fs-factory.cpp" -#endif - -#if defined(__SYMBIAN32__) - #include "backends/factories/symbian/symbian-fs-factory.cpp" -#endif - -#if defined(UNIX) - #include "backends/factories/posix/posix-fs-factory.cpp" -#endif - -#if defined(WIN32) - #include "backends/factories/windows/windows-fs-factory.cpp" -#endif - -/** - * Creates concrete FilesystemFactory and FileFactory objects depending on the current architecture. - */ -class FilesystemFactoryMaker { -public: - - /** - * Returns the correct concrete filesystem factory depending on the current build architecture. - */ - static AbstractFilesystemFactory *makeFactory(); - -protected: - FilesystemFactoryMaker() {}; // avoid instances of this class -}; +#include "backends/factories/fs-factory-maker.h" AbstractFilesystemFactory *FilesystemFactoryMaker::makeFactory(){ #if defined(__amigaos4__) return &AmigaOSFilesystemFactory::instance(); - #endif - - #if defined(__DC__) + #elif defined(__DC__) return &RoninCDFilesystemFactory::instance(); - #endif - - #if defined(__DS__) + #elif defined(__DS__) return &DSFilesystemFactory::instance(); - #endif - - #if defined(__GP32__) + #elif defined(__GP32__) return &GP32FilesystemFactory::instance(); - #endif - - #if defined(__MORPHOS__) + #elif defined(__MORPHOS__) return &ABoxFilesystemFactory::instance(); - #endif - - #if defined(PALMOS_MODE) + #elif defined(PALMOS_MODE) return &PalmOSFilesystemFactory::instance(); - #endif - - #if defined(__PLAYSTATION2__) + #elif defined(__PLAYSTATION2__) return &Ps2FilesystemFactory::instance(); - #endif - - #if defined(__PSP__) + #elif defined(__PSP__) return &PSPFilesystemFactory::instance(); - #endif - - #if defined(__SYMBIAN32__) + #elif defined(__SYMBIAN32__) return &SymbianFilesystemFactory::instance(); - #endif - - #if defined(UNIX) + #elif defined(UNIX) return &POSIXFilesystemFactory::instance(); - #endif - - #if defined(WIN32) + #elif defined(WIN32) return &WindowsFilesystemFactory::instance(); #endif } diff --git a/backends/factories/fs-factory-maker.h b/backends/factories/fs-factory-maker.h new file mode 100644 index 00000000000..f9fc0ff85f6 --- /dev/null +++ b/backends/factories/fs-factory-maker.h @@ -0,0 +1,76 @@ +/* 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. + * + * 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 FS_FACTORY_MAKER_H +#define FS_FACTORY_MAKER_H + +#include "backends/factories/abstract-fs-factory.h" + +/* + * All the following includes choose, at compile time, which specific backend will be used + * during the execution of the ScummVM. + * + * It has to be done this way because not all the necessary libraries will be available in + * all build environments. Additionally, this results in smaller binaries. + */ +#if defined(__amigaos4__) + #include "backends/factories/amigaos4/amigaos4-fs-factory.cpp" +#elif defined(__DC__) + #include "backends/factories/dc/ronincd-fs-factory.cpp" +#elif defined(__DS__) + #include "backends/factories/ds/ds-fs-factory.cpp" +#elif defined(__GP32__) + #include "backends/factories/gp32/gp32-fs-factory.cpp" +#elif defined(__MORPHOS__) + #include "backends/factories/morphos/abox-fs-factory.cpp" +#elif defined(PALMOS_MODE) + #include "backends/factories/palmos/palmos-fs-factory.cpp" +#elif defined(__PLAYSTATION2__) + #include "backends/factories/ps2/ps2-fs-factory.cpp" +#elif defined(__PSP__) + #include "backends/factories/psp/psp-fs-factory.cpp" +#elif defined(__SYMBIAN32__) + #include "backends/factories/symbian/symbian-fs-factory.cpp" +#elif defined(UNIX) + #include "backends/factories/posix/posix-fs-factory.cpp" +#elif defined(WIN32) + #include "backends/factories/windows/windows-fs-factory.cpp" +#endif + +/** + * Creates concrete FilesystemFactory and FileFactory objects depending on the current architecture. + */ +class FilesystemFactoryMaker { +public: + + /** + * Returns the correct concrete filesystem factory depending on the current build architecture. + */ + static AbstractFilesystemFactory *makeFactory(); + +protected: + FilesystemFactoryMaker() {}; // avoid instances of this class +}; + +#endif //FS_FACTORY_MAKER_H diff --git a/backends/factories/gp32/gp32-fs-factory.cpp b/backends/factories/gp32/gp32-fs-factory.cpp index bffbffa21da..43d6a5330c7 100644 --- a/backends/factories/gp32/gp32-fs-factory.cpp +++ b/backends/factories/gp32/gp32-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/gp32/gp32-fs-factory.h" #include "backends/fs/gp32/gp32-fs.cpp" #include "backends/file/base-file.h" diff --git a/backends/factories/morphos/abox-fs-factory.cpp b/backends/factories/morphos/abox-fs-factory.cpp index 5659baf6f9c..961a7cbb9d1 100644 --- a/backends/factories/morphos/abox-fs-factory.cpp +++ b/backends/factories/morphos/abox-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/morphos/abox-fs-factory.h" #include "backends/fs/morphos/abox-fs.cpp" #include "backends/file/base-file.h" diff --git a/backends/factories/morphos/abox-fs-factory.h b/backends/factories/morphos/abox-fs-factory.h index ff282b5bb9a..c265b464a4e 100644 --- a/backends/factories/morphos/abox-fs-factory.h +++ b/backends/factories/morphos/abox-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 ABOX_FILESYSTEM_FACTORY_H #define ABOX_FILESYSTEM_FACTORY_H diff --git a/backends/factories/palmos/palmos-fs-factory.cpp b/backends/factories/palmos/palmos-fs-factory.cpp index 275118b5188..bb90857eacc 100644 --- a/backends/factories/palmos/palmos-fs-factory.cpp +++ b/backends/factories/palmos/palmos-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/palmos/palmos-fs-factory.h" #include "backends/fs/palmos/palmos-fs.cpp" #include "backends/file/base-file.h" diff --git a/backends/factories/posix/posix-fs-factory.cpp b/backends/factories/posix/posix-fs-factory.cpp index 9b77e315572..1887aa8d5fd 100644 --- a/backends/factories/posix/posix-fs-factory.cpp +++ b/backends/factories/posix/posix-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/posix/posix-fs-factory.h" #include "backends/fs/posix/posix-fs.cpp" #include "backends/file/posix/posix-file.cpp" @@ -19,6 +43,6 @@ AbstractFilesystemNode *POSIXFilesystemFactory::makeFileNodePath(const String &p return new POSIXFilesystemNode(path, true); } -BaseFile *POSIXFilesystemFactory::makeBaseFile() const { - return new POSIXFile(); +Common::BaseFile *POSIXFilesystemFactory::makeBaseFile() const { + return new Common::POSIXFile(); } diff --git a/backends/factories/posix/posix-fs-factory.h b/backends/factories/posix/posix-fs-factory.h index aef411c92bc..0122f7ac582 100644 --- a/backends/factories/posix/posix-fs-factory.h +++ b/backends/factories/posix/posix-fs-factory.h @@ -16,7 +16,7 @@ public: virtual AbstractFilesystemNode *makeRootFileNode() const; virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; - virtual BaseFile *makeBaseFile() const; + virtual Common::BaseFile *makeBaseFile() const; protected: POSIXFilesystemFactory() {}; diff --git a/backends/factories/ps2/ps2-fs-factory.cpp b/backends/factories/ps2/ps2-fs-factory.cpp index cd6f2937945..a56f376ec88 100644 --- a/backends/factories/ps2/ps2-fs-factory.cpp +++ b/backends/factories/ps2/ps2-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/ps2/ps2-fs-factory.h" #include "backends/fs/ps2/ps2-fs.cpp" #include "backends/file/ps2/ps2-file.h" diff --git a/backends/factories/ps2/ps2-fs-factory.h b/backends/factories/ps2/ps2-fs-factory.h index e1ddee9677f..413842789f4 100644 --- a/backends/factories/ps2/ps2-fs-factory.h +++ b/backends/factories/ps2/ps2-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 PS2_FILESYSTEM_FACTORY_H #define PS2_FILESYSTEM_FACTORY_H diff --git a/backends/factories/psp/psp-fs-factory.cpp b/backends/factories/psp/psp-fs-factory.cpp index 9c9bef21e7b..0791904d96e 100644 --- a/backends/factories/psp/psp-fs-factory.cpp +++ b/backends/factories/psp/psp-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/psp/psp-fs-factory.h" #include "backends/fs/psp/psp_fs.cpp" #include "backends/file/base-file.h" diff --git a/backends/factories/psp/psp-fs-factory.h b/backends/factories/psp/psp-fs-factory.h index 0d30efd5ad0..10a9bcc7111 100644 --- a/backends/factories/psp/psp-fs-factory.h +++ b/backends/factories/psp/psp-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 PSP_FILESYSTEM_FACTORY_H #define PSP_FILESYSTEM_FACTORY_H diff --git a/backends/factories/symbian/symbian-fs-factory.cpp b/backends/factories/symbian/symbian-fs-factory.cpp index a21b40a0954..04fb3195d9f 100644 --- a/backends/factories/symbian/symbian-fs-factory.cpp +++ b/backends/factories/symbian/symbian-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/symbian/symbian-fs-factory.h" #include "backends/fs/symbian/symbian-fs.cpp" #include "backends/file/symbian/symbian-file.h" diff --git a/backends/factories/symbian/symbian-fs-factory.h b/backends/factories/symbian/symbian-fs-factory.h index 49f92410ce8..edf39969d2f 100644 --- a/backends/factories/symbian/symbian-fs-factory.h +++ b/backends/factories/symbian/symbian-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 SYMBIAN_FILESYSTEM_FACTORY_H #define SYMBIAN_FILESYSTEM_FACTORY_H diff --git a/backends/factories/windows/windows-fs-factory.cpp b/backends/factories/windows/windows-fs-factory.cpp index 55c48c3b9cd..57976b6ad9c 100644 --- a/backends/factories/windows/windows-fs-factory.cpp +++ b/backends/factories/windows/windows-fs-factory.cpp @@ -1,3 +1,27 @@ +/* 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. + * + * 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: $ + */ + #include "backends/factories/windows/windows-fs-factory.h" #include "backends/fs/windows/windows-fs.cpp" #include "backends/file/base-file.h" diff --git a/backends/factories/windows/windows-fs-factory.h b/backends/factories/windows/windows-fs-factory.h index 1f85d8f1c34..b1272a6bcb4 100644 --- a/backends/factories/windows/windows-fs-factory.h +++ b/backends/factories/windows/windows-fs-factory.h @@ -1,3 +1,27 @@ +/* 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. + * + * 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 diff --git a/backends/file/base-file.cpp b/backends/file/base-file.cpp index 3174f5828c2..e42f50ce981 100644 --- a/backends/file/base-file.cpp +++ b/backends/file/base-file.cpp @@ -37,6 +37,8 @@ #include "CoreFoundation/CoreFoundation.h" #endif +namespace Common { + BaseFile::BaseFile() { _handle = 0; _ioFailed = false; @@ -224,3 +226,5 @@ long BaseFile::_ftell(FILE *stream) const { int BaseFile::_fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream) { return fwrite(ptr, obj_size, count, stream); } + +} // End of namespace Common diff --git a/backends/file/base-file.h b/backends/file/base-file.h index f383a1a453a..d28655b31ee 100644 --- a/backends/file/base-file.h +++ b/backends/file/base-file.h @@ -30,12 +30,14 @@ #include "common/str.h" #include "common/stream.h" -using namespace Common; +//using namespace Common; + +namespace Common { /** * Implements several file related functions used by the Common::File wrapper. */ -class BaseFile : public Common::SeekableReadStream { +class BaseFile : public SeekableReadStream { protected: /** File handle to the actual file; 0 if no file is open. */ void *_handle; @@ -177,4 +179,6 @@ public: //uint32 write(const void *dataPtr, uint32 dataSize); }; +} // End of namespace Common + #endif //BACKENDS_BASE_FILE_H diff --git a/backends/file/posix/posix-file.cpp b/backends/file/posix/posix-file.cpp index 84c82fa5c55..7419161ccdb 100644 --- a/backends/file/posix/posix-file.cpp +++ b/backends/file/posix/posix-file.cpp @@ -1,5 +1,7 @@ #include "backends/file/posix/posix-file.h" +namespace Common { + POSIXFile::POSIXFile() : BaseFile() { // } @@ -39,3 +41,5 @@ long POSIXFile::_ftell(FILE *stream) const { int POSIXFile::_fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream) { return fwrite(ptr, obj_size, count, stream); } + +} // End of namespace Common diff --git a/backends/file/posix/posix-file.h b/backends/file/posix/posix-file.h index 00ce307df53..e74338b8d89 100644 --- a/backends/file/posix/posix-file.h +++ b/backends/file/posix/posix-file.h @@ -27,6 +27,8 @@ #include "backends/file/base-file.cpp" +namespace Common { + /** * Implements several POSIX specific file related functions used by the Common::File wrapper. * @@ -47,4 +49,6 @@ protected: int _fwrite(const void * ptr, size_t obj_size, size_t count, FILE * stream); }; +} // End of namespace Common + #endif //BACKENDS_POSIX_FILE_H diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 85fcbcdebbe..e506d96a0b6 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -79,7 +79,7 @@ public: virtual ~AbstractFilesystemNode() {} /* - * Indicates whether the object refered by this path exists in the filesystem or not. + * Indicates whether the object referred by this path exists in the filesystem or not. */ virtual bool exists() const = 0; @@ -102,6 +102,18 @@ public: */ virtual String getDisplayName() const { return getName(); } + /** + * 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. + */ + virtual const char *getLastPathComponent(const Common::String &str) const = 0; + /** * Returns a string with an architecture dependent path description. */ @@ -118,12 +130,28 @@ public: virtual bool isDirectory() const = 0; /** - * Indicates whether this path can be read from or not. + * 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 this path can be written to or not. + * 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; @@ -132,4 +160,4 @@ public: */ }; -#endif +#endif //BACKENDS_ABSTRACT_FS_H diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index e1228c7ff27..6554544c7fd 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -32,7 +32,7 @@ #include /** - * Implementation of the ScummVM file system API based on POSIX. + * Implementation of the ScummVM file system API based on Ronin. * * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 3708acd2a81..9fd5b8a1858 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -64,6 +64,7 @@ public: virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; } virtual String getDisplayName() const { return _displayName; } + virtual const char *getLastPathComponent(const Common::String &str) const; virtual String getName() const { return _displayName; } virtual String getPath() const { return _path; } virtual bool isDirectory() const { return _isDirectory; } @@ -81,27 +82,6 @@ private: 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. - */ -static const char *lastPathComponent(const Common::String &str) { - 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; @@ -142,7 +122,7 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) { assert(p.size() > 0); _path = p; - _displayName = lastPathComponent(_path); + _displayName = getLastPathComponent(_path); if (verify) { setFlags(); @@ -236,12 +216,23 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, boo return true; } +const char *POSIXFilesystemNode::getLastPathComponent(const Common::String &str) const { + const char *start = str.c_str(); + const char *cur = start + str.size() - 2; + + while (cur >= start && *cur != '/') { + --cur; + } + + return cur + 1; +} + AbstractFilesystemNode *POSIXFilesystemNode::getParent() const { if (_path == "/") return 0; const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char *end = getLastPathComponent(_path); return new POSIXFilesystemNode(String(start, end - start), true); } diff --git a/common/file.cpp b/common/file.cpp index 30ac870f057..e70a9328cb5 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -24,14 +24,10 @@ */ #include "common/file.h" -#include "common/fs.h" #include "common/hashmap.h" #include "common/util.h" #include "common/hash-str.h" - -#if defined(UNIX) || defined(__SYMBIAN32__) #include -#endif #ifdef MACOSX #include "CoreFoundation/CoreFoundation.h" diff --git a/common/file.h b/common/file.h index c18776a3774..19b1d45144f 100644 --- a/common/file.h +++ b/common/file.h @@ -30,6 +30,9 @@ #include "common/scummsys.h" #include "common/str.h" #include "common/stream.h" +#include "common/fs.h" +#include "backends/file/base-file.h" +//#include "backends/factories/fs-factory-maker.h" class FilesystemNode; @@ -38,7 +41,7 @@ namespace Common { class File : public SeekableReadStream, public WriteStream { protected: /** File handle to the actual file; 0 if no file is open. */ - //BaseFile *_test; + BaseFile *_test; /** File handle to the actual file; 0 if no file is open. */ void *_handle; diff --git a/common/fs.cpp b/common/fs.cpp index 40d9e4de148..442e3ed4d72 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -24,6 +24,7 @@ #include "common/stdafx.h" #include "common/util.h" +#include "common/fs.h" #include "backends/fs/abstract-fs.h" #include "backends/factories/fs-factory-maker.cpp" @@ -107,12 +108,13 @@ FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { return *this; } -bool FilesystemNode::operator< (const FilesystemNode& node) const +bool FilesystemNode::operator<(const FilesystemNode& node) const { if (isDirectory() && !node.isDirectory()) return true; if (!isDirectory() && node.isDirectory()) return false; + return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0; } @@ -130,6 +132,7 @@ void FilesystemNode::decRefCount() { bool FilesystemNode::exists() const { if (_realNode == 0) return false; + return _realNode->exists(); } @@ -189,62 +192,78 @@ Common::String FilesystemNode::getPath() const { bool FilesystemNode::isDirectory() const { if (_realNode == 0) return false; + return _realNode->isDirectory(); } bool FilesystemNode::isReadable() const { if (_realNode == 0) return false; + return _realNode->isReadable(); } bool FilesystemNode::isWritable() const { if (_realNode == 0) return false; + return _realNode->isWritable(); } bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const { - for(FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) - { - if(entry->isDirectory()) { - lookupFileRec(results, *entry, filename, hidden, exhaustive); + int matches = 0; + + for (FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) { + if (entry->isDirectory()) { + matches += lookupFileRec(results, *entry, filename, hidden, exhaustive); } } - - //TODO: we would return true even if no matches were found, if the initial results list isn't empty - return ((results.size() > 0) ? true : false); + + return ((matches > 0) ? true : false); } bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const { - lookupFileRec(results, dir, filename, hidden, exhaustive); + int matches; - //TODO: we would return true even if no matches were found, if the initial results list isn't empty - return ((results.size() > 0) ? true : false); + if (!dir.isDirectory()) + return false; + + matches = lookupFileRec(results, dir, filename, hidden, exhaustive); + + return ((matches > 0) ? true : false); } -void FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const +int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const { FSList entries; + FSList children; + int matches = 0; dir.getChildren(entries, FilesystemNode::kListAll, hidden); - for(FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) - { - if(entry->isDirectory()) { - lookupFileRec(results, *entry, filename, hidden, exhaustive); + //Breadth search (entries in the same level) + for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) { + if (entry->isDirectory()) { + children.push_back(*entry); } else { //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, // so it might be a good idea to include it inside the backend class. This would enforce its // implementation by all ports. - if(matchString(lastPathComponent(entry->getPath()), filename.c_str())) { + if(matchString(_realNode->getLastPathComponent(entry->getPath()), filename.c_str())) { results.push_back(*entry); + matches++; - if(!exhaustive) { + if (!exhaustive) break; - } } } } + + //Depth search (entries in lower levels) + for (FSList::iterator child = children.begin(); child != children.end(); ++child) { + matches += lookupFileRec(results, *child, filename, hidden, exhaustive); + } + + return matches; } diff --git a/common/fs.h b/common/fs.h index 6a2f049be1c..7f634791d6a 100644 --- a/common/fs.h +++ b/common/fs.h @@ -62,6 +62,8 @@ class FSList : public Common::Array {}; * paths (MacOS 9 doesn't even have the notion of a "current directory"). * And if we ever want to support devices with no FS in the classical sense (Palm...), * we can build upon this. + * + * This class acts as a wrapper around the AbstractFilesystemNode class defined in backends/fs. */ class FilesystemNode { private: @@ -80,9 +82,9 @@ public: }; /** - * Create a new invalid FilesystemNode. In other words, isValid() for that - * node returns false, and if you try to get it's path, an assert is - * triggered. + * Create a new pathless FilesystemNode. Since there's no path associated + * with this node, path-related operations (i.e. exists(), isDirectory(), + * getPath()) will always return false or raise an assertion. */ FilesystemNode(); @@ -116,10 +118,12 @@ public: * Compare the name of this node to the name of another. Directories * go before normal files. */ - bool operator< (const FilesystemNode& node) const; + bool operator<(const FilesystemNode& node) const; /* - * Indicates whether the object refered by this path exists in the filesystem or not. + * Indicates whether the object referred by this path exists in the filesystem or not. + * + * @return bool true if the path exists, false otherwise. */ virtual bool exists() const; @@ -177,34 +181,53 @@ public: FilesystemNode getParent() const; /** - * Indicates whether this path refers to a directory or not. + * Indicates whether the path refers to a directory or not. * - * @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 + * @todo Currently we assume that a node that is not a directory + * automatically is a file (ignoring things like symlinks or pipes). + * That might actually be OK... but we could still add an isFile method. + * Or even replace isDirectory by a getType() method that can return values like * kDirNodeType, kFileNodeType, kInvalidNodeType. */ virtual bool isDirectory() const; /** - * Indicates whether this path can be read from or not. + * 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; /** - * Indicates whether this path can be written to or not. + * 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; /** * Searches recursively for a filename inside the given directories. * + * For each directory in the directory list a breadth-first search is performed, + * that is, the current directory entries are scanned before going into subdirectories. + * * @param results List to put the matches in. * @param fslist List of directories to search within. * @param filename Name of the file to look for. - * @param hidden Whether to search hidden files or not. Default: false - * @param exhaustive Whether to continue searching after one match has been found. Default: false + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. * * @return true if matches could be found, false otherwise. */ @@ -213,11 +236,14 @@ public: /** * Searches recursively for a filename inside the given directory. * + * The search is performed breadth-first, that is, the current directory entries + * are scanned before going into subdirectories. + * * @param results List to put the matches in. * @param FilesystemNode Directory to search within. * @param filename Name of the file to look for. - * @param hidden Whether to search hidden files or not. Default: false - * @param exhaustive Whether to continue searching after one match has been found. Default: false + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. * * @return true if matches could be found, false otherwise. */ @@ -233,13 +259,18 @@ protected: /** * Searches recursively for a filename inside the given directory. * + * The search is performed breadth-first, that is, the current directory entries + * are scanned before going into subdirectories. + * * @param results List to put the matches in. * @param FilesystemNode Directory to search within. * @param filename Name of the file to look for. * @param hidden Whether to search hidden files or not. * @param exhaustive Whether to continue searching after one match has been found. + * + * @return The number of matches found. */ - void lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; + int lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; }; //} // End of namespace Common