1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-14 00:14:18 +00:00

Projucer: Cleaned up the module scanning code

This commit is contained in:
ed 2018-07-10 17:33:43 +01:00
parent b14988fb1d
commit 84cc1dc4a0
5 changed files with 83 additions and 170 deletions

View file

@ -157,31 +157,29 @@ StringArray ModuleList::getIDs() const
return results;
}
Result ModuleList::tryToAddModuleFromFolder (const File& path)
bool ModuleList::tryToAddModuleFromFolder (const File& path)
{
ModuleDescription m (path);
if (m.isValid())
{
modules.add (new ModuleDescription (m));
return Result::ok();
return true;
}
return Result::fail (path.getFullPathName() + " is not a valid module");
return false;
}
Result ModuleList::addAllModulesInFolder (const File& path)
void ModuleList::addAllModulesInFolder (const File& path)
{
if (! tryToAddModuleFromFolder (path))
{
int subfolders = 5;
return addAllModulesInSubfoldersRecursively (path, subfolders);
addAllModulesInSubfoldersRecursively (path, subfolders);
}
return Result::ok();
}
Result ModuleList::addAllModulesInSubfoldersRecursively (const File& path, int depth)
void ModuleList::addAllModulesInSubfoldersRecursively (const File& path, int depth)
{
if (depth > 0)
{
@ -193,58 +191,32 @@ Result ModuleList::addAllModulesInSubfoldersRecursively (const File& path, int d
addAllModulesInSubfoldersRecursively (childPath, depth - 1);
}
}
return Result::ok();
}
static File getModuleFolderFromPathIfItExists (const String& path, const String& moduleID, const Project& project)
//==============================================================================
static File getModuleFolderFromPathIfItExists (const String& path, const String& moduleID)
{
if (path.isNotEmpty())
{
auto moduleFolder = project.resolveFilename (path);
ModuleList list;
list.addAllModulesInFolder (path);
if (moduleFolder.exists())
{
if (ModuleDescription (moduleFolder).getID() == moduleID)
return moduleFolder;
auto f = moduleFolder.getChildFile (moduleID);
if (ModuleDescription (f).getID() == moduleID)
return f;
}
if (auto* desc = list.getModuleWithID (moduleID))
return desc->getFolder();
}
return {};
}
static File getPathToSpecifiedModule (Project& project, StringRef moduleID)
{
auto& modules = project.getModules();
if (! modules.shouldUseGlobalPath (moduleID))
{
for (Project::ExporterIterator exporter (project); exporter.next();)
{
if (! exporter->mayCompileOnCurrentOS())
continue;
auto path = getModuleFolderFromPathIfItExists (exporter->getPathForModuleString (moduleID), moduleID, project);
if (path != File())
return path;
}
}
return {};
}
static Array<File> getAllPossibleModulePathsFromExporters (Project& project)
static Array<File> getAllPossibleModulePathsFromExporters (Project& project, bool onlyThisOS)
{
StringArray paths;
for (Project::ExporterIterator exporter (project); exporter.next();)
{
if (onlyThisOS && ! exporter->mayCompileOnCurrentOS())
continue;
auto& modules = project.getModules();
auto n = modules.getNumModules();
@ -285,21 +257,14 @@ static Array<File> getAllPossibleModulePathsFromExporters (Project& project)
return files;
}
Result ModuleList::scanProjectExporterModulePaths (Project& project)
void ModuleList::scanProjectExporterModulePaths (Project& project)
{
modules.clear();
Result result (Result::ok());
for (auto& m : getAllPossibleModulePathsFromExporters (project))
{
result = addAllModulesInFolder (m);
if (result.failed())
break;
}
for (auto& m : getAllPossibleModulePathsFromExporters (project, false))
addAllModulesInFolder (m);
sort();
return result;
}
void ModuleList::scanGlobalJuceModulePath()
@ -679,7 +644,7 @@ EnabledModuleList::EnabledModuleList (Project& p, const ValueTree& s)
ModuleDescription EnabledModuleList::getModuleInfo (const String& moduleID)
{
return ModuleDescription (getModuleFolder (moduleID));
return ModuleDescription (findFolderForModule (moduleID));
}
bool EnabledModuleList::isModuleEnabled (const String& moduleID) const
@ -711,49 +676,36 @@ Value EnabledModuleList::shouldShowAllModuleFilesInProject (const String& module
.getPropertyAsValue (Ids::showAllCode, getUndoManager());
}
File EnabledModuleList::findUserModuleFolder (const String& possiblePaths, const String& moduleID)
{
auto paths = StringArray::fromTokens (possiblePaths, ";", {});
for (auto p : paths)
{
p = p.replace ("~", File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
auto f = File::createFileWithoutCheckingPath (p.trim());
if (f.exists())
{
auto moduleFolder = getModuleFolderFromPathIfItExists (f.getFullPathName(), moduleID, project);
if (moduleFolder != File())
return moduleFolder;
}
}
return {};
}
File EnabledModuleList::getModuleFolder (const String& moduleID)
File EnabledModuleList::findFolderForModule (const String& moduleID)
{
if (shouldUseGlobalPath (moduleID))
{
if (isJUCEModule (moduleID))
return getModuleFolderFromPathIfItExists (getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString(), moduleID, project);
return File (getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString()).getChildFile (moduleID);
return findUserModuleFolder (getAppSettings().getStoredPath (Ids::defaultUserModulePath).toString(), moduleID);
ModuleList list;
list.scanGlobalUserModulePath();
if (auto* desc = list.getModuleWithID (moduleID))
return desc->getFolder();
}
else
{
auto path = getPathToSpecifiedModule (project, moduleID);
for (auto p : getAllPossibleModulePathsFromExporters (project, true))
{
auto f = getModuleFolderFromPathIfItExists (p.getFullPathName(), moduleID);
if (path != File())
return path;
}
if (f != File())
return f;
}
auto paths = getAllPossibleModulePathsFromExporters (project);
for (auto p : paths)
{
auto f = getModuleFolderFromPathIfItExists (p.getFullPathName(), moduleID, project);
if (f != File())
return f;
for (auto p : getAllPossibleModulePathsFromExporters (project, false))
{
auto f = getModuleFolderFromPathIfItExists (p.getFullPathName(), moduleID);
if (f != File())
return f;
}
}
return {};
@ -916,20 +868,9 @@ void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
shouldCopyModuleFilesLocally (project.getModules().getModuleID (i)) = copyLocally;
}
File EnabledModuleList::findGlobalModulesFolder()
{
auto& settings = getAppSettings();
auto path = settings.getStoredPath (Ids::defaultJuceModulePath).toString();
if (settings.isGlobalPathValid ({}, Ids::defaultJuceModulePath, path))
return { path };
return {};
}
File EnabledModuleList::findDefaultModulesFolder (Project& project)
{
auto globalPath = findGlobalModulesFolder();
File globalPath (getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString());
if (globalPath != File())
return globalPath;