From f62fd4f25f5fcc237d59054af0d6182da8d8eff8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 3 May 2011 10:33:03 +0200 Subject: BACKENDS: Avoid #including .cpp files So far, the various *-fs-factory.cpp files were #including the corresponding *-fs.cpp files. This is surprising and hence could lead to all kinds of problems). To fix this, provide proper headers for the *-fs.cpp files. This also makes code reuse via subclassing possible. Since not all ports were tested, this will likely lead to a few easy to fix compile regressions. --- backends/fs/symbian/symbian-fs-factory.cpp | 2 +- backends/fs/symbian/symbian-fs.cpp | 136 +++++++++++------------------ backends/fs/symbian/symbian-fs.h | 73 ++++++++++++++++ 3 files changed, 124 insertions(+), 87 deletions(-) create mode 100644 backends/fs/symbian/symbian-fs.h (limited to 'backends/fs/symbian') diff --git a/backends/fs/symbian/symbian-fs-factory.cpp b/backends/fs/symbian/symbian-fs-factory.cpp index c70a67f339..9afacfebf5 100644 --- a/backends/fs/symbian/symbian-fs-factory.cpp +++ b/backends/fs/symbian/symbian-fs-factory.cpp @@ -24,7 +24,7 @@ #if defined(__SYMBIAN32__) #include "backends/fs/symbian/symbian-fs-factory.h" -#include "backends/fs/symbian/symbian-fs.cpp" +#include "backends/fs/symbian/symbian-fs.h" AbstractFSNode *SymbianFilesystemFactory::makeRootFileNode() const { return new SymbianFilesystemNode(true); diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp index 5d4951e269..b8fc5e19f6 100644 --- a/backends/fs/symbian/symbian-fs.cpp +++ b/backends/fs/symbian/symbian-fs.cpp @@ -23,7 +23,8 @@ */ #if defined (__SYMBIAN32__) -#include "backends/fs/abstract-fs.h" + +#include "backends/fs/symbian/symbian-fs.h" #include "backends/fs/symbian/symbianstream.h" #include "backends/platform/symbian/src/symbianos.h" @@ -34,67 +35,12 @@ #define KDriveLabelSize 30 -/** - * Implementation of the ScummVM file system API based on POSIX. - * - * Parts of this class are documented in the base interface class, AbstractFSNode. - */ -class SymbianFilesystemNode : public AbstractFSNode { -protected: - Common::String _displayName; - Common::String _path; - TBool _isDirectory; - TBool _isValid; - TBool _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 Common::String with the path the new node should point to. - */ - SymbianFilesystemNode(const Common::String &path); - - virtual bool exists() const { - TFileName fname; - TPtrC8 ptr((const unsigned char*) _path.c_str(), _path.size()); - fname.Copy(ptr); - TBool fileExists = BaflUtils::FileExists(static_cast (g_system)->FsSession(), fname); - if (!fileExists) { - TParsePtrC parser(fname); - if (parser.PathPresent() && parser.Path().Compare(_L("\\")) == KErrNone && !parser.NameOrExtPresent()) { - fileExists = ETrue; - } - } - return fileExists; - } - virtual Common::String getDisplayName() const { return _displayName; } - virtual Common::String getName() const { return _displayName; } - virtual Common::String getPath() const { return _path; } - virtual bool isDirectory() const { return _isDirectory; } - virtual bool isReadable() const { return access(_path.c_str(), R_OK) == 0; } //FIXME: this is just a stub - virtual bool isWritable() const { return access(_path.c_str(), W_OK) == 0; } //FIXME: this is just a stub - - virtual AbstractFSNode *getChild(const Common::String &n) const; - virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; - virtual AbstractFSNode *getParent() const; - - virtual Common::SeekableReadStream *createReadStream(); - virtual Common::WriteStream *createWriteStream(); -}; - /** * Fixes the path by changing all slashes to backslashes. * * @param path Common::String with the path to be fixed. */ -static void fixFilePath(Common::String& aPath){ +static void fixFilePath(Common::String &aPath){ TInt len = aPath.size(); for (TInt index = 0; index < len; index++) { @@ -106,18 +52,15 @@ static void fixFilePath(Common::String& aPath){ SymbianFilesystemNode::SymbianFilesystemNode(bool aIsRoot) { _path = ""; - _isValid = ETrue; - _isDirectory = ETrue; + _isValid = true; + _isDirectory = true; _isPseudoRoot = aIsRoot; _displayName = "Root"; } SymbianFilesystemNode::SymbianFilesystemNode(const Common::String &path) { - if (path.size() == 0) - _isPseudoRoot = ETrue; - else - _isPseudoRoot = EFalse; + _isPseudoRoot = path.empty(); _path = path; @@ -131,18 +74,41 @@ SymbianFilesystemNode::SymbianFilesystemNode(const Common::String &path) { fname.Copy(ptr); if (static_cast(g_system)->FsSession().Entry(fname, fileAttribs) == KErrNone) { - _isValid = ETrue; + _isValid = true; _isDirectory = fileAttribs.IsDir(); } else { - _isValid = ETrue; - _isDirectory = EFalse; + _isValid = true; + _isDirectory = false; TParsePtrC parser(fname); if (parser.PathPresent() && parser.Path().Compare(_L("\\")) == KErrNone && !parser.NameOrExtPresent()) { - _isDirectory = ETrue; + _isDirectory = true; } } } +bool SymbianFilesystemNode::exists() const { + TFileName fname; + TPtrC8 ptr((const unsigned char*) _path.c_str(), _path.size()); + fname.Copy(ptr); + bool fileExists = BaflUtils::FileExists(static_cast (g_system)->FsSession(), fname); + if (!fileExists) { + TParsePtrC parser(fname); + if (parser.PathPresent() && parser.Path().Compare(_L("\\")) == KErrNone && !parser.NameOrExtPresent()) { + fileExists = true; + } + } + return fileExists; +} + +bool SymbianFilesystemNode::isReadable() const { + return access(_path.c_str(), R_OK) == 0; +} + +bool SymbianFilesystemNode::isWritable() const { + return access(_path.c_str(), W_OK) == 0; +} + + AbstractFSNode *SymbianFilesystemNode::getChild(const Common::String &n) const { assert(_isDirectory); Common::String newPath(_path); @@ -191,9 +157,9 @@ bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b SymbianFilesystemNode entry(false); entry._displayName = (char*) driveString8.PtrZ(); // drive_name - entry._isDirectory = ETrue; - entry._isValid = ETrue; - entry._isPseudoRoot = EFalse; + entry._isDirectory = true; + entry._isValid = true; + entry._isPseudoRoot = false; entry._path = path; myList.push_back(new SymbianFilesystemNode(entry)); } @@ -209,20 +175,20 @@ bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b if (static_cast(g_system)->FsSession().GetDir(fname, KEntryAttNormal|KEntryAttDir, 0, dirPtr) == KErrNone) { CleanupStack::PushL(dirPtr); - TInt cnt=dirPtr->Count(); - for (TInt loop=0;loopCount(); + for (TInt loop = 0; loop < cnt; loop++) { + TEntry fileentry = (*dirPtr)[loop]; nameBuf.Copy(fileentry.iName); - SymbianFilesystemNode entry(EFalse); - entry._isPseudoRoot = EFalse; + SymbianFilesystemNode entry(false); + entry._isPseudoRoot = false; - entry._displayName =(char*) nameBuf.PtrZ(); + entry._displayName =(char *)nameBuf.PtrZ(); entry._path = _path; if (entry._path.lastChar() != '\\') entry._path+= '\\'; - entry._path +=(char*) nameBuf.PtrZ(); + entry._path +=(char *)nameBuf.PtrZ(); entry._isDirectory = fileentry.IsDir(); // Honor the chosen mode @@ -245,29 +211,27 @@ AbstractFSNode *SymbianFilesystemNode::getParent() const { // 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(EFalse); + p = new SymbianFilesystemNode(false); const char *start = _path.c_str(); const char *end = lastPathComponent(_path, '\\'); p->_path = Common::String(start, end - start); - p->_isValid = ETrue; - p->_isDirectory = ETrue; + p->_isValid = true; + p->_isDirectory = true; p->_displayName = lastPathComponent(p->_path, '\\'); - } - else - { - p = new SymbianFilesystemNode(ETrue); + } else { + p = new SymbianFilesystemNode(true); } return p; } Common::SeekableReadStream *SymbianFilesystemNode::createReadStream() { - return SymbianStdioStream::makeFromPath(getPath().c_str(), false); + return SymbianStdioStream::makeFromPath(getPath(), false); } Common::WriteStream *SymbianFilesystemNode::createWriteStream() { - return SymbianStdioStream::makeFromPath(getPath().c_str(), true); + return SymbianStdioStream::makeFromPath(getPath(), true); } #endif //#if defined (__SYMBIAN32__) diff --git a/backends/fs/symbian/symbian-fs.h b/backends/fs/symbian/symbian-fs.h new file mode 100644 index 0000000000..9b0e80c3d6 --- /dev/null +++ b/backends/fs/symbian/symbian-fs.h @@ -0,0 +1,73 @@ +/* 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_H +#define SYMBIAN_FILESYSTEM_H + +#include "backends/fs/abstract-fs.h" + +/** + * Implementation of the ScummVM file system API based on POSIX. + * + * Parts of this class are documented in the base interface class, AbstractFSNode. + */ +class SymbianFilesystemNode : public AbstractFSNode { +protected: + Common::String _displayName; + Common::String _path; + bool _isDirectory; + bool _isValid; + 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 Common::String with the path the new node should point to. + */ + SymbianFilesystemNode(const Common::String &path); + + virtual bool exists() const; + virtual Common::String getDisplayName() const { return _displayName; } + virtual Common::String getName() const { return _displayName; } + virtual Common::String getPath() const { return _path; } + virtual bool isDirectory() const { return _isDirectory; } + virtual bool isReadable() const; + virtual bool isWritable() const; + + virtual AbstractFSNode *getChild(const Common::String &n) const; + virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; + virtual AbstractFSNode *getParent() const; + + virtual Common::SeekableReadStream *createReadStream(); + virtual Common::WriteStream *createWriteStream(); +}; + +#endif -- cgit v1.2.3