From c459f054b46b8791ce206c2ee13d455a9c10fe4d Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 3 May 2007 02:39:33 +0000 Subject: Use abstract factories to initialize FilesystemNode objects. svn-id: r26739 --- backends/fs/posix/POSIXFilesystemFactory.cpp | 25 +++++ backends/fs/posix/POSIXFilesystemFactory.h | 38 ++++++++ backends/fs/posix/posix-fs.cpp | 133 +++++++++++++++------------ 3 files changed, 137 insertions(+), 59 deletions(-) create mode 100644 backends/fs/posix/POSIXFilesystemFactory.cpp create mode 100644 backends/fs/posix/POSIXFilesystemFactory.h (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/POSIXFilesystemFactory.cpp b/backends/fs/posix/POSIXFilesystemFactory.cpp new file mode 100644 index 0000000000..9a13c37c30 --- /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 0000000000..b471460445 --- /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 14ed0d39b9..4ab0c4f207 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; -} - -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; + return new POSIXFilesystemNode(String(start, end - start), false); } -#endif // defined(UNIX) +#endif //#if defined(UNIX) -- cgit v1.2.3 From 86324f00bc561c03b281170125ef2fde14cae132 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 12 May 2007 18:17:40 +0000 Subject: Renamed files and minor tweaks. Thanks LordHoto :) svn-id: r26810 --- backends/fs/posix/POSIXFilesystemFactory.cpp | 25 ------------------ backends/fs/posix/POSIXFilesystemFactory.h | 38 ---------------------------- backends/fs/posix/posix-fs-factory.cpp | 25 ++++++++++++++++++ backends/fs/posix/posix-fs-factory.h | 33 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 63 deletions(-) delete mode 100644 backends/fs/posix/POSIXFilesystemFactory.cpp delete mode 100644 backends/fs/posix/POSIXFilesystemFactory.h create mode 100644 backends/fs/posix/posix-fs-factory.cpp create mode 100644 backends/fs/posix/posix-fs-factory.h (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/POSIXFilesystemFactory.cpp b/backends/fs/posix/POSIXFilesystemFactory.cpp deleted file mode 100644 index 9a13c37c30..0000000000 --- a/backends/fs/posix/POSIXFilesystemFactory.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#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 deleted file mode 100644 index b471460445..0000000000 --- a/backends/fs/posix/POSIXFilesystemFactory.h +++ /dev/null @@ -1,38 +0,0 @@ -#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-factory.cpp b/backends/fs/posix/posix-fs-factory.cpp new file mode 100644 index 0000000000..b302bb31e8 --- /dev/null +++ b/backends/fs/posix/posix-fs-factory.cpp @@ -0,0 +1,25 @@ +#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; +} + +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/posix-fs-factory.h b/backends/fs/posix/posix-fs-factory.h new file mode 100644 index 0000000000..5195491b95 --- /dev/null +++ b/backends/fs/posix/posix-fs-factory.h @@ -0,0 +1,33 @@ +#ifndef POSIX_FILESYSTEM_FACTORY_H +#define POSIX_FILESYSTEM_FACTORY_H + +#include "backends/fs/abstract-fs-factory.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(); + + virtual AbstractFilesystemNode *makeRootFileNode() const; + virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; + virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; + +protected: + POSIXFilesystemFactory() {}; + +private: + static POSIXFilesystemFactory *_instance; +}; + +#endif /*POSIX_FILESYSTEM_FACTORY_H*/ -- cgit v1.2.3 From d1f56d93f934150f4b579c2e90564e2bf035f113 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 12 May 2007 20:00:52 +0000 Subject: Use common/singleton.h in the concrete fs factories. svn-id: r26814 --- backends/fs/posix/posix-fs-factory.cpp | 9 +-------- backends/fs/posix/posix-fs-factory.h | 12 +++--------- 2 files changed, 4 insertions(+), 17 deletions(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs-factory.cpp b/backends/fs/posix/posix-fs-factory.cpp index b302bb31e8..bed3dc5f8f 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 5195491b95..93f0ac115b 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*/ -- cgit v1.2.3 From 3e7c5b027e2131cde30d994ccdb27c77f0118ffe Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 4 Jun 2007 03:46:56 +0000 Subject: Added a missing include in non-POSIX factories. For the POSIX and Windows architectures, added exists(), isReadable() and isWritable() svn-id: r27073 --- backends/fs/posix/posix-fs.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 966bfe34e6..712a8ce68d 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(); -- cgit v1.2.3 From fedfe66831ebed2822fe74c86ed59b6d69326f3d Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 4 Jun 2007 22:02:35 +0000 Subject: Added stubs for the exists(), isReadable() and isWritable() methods for all architectures. svn-id: r27087 --- backends/fs/posix/posix-fs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 712a8ce68d..2e222f34f8 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; -- cgit v1.2.3 From f7ea7e666da6e484577d0341fb0331dff75c69f7 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 16 Jun 2007 17:31:36 +0000 Subject: 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/posix/posix-fs.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 2e222f34f8..fb5c9dc5d7 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; -- cgit v1.2.3 From 8ebf479bc5db8cf4996cc0820269aaf04139b940 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 17 Jun 2007 17:17:38 +0000 Subject: Added a new parameter to the getChildren function, which allows including hidden files in the results. svn-id: r27514 --- backends/fs/posix/posix-fs.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index fb5c9dc5d7..c976830402 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); -- cgit v1.2.3 From 0ac96302fe9c04df79cb01a77d19535b45fe2db0 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 20 Jun 2007 00:28:04 +0000 Subject: 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 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index c976830402..385bab833c 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() != '/') -- cgit v1.2.3 From b95b3fe4f39dee9f46a522c05791628d085b2704 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 19 Jul 2007 20:21:47 +0000 Subject: 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(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 385bab833c..3708acd2a8 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) -- cgit v1.2.3 From 1400d28bfb37fc94f3c44dec0a4d0cef65fb8fb7 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 1 Aug 2007 22:07:50 +0000 Subject: 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 --- backends/fs/posix/posix-fs-factory.cpp | 18 ------------------ backends/fs/posix/posix-fs-factory.h | 27 --------------------------- 2 files changed, 45 deletions(-) delete mode 100644 backends/fs/posix/posix-fs-factory.cpp delete mode 100644 backends/fs/posix/posix-fs-factory.h (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs-factory.cpp b/backends/fs/posix/posix-fs-factory.cpp deleted file mode 100644 index bed3dc5f8f..0000000000 --- a/backends/fs/posix/posix-fs-factory.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "backends/fs/posix/posix-fs-factory.h" -#include "backends/fs/posix/posix-fs.cpp" - -DECLARE_SINGLETON(POSIXFilesystemFactory); - -AbstractFilesystemNode *POSIXFilesystemFactory::makeRootFileNode() const { - return new POSIXFilesystemNode(); -} - -AbstractFilesystemNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const { - char buf[MAXPATHLEN]; - getcwd(buf, MAXPATHLEN); - return new POSIXFilesystemNode(buf, true); -} - -AbstractFilesystemNode *POSIXFilesystemFactory::makeFileNodePath(const String &path) const { - return new POSIXFilesystemNode(path, true); -} diff --git a/backends/fs/posix/posix-fs-factory.h b/backends/fs/posix/posix-fs-factory.h deleted file mode 100644 index 93f0ac115b..0000000000 --- a/backends/fs/posix/posix-fs-factory.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef POSIX_FILESYSTEM_FACTORY_H -#define POSIX_FILESYSTEM_FACTORY_H - -#include "common/singleton.h" -#include "backends/fs/abstract-fs-factory.h" - -/** - * Creates POSIXFilesystemNode objects. - * - * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. - */ -class POSIXFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton { -public: - typedef Common::String String; - - virtual AbstractFilesystemNode *makeRootFileNode() const; - virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; - virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; - -protected: - POSIXFilesystemFactory() {}; - -private: - friend class Common::Singleton; -}; - -#endif /*POSIX_FILESYSTEM_FACTORY_H*/ -- cgit v1.2.3 From 1dc13a641dd82825334e81bb3eb3b4ebd69d2552 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 18 Aug 2007 05:24:18 +0000 Subject: Merged some of the changes from the trunk patch back in to the GSoC fsnode branch. svn-id: r28649 --- backends/fs/posix/posix-fs.cpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'backends/fs/posix') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 3708acd2a8..9fd5b8a185 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); } -- cgit v1.2.3