2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2005-06-21 19:53:19 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-12-04 08:49:08 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-06-21 19:53:19 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-06-21 19:53:19 +00:00
|
|
|
*/
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
#if defined (__SYMBIAN32__)
|
2006-05-03 10:14:05 +00:00
|
|
|
#include "backends/fs/abstract-fs.h"
|
2008-09-03 12:56:46 +00:00
|
|
|
#include "backends/fs/stdiostream.h"
|
2008-08-19 08:54:28 +00:00
|
|
|
#include "backends/platform/symbian/src/SymbianOS.h"
|
2005-06-21 19:53:19 +00:00
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <eikenv.h>
|
|
|
|
#include <f32file.h>
|
2006-05-01 14:20:02 +00:00
|
|
|
#include <bautils.h>
|
2005-06-21 19:53:19 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
2005-06-21 19:53:19 +00:00
|
|
|
* Implementation of the ScummVM file system API based on POSIX.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* Parts of this class are documented in the base interface class, AbstractFilesystemNode.
|
2005-06-21 19:53:19 +00:00
|
|
|
*/
|
|
|
|
class SymbianFilesystemNode : public AbstractFilesystemNode {
|
|
|
|
protected:
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::String _displayName;
|
|
|
|
Common::String _path;
|
2005-06-21 19:53:19 +00:00
|
|
|
bool _isDirectory;
|
|
|
|
bool _isValid;
|
|
|
|
bool _isPseudoRoot;
|
|
|
|
|
|
|
|
public:
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Creates a SymbianFilesystemNode with the root node as path.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-05-03 02:39:33 +00:00
|
|
|
* @param aIsRoot true if the node will be a pseudo root, false otherwise.
|
|
|
|
*/
|
2005-06-21 19:53:19 +00:00
|
|
|
SymbianFilesystemNode(bool aIsRoot);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Creates a SymbianFilesystemNode for a given path.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-09-03 11:22:51 +00:00
|
|
|
* @param path Common::String with the path the new node should point to.
|
2007-05-03 02:39:33 +00:00
|
|
|
*/
|
2008-09-03 11:22:51 +00:00
|
|
|
SymbianFilesystemNode(const Common::String &path);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
|
|
|
virtual bool exists() const {
|
2008-01-20 17:12:00 +00:00
|
|
|
TFileName fname;
|
|
|
|
TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size());
|
|
|
|
fname.Copy(ptr);
|
2008-08-19 08:54:28 +00:00
|
|
|
TBool fileExists = BaflUtils::FileExists(static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession(), fname);
|
2008-01-21 20:48:25 +00:00
|
|
|
return fileExists;
|
2008-01-20 17:12:00 +00:00
|
|
|
}
|
2008-09-03 11:22:51 +00:00
|
|
|
virtual Common::String getDisplayName() const { return _displayName; }
|
|
|
|
virtual Common::String getName() const { return _displayName; }
|
|
|
|
virtual Common::String getPath() const { return _path; }
|
2005-06-21 19:53:19 +00:00
|
|
|
virtual bool isDirectory() const { return _isDirectory; }
|
2008-01-21 20:48:25 +00:00
|
|
|
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
|
2005-06-21 19:53:19 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
virtual AbstractFilesystemNode *getChild(const Common::String &n) const;
|
2007-07-09 01:26:54 +00:00
|
|
|
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
|
2007-05-03 02:39:33 +00:00
|
|
|
virtual AbstractFilesystemNode *getParent() const;
|
2008-09-03 12:56:46 +00:00
|
|
|
|
|
|
|
virtual Common::SeekableReadStream *openForReading();
|
|
|
|
virtual Common::WriteStream *openForWriting();
|
2005-06-21 19:53:19 +00:00
|
|
|
};
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Fixes the path by changing all slashes to backslashes.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-09-03 11:22:51 +00:00
|
|
|
* @param path Common::String with the path to be fixed.
|
2007-05-03 02:39:33 +00:00
|
|
|
*/
|
2008-04-02 21:19:17 +00:00
|
|
|
static void fixFilePath(Common::String& aPath){
|
|
|
|
TInt len = aPath.size();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-03-12 20:13:07 +00:00
|
|
|
for (TInt index = 0; index < len; index++) {
|
2008-04-02 21:19:17 +00:00
|
|
|
if (aPath[index] == '/') {
|
|
|
|
aPath.setChar('\\', index);
|
2007-03-12 20:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-21 19:53:19 +00:00
|
|
|
SymbianFilesystemNode::SymbianFilesystemNode(bool aIsRoot) {
|
|
|
|
_path = "";
|
|
|
|
_isValid = true;
|
|
|
|
_isDirectory = true;
|
|
|
|
_isPseudoRoot = aIsRoot;
|
|
|
|
_displayName = "Root";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
SymbianFilesystemNode::SymbianFilesystemNode(const Common::String &path) {
|
2005-06-21 19:53:19 +00:00
|
|
|
if (path.size() == 0)
|
|
|
|
_isPseudoRoot = true;
|
2006-05-01 15:36:54 +00:00
|
|
|
else
|
|
|
|
_isPseudoRoot = false;
|
|
|
|
|
2005-06-21 19:53:19 +00:00
|
|
|
_path = path;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-03-12 20:13:07 +00:00
|
|
|
fixFilePath(_path);
|
|
|
|
|
2008-08-27 20:31:22 +00:00
|
|
|
_displayName = lastPathComponent(_path, '\\');
|
2007-02-28 21:25:05 +00:00
|
|
|
|
|
|
|
TEntry fileAttribs;
|
|
|
|
TFileName fname;
|
|
|
|
TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size());
|
|
|
|
fname.Copy(ptr);
|
|
|
|
|
2008-08-19 08:54:28 +00:00
|
|
|
if (static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession().Entry(fname, fileAttribs) == KErrNone) {
|
2007-02-28 21:25:05 +00:00
|
|
|
_isValid = true;
|
|
|
|
_isDirectory = fileAttribs.IsDir();
|
|
|
|
} else {
|
|
|
|
_isValid = false;
|
|
|
|
_isDirectory = false;
|
|
|
|
}
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
AbstractFilesystemNode *SymbianFilesystemNode::getChild(const Common::String &n) const {
|
2007-05-03 02:39:33 +00:00
|
|
|
assert(_isDirectory);
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::String newPath(_path);
|
2007-05-03 02:39:33 +00:00
|
|
|
|
|
|
|
if (_path.lastChar() != '\\')
|
|
|
|
newPath += '\\';
|
2008-09-07 16:43:03 +00:00
|
|
|
newPath += n;
|
2007-05-03 02:39:33 +00:00
|
|
|
|
|
|
|
return new SymbianFilesystemNode(newPath);
|
|
|
|
}
|
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
|
2005-06-21 19:53:19 +00:00
|
|
|
assert(_isDirectory);
|
|
|
|
|
2007-07-09 01:26:54 +00:00
|
|
|
//TODO: honor the hidden flag
|
|
|
|
|
2006-04-27 23:14:54 +00:00
|
|
|
if (_isPseudoRoot) {
|
2005-06-21 19:53:19 +00:00
|
|
|
// Drives enumeration
|
2008-08-19 08:54:28 +00:00
|
|
|
RFs& fs = static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession();
|
2005-12-03 21:29:13 +00:00
|
|
|
TInt driveNumber;
|
|
|
|
TChar driveLetter;
|
2006-02-12 00:27:19 +00:00
|
|
|
TUint driveLetterValue;
|
2005-12-03 21:29:13 +00:00
|
|
|
TVolumeInfo volumeInfo;
|
|
|
|
TBuf8<30> driveLabel8;
|
|
|
|
TBuf8<30> driveString8;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-12-03 21:29:13 +00:00
|
|
|
for (driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++) {
|
|
|
|
TInt err = fs.Volume(volumeInfo, driveNumber);
|
|
|
|
if (err != KErrNone)
|
2008-01-27 19:47:41 +00:00
|
|
|
continue;
|
2007-09-18 20:16:33 +00:00
|
|
|
if (fs.DriveToChar(driveNumber,driveLetter) != KErrNone)
|
2006-02-12 00:27:19 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
driveLetterValue = driveLetter;
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
if (volumeInfo.iName.Length() > 0) {
|
2005-12-03 21:29:13 +00:00
|
|
|
driveLabel8.Copy(volumeInfo.iName); // 16 to 8bit des // enabling this line alone gives KERN-EXEC 3 with non-optimized GCC? WHY? grrr
|
2006-02-12 00:27:19 +00:00
|
|
|
driveString8.Format(_L8("Drive %c: (%S)"), driveLetterValue, &driveLabel8);
|
2005-12-03 21:29:13 +00:00
|
|
|
} else {
|
2006-02-12 00:27:19 +00:00
|
|
|
driveString8.Format(_L8("Drive %c:"), driveLetterValue);
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-12-03 21:29:13 +00:00
|
|
|
char path[10];
|
|
|
|
sprintf(path,"%c:\\", driveNumber+'A');
|
2008-01-27 19:47:41 +00:00
|
|
|
|
|
|
|
SymbianFilesystemNode entry(false);
|
2005-12-03 21:29:13 +00:00
|
|
|
entry._displayName = (char*)driveString8.PtrZ(); // drive_name
|
|
|
|
entry._isDirectory = true;
|
|
|
|
entry._isValid = true;
|
|
|
|
entry._isPseudoRoot = false;
|
|
|
|
entry._path = path;
|
2006-05-03 11:13:21 +00:00
|
|
|
myList.push_back(new SymbianFilesystemNode(entry));
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size());
|
|
|
|
TFileName fname;
|
|
|
|
fname.Copy(ptr);
|
|
|
|
TBuf8<256>nameBuf;
|
|
|
|
CDir* dirPtr;
|
2008-08-19 08:54:28 +00:00
|
|
|
if (static_cast<OSystem_SDL_Symbian*>(g_system)->FsSession().GetDir(fname,KEntryAttNormal|KEntryAttDir,0,dirPtr)==KErrNone) {
|
2005-06-21 19:53:19 +00:00
|
|
|
CleanupStack::PushL(dirPtr);
|
|
|
|
TInt cnt=dirPtr->Count();
|
2007-09-18 20:16:33 +00:00
|
|
|
for (TInt loop=0;loop<cnt;loop++) {
|
2005-06-21 19:53:19 +00:00
|
|
|
TEntry fileentry=(*dirPtr)[loop];
|
|
|
|
nameBuf.Copy(fileentry.iName);
|
|
|
|
SymbianFilesystemNode entry(false);
|
|
|
|
entry._isPseudoRoot = false;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-06-21 19:53:19 +00:00
|
|
|
entry._displayName =(char*)nameBuf.PtrZ();
|
|
|
|
entry._path = _path;
|
|
|
|
entry._path +=(char*)nameBuf.PtrZ();
|
|
|
|
entry._isDirectory = fileentry.IsDir();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-06-21 19:53:19 +00:00
|
|
|
// Honor the chosen mode
|
2008-09-03 11:22:51 +00:00
|
|
|
if ((mode == Common::FilesystemNode::kListFilesOnly && entry._isDirectory) ||
|
|
|
|
(mode == Common::FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
|
2005-06-21 19:53:19 +00:00
|
|
|
continue;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-06-21 19:53:19 +00:00
|
|
|
if (entry._isDirectory)
|
|
|
|
entry._path += "\\";
|
2006-05-03 11:13:21 +00:00
|
|
|
myList.push_back(new SymbianFilesystemNode(entry));
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
|
|
|
CleanupStack::PopAndDestroy(dirPtr);
|
|
|
|
}
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-03 20:43:26 +00:00
|
|
|
return true;
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
AbstractFilesystemNode *SymbianFilesystemNode::getParent() const {
|
2005-06-21 19:53:19 +00:00
|
|
|
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) {
|
2007-05-03 02:39:33 +00:00
|
|
|
p = new SymbianFilesystemNode(false);
|
2005-06-21 19:53:19 +00:00
|
|
|
const char *start = _path.c_str();
|
2008-08-27 20:31:22 +00:00
|
|
|
const char *end = lastPathComponent(_path, '\\');
|
2005-06-21 19:53:19 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
p->_path = Common::String(start, end - start);
|
2005-06-21 19:53:19 +00:00
|
|
|
p->_isValid = true;
|
|
|
|
p->_isDirectory = true;
|
2008-08-27 20:31:22 +00:00
|
|
|
p->_displayName = lastPathComponent(p->_path, '\\');
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-03 02:39:33 +00:00
|
|
|
p = new SymbianFilesystemNode(true);
|
2005-06-21 19:53:19 +00:00
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2005-06-21 19:53:19 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2008-09-03 12:56:46 +00:00
|
|
|
Common::SeekableReadStream *SymbianFilesystemNode::openForReading() {
|
|
|
|
return StdioStream::makeFromPath(getPath().c_str(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::WriteStream *SymbianFilesystemNode::openForWriting() {
|
|
|
|
return StdioStream::makeFromPath(getPath().c_str(), true);
|
|
|
|
}
|
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
#endif //#if defined (__SYMBIAN32__)
|