diff options
Diffstat (limited to 'backends/fs')
-rw-r--r-- | backends/fs/amigaos4/amigaos4-fs.cpp | 2 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs-factory.cpp | 2 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs.cpp | 192 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs.h | 57 | ||||
-rw-r--r-- | backends/fs/palmos/palmos-fs-factory.cpp | 42 | ||||
-rw-r--r-- | backends/fs/palmos/palmos-fs-factory.h | 49 | ||||
-rw-r--r-- | backends/fs/palmos/palmos-fs.cpp | 212 | ||||
-rw-r--r-- | backends/fs/psp/psp-stream.cpp | 14 |
8 files changed, 111 insertions, 459 deletions
diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp index fe6164cb0c..8a57a3cf1c 100644 --- a/backends/fs/amigaos4/amigaos4-fs.cpp +++ b/backends/fs/amigaos4/amigaos4-fs.cpp @@ -368,7 +368,7 @@ bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b } if (ERROR_NO_MORE_ENTRIES != IDOS->IoErr() ) { - debug(6, "An error occured during ExamineDir"); + debug(6, "An error occurred during ExamineDir"); ret = false; } else { ret = true; diff --git a/backends/fs/ds/ds-fs-factory.cpp b/backends/fs/ds/ds-fs-factory.cpp index 0dfa70b716..4919c04174 100644 --- a/backends/fs/ds/ds-fs-factory.cpp +++ b/backends/fs/ds/ds-fs-factory.cpp @@ -27,7 +27,7 @@ #include "backends/fs/ds/ds-fs.h" #include "dsmain.h" //for the isGBAMPAvailable() function -DECLARE_SINGLETON(DSFilesystemFactory); +DECLARE_SINGLETON(DSFilesystemFactory) AbstractFSNode *DSFilesystemFactory::makeRootFileNode() const { if (DS::isGBAMPAvailable()) { diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index 6fc2894925..675084ff56 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -8,15 +8,18 @@ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ * */ @@ -115,7 +118,7 @@ DSFileSystemNode::DSFileSystemNode(const Common::String& path, bool isDir) { // consolePrintf("Found: %d, Dir: %d\n", _isValid, _isDirectory); } -DSFileSystemNode::DSFileSystemNode(const DSFileSystemNode* node) { +DSFileSystemNode::DSFileSystemNode(const DSFileSystemNode *node) { //TODO: not implemented? } @@ -144,7 +147,7 @@ bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode, bool _zipFile->changeToRoot(); /* // This is the root dir, so add the RAM folder - DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/ram"); + DSFileSystemNode *dsfsn = new DSFileSystemNode("ds:/ram"); dsfsn->_isDirectory = true; dirList->push_back(wrap(dsfsn)); */ @@ -162,7 +165,7 @@ bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode, bool if ( (_zipFile->isDirectory() && ((mode == Common::FSNode::kListDirectoriesOnly) || (mode == Common::FSNode::kListAll)) ) || (!_zipFile->isDirectory() && ((mode == Common::FSNode::kListFilesOnly) || (mode == Common::FSNode::kListAll)) ) ) { - DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/" + Common::String(n), _zipFile->isDirectory()); + DSFileSystemNode *dsfsn = new DSFileSystemNode("ds:/" + Common::String(n), _zipFile->isDirectory()); dsfsn->_isDirectory = _zipFile->isDirectory(); dirList.push_back((dsfsn)); } @@ -173,15 +176,15 @@ bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode, bool return true; } -AbstractFSNode* DSFileSystemNode::getParent() const { +AbstractFSNode *DSFileSystemNode::getParent() const { // consolePrintf("parent\n"); DSFileSystemNode *p; if (_path != "ds:/") { - char *path = (char *) _path.c_str(); + const char *path = (const char *)_path.c_str(); int lastSlash = 4; - for (int r = 4; r < (int) _path.size(); r++) { + for (uint r = 4; r < _path.size(); r++) { if (path[r] == '\\') { lastSlash = r; } @@ -259,7 +262,7 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path) { _path = path; } -GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDirectory) { +GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDir) { //consolePrintf("'%s'",path.c_str()); int lastSlash = 3; @@ -272,11 +275,11 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path, bool isDire _displayName = Common::String(path.c_str() + lastSlash + 1); _path = path; _isValid = true; - _isDirectory = isDirectory; + _isDirectory = isDir; } -GBAMPFileSystemNode::GBAMPFileSystemNode(const GBAMPFileSystemNode* node) { +GBAMPFileSystemNode::GBAMPFileSystemNode(const GBAMPFileSystemNode *node) { //TODO: not implemented? } @@ -319,7 +322,7 @@ bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode, bo if ( ((entryType == TYPE_DIR) && ((mode == Common::FSNode::kListDirectoriesOnly) || (mode == Common::FSNode::kListAll))) || ((entryType == TYPE_FILE) && ((mode == Common::FSNode::kListFilesOnly) || (mode == Common::FSNode::kListAll))) ) { - GBAMPFileSystemNode* dsfsn; + GBAMPFileSystemNode *dsfsn; //consolePrintf("Fname: %s\n", fname); @@ -348,15 +351,15 @@ bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode, bo return true; } -AbstractFSNode* GBAMPFileSystemNode::getParent() const { +AbstractFSNode *GBAMPFileSystemNode::getParent() const { // consolePrintf("parent\n"); GBAMPFileSystemNode *p; if (_path != "mp:/") { - char *path = (char *) _path.c_str(); + const char *path = (const char *)_path.c_str(); int lastSlash = 4; - for (int r = 4; r < (int) strlen((char *) path); r++) { + for (uint r = 4; r < strlen(path); r++) { if (path[r] == '/') { lastSlash = r; } @@ -413,18 +416,12 @@ bool DSFileStream::eos() const { } int32 DSFileStream::pos() const { - if (_writeBufferPos > 0) { - // Discard constness. Bad, but I can't see another way. - ((DSFileStream *) (this))->flush(); - } + assert(_writeBufferPos == 0); // This method may only be called when reading! return std_ftell((FILE *)_handle); } int32 DSFileStream::size() const { - if (_writeBufferPos > 0) { - // Discard constness. Bad, but I can't see another way. - ((DSFileStream *) (this))->flush(); - } + assert(_writeBufferPos == 0); // This method may only be called when reading! int32 oldPos = std_ftell((FILE *)_handle); std_fseek((FILE *)_handle, 0, SEEK_END); int32 length = std_ftell((FILE *)_handle); @@ -444,16 +441,15 @@ uint32 DSFileStream::read(void *ptr, uint32 len) { if (_writeBufferPos > 0) { flush(); } - return std_fread((byte *)ptr, 1, len, (FILE *)_handle); + return std_fread(ptr, 1, len, (FILE *)_handle); } uint32 DSFileStream::write(const void *ptr, uint32 len) { if (_writeBufferPos + len < WRITE_BUFFER_SIZE) { memcpy(_writeBuffer + _writeBufferPos, ptr, len); _writeBufferPos += len; - } - else - { + return len; + } else { if (_writeBufferPos > 0) { flush(); } @@ -483,29 +479,31 @@ DSFileStream *DSFileStream::makeFromPath(const Common::String &path, bool writeM // Stdio replacements -#define MAX_FILE_HANDLES 32 +enum { + MAX_FILE_HANDLES = 32 +}; -bool inited = false; -DS::fileHandle handle[MAX_FILE_HANDLES]; +static bool inited = false; +static DS::fileHandle s_handle[MAX_FILE_HANDLES]; -FILE* std_fopen(const char* name, const char* mode) { +FILE *std_fopen(const char *name, const char *mode) { if (!inited) { for (int r = 0; r < MAX_FILE_HANDLES; r++) { - handle[r].used = false; + s_handle[r].used = false; } inited = true; currentDir[0] = '\0'; } - char* realName = (char *) name; + char realName[MAXPATHLEN]; // Remove file system prefix 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; + strlcpy(realName, name + 4, MAXPATHLEN); + } else if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) { + strlcpy(realName, name + 4, MAXPATHLEN); + } else { + strlcpy(realName, name, MAXPATHLEN); } // consolePrintf("Open file:"); @@ -515,13 +513,14 @@ FILE* std_fopen(const char* name, const char* mode) { FAT_chdir("/"); // Turn all back slashes into forward slashes for gba_nds_fat - char* p = realName; + char *p = realName; while (*p) { - if (*p == '\\') *p = '/'; + if (*p == '\\') + *p = '/'; p++; } - FAT_FILE* result = FAT_fopen(realName, mode); + FAT_FILE *result = FAT_fopen(realName, mode); if (result == 0) { // consolePrintf("Error code %d\n", result); @@ -531,42 +530,21 @@ FILE* std_fopen(const char* name, const char* mode) { } // MT_memoryReport(); - return (FILE *) result; + return (FILE *)result; } // Fail to open file for writing. It's in ROM! // Allocate a file handle int r = 0; - while (handle[r].used) { + while (s_handle[r].used) { r++; assert(r < MAX_FILE_HANDLES); } -#ifdef GBA_SRAM_SAVE - if (strchr(mode, 'w')) { -// consolePrintf("Writing %s\n", realName); - handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, true); - } else { -// consolePrintf("Reading %s\n", realName); - handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, false); - } -#endif - - if (handle[r].sramFile) { - handle[r].used = true; - handle[r].pos = 0; - handle[r].data = NULL; - handle[r].size = handle[r].sramFile->getSize(); -// consolePrintf("Found it"); - return &handle[r]; - } - -// consolePrintf("Not in SRAM!"); - - char* data; + char *data; - ZipFile* zip = DSFileSystemNode::getZip(); + ZipFile *zip = DSFileSystemNode::getZip(); if (!zip) { // consolePrintf("No zip yet!"); return NULL; @@ -578,7 +556,7 @@ FILE* std_fopen(const char* name, const char* mode) { if (currentDir[0] != 0) { char nameWithPath[128]; - sprintf(nameWithPath, "%s\%s", currentDir, realName); + sprintf(nameWithPath, "%s\\%s", currentDir, realName); strcpy(realName, nameWithPath); } @@ -589,17 +567,18 @@ FILE* std_fopen(const char* name, const char* mode) { zip->setAllFilesVisible(false); // Allocate a file handle - int r = 0; - while (handle[r].used) r++; + r = 0; + while (s_handle[r].used) + r++; - handle[r].used = true; - handle[r].pos = 0; - handle[r].data = data; - handle[r].size = zip->getFileSize(); + s_handle[r].used = true; + s_handle[r].pos = 0; + s_handle[r].data = data; + s_handle[r].size = zip->getFileSize(); // consolePrintf("Opened file %d: %s (%s) ", r, realName, name); - return &handle[r]; + return &s_handle[r]; } else { zip->setAllFilesVisible(false); // consolePrintf("Not found: %s (%s) ", realName, name); @@ -607,7 +586,7 @@ FILE* std_fopen(const char* name, const char* mode) { } } -void std_fclose(FILE* handle) { +void std_fclose(FILE *handle) { if (DS::isGBAMPAvailable()) { FAT_fclose((FAT_FILE *) handle); @@ -615,19 +594,15 @@ void std_fclose(FILE* handle) { } handle->used = false; - if (handle->sramFile) { - delete handle->sramFile; - handle->sramFile = NULL; - } } -size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { +size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle) { // consolePrintf("fread %d,%d %d ", size, numItems, ptr); if (DS::isGBAMPAvailable()) { readPastEndOfFile = false; - int bytes = FAT_fread((void *) ptr, size, numItems, (FAT_FILE *) handle); + int bytes = FAT_fread(ptr, size, numItems, (FAT_FILE *) handle); if (!FAT_feof((FAT_FILE *) handle)) { return numItems; } else { @@ -638,36 +613,22 @@ size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { return numItems; } - if (handle->sramFile) { - int bytes = 0; - int result = 1; - //consolePrintf("fread size=", size * numItems); - for (int r = 0; (r < (s32) size * (s32) numItems) && (result > 0); r++) { - result = handle->sramFile->read((void *) ( ((char *) (ptr)) + r), 1); - bytes += result; - //consolePrintf("'%d',", ((char *) (ptr))[0]); - } - - handle->pos += bytes; - - return bytes / size; - } - - if ((int)(handle->pos + size * numItems) > handle->size) { + if (handle->pos > handle->size) + numItems = 0; + else if ((int)(handle->pos + size * numItems) > handle->size) numItems = (handle->size - handle->pos) / size; - if (numItems < 0) numItems = 0; - } // consolePrintf("read %d ", size * numItems); - memcpy((void *) ptr, handle->data + handle->pos, size * numItems); + memcpy(ptr, handle->data + handle->pos, size * numItems); handle->pos += size * numItems; return numItems; } -size_t std_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle) { - if ((handle == stdin)) return 0; +size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle) { + if ((handle == stdin)) + return 0; if ((handle == stderr) || (handle == stdout)) { // consolePrintf((char *) ptr); @@ -677,7 +638,7 @@ 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); + FAT_fwrite(ptr, size, numItems, (FAT_FILE *) handle); return numItems; int length = size * numItems; @@ -694,36 +655,27 @@ 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; - } else { - return 0; - } + return 0; } -bool std_feof(FILE* handle) { +bool std_feof(FILE *handle) { // consolePrintf("feof "); if (DS::isGBAMPAvailable()) { return readPastEndOfFile && FAT_feof((FAT_FILE *) handle); } - if (handle->sramFile) { - return handle->sramFile->eos(); - } - // consolePrintf("feof %s", handle->pos >= handle->size? "true": "false"); return handle->pos >= handle->size; } -int std_fflush(FILE* handle) { +int std_fflush(FILE *handle) { //FIXME: not implemented? // consolePrintf("fflush "); return 0; } -long int std_ftell(FILE* handle) { +long int std_ftell(FILE *handle) { if (DS::isGBAMPAvailable()) { return FAT_ftell((FAT_FILE *) handle); } @@ -731,7 +683,7 @@ long int std_ftell(FILE* handle) { return handle->pos; } -int std_fseek(FILE* handle, long int offset, int whence) { +int std_fseek(FILE *handle, long int offset, int whence) { // consolePrintf("fseek %d %d ", offset, whence); if (DS::isGBAMPAvailable()) { @@ -756,14 +708,14 @@ int std_fseek(FILE* handle, long int offset, int whence) { return 0; } -int std_ferror(FILE* handle) { +int std_ferror(FILE *handle) { //FIXME: not implemented? // consolePrintf("ferror "); return readPastEndOfFile; } -void std_clearerr(FILE* handle) { +void std_clearerr(FILE *handle) { //FIXME: not implemented? readPastEndOfFile = false; // consolePrintf("clearerr "); diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index c8bf7d6cf2..6961022848 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -8,27 +8,30 @@ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ * */ #ifndef _DS_FS_H #define _DS_FS_H -//#include <NDS/ARM9/console.h> #include "common/fs.h" +#include "common/stream.h" +#include "backends/fs/abstract-fs.h" + #include "zipreader.h" -#include "ramsave.h" #include "fat/gba_nds_fat.h" -#include "backends/fs/abstract-fs.h" namespace DS { @@ -40,7 +43,7 @@ namespace DS { */ class DSFileSystemNode : public AbstractFSNode { protected: - static ZipFile* _zipFile; + static ZipFile *_zipFile; Common::String _displayName; Common::String _path; @@ -96,7 +99,7 @@ public: * Returns the zip file this node points to. * TODO: check this documentation. */ - static ZipFile* getZip() { return _zipFile; } + static ZipFile *getZip() { return _zipFile; } }; /** @@ -161,16 +164,16 @@ public: struct fileHandle { int pos; bool used; - char* data; + char *data; int size; - - DSSaveFile* sramFile; }; class DSFileStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable { protected: - static const int WRITE_BUFFER_SIZE = 512; + enum { + WRITE_BUFFER_SIZE = 512 + }; /** File handle to the actual file. */ void *_handle; @@ -206,24 +209,24 @@ public: #undef stdout #undef stdin -#define stdout ((DS::fileHandle*) -1) -#define stderr ((DS::fileHandle*) -2) -#define stdin ((DS::fileHandle*) -3) +#define stdout ((DS::fileHandle *) -1) +#define stderr ((DS::fileHandle *) -2) +#define stdin ((DS::fileHandle *) -3) #define FILE DS::fileHandle // Please do not remove any of these prototypes that appear not to be required. -FILE* std_fopen(const char* name, const char* mode); -void std_fclose(FILE* handle); -size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle); -size_t std_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle); -bool std_feof(FILE* handle); -long int std_ftell(FILE* handle); -int std_fseek(FILE* handle, long int offset, int whence); -void std_clearerr(FILE* handle); -int std_fflush(FILE* handle); -int std_ferror(FILE* handle); - -} //namespace DS +FILE* std_fopen(const char *name, const char *mode); +void std_fclose(FILE *handle); +size_t std_fread(void *ptr, size_t size, size_t numItems, FILE *handle); +size_t std_fwrite(const void *ptr, size_t size, size_t numItems, FILE *handle); +bool std_feof(FILE *handle); +long int std_ftell(FILE *handle); +int std_fseek(FILE *handle, long int offset, int whence); +void std_clearerr(FILE *handle); +int std_fflush(FILE *handle); +int std_ferror(FILE *handle); + +} // End of namespace DS #endif //_DS_FS_H diff --git a/backends/fs/palmos/palmos-fs-factory.cpp b/backends/fs/palmos/palmos-fs-factory.cpp deleted file mode 100644 index 97b3644205..0000000000 --- a/backends/fs/palmos/palmos-fs-factory.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* 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(PALMOS_MODE) -#include "backends/fs/palmos/palmos-fs-factory.h" -#include "backends/fs/palmos/palmos-fs.cpp" - -DECLARE_SINGLETON(PalmOSFilesystemFactory) - -AbstractFSNode *PalmOSFilesystemFactory::makeRootFileNode() const { - return new PalmOSFilesystemNode(); -} - -AbstractFSNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() const { - return new PalmOSFilesystemNode(); -} - -AbstractFSNode *PalmOSFilesystemFactory::makeFileNodePath(const Common::String &path) const { - return new PalmOSFilesystemNode(path); -} -#endif diff --git a/backends/fs/palmos/palmos-fs-factory.h b/backends/fs/palmos/palmos-fs-factory.h deleted file mode 100644 index 72729c570d..0000000000 --- a/backends/fs/palmos/palmos-fs-factory.h +++ /dev/null @@ -1,49 +0,0 @@ -/* 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 PALMOS_FILESYSTEM_FACTORY_H -#define PALMOS_FILESYSTEM_FACTORY_H - -#include "common/singleton.h" -#include "backends/fs/fs-factory.h" - -/** - * Creates PalmOSFilesystemNode objects. - * - * Parts of this class are documented in the base interface class, FilesystemFactory. - */ -class PalmOSFilesystemFactory : public FilesystemFactory, public Common::Singleton<PalmOSFilesystemFactory> { -public: - virtual AbstractFSNode *makeRootFileNode() const; - virtual AbstractFSNode *makeCurrentDirectoryFileNode() const; - virtual AbstractFSNode *makeFileNodePath(const Common::String &path) const; - -protected: - PalmOSFilesystemFactory() {}; - -private: - friend class Common::Singleton<SingletonBaseType>; -}; - -#endif /*PALMOS_FILESYSTEM_FACTORY_H*/ diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp deleted file mode 100644 index 4e05f75d19..0000000000 --- a/backends/fs/palmos/palmos-fs.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* 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(PALMOS_MODE) - -#include "PalmVersion.h" -#include "globals.h" - -#include "backends/fs/abstract-fs.h" -#include "backends/fs/stdiostream.h" - -/** - * Implementation of the ScummVM file system API based on PalmOS VFS API. - * - * Parts of this class are documented in the base interface class, AbstractFSNode. - */ -class PalmOSFilesystemNode : public AbstractFSNode { -protected: - Common::String _displayName; - Common::String _path; - bool _isDirectory; - bool _isValid; - bool _isPseudoRoot; // TODO: get rid of this - -public: - /** - * Creates a PalmOSFilesystemNode with the root node as path. - */ - PalmOSFilesystemNode(); - - /** - * Creates a PalmOSFilesystemNode for a given path. - * - * @param path Common::String with the path the new node should point to. - */ - PalmOSFilesystemNode(const Common::String &p); - - virtual bool exists() const { return _isValid; } - 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 true; } //FIXME: this is just a stub - virtual bool isWritable() const { return true; } //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(); - -private: - /** - * Adds a single PalmOSFilesystemNode 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 Common::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); -}; - -void PalmOSFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, FileInfoType* find_data) { - PalmOSFilesystemNode entry; - bool isDir; - - isDir = (find_data->attributes & vfsFileAttrDirectory); - - if ((!isDir && mode == Common::FSNode::kListDirectoriesOnly) || - (isDir && mode == Common::FSNode::kListFilesOnly)) - return; - - entry._isDirectory = isDir; - entry._displayName = find_data->nameP; - entry._path = base; - entry._path += find_data->nameP; - - if (entry._isDirectory) - entry._path += "/"; - - entry._isValid = true; - entry._isPseudoRoot = false; - - list.push_back(new PalmOSFilesystemNode(entry)); -} - -PalmOSFilesystemNode::PalmOSFilesystemNode() { - _isDirectory = true; - _displayName = "Root"; - _isValid = true; - _path = "/"; - _isPseudoRoot = false; -} - -PalmOSFilesystemNode::PalmOSFilesystemNode(const Common::String &p) { - assert(p.size() > 0); - - _path = p; - _displayName = lastPathComponent(_path, '/'); - - UInt32 attr; - FileRef handle; - Err error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (!error) { - error = VFSFileGetAttributes(handle, &attr); - VFSFileClose(handle); - } - - if (error) { - _isValid = false; - _isDirectory = false; - - } else { - _isValid = true; - _isDirectory = (attr & vfsFileAttrDirectory); - } - - _isPseudoRoot = false; -} - -AbstractFSNode *PalmOSFilesystemNode::getChild(const Common::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); - - Common::String newPath(_path); - if (_path.lastChar() != '/') - newPath += '/'; - newPath += n; - - return new PalmOSFilesystemNode(newPath); -} - -bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { - assert(_isDirectory); - - //TODO: honor the hidden flag - - Err error; - Char nameP[256]; - FileInfoType desc; - FileRef handle; - UInt32 dirIterator = expIteratorStart; - - desc.nameP = nameP; - desc.nameBufLen = 256; - - error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); - if (error) - return false; - - while (dirIterator != expIteratorStop) { - error = VFSDirEntryEnumerate(handle, &dirIterator, &desc); - if (!error) - addFile(myList, mode, _path.c_str(), &desc); - } - - VFSFileClose(handle); - return true; -} - -AbstractFSNode *PalmOSFilesystemNode::getParent() const { - PalmOSFilesystemNode *p = 0; - - if (!_isPseudoRoot) { - const char *start = _path.c_str(); - const char *end = lastPathComponent(_path, '/'); - - p = new PalmOSFilesystemNode(); - p->_path = Common::String(start, end - start); - p->_isValid = true; - p->_isDirectory = true; - p->_displayName = lastPathComponent(p->_path, '/'); - p->_isPseudoRoot =(p->_path == "/"); - } - - return p; -} - -Common::SeekableReadStream *PalmOSFilesystemNode::createReadStream() { - return StdioStream::makeFromPath(getPath().c_str(), false); -} - -Common::WriteStream *PalmOSFilesystemNode::createWriteStream() { - return StdioStream::makeFromPath(getPath().c_str(), true); -} - -#endif // PALMOS_MODE diff --git a/backends/fs/psp/psp-stream.cpp b/backends/fs/psp/psp-stream.cpp index 83ff095aa8..67c73beeaa 100644 --- a/backends/fs/psp/psp-stream.cpp +++ b/backends/fs/psp/psp-stream.cpp @@ -81,10 +81,10 @@ PSPIoStream::PSPIoStream(const Common::String &path, bool writeMode) PSPIoStream::~PSPIoStream() { DEBUG_ENTER_FUNC(); - if (PowerMan.beginCriticalSection() == PowerManager::Blocked) + if (PowerMan.beginCriticalSection()) PSP_DEBUG_PRINT_FUNC("Suspended\n"); - PowerMan.unregisterSuspend(this); // Unregister with powermanager to be suspended + PowerMan.unregisterForSuspend(this); // Unregister with powermanager to be suspended // Must do this before fclose() or resume() will reopen. fclose((FILE *)_handle); // We don't need a critical section. Worst case, the handle gets closed on its own @@ -100,7 +100,7 @@ PSPIoStream::~PSPIoStream() { */ void *PSPIoStream::open() { DEBUG_ENTER_FUNC(); - if (PowerMan.beginCriticalSection() == PowerManager::Blocked) { + if (PowerMan.beginCriticalSection()) { // No need to open. Just return the _handle resume() already opened. PSP_DEBUG_PRINT_FUNC("Suspended\n"); } @@ -118,7 +118,7 @@ void *PSPIoStream::open() { _cache = (char *)memalign(64, CACHE_SIZE); } - PowerMan.registerSuspend(this); // Register with the powermanager to be suspended + PowerMan.registerForSuspend(this); // Register with the powermanager to be suspended PowerMan.endCriticalSection(); @@ -233,7 +233,7 @@ uint32 PSPIoStream::read(void *ptr, uint32 len) { } } - if (PowerMan.beginCriticalSection() == PowerManager::Blocked) + if (PowerMan.beginCriticalSection()) PSP_DEBUG_PRINT_FUNC("Suspended\n"); @@ -309,7 +309,7 @@ inline bool PSPIoStream::isOffsetInCache(uint32 offset) { uint32 PSPIoStream::write(const void *ptr, uint32 len) { DEBUG_ENTER_FUNC(); // Check if we can access the file - if (PowerMan.beginCriticalSection() == PowerManager::Blocked) + if (PowerMan.beginCriticalSection()) PSP_DEBUG_PRINT_FUNC("Suspended\n"); PSP_DEBUG_PRINT_FUNC("filename[%s], len[0x%x]\n", _path.c_str(), len); @@ -346,7 +346,7 @@ uint32 PSPIoStream::write(const void *ptr, uint32 len) { bool PSPIoStream::flush() { DEBUG_ENTER_FUNC(); // Enter critical section - if (PowerMan.beginCriticalSection() == PowerManager::Blocked) + if (PowerMan.beginCriticalSection()) PSP_DEBUG_PRINT_FUNC("Suspended\n"); int ret = fflush((FILE *)_handle); |