diff options
-rw-r--r-- | backends/fs/abstract-fs.h | 10 | ||||
-rw-r--r-- | backends/fs/amigaos4/amigaos4-fs.cpp | 38 | ||||
-rw-r--r-- | backends/fs/dc/dc-fs.cpp | 4 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs.cpp | 94 | ||||
-rw-r--r-- | backends/fs/ds/ds-fs.h | 2 | ||||
-rw-r--r-- | backends/fs/gp32/gp32-fs.cpp | 4 | ||||
-rw-r--r-- | backends/fs/morphos/abox-fs.cpp | 51 | ||||
-rw-r--r-- | backends/fs/palmos/palmos-fs.cpp | 6 | ||||
-rw-r--r-- | backends/fs/posix/posix-fs.cpp | 3 | ||||
-rw-r--r-- | backends/fs/ps2/ps2-fs.cpp | 17 | ||||
-rw-r--r-- | backends/fs/psp/psp-fs.cpp | 6 | ||||
-rw-r--r-- | backends/fs/symbian/symbian-fs.cpp | 4 | ||||
-rw-r--r-- | backends/fs/windows/windows-fs.cpp | 4 |
13 files changed, 144 insertions, 99 deletions
diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index aeae0ac1c2..611948691e 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -101,9 +101,15 @@ public: * @note By default, this method returns the value of getName(). */ virtual String getDisplayName() const { return getName(); } - + /** - * Returns a string with an architecture dependent path description. + * Returns the last component of the path pointed by this FilesystemNode. + * + * Examples (POSIX): + * /foo/bar.txt would return /bar.txt + * /foo/bar/ would return /bar/ + * + * @note This method is very architecture dependent, please check the concrete implementation for more information. */ virtual String getName() const = 0; diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp index c3a98e9b8a..ef6447fcf7 100644 --- a/backends/fs/amigaos4/amigaos4-fs.cpp +++ b/backends/fs/amigaos4/amigaos4-fs.cpp @@ -93,7 +93,6 @@ public: virtual String getPath() const { return _sPath; }; virtual bool isDirectory() const { return _bIsDirectory; }; virtual bool isReadable() const { return true; } //FIXME: this is just a stub - virtual bool isValid() const { return _bIsValid; }; virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -106,9 +105,6 @@ public: virtual AbstractFSList listVolumes() const; }; -// TODO: this is ripped of -// AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) -// maybe change it to use this function instead? /** * Returns the last component of a given path. * @@ -117,6 +113,12 @@ public: */ const char *lastPathComponent(const Common::String &str) { int offset = str.size(); + + if (offset <= 0) { + debug(6, "Bad offset"); + return; + } + const char *p = str.c_str(); while (offset > 0 && (p[offset-1] == '/' || p[offset-1] == ':')) @@ -151,19 +153,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) { } _sPath = p; - - // Extract last component from path - const char *str = p.c_str(); - - while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':')) - offset--; - - while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { - len++; - offset--; - } - - _sDisplayName = String(str + offset, len); + _sDisplayName = lastPathComponent(_sPath); _pFileLock = 0; _bIsDirectory = false; @@ -352,7 +342,12 @@ bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b if (lock) { AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name); if (entry) { - if (entry->isValid()) + //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode + // specification, the following call had to be changed: + // if (entry->isValid()) + // Please verify that the logic of the code remains coherent. Also, remember + // that the isReadable() and isWritable() methods are available. + if (entry->exists()) myList.push_back(entry); else delete entry; @@ -453,7 +448,12 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const { AmigaOSFilesystemNode *entry = new AmigaOSFilesystemNode(volumeLock, buffer); if (entry) { - if (entry->isValid()) + //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode + // specification, the following call had to be changed: + // if (entry->isValid()) + // Please verify that the logic of the code remains coherent. Also, remember + // that the isReadable() and isWritable() methods are available. + if(entry->exists()) myList.push_back(entry); else delete entry; diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index a814d05cec..32170eef27 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -62,7 +62,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -81,6 +80,9 @@ public: * @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; diff --git a/backends/fs/ds/ds-fs.cpp b/backends/fs/ds/ds-fs.cpp index 891f0df636..c5d0107f7b 100644 --- a/backends/fs/ds/ds-fs.cpp +++ b/backends/fs/ds/ds-fs.cpp @@ -36,12 +36,30 @@ namespace DS { ZipFile* DSFileSystemNode::_zipFile = NULL; char currentDir[128]; +const char *lastPathComponentDS(const Common::String &str) { + if (str.empty()) + return ""; + + char disp[128]; + char* pathStr = (char *) str.c_str(); + int lastSlash = 3; + + for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { + if (path[r] == '\\') { + lastSlash = r; + } + } + + strcpy(disp, pathStr + lastSlash + 1); + + return disp; +} + DSFileSystemNode::DSFileSystemNode() { - _displayName = "ds:/"; _path = "ds:/"; + _displayName = "ds:/"; _isValid = true; _isDirectory = true; - _path = "ds:/"; /* if (!_archive) { _archive = (GBFS_FILE *) find_first_gbfs_file(scummdata); @@ -56,23 +74,12 @@ DSFileSystemNode::DSFileSystemNode() { DSFileSystemNode::DSFileSystemNode(const String& path) { // consolePrintf("--%s ",path.c_str()); - char disp[128]; - char* pathStr = (char *) path.c_str(); - - int lastSlash = 3; - for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { - if (path[r] == '\\') { - lastSlash = r; - } - } - - strcpy(disp, pathStr + lastSlash + 1); - - _displayName = String(disp); _path = path; + _displayName = lastPathComponentDS(_path); // _isValid = true; // _isDirectory = false; + char* pathStr = (char *) path.c_str(); if (!strncmp(pathStr, "ds:/", 4)) { pathStr += 4; } @@ -99,19 +106,8 @@ DSFileSystemNode::DSFileSystemNode(const String& path) { DSFileSystemNode::DSFileSystemNode(const String& path, bool isDir) { // consolePrintf("--%s ",path.c_str()); - char disp[128]; - char* pathStr = (char *) path.c_str(); - int lastSlash = 3; - for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { - if (path[r] == '\\') { - lastSlash = r; - } - } - - strcpy(disp, pathStr + lastSlash + 1); - - _displayName = String(disp); _path = path; + _displayName = lastPathComponentDS(_path); _isValid = true; _isDirectory = isDir; @@ -206,20 +202,14 @@ AbstractFilesystemNode* DSFileSystemNode::getParent() const { // GBAMPFileSystemNode - File system using GBA Movie Player and CF card // ////////////////////////////////////////////////////////////////////////// -GBAMPFileSystemNode::GBAMPFileSystemNode() { - _displayName = "mp:/"; - _path = "mp:/"; - _isValid = true; - _isDirectory = true; - _path = "mp:/"; -} - -GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { -// consolePrintf("'%s'",path.c_str()); +const char *lastPathComponentGBAMP(const Common::String &str) { + if (str.empty()) + return ""; char disp[128]; - char* pathStr = (char *) path.c_str(); + char* pathStr = (char *) str.c_str(); int lastSlash = 3; + for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { if ((path[r] == '\\') || (path[r] == '/')) { lastSlash = r; @@ -227,7 +217,20 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { } strcpy(disp, pathStr + lastSlash + 1); + + return disp; +} + +GBAMPFileSystemNode::GBAMPFileSystemNode() { + _path = "mp:/"; + _displayName = "mp:/"; + _isValid = true; + _isDirectory = true; +} +GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { +// consolePrintf("'%s'",path.c_str()); + char check[128]; int success; @@ -243,8 +246,8 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { } // consolePrintf("Path: %s (%d)\n", check, success); - _displayName = String(disp); _path = path; + _displayName = lastPathComponentGBAMP(_path); _isValid = success == FT_FILE; _isDirectory = success == FT_DIR; } @@ -252,19 +255,8 @@ GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path) { GBAMPFileSystemNode::GBAMPFileSystemNode(const String& path, bool isDirectory) { // consolePrintf("'%s'",path.c_str()); - char disp[128]; - char* pathStr = (char *) path.c_str(); - int lastSlash = 3; - for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { - if ((path[r] == '\\') || (path[r] == '/')) { - lastSlash = r; - } - } - - strcpy(disp, pathStr + lastSlash + 1); - - _displayName = String(disp); _path = path; + _displayName = lastPathComponentGBAMP(_path); _isValid = true; _isDirectory = isDirectory; } diff --git a/backends/fs/ds/ds-fs.h b/backends/fs/ds/ds-fs.h index ead0acc05e..70228f5e38 100644 --- a/backends/fs/ds/ds-fs.h +++ b/backends/fs/ds/ds-fs.h @@ -83,7 +83,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub /** @@ -149,7 +148,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub /** diff --git a/backends/fs/gp32/gp32-fs.cpp b/backends/fs/gp32/gp32-fs.cpp index 4fb88467ea..1df07a0d37 100644 --- a/backends/fs/gp32/gp32-fs.cpp +++ b/backends/fs/gp32/gp32-fs.cpp @@ -60,7 +60,6 @@ public: // FIXME: isValid should return false if this Node can't be used! // so client code can rely on the return value. virtual bool isReadable() const { return true; } //FIXME: this is just a stub - virtual bool isValid() const { return true; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -82,6 +81,9 @@ const char gpRootPath[] = "gp:\\"; * @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; diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp index 05c13662bc..7b8bb4e451 100644 --- a/backends/fs/morphos/abox-fs.cpp +++ b/backends/fs/morphos/abox-fs.cpp @@ -80,7 +80,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &name) const; @@ -93,12 +92,33 @@ public: static AbstractFSList getRootChildren(); }; +/** + * Returns the last component of a given path. + * + * @param str String containing the path. + * @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 *str = _path.c_str(); + while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) + offset--; + while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { + len++; + offset--; + } + + return str + offset; +} + ABoxFilesystemNode::ABoxFilesystemNode() { + _path = ""; _displayName = "Mounted Volumes"; _isValid = true; _isDirectory = true; - _path = ""; _lock = NULL; } @@ -108,16 +128,7 @@ ABoxFilesystemNode::ABoxFilesystemNode(const String &p) { assert(offset > 0); _path = p; - - // Extract last component from path - const char *str = p.c_str(); - while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) - offset--; - while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { - len++; - offset--; - } - _displayName = String(str + offset, len); + _displayName = lastPathComponent(_path); _lock = NULL; _isDirectory = false; @@ -212,10 +223,10 @@ ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name) ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node) { + _path = node._path; _displayName = node._displayName; _isValid = node._isValid; _isDirectory = node._isDirectory; - _path = node._path; _lock = DupLock(node._lock); } @@ -299,7 +310,12 @@ bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool h entry = new ABoxFilesystemNode(lock, fib->fib_FileName); if (entry) { - if (entry->isValid()) + //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode + // specification, the following call had to be changed: + // if (entry->isValid()) + // Please verify that the logic of the code remains coherent. Also, remember + // that the isReadable() and isWritable() methods are available. + if (entry->exists()) list.push_back(entry); else delete entry; @@ -378,7 +394,12 @@ AbstractFSList ABoxFilesystemNode::getRootChildren() entry = new ABoxFilesystemNode(volume_lock, name); if (entry) { - if (entry->isValid()) + //FIXME: since the isValid() function is no longer part of the AbstractFilesystemNode + // specification, the following call had to be changed: + // if (entry->isValid()) + // Please verify that the logic of the code remains coherent. Also, remember + // that the isReadable() and isWritable() methods are available. + if (entry->exists()) list.push_back(entry); else delete entry; diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp index cda3ee3c33..5ad3302d79 100644 --- a/backends/fs/palmos/palmos-fs.cpp +++ b/backends/fs/palmos/palmos-fs.cpp @@ -61,7 +61,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -92,6 +91,9 @@ private: * @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; @@ -136,7 +138,7 @@ PalmOSFilesystemNode::PalmOSFilesystemNode() { PalmOSFilesystemNode::PalmOSFilesystemNode(const String &p) { _path = p; - _displayName = lastPathComponent(p); + _displayName = lastPathComponent(_path); UInt32 attr; FileRef handle; diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 1f66d5639d..8d455b99e3 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -91,6 +91,9 @@ private: * @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; diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp index 727e1a894f..f371af6e57 100644 --- a/backends/fs/ps2/ps2-fs.cpp +++ b/backends/fs/ps2/ps2-fs.cpp @@ -68,7 +68,6 @@ public: virtual 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 isValid() const { return !_isRoot; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); } @@ -77,6 +76,22 @@ public: virtual AbstractFilesystemNode *getParent() const; }; +/** + * Returns the last component of a given path. + * + * @param str String containing the path. + * @return Pointer to the first char of the last component inside str. + */ +const char *lastPathComponent(const Common::String &str) { + //FIXME: implement this method properly. + // This code is probably around the constructors, + // but I couldn't figure it out without having + // doubts on the correctness of my assumptions. + // Therefore, I leave it to the porter to correctly + // implement this method. + assert(false); +} + Ps2FilesystemNode::Ps2FilesystemNode() { _isDirectory = true; _isRoot = true; diff --git a/backends/fs/psp/psp-fs.cpp b/backends/fs/psp/psp-fs.cpp index dfe52c1125..518a54d7d9 100644 --- a/backends/fs/psp/psp-fs.cpp +++ b/backends/fs/psp/psp-fs.cpp @@ -64,7 +64,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -83,6 +82,9 @@ public: * @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; @@ -170,8 +172,6 @@ bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool } AbstractFilesystemNode *PSPFilesystemNode::getParent() const { - assert(_isValid); - if (_path == ROOT_PATH) return 0; diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp index 0d7b37ee4d..845a03b91b 100644 --- a/backends/fs/symbian/symbian-fs.cpp +++ b/backends/fs/symbian/symbian-fs.cpp @@ -64,7 +64,6 @@ public: virtual 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 isValid() const { return _isValid; } virtual bool isWritable() const { return true; } //FIXME: this is just a stub virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -83,6 +82,9 @@ public: * @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; diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp index e048980ba1..7bb2681e3c 100644 --- a/backends/fs/windows/windows-fs.cpp +++ b/backends/fs/windows/windows-fs.cpp @@ -92,7 +92,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; @@ -139,6 +138,9 @@ private: * @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; |