diff options
Diffstat (limited to 'backends/platform/dc/dc-fs.cpp')
-rw-r--r-- | backends/platform/dc/dc-fs.cpp | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/backends/platform/dc/dc-fs.cpp b/backends/platform/dc/dc-fs.cpp index f4dc4037df..0da77e317e 100644 --- a/backends/platform/dc/dc-fs.cpp +++ b/backends/platform/dc/dc-fs.cpp @@ -34,18 +34,15 @@ * * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ - -/* A file */ class RoninCDFileNode : public AbstractFilesystemNode { protected: String _path; - static const char *lastPathComponent(const Common::String &str); public: RoninCDFileNode(const String &path) : _path(path) {}; virtual bool exists() const { return true; } - virtual String getName() const { return lastPathComponent(_path); } + virtual String getName() const { return lastPathComponent(_path, '/'); } virtual String getPath() const { return _path; } virtual bool isDirectory() const { return false; } virtual bool isReadable() const { return true; } @@ -61,7 +58,7 @@ public: /* A directory */ class RoninCDDirectoryNode : public RoninCDFileNode { public: - RoninCDDirectoryNode(const String &path) : RoninCDFileNode(path) {}; + RoninCDDirectoryNode(const String &path) : RoninCDFileNode(path) {}; virtual bool isDirectory() const { return true; } virtual AbstractFilesystemNode *getChild(const String &n) const; @@ -77,32 +74,7 @@ public: virtual bool isReadable() const { return false; } }; -/** - * Returns the last component of a given path. - * - * Examples: - * /foo/bar.txt would return /bar.txt - * /foo/bar/ would return /bar/ - * - * @param str String containing the path. - * @return Pointer to the first char of the last component inside str. - */ -const char *RoninCDFileNode::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; -} - -AbstractFilesystemNode *RoninCDFileNode::makeFileNodePath(const Common::String &path) -{ +AbstractFilesystemNode *RoninCDFileNode::makeFileNodePath(const Common::String &path) { assert(path.size() > 0); int fd; @@ -110,12 +82,10 @@ AbstractFilesystemNode *RoninCDFileNode::makeFileNodePath(const Common::String & if ((fd = open(path.c_str(), O_RDONLY)) >= 0) { close(fd); return new RoninCDFileNode(path); - } - else if ((fd = open(path.c_str(), O_DIR|O_RDONLY)) >= 0) { + } else if ((fd = open(path.c_str(), O_DIR|O_RDONLY)) >= 0) { close(fd); return new RoninCDDirectoryNode(path); - } - else { + } else { return NULL; } } @@ -168,7 +138,7 @@ AbstractFilesystemNode *RoninCDFileNode::getParent() const { return 0; const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char *end = lastPathComponent(_path, '/'); return new RoninCDDirectoryNode(String(start, end - start)); } |