mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-03 23:52:41 +00:00
Added isValid to FilesystemNode and AbstractFilesystemNode. See my mail to -devel for more information.
svn-id: r23567
This commit is contained in:
parent
c59e7ece0a
commit
63aec29edb
@ -104,6 +104,8 @@ public:
|
||||
// By default, we use the actual file name as 'display name'.
|
||||
virtual String displayName() const { return name(); }
|
||||
|
||||
virtual bool isValid() const = 0;
|
||||
|
||||
virtual bool isDirectory() const = 0;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,8 @@ public:
|
||||
|
||||
virtual String displayName() const { return _displayName; }
|
||||
virtual String name() const { return _displayName; }
|
||||
// FIXME: isValid should return false if this Node can't be used!
|
||||
// client code can rely on the return value.
|
||||
virtual bool isValid() const { return true; }
|
||||
virtual bool isDirectory() const { return _isDirectory; }
|
||||
virtual String path() const { return _path; }
|
||||
|
@ -277,6 +277,15 @@ bool File::open(const String &filename, AccessMode mode) {
|
||||
|
||||
bool File::open(const FilesystemNode &node, AccessMode mode) {
|
||||
assert(mode == kFileReadMode || mode == kFileWriteMode);
|
||||
|
||||
if (!node.isValid()) {
|
||||
warning("File::open: Trying to open an invalid FilesystemNode object");
|
||||
return false;
|
||||
} else if (node.isDirectory()) {
|
||||
warning("File::open: Trying to open a FilesystemNode which is a directory");
|
||||
return false;
|
||||
}
|
||||
|
||||
String filename(node.name());
|
||||
|
||||
if (_handle) {
|
||||
@ -288,10 +297,8 @@ bool File::open(const FilesystemNode &node, AccessMode mode) {
|
||||
|
||||
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
|
||||
|
||||
|
||||
_handle = fopen(node.path().c_str(), modeStr);
|
||||
|
||||
|
||||
if (_handle == NULL) {
|
||||
if (mode == kFileReadMode)
|
||||
debug(2, "File %s not found", filename.c_str());
|
||||
@ -313,6 +320,9 @@ bool File::exists(const String &filename) {
|
||||
// First try to find the file it via a FilesystemNode (in case an absolute
|
||||
// path was passed). But we only use this to filter out directories.
|
||||
FilesystemNode file(filename);
|
||||
// FIXME: can't use isValid() here since at the time of writing
|
||||
// FilesystemNode is to be unable to find for example files
|
||||
// added in extrapath
|
||||
if (file.isDirectory())
|
||||
return false;
|
||||
|
||||
|
@ -77,6 +77,12 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool FilesystemNode::isValid() const {
|
||||
if (_realNode == 0)
|
||||
return false;
|
||||
return _realNode->isValid();
|
||||
}
|
||||
|
||||
FilesystemNode FilesystemNode::getParent() const {
|
||||
if (_realNode == 0)
|
||||
return *this;
|
||||
|
@ -113,6 +113,11 @@ public:
|
||||
*/
|
||||
FilesystemNode &operator =(const FilesystemNode &node);
|
||||
|
||||
/**
|
||||
* Checks if the FilesystemNode is valid for any usage
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Get the parent node of this node. If this node has no parent node,
|
||||
* then it returns a duplicate of this node.
|
||||
|
Loading…
Reference in New Issue
Block a user