fix PSPFilesystemNode::parent() + some minor cleanup

svn-id: r22727
This commit is contained in:
Joost Peters 2006-05-28 22:02:38 +00:00
parent 8c1d71851a
commit 69b5d6fa3d

View file

@ -31,6 +31,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#define ROOT_PATH "ms0:/"
/* /*
* Implementation of the ScummVM file system API based on PSPSDK API. * Implementation of the ScummVM file system API based on PSPSDK API.
@ -41,7 +43,6 @@ protected:
String _displayName; String _displayName;
bool _isDirectory; bool _isDirectory;
bool _isValid; bool _isValid;
bool _isPseudoRoot;
String _path; String _path;
public: public:
@ -70,8 +71,7 @@ PSPFilesystemNode::PSPFilesystemNode() {
_isDirectory = true; _isDirectory = true;
_displayName = "Root"; _displayName = "Root";
_isValid = true; _isValid = true;
_path = "ms0:/"; _path = ROOT_PATH;
_isPseudoRoot = true;
} }
PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) { PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) {
@ -110,7 +110,6 @@ bool PSPFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
PSPFilesystemNode entry; PSPFilesystemNode entry;
entry._isValid = true; entry._isValid = true;
entry._isPseudoRoot = false;
entry._displayName = dir.d_name; entry._displayName = dir.d_name;
entry._path = _path; entry._path = _path;
entry._path += dir.d_name; entry._path += dir.d_name;
@ -146,20 +145,16 @@ const char *lastPathComponent(const Common::String &str) {
} }
AbstractFilesystemNode *PSPFilesystemNode::parent() const { AbstractFilesystemNode *PSPFilesystemNode::parent() const {
assert(_isValid || _isPseudoRoot); assert(_isValid);
if (_isPseudoRoot)
if (_path == ROOT_PATH)
return 0; return 0;
PSPFilesystemNode *p = new PSPFilesystemNode();
if (_path.size() > 5) { const char *start = _path.c_str();
const char *start = _path.c_str(); const char *end = lastPathComponent(_path);
const char *end = lastPathComponent(_path);
PSPFilesystemNode *p = new PSPFilesystemNode(String(start, end - start), false);
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;
p->_displayName = lastPathComponent(p->_path);
p->_isPseudoRoot = false;
}
return p; return p;
} }