diff options
Diffstat (limited to 'backends/fs/symbian/symbian-fs.cpp')
| -rw-r--r-- | backends/fs/symbian/symbian-fs.cpp | 162 |
1 files changed, 76 insertions, 86 deletions
diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp index 85fc58179a..1c6d8435a9 100644 --- a/backends/fs/symbian/symbian-fs.cpp +++ b/backends/fs/symbian/symbian-fs.cpp @@ -24,12 +24,16 @@ #if defined (__SYMBIAN32__) #include "backends/fs/abstract-fs.h" +#include "backends/fs/symbian/symbianstream.h" +#include "backends/platform/symbian/src/symbianos.h" #include <dirent.h> #include <eikenv.h> #include <f32file.h> #include <bautils.h> +#define KDriveLabelSize 30 + /** * Implementation of the ScummVM file system API based on POSIX. * @@ -37,12 +41,11 @@ */ class SymbianFilesystemNode : public AbstractFilesystemNode { protected: - String _displayName; - String _path; - bool _isDirectory; - bool _isValid; - bool _isPseudoRoot; - + Common::String _displayName; + Common::String _path; + TBool _isDirectory; + TBool _isValid; + TBool _isPseudoRoot; public: /** * Creates a SymbianFilesystemNode with the root node as path. @@ -54,57 +57,36 @@ public: /** * Creates a SymbianFilesystemNode for a given path. * - * @param path String with the path the new node should point to. + * @param path Common::String with the path the new node should point to. */ - SymbianFilesystemNode(const String &path); + SymbianFilesystemNode(const Common::String &path); virtual bool exists() const { TFileName fname; - TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size()); + TPtrC8 ptr((const unsigned char*) _path.c_str(), _path.size()); fname.Copy(ptr); - TBool fileExists = BaflUtils::FileExists(CEikonEnv::Static()->FsSession(), fname); + TBool fileExists = BaflUtils::FileExists(static_cast<OSystem_SDL_Symbian*> (g_system)->FsSession(), fname); return fileExists; } - virtual String getDisplayName() const { return _displayName; } - virtual String getName() const { return _displayName; } - virtual String getPath() const { return _path; } + 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 AbstractFilesystemNode *getChild(const String &n) const; + virtual AbstractFilesystemNode *getChild(const Common::String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) 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. - */ -const char *lastPathComponent(const Common::String &str) { - if(str.empty()) - return ""; - - const char *start = str.c_str(); - const char *cur = start + str.size() - 2; - - while (cur >= start && *cur != '\\') { - --cur; - } - - return cur + 1; -} + virtual Common::SeekableReadStream *openForReading(); + virtual Common::WriteStream *openForWriting(); +}; /** * Fixes the path by changing all slashes to backslashes. * - * @param path String with the path to be fixed. + * @param path Common::String with the path to be fixed. */ static void fixFilePath(Common::String& aPath){ TInt len = aPath.size(); @@ -118,54 +100,47 @@ static void fixFilePath(Common::String& aPath){ SymbianFilesystemNode::SymbianFilesystemNode(bool aIsRoot) { _path = ""; - _isValid = true; - _isDirectory = true; + _isValid = ETrue; + _isDirectory = ETrue; _isPseudoRoot = aIsRoot; _displayName = "Root"; } -SymbianFilesystemNode::SymbianFilesystemNode(const String &path) { +SymbianFilesystemNode::SymbianFilesystemNode(const Common::String &path) { if (path.size() == 0) - _isPseudoRoot = true; + _isPseudoRoot = ETrue; else - _isPseudoRoot = false; + _isPseudoRoot = EFalse; _path = path; fixFilePath(_path); - _displayName = lastPathComponent(_path); + _displayName = lastPathComponent(_path, '\\'); TEntry fileAttribs; TFileName fname; TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size()); fname.Copy(ptr); - if (CEikonEnv::Static()->FsSession().Entry(fname, fileAttribs) == KErrNone) { - _isValid = true; + if (static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession().Entry(fname, fileAttribs) == KErrNone) { + _isValid = ETrue; _isDirectory = fileAttribs.IsDir(); } else { - _isValid = false; - _isDirectory = false; + _isValid = ETrue; + _isDirectory = EFalse; } } -AbstractFilesystemNode *SymbianFilesystemNode::getChild(const String &n) const { +AbstractFilesystemNode *SymbianFilesystemNode::getChild(const Common::String &n) const { assert(_isDirectory); - String newPath(_path); + Common::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; + newPath += n; return new SymbianFilesystemNode(newPath); } @@ -177,19 +152,19 @@ bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b if (_isPseudoRoot) { // Drives enumeration - RFs fs = CEikonEnv::Static()->FsSession(); + RFs& fs = static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession(); TInt driveNumber; TChar driveLetter; TUint driveLetterValue; TVolumeInfo volumeInfo; - TBuf8<30> driveLabel8; - TBuf8<30> driveString8; + TBuf8<KDriveLabelSize> driveLabel8; + TBuf8<KDriveLabelSize> driveString8; for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) { TInt err = fs.Volume(volumeInfo, driveNumber); if (err != KErrNone) continue; - if (fs.DriveToChar(driveNumber,driveLetter) != KErrNone) + if (fs.DriveToChar(driveNumber, driveLetter) != KErrNone) continue; driveLetterValue = driveLetter; @@ -205,40 +180,46 @@ bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b sprintf(path,"%c:\\", driveNumber+'A'); SymbianFilesystemNode entry(false); - entry._displayName = (char*)driveString8.PtrZ(); // drive_name - entry._isDirectory = true; - entry._isValid = true; - entry._isPseudoRoot = false; + entry._displayName = (char*) driveString8.PtrZ(); // drive_name + entry._isDirectory = ETrue; + entry._isValid = ETrue; + entry._isPseudoRoot = EFalse; entry._path = path; myList.push_back(new SymbianFilesystemNode(entry)); } } else { - TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size()); + TPtrC8 ptr((const unsigned char*) _path.c_str(), _path.size()); TFileName fname; - fname.Copy(ptr); TBuf8<256>nameBuf; CDir* dirPtr; - if (CEikonEnv::Static()->FsSession().GetDir(fname,KEntryAttNormal|KEntryAttDir,0,dirPtr)==KErrNone) { + fname.Copy(ptr); + + if (_path.lastChar() != '\\') + fname.Append('\\'); + + if (static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession().GetDir(fname, KEntryAttNormal|KEntryAttDir, 0, dirPtr) == KErrNone) { CleanupStack::PushL(dirPtr); TInt cnt=dirPtr->Count(); for (TInt loop=0;loop<cnt;loop++) { TEntry fileentry=(*dirPtr)[loop]; nameBuf.Copy(fileentry.iName); - SymbianFilesystemNode entry(false); - entry._isPseudoRoot = false; + SymbianFilesystemNode entry(EFalse); + entry._isPseudoRoot = EFalse; - entry._displayName =(char*)nameBuf.PtrZ(); + entry._displayName =(char*) nameBuf.PtrZ(); entry._path = _path; - entry._path +=(char*)nameBuf.PtrZ(); + + if (entry._path.lastChar() != '\\') + entry._path+= '\\'; + + entry._path +=(char*) nameBuf.PtrZ(); entry._isDirectory = fileentry.IsDir(); // Honor the chosen mode - if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) || - (mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory)) + if ((mode == Common::FilesystemNode::kListFilesOnly && entry._isDirectory) || + (mode == Common::FilesystemNode::kListDirectoriesOnly && !entry._isDirectory)) continue; - - if (entry._isDirectory) - entry._path += "\\"; + myList.push_back(new SymbianFilesystemNode(entry)); } CleanupStack::PopAndDestroy(dirPtr); @@ -254,21 +235,30 @@ AbstractFilesystemNode *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(false); + p = new SymbianFilesystemNode(EFalse); const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char *end = lastPathComponent(_path, '\\'); - p->_path = String(start, end - start); - p->_isValid = true; - p->_isDirectory = true; - p->_displayName = lastPathComponent(p->_path); + p->_path = Common::String(start, end - start); + p->_isValid = ETrue; + p->_isDirectory = ETrue; + p->_displayName = lastPathComponent(p->_path, '\\'); } else { - p = new SymbianFilesystemNode(true); + p = new SymbianFilesystemNode(ETrue); } return p; } +Common::SeekableReadStream *SymbianFilesystemNode::openForReading() { + return SymbianStdioStream::makeFromPath(getPath().c_str(), false); +} + +Common::WriteStream *SymbianFilesystemNode::openForWriting() { + return SymbianStdioStream::makeFromPath(getPath().c_str(), true); +} #endif //#if defined (__SYMBIAN32__) + + |
