mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 19:51:49 +00:00
Reworked FilesystemNode::lookupFile (fixing doxygen comment, making it possible to restrict the search depth, fixed the 'exhaustive' mode and some other tweaks)
svn-id: r30644
This commit is contained in:
parent
4204371c19
commit
223f22c773
@ -171,61 +171,40 @@ bool FilesystemNode::isWritable() const {
|
||||
return _realNode->isWritable();
|
||||
}
|
||||
|
||||
bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &pattern, bool hidden, bool exhaustive) const
|
||||
{
|
||||
int matches = 0;
|
||||
|
||||
for (FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) {
|
||||
if (entry->isDirectory()) {
|
||||
matches += lookupFileRec(results, *entry, pattern, hidden, exhaustive);
|
||||
}
|
||||
}
|
||||
|
||||
return ((matches > 0) ? true : false);
|
||||
}
|
||||
|
||||
bool FilesystemNode::lookupFile(FSList &results, Common::String &pattern, bool hidden, bool exhaustive) const
|
||||
{
|
||||
int matches;
|
||||
|
||||
bool FilesystemNode::lookupFile(FSList &results, const Common::String &p, bool hidden, bool exhaustive, int depth) const {
|
||||
if (!isDirectory())
|
||||
return false;
|
||||
|
||||
FilesystemNode dir = *this;
|
||||
matches = lookupFileRec(results, dir, pattern, hidden, exhaustive);
|
||||
|
||||
return ((matches > 0) ? true : false);
|
||||
}
|
||||
|
||||
int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &pattern, bool hidden, bool exhaustive) const
|
||||
{
|
||||
FSList entries;
|
||||
FSList children;
|
||||
int matches = 0;
|
||||
FSList subdirs;
|
||||
Common::String pattern = p;
|
||||
|
||||
pattern.toUppercase();
|
||||
dir.getChildren(entries, FilesystemNode::kListAll, hidden);
|
||||
|
||||
//Breadth search (entries in the same level)
|
||||
for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) {
|
||||
// First match all files on this level
|
||||
getChildren(children, FilesystemNode::kListAll, hidden);
|
||||
for (FSList::iterator entry = children.begin(); entry != children.end(); ++entry) {
|
||||
if (entry->isDirectory()) {
|
||||
children.push_back(*entry);
|
||||
if (depth != 0)
|
||||
subdirs.push_back(*entry);
|
||||
} else {
|
||||
Common::String filename = entry->getName();
|
||||
filename.toUppercase();
|
||||
if (Common::matchString(filename.c_str(), pattern.c_str())) {
|
||||
results.push_back(*entry);
|
||||
matches++;
|
||||
|
||||
if (!exhaustive)
|
||||
break;
|
||||
return true; // Abort on first match if no exhaustive search was requested
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Depth search (entries in lower levels)
|
||||
for (FSList::iterator child = children.begin(); child != children.end(); ++child) {
|
||||
matches += lookupFileRec(results, *child, pattern, hidden, exhaustive);
|
||||
// Now scan all subdirs
|
||||
for (FSList::iterator child = subdirs.begin(); child != subdirs.end(); ++child) {
|
||||
child->lookupFile(results, pattern, hidden, exhaustive, depth - 1);
|
||||
if (!exhaustive && !results.empty())
|
||||
return true; // Abort on first match if no exhaustive search was requested
|
||||
}
|
||||
|
||||
return matches;
|
||||
return !results.empty();
|
||||
}
|
||||
|
45
common/fs.h
45
common/fs.h
@ -216,37 +216,24 @@ public:
|
||||
* @return bool true if the object can be written to, false otherwise.
|
||||
*/
|
||||
virtual bool isWritable() const;
|
||||
|
||||
|
||||
/**
|
||||
* Searches recursively for a filename inside the given directories.
|
||||
* Searches recursively for files matching the specified pattern inside this directory and
|
||||
* all its subdirectories. It is safe to call this method for non-directories, in this case
|
||||
* it will just return false.
|
||||
*
|
||||
* For each directory in the directory list a breadth-first search is performed,
|
||||
* that is, the current directory entries are scanned before going into subdirectories.
|
||||
*
|
||||
* @param results List to put the matches in.
|
||||
* @param fslist List of directories to search within.
|
||||
* @param pattern Pattern of the files to look for.
|
||||
* @param hidden Whether to search hidden files or not.
|
||||
* @param exhaustive Whether to continue searching after one match has been found.
|
||||
*
|
||||
* @return true if matches could be found, false otherwise.
|
||||
*/
|
||||
virtual bool lookupFile(FSList &results, FSList &fslist, Common::String &pattern, bool hidden, bool exhaustive) const;
|
||||
|
||||
/**
|
||||
* Searches recursively for a filename inside this directory.
|
||||
*
|
||||
* The search is performed breadth-first, that is, the current directory entries
|
||||
* are scanned before going into subdirectories.
|
||||
* The files in each directory are scanned first. Other than that, a depth first search
|
||||
* is performed.
|
||||
*
|
||||
* @param results List to put the matches in.
|
||||
* @param pattern Pattern of the files to look for.
|
||||
* @param hidden Whether to search hidden files or not.
|
||||
* @param exhaustive Whether to continue searching after one match has been found.
|
||||
* @param depth How many levels to search through (-1 = search all subdirs, 0 = only the current one)
|
||||
*
|
||||
* @return true if matches could be found, false otherwise.
|
||||
*/
|
||||
virtual bool lookupFile(FSList &results, Common::String &pattern, bool hidden, bool exhaustive) const;
|
||||
virtual bool lookupFile(FSList &results, const Common::String &pattern, bool hidden, bool exhaustive, int depth = -1) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -254,22 +241,6 @@ protected:
|
||||
* deletes the corresponding underlying references.
|
||||
*/
|
||||
void decRefCount();
|
||||
|
||||
/**
|
||||
* Searches recursively for a filename inside the given directory.
|
||||
*
|
||||
* The search is performed breadth-first, that is, the current directory entries
|
||||
* are scanned before going into subdirectories.
|
||||
*
|
||||
* @param results List to put the matches in.
|
||||
* @param dir Directory to search within.
|
||||
* @param pattern Pattern of the files to look for.
|
||||
* @param hidden Whether to search hidden files or not.
|
||||
* @param exhaustive Whether to continue searching after one match has been found.
|
||||
*
|
||||
* @return The number of matches found.
|
||||
*/
|
||||
int lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &pattern, bool hidden, bool exhaustive) const;
|
||||
};
|
||||
|
||||
//} // End of namespace Common
|
||||
|
Loading…
x
Reference in New Issue
Block a user