diff options
author | David Corrales | 2007-10-07 00:28:38 +0000 |
---|---|---|
committer | David Corrales | 2007-10-07 00:28:38 +0000 |
commit | aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74 (patch) | |
tree | 86915d69c1463c4ff6fda79ab849b0f62432647b /backends/fs/morphos | |
parent | 0fab64817fd027a8321e047c1007d0e7e9e135fc (diff) | |
download | scummvm-rg350-aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74.tar.gz scummvm-rg350-aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74.tar.bz2 scummvm-rg350-aba30d7ea8541f7260ec7b96a8d33dd7dc06ed74.zip |
Commit of patch #1804861. It implements a static lastPathComponent() function in each backend, used to extract the last path component of a given path, returned by getName().
svn-id: r29159
Diffstat (limited to 'backends/fs/morphos')
-rw-r--r-- | backends/fs/morphos/abox-fs.cpp | 51 |
1 files changed, 36 insertions, 15 deletions
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; |