1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +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

@ -751,10 +751,7 @@ void LatestVersionChecker::modalStateFinished (int result,
void LatestVersionChecker::askUserForLocationToDownload (URL& newVersionToDownload, const String& extraHeaders)
{
File targetFolder (EnabledModuleList::findGlobalModulesFolder());
if (isJUCEModulesFolder (targetFolder))
targetFolder = targetFolder.getParentDirectory();
File targetFolder (getAppSettings().getStoredPath (Ids::jucePath).toString());
FileChooser chooser (TRANS("Please select the location into which you'd like to install the new version"),
targetFolder);

View file

@ -558,20 +558,28 @@ public:
auto& modules = project.getModules();
PopupMenu knownModules, jucePathModules, userPathModules, exporterPathsModules;
ModuleList list;
list.scanGlobalJuceModulePath();
int index = 100;
for (auto m : getAvailableModulesInGlobalJucePath())
for (auto m : list.getIDs())
jucePathModules.addItem (index++, m, ! modules.isModuleEnabled (m));
knownModules.addSubMenu ("Global JUCE modules path", jucePathModules);
list.scanGlobalUserModulePath();
index = 200;
for (auto m : getAvailableModulesInGlobalUserPath())
for (auto m : list.getIDs())
userPathModules.addItem (index++, m, ! modules.isModuleEnabled (m));
knownModules.addSubMenu ("Global user modules path", userPathModules);
list.scanProjectExporterModulePaths (project);
index = 300;
for (auto m : getAvailableModulesInExporterPaths())
for (auto m : list.getIDs())
exporterPathsModules.addItem (index++, m, ! modules.isModuleEnabled (m));
knownModules.addSubMenu ("Exporter paths", exporterPathsModules);
@ -594,62 +602,30 @@ public:
}
else if (resultCode > 0)
{
ModuleList list;
int offset = -1;
if (resultCode < 200)
modules.addModuleInteractive (getAvailableModulesInGlobalJucePath() [resultCode - 100]);
{
list.scanGlobalJuceModulePath();
offset = 100;
}
else if (resultCode < 300)
modules.addModuleInteractive (getAvailableModulesInGlobalUserPath() [resultCode - 200]);
{
list.scanGlobalUserModulePath();
offset = 200;
}
else if (resultCode < 400)
modules.addModuleInteractive (getAvailableModulesInExporterPaths() [resultCode - 300]);
{
list.scanProjectExporterModulePaths (project);
offset = 300;
}
if (offset != -1)
modules.addModuleInteractive (list.getIDs() [resultCode - offset]);
}
}
StringArray getAvailableModulesInGlobalJucePath()
{
ModuleList list;
list.addAllModulesInFolder ({ getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString() });
return list.getIDs();
}
StringArray getAvailableModulesInGlobalUserPath()
{
ModuleList list;
auto paths = StringArray::fromTokens (getAppSettings().getStoredPath (Ids::defaultUserModulePath).toString(), ";", {});
for (auto p : paths)
{
p = p.replace ("~", File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
auto f = File::createFileWithoutCheckingPath (p.trim());
if (f.exists())
list.addAllModulesInFolder (f);
}
auto ids = list.getIDs();
ids.removeDuplicates (false);
for (auto m : getAvailableModulesInGlobalJucePath())
ids.removeString (m);
return ids;
}
StringArray getAvailableModulesInExporterPaths()
{
ModuleList list;
list.scanProjectExporterModulePaths (project);
auto ids = list.getIDs();
for (auto m : getAvailableModulesInGlobalJucePath())
ids.removeString (m);
for (auto m : getAvailableModulesInGlobalUserPath())
ids.removeString (m);
return ids;
}
//==============================================================================
void valueTreeChildAdded (ValueTree& parentTree, ValueTree&) override { refreshIfNeeded (parentTree); }
void valueTreeChildRemoved (ValueTree& parentTree, ValueTree&, int) override { refreshIfNeeded (parentTree); }

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;

View file

@ -75,11 +75,12 @@ struct ModuleList
StringArray getIDs() const;
void sort();
Result tryToAddModuleFromFolder (const File&);
bool tryToAddModuleFromFolder (const File&);
Result addAllModulesInFolder (const File&);
Result addAllModulesInSubfoldersRecursively (const File&, int depth);
Result scanProjectExporterModulePaths (Project&);
void addAllModulesInFolder (const File&);
void addAllModulesInSubfoldersRecursively (const File&, int depth);
void scanProjectExporterModulePaths (Project&);
void scanGlobalJuceModulePath();
void scanGlobalUserModulePath();
@ -138,7 +139,6 @@ class EnabledModuleList
public:
EnabledModuleList (Project&, const ValueTree&);
static File findGlobalModulesFolder();
static File findDefaultModulesFolder (Project&);
bool isModuleEnabled (const String& moduleID) const;
@ -153,7 +153,6 @@ public:
bool isAudioPluginModuleMissing() const;
ModuleDescription getModuleInfo (const String& moduleID);
File getModuleFolder (const String& moduleID);
void addModule (const File& moduleManifestFile, bool copyLocally, bool useGlobalPath, bool sendAnalyticsEvent);
void addModuleInteractive (const String& moduleID);
@ -181,7 +180,7 @@ public:
private:
UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
File findUserModuleFolder (const String& possiblePaths, const String& moduleID);
File findFolderForModule (const String& moduleID);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EnabledModuleList)
};

View file

@ -31,14 +31,14 @@
class ModulesFolderPathBox : public Component
{
public:
ModulesFolderPathBox (File initialFileOrDirectory)
ModulesFolderPathBox (String initialFileOrDirectory)
: currentPathBox ("currentPathBox"),
openFolderButton (TRANS("...")),
modulesLabel (String(), TRANS("Modules Folder") + ":"),
useGlobalPathsToggle ("Use global module path")
{
if (initialFileOrDirectory == File())
initialFileOrDirectory = EnabledModuleList::findGlobalModulesFolder();
if (initialFileOrDirectory.isEmpty())
initialFileOrDirectory = getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString();
setModulesFolder (initialFileOrDirectory);
@ -85,7 +85,7 @@ public:
for (;;)
{
FileChooser fc ("Select your JUCE modules folder...",
EnabledModuleList::findGlobalModulesFolder(),
{ getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString() },
"*");
if (! fc.browseForDirectory())
@ -286,7 +286,7 @@ public:
WizardComp()
: platformTargets(),
projectName (TRANS("Project name")),
modulesPathBox (EnabledModuleList::findGlobalModulesFolder())
modulesPathBox (getAppSettings().getStoredPath (Ids::defaultJuceModulePath).toString())
{
setOpaque (false);