mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 00:15:30 +00:00
Modified FSDirectory::lookupCache to return a FSNode *pointer*, so that we can distinguish between lookup failures and invalid cache entries. Also changed SearchSet::createReadStreamForMember to not use hasFile anymore, based on the assumption that any Archive::createReadStreamForMember implementation has to verify whether the member name is valid anyway (clarified the doxygen docs accordingly)
svn-id: r38787
This commit is contained in:
parent
c397b37bfb
commit
9b45dd2849
@ -99,49 +99,51 @@ FSNode FSDirectory::getFSNode() const {
|
||||
return _node;
|
||||
}
|
||||
|
||||
FSNode FSDirectory::lookupCache(NodeCache &cache, const String &name) const {
|
||||
FSNode *FSDirectory::lookupCache(NodeCache &cache, const String &name) const {
|
||||
// make caching as lazy as possible
|
||||
if (!name.empty()) {
|
||||
ensureCached();
|
||||
|
||||
if (cache.contains(name))
|
||||
return cache[name];
|
||||
return &cache[name];
|
||||
}
|
||||
|
||||
return FSNode();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FSDirectory::hasFile(const String &name) {
|
||||
if (name.empty() || !_node.isDirectory())
|
||||
return false;
|
||||
|
||||
FSNode node = lookupCache(_fileCache, name);
|
||||
return node.exists();
|
||||
FSNode *node = lookupCache(_fileCache, name);
|
||||
return node && node->exists();
|
||||
}
|
||||
|
||||
ArchiveMemberPtr FSDirectory::getMember(const String &name) {
|
||||
if (name.empty() || !_node.isDirectory())
|
||||
return ArchiveMemberPtr();
|
||||
|
||||
FSNode node = lookupCache(_fileCache, name);
|
||||
FSNode *node = lookupCache(_fileCache, name);
|
||||
|
||||
if (!node.exists()) {
|
||||
if (!node || !node->exists()) {
|
||||
warning("FSDirectory::getMember: FSNode does not exist");
|
||||
return ArchiveMemberPtr();
|
||||
} else if (node.isDirectory()) {
|
||||
} else if (node->isDirectory()) {
|
||||
warning("FSDirectory::getMember: FSNode is a directory");
|
||||
return ArchiveMemberPtr();
|
||||
}
|
||||
|
||||
return ArchiveMemberPtr(new FSNode(node));
|
||||
return ArchiveMemberPtr(new FSNode(*node));
|
||||
}
|
||||
|
||||
SeekableReadStream *FSDirectory::createReadStreamForMember(const String &name) const {
|
||||
if (name.empty() || !_node.isDirectory())
|
||||
return 0;
|
||||
|
||||
FSNode node = lookupCache(_fileCache, name);
|
||||
SeekableReadStream *stream = node.createReadStream();
|
||||
FSNode *node = lookupCache(_fileCache, name);
|
||||
if (!node)
|
||||
return 0;
|
||||
SeekableReadStream *stream = node->createReadStream();
|
||||
if (!stream)
|
||||
warning("FSDirectory::createReadStreamForMember: Can't create stream for file '%s'", name.c_str());
|
||||
|
||||
@ -156,8 +158,11 @@ FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &na
|
||||
if (name.empty() || !_node.isDirectory())
|
||||
return 0;
|
||||
|
||||
FSNode node = lookupCache(_subDirCache, name);
|
||||
return new FSDirectory(prefix, node, depth);
|
||||
FSNode *node = lookupCache(_subDirCache, name);
|
||||
if (!node)
|
||||
return 0;
|
||||
|
||||
return new FSDirectory(prefix, *node, depth);
|
||||
}
|
||||
|
||||
void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const {
|
||||
@ -380,8 +385,9 @@ SeekableReadStream *SearchSet::createReadStreamForMember(const String &name) con
|
||||
|
||||
ArchiveNodeList::iterator it = _list.begin();
|
||||
for ( ; it != _list.end(); ++it) {
|
||||
if (it->_arc->hasFile(name))
|
||||
return it->_arc->createReadStreamForMember(name);
|
||||
SeekableReadStream *stream = it->_arc->createReadStreamForMember(name);
|
||||
if (stream)
|
||||
return stream;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -116,7 +116,8 @@ public:
|
||||
virtual ArchiveMemberPtr getMember(const String &name) = 0;
|
||||
|
||||
/**
|
||||
* Create a stream bound to a file in the archive.
|
||||
* Create a stream bound to a member in the archive. If no member with the
|
||||
* specified name exists, then 0 is returned.
|
||||
* @return the newly created input stream
|
||||
*/
|
||||
virtual SeekableReadStream *createReadStreamForMember(const String &name) const = 0;
|
||||
|
@ -268,7 +268,7 @@ class FSDirectory : public Archive {
|
||||
mutable int _depth;
|
||||
|
||||
// look for a match
|
||||
FSNode lookupCache(NodeCache &cache, const String &name) const;
|
||||
FSNode *lookupCache(NodeCache &cache, const String &name) const;
|
||||
|
||||
// cache management
|
||||
void cacheDirectoryRecursive(FSNode node, int depth, const String& prefix) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user