1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Fix addAllModulesInFolder to scan only 2 subfolder levels

Other existing behavior remains:
* check whether the folder itself is a valid module
* always return Result::ok()
* may contain duplicate modules
This commit is contained in:
stefan 2016-10-06 18:37:43 +02:00
parent 46b38d77ab
commit 8f1d37a72e
2 changed files with 26 additions and 6 deletions

View file

@ -168,22 +168,39 @@ StringArray ModuleList::getIDs() const
return results;
}
Result ModuleList::addAllModulesInFolder (const File& path)
Result ModuleList::tryToAddModuleFromFolder (const File& path)
{
ModuleDescription m (path);
if (m.isValid())
{
modules.add (new ModuleDescription (m));
return Result::ok();
}
else
return Result::fail (path.getFullPathName() + " is not a valid module");
}
Result ModuleList::addAllModulesInFolder (const File& path)
{
if (! tryToAddModuleFromFolder (path))
{
const int subfolders = 2;
return addAllModulesInSubfoldersRecursively (path, subfolders);
}
return Result::ok();
}
Result ModuleList::addAllModulesInSubfoldersRecursively (const File& path, int depth)
{
if (depth > 0)
{
for (DirectoryIterator iter (path, false, "*", File::findDirectories); iter.next();)
{
Result r = addAllModulesInFolder (iter.getFile().getLinkedTarget());
const File& childPath = iter.getFile().getLinkedTarget();
if (r.failed())
return r;
if (! tryToAddModuleFromFolder (childPath))
addAllModulesInSubfoldersRecursively (childPath, depth - 1);
}
}