The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

819 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_Module.h"
  19. #include "jucer_ProjectType.h"
  20. #include "../Project Saving/jucer_ProjectExporter.h"
  21. #include "../Project Saving/jucer_ProjectSaver.h"
  22. #include "../Project Saving/jucer_ProjectExport_XCode.h"
  23. static String trimCommentCharsFromStartOfLine (const String& line)
  24. {
  25. return line.trimStart().trimCharactersAtStart ("*/").trimStart();
  26. }
  27. static var parseModuleDesc (const StringArray& lines)
  28. {
  29. DynamicObject* o = new DynamicObject();
  30. var result (o);
  31. for (int i = 0; i < lines.size(); ++i)
  32. {
  33. String line = trimCommentCharsFromStartOfLine (lines[i]);
  34. int colon = line.indexOfChar (':');
  35. if (colon >= 0)
  36. {
  37. String key = line.substring (0, colon).trim();
  38. String value = line.substring (colon + 1).trim();
  39. o->setProperty (key, value);
  40. }
  41. }
  42. return result;
  43. }
  44. static var parseModuleDesc (const File& header)
  45. {
  46. StringArray lines;
  47. header.readLines (lines);
  48. for (int i = 0; i < lines.size(); ++i)
  49. {
  50. if (trimCommentCharsFromStartOfLine (lines[i]).startsWith ("BEGIN_JUCE_MODULE_DECLARATION"))
  51. {
  52. StringArray desc;
  53. for (int j = i + 1; j < lines.size(); ++j)
  54. {
  55. if (trimCommentCharsFromStartOfLine (lines[j]).startsWith ("END_JUCE_MODULE_DECLARATION"))
  56. return parseModuleDesc (desc);
  57. desc.add (lines[j]);
  58. }
  59. break;
  60. }
  61. }
  62. return var();
  63. }
  64. ModuleDescription::ModuleDescription (const File& folder)
  65. : moduleFolder (folder),
  66. moduleInfo (parseModuleDesc (getHeader()))
  67. {
  68. }
  69. File ModuleDescription::getHeader() const
  70. {
  71. const char* extensions[] = { ".h", ".hpp", ".hxx" };
  72. for (int i = 0; i < numElementsInArray (extensions); ++i)
  73. {
  74. File header (moduleFolder.getChildFile (moduleFolder.getFileName() + extensions[i]));
  75. if (header.existsAsFile())
  76. return header;
  77. }
  78. return File();
  79. }
  80. StringArray ModuleDescription::getDependencies() const
  81. {
  82. StringArray deps = StringArray::fromTokens (moduleInfo ["dependencies"].toString(), " \t;,", "\"'");
  83. deps.trim();
  84. deps.removeEmptyStrings();
  85. return deps;
  86. }
  87. //==============================================================================
  88. ModuleList::ModuleList()
  89. {
  90. }
  91. ModuleList::ModuleList (const ModuleList& other)
  92. {
  93. operator= (other);
  94. }
  95. ModuleList& ModuleList::operator= (const ModuleList& other)
  96. {
  97. modules.clear();
  98. modules.addCopiesOf (other.modules);
  99. return *this;
  100. }
  101. const ModuleDescription* ModuleList::getModuleWithID (const String& moduleID) const
  102. {
  103. for (int i = 0; i < modules.size(); ++i)
  104. {
  105. ModuleDescription* m = modules.getUnchecked(i);
  106. if (m->getID() == moduleID)
  107. return m;
  108. }
  109. return nullptr;
  110. }
  111. struct ModuleSorter
  112. {
  113. static int compareElements (const ModuleDescription* m1, const ModuleDescription* m2)
  114. {
  115. return m1->getID().compareIgnoreCase (m2->getID());
  116. }
  117. };
  118. void ModuleList::sort()
  119. {
  120. ModuleSorter sorter;
  121. modules.sort (sorter);
  122. }
  123. StringArray ModuleList::getIDs() const
  124. {
  125. StringArray results;
  126. for (int i = 0; i < modules.size(); ++i)
  127. results.add (modules.getUnchecked(i)->getID());
  128. results.sort (true);
  129. return results;
  130. }
  131. Result ModuleList::addAllModulesInFolder (const File& path)
  132. {
  133. ModuleDescription m (path);
  134. if (m.isValid())
  135. {
  136. modules.add (new ModuleDescription (m));
  137. }
  138. else
  139. {
  140. for (DirectoryIterator iter (path, false, "*", File::findDirectories); iter.next();)
  141. {
  142. Result r = addAllModulesInFolder (iter.getFile().getLinkedTarget());
  143. if (r.failed())
  144. return r;
  145. }
  146. }
  147. return Result::ok();
  148. }
  149. static Array<File> getAllPossibleModulePaths (Project& project)
  150. {
  151. StringArray paths;
  152. for (Project::ExporterIterator exporter (project); exporter.next();)
  153. {
  154. for (int i = 0; i < project.getModules().getNumModules(); ++i)
  155. {
  156. const String path (exporter->getPathForModuleString (project.getModules().getModuleID (i)));
  157. if (path.isNotEmpty())
  158. paths.addIfNotAlreadyThere (path);
  159. }
  160. String oldPath (exporter->getLegacyModulePath());
  161. if (oldPath.isNotEmpty())
  162. paths.addIfNotAlreadyThere (oldPath);
  163. }
  164. Array<File> files;
  165. for (int i = 0; i < paths.size(); ++i)
  166. {
  167. const File f (project.resolveFilename (paths[i]));
  168. if (f.isDirectory())
  169. {
  170. files.add (f);
  171. if (f.getChildFile ("modules").isDirectory())
  172. files.addIfNotAlreadyThere (f.getChildFile ("modules"));
  173. }
  174. }
  175. return files;
  176. }
  177. Result ModuleList::scanAllKnownFolders (Project& project)
  178. {
  179. modules.clear();
  180. Result result (Result::ok());
  181. const Array<File> modulePaths (getAllPossibleModulePaths (project));
  182. for (int i = 0; i < modulePaths.size(); ++i)
  183. {
  184. result = addAllModulesInFolder (modulePaths.getReference(i));
  185. if (result.failed())
  186. break;
  187. }
  188. sort();
  189. return result;
  190. }
  191. //==============================================================================
  192. LibraryModule::LibraryModule (const ModuleDescription& d)
  193. : moduleInfo (d)
  194. {
  195. }
  196. //==============================================================================
  197. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  198. {
  199. Project& project = projectSaver.project;
  200. EnabledModuleList& modules = project.getModules();
  201. const String id (getID());
  202. if (modules.shouldCopyModuleFilesLocally (id).getValue())
  203. {
  204. const File juceModuleFolder (moduleInfo.getFolder());
  205. const File localModuleFolder (project.getLocalModuleFolder (id));
  206. localModuleFolder.createDirectory();
  207. projectSaver.copyFolder (juceModuleFolder, localModuleFolder);
  208. }
  209. out << "#include <" << moduleInfo.moduleFolder.getFileName() << "/"
  210. << moduleInfo.getHeader().getFileName()
  211. << ">" << newLine;
  212. }
  213. //==============================================================================
  214. static void parseAndAddLibs (StringArray& libList, const String& libs)
  215. {
  216. libList.addTokens (libs, ", ", StringRef());
  217. libList.trim();
  218. libList.sort (false);
  219. libList.removeDuplicates (false);
  220. }
  221. void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  222. {
  223. Project& project = exporter.getProject();
  224. RelativePath modulePath = exporter.getModuleFolderRelativeToProject (getID());
  225. exporter.addToExtraSearchPaths (modulePath.getParentDirectory());
  226. const String extraInternalSearchPaths (moduleInfo.getExtraSearchPaths().trim());
  227. if (extraInternalSearchPaths.isNotEmpty())
  228. {
  229. StringArray paths;
  230. paths.addTokens (extraInternalSearchPaths, true);
  231. for (int i = 0; i < paths.size(); ++i)
  232. exporter.addToExtraSearchPaths (modulePath.getChildFile (paths.getReference(i)));
  233. }
  234. {
  235. const String extraDefs (moduleInfo.getPreprocessorDefs().trim());
  236. if (extraDefs.isNotEmpty())
  237. exporter.getExporterPreprocessorDefs() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs;
  238. }
  239. {
  240. Array<File> compiled;
  241. const File localModuleFolder = project.getModules().shouldCopyModuleFilesLocally (getID()).getValue()
  242. ? project.getLocalModuleFolder (getID())
  243. : moduleInfo.getFolder();
  244. findAndAddCompiledUnits (exporter, &projectSaver, compiled);
  245. if (project.getModules().shouldShowAllModuleFilesInProject (getID()).getValue())
  246. addBrowseableCode (exporter, compiled, localModuleFolder);
  247. }
  248. if (exporter.isXcode())
  249. {
  250. XCodeProjectExporter& xcodeExporter = dynamic_cast<XCodeProjectExporter&> (exporter);
  251. if (project.isAUPluginHost())
  252. xcodeExporter.xcodeFrameworks.addTokens (xcodeExporter.isOSX() ? "AudioUnit CoreAudioKit" : "CoreAudioKit", false);
  253. const String frameworks (moduleInfo.moduleInfo [xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString());
  254. xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", StringRef());
  255. parseAndAddLibs (xcodeExporter.xcodeLibs, moduleInfo.moduleInfo [exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString());
  256. }
  257. else if (exporter.isLinux())
  258. {
  259. parseAndAddLibs (exporter.linuxLibs, moduleInfo.moduleInfo ["linuxLibs"].toString());
  260. }
  261. else if (exporter.isCodeBlocks() && exporter.isWindows())
  262. {
  263. parseAndAddLibs (exporter.mingwLibs, moduleInfo.moduleInfo ["mingwLibs"].toString());
  264. }
  265. }
  266. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  267. {
  268. const File header (moduleInfo.getHeader());
  269. jassert (header.exists());
  270. StringArray lines;
  271. header.readLines (lines);
  272. for (int i = 0; i < lines.size(); ++i)
  273. {
  274. String line (lines[i].trim());
  275. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  276. {
  277. ScopedPointer<Project::ConfigFlag> config (new Project::ConfigFlag());
  278. config->sourceModuleID = getID();
  279. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  280. if (config->symbol.length() > 2)
  281. {
  282. ++i;
  283. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  284. {
  285. if (lines[i].trim().isNotEmpty())
  286. config->description = config->description.trim() + " " + lines[i].trim();
  287. ++i;
  288. }
  289. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  290. config->value.referTo (project.getConfigFlag (config->symbol));
  291. flags.add (config.release());
  292. }
  293. }
  294. }
  295. }
  296. //==============================================================================
  297. struct FileSorter
  298. {
  299. static int compareElements (const File& f1, const File& f2)
  300. {
  301. return f1.getFileName().compareNatural (f2.getFileName());
  302. }
  303. };
  304. bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
  305. {
  306. String fileWithoutSuffix = f.getFileNameWithoutExtension() + String (".");
  307. return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
  308. || fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
  309. }
  310. void LibraryModule::CompileUnit::writeInclude (MemoryOutputStream&) const
  311. {
  312. }
  313. bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
  314. {
  315. Project& project = exporter.getProject();
  316. if ((hasSuffix (file, "_OSX") && ! exporter.isOSX())
  317. || (hasSuffix (file, "_iOS") && ! exporter.isiOS())
  318. || (hasSuffix (file, "_Windows") && ! exporter.isWindows())
  319. || (hasSuffix (file, "_Linux") && ! exporter.isLinux())
  320. || (hasSuffix (file, "_Android") && ! exporter.isAndroid())
  321. || (hasSuffix (file, "_AU") && ! (project.shouldBuildAU() .getValue() && exporter.supportsAU()))
  322. || (hasSuffix (file, "_AUv3") && ! (project.shouldBuildAUv3().getValue() && exporter.supportsAUv3()))
  323. || (hasSuffix (file, "_AAX") && ! (project.shouldBuildAAX() .getValue() && exporter.supportsAAX()))
  324. || (hasSuffix (file, "_RTAS") && ! (project.shouldBuildRTAS().getValue() && exporter.supportsRTAS()))
  325. || (hasSuffix (file, "_VST2") && ! (project.shouldBuildVST() .getValue() && exporter.supportsVST()))
  326. || (hasSuffix (file, "_VST3") && ! (project.shouldBuildVST3().getValue() && exporter.supportsVST3()))
  327. || (hasSuffix (file, "_Standalone") && ! (project.shouldBuildStandalone().getValue() && exporter.supportsStandalone())))
  328. return false;
  329. return exporter.usesMMFiles() ? isCompiledForObjC
  330. : isCompiledForNonObjC;
  331. }
  332. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits() const
  333. {
  334. Array<File> files;
  335. getFolder().findChildFiles (files, File::findFiles, false);
  336. FileSorter sorter;
  337. files.sort (sorter);
  338. Array<LibraryModule::CompileUnit> units;
  339. for (int i = 0; i < files.size(); ++i)
  340. {
  341. CompileUnit cu;
  342. cu.file = files.getReference(i);
  343. if (cu.file.getFileName().startsWithIgnoreCase (getID())
  344. && cu.file.hasFileExtension (sourceFileExtensions))
  345. {
  346. units.add (cu);
  347. }
  348. }
  349. for (int i = 0; i < units.size(); ++i)
  350. {
  351. CompileUnit& cu = units.getReference(i);
  352. cu.isCompiledForObjC = true;
  353. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");
  354. if (cu.isCompiledForNonObjC)
  355. if (files.contains (cu.file.withFileExtension ("mm")))
  356. cu.isCompiledForObjC = false;
  357. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  358. }
  359. return units;
  360. }
  361. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  362. ProjectSaver* projectSaver,
  363. Array<File>& result) const
  364. {
  365. Array<CompileUnit> units = getAllCompileUnits();
  366. for (int i = 0; i < units.size(); ++i)
  367. {
  368. const CompileUnit& cu = units.getReference(i);
  369. if (cu.isNeededForExporter (exporter))
  370. {
  371. File localFile = exporter.getProject().getGeneratedCodeFolder().getChildFile (cu.file.getFileName());
  372. result.add (localFile);
  373. if (projectSaver != nullptr)
  374. projectSaver->addFileToGeneratedGroup (localFile);
  375. }
  376. }
  377. }
  378. static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path)
  379. {
  380. const int slash = path.indexOfChar (File::separator);
  381. if (slash >= 0)
  382. {
  383. const String topLevelGroup (path.substring (0, slash));
  384. const String remainingPath (path.substring (slash + 1));
  385. Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup));
  386. addFileWithGroups (newGroup, file, remainingPath);
  387. }
  388. else
  389. {
  390. if (! group.containsChildForFile (file))
  391. group.addRelativeFile (file, -1, false);
  392. }
  393. }
  394. void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesFound) const
  395. {
  396. Array<File> tempList;
  397. FileSorter sorter;
  398. DirectoryIterator iter (folder, true, "*", File::findFiles);
  399. bool isHiddenFile;
  400. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  401. if (! isHiddenFile && iter.getFile().hasFileExtension (browseableFileExtensions))
  402. tempList.addSorted (sorter, iter.getFile());
  403. filesFound.addArray (tempList);
  404. }
  405. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  406. {
  407. if (sourceFiles.size() == 0)
  408. findBrowseableFiles (localModuleFolder, sourceFiles);
  409. Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false));
  410. const RelativePath moduleFromProject (exporter.getModuleFolderRelativeToProject (getID()));
  411. for (int i = 0; i < sourceFiles.size(); ++i)
  412. {
  413. const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder));
  414. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  415. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  416. if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i)))
  417. addFileWithGroups (sourceGroup,
  418. moduleFromProject.getChildFile (pathWithinModule),
  419. pathWithinModule);
  420. }
  421. sourceGroup.sortAlphabetically (true, true);
  422. sourceGroup.addFileAtIndex (moduleInfo.getHeader(), -1, false);
  423. exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr);
  424. }
  425. //==============================================================================
  426. EnabledModuleList::EnabledModuleList (Project& p, const ValueTree& s)
  427. : project (p), state (s)
  428. {
  429. }
  430. ModuleDescription EnabledModuleList::getModuleInfo (const String& moduleID)
  431. {
  432. return ModuleDescription (getModuleFolder (moduleID));
  433. }
  434. bool EnabledModuleList::isModuleEnabled (const String& moduleID) const
  435. {
  436. for (int i = 0; i < state.getNumChildren(); ++i)
  437. if (state.getChild(i) [Ids::ID] == moduleID)
  438. return true;
  439. return false;
  440. }
  441. bool EnabledModuleList::isAudioPluginModuleMissing() const
  442. {
  443. return project.getProjectType().isAudioPlugin()
  444. && ! isModuleEnabled ("juce_audio_plugin_client");
  445. }
  446. Value EnabledModuleList::shouldShowAllModuleFilesInProject (const String& moduleID)
  447. {
  448. return state.getChildWithProperty (Ids::ID, moduleID)
  449. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  450. }
  451. File EnabledModuleList::findLocalModuleFolder (const String& moduleID, bool useExportersForOtherOSes)
  452. {
  453. for (Project::ExporterIterator exporter (project); exporter.next();)
  454. {
  455. if (useExportersForOtherOSes || exporter->mayCompileOnCurrentOS())
  456. {
  457. const String path (exporter->getPathForModuleString (moduleID));
  458. if (path.isNotEmpty())
  459. {
  460. const File moduleFolder (project.resolveFilename (path));
  461. if (moduleFolder.exists())
  462. {
  463. if (ModuleDescription (moduleFolder).isValid())
  464. return moduleFolder;
  465. File f = moduleFolder.getChildFile (moduleID);
  466. if (ModuleDescription (f).isValid())
  467. return f;
  468. f = moduleFolder.getChildFile ("modules")
  469. .getChildFile (moduleID);
  470. if (ModuleDescription (f).isValid())
  471. return f;
  472. }
  473. }
  474. }
  475. }
  476. return File();
  477. }
  478. File EnabledModuleList::getModuleFolder (const String& moduleID)
  479. {
  480. File f = findLocalModuleFolder (moduleID, false);
  481. if (f == File())
  482. f = findLocalModuleFolder (moduleID, true);
  483. return f;
  484. }
  485. struct ModuleTreeSorter
  486. {
  487. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  488. {
  489. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  490. }
  491. };
  492. void EnabledModuleList::sortAlphabetically()
  493. {
  494. ModuleTreeSorter sorter;
  495. state.sort (sorter, getUndoManager(), false);
  496. }
  497. Value EnabledModuleList::shouldCopyModuleFilesLocally (const String& moduleID) const
  498. {
  499. return state.getChildWithProperty (Ids::ID, moduleID)
  500. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  501. }
  502. void EnabledModuleList::addModule (const File& moduleFolder, bool copyLocally)
  503. {
  504. ModuleDescription info (moduleFolder);
  505. if (info.isValid())
  506. {
  507. const String moduleID (info.getID());
  508. if (! isModuleEnabled (moduleID))
  509. {
  510. ValueTree module (Ids::MODULE);
  511. module.setProperty (Ids::ID, moduleID, nullptr);
  512. state.addChild (module, -1, getUndoManager());
  513. sortAlphabetically();
  514. shouldShowAllModuleFilesInProject (moduleID) = true;
  515. shouldCopyModuleFilesLocally (moduleID) = copyLocally;
  516. RelativePath path (moduleFolder.getParentDirectory(),
  517. project.getProjectFolder(), RelativePath::projectFolder);
  518. for (Project::ExporterIterator exporter (project); exporter.next();)
  519. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  520. }
  521. }
  522. }
  523. void EnabledModuleList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  524. {
  525. for (int i = state.getNumChildren(); --i >= 0;)
  526. if (state.getChild(i) [Ids::ID] == moduleID)
  527. state.removeChild (i, getUndoManager());
  528. for (Project::ExporterIterator exporter (project); exporter.next();)
  529. exporter->removePathForModule (moduleID);
  530. }
  531. void EnabledModuleList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  532. {
  533. for (int i = 0; i < getNumModules(); ++i)
  534. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  535. }
  536. StringArray EnabledModuleList::getAllModules() const
  537. {
  538. StringArray moduleIDs;
  539. for (int i = 0; i < getNumModules(); ++i)
  540. moduleIDs.add (getModuleID(i));
  541. return moduleIDs;
  542. }
  543. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  544. {
  545. ModuleDescription info (project.getModules().getModuleInfo (moduleID));
  546. for (auto uid : info.getDependencies())
  547. {
  548. if (! dependencies.contains (uid, true))
  549. {
  550. dependencies.add (uid);
  551. getDependencies (project, uid, dependencies);
  552. }
  553. }
  554. }
  555. StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const
  556. {
  557. StringArray dependencies, extraDepsNeeded;
  558. getDependencies (project, moduleID, dependencies);
  559. for (auto dep : dependencies)
  560. if (dep != moduleID && ! isModuleEnabled (dep))
  561. extraDepsNeeded.add (dep);
  562. return extraDepsNeeded;
  563. }
  564. bool EnabledModuleList::areMostModulesCopiedLocally() const
  565. {
  566. int numYes = 0, numNo = 0;
  567. for (int i = getNumModules(); --i >= 0;)
  568. {
  569. if (shouldCopyModuleFilesLocally (getModuleID (i)).getValue())
  570. ++numYes;
  571. else
  572. ++numNo;
  573. }
  574. return numYes > numNo;
  575. }
  576. void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
  577. {
  578. for (int i = getNumModules(); --i >= 0;)
  579. shouldCopyModuleFilesLocally (project.getModules().getModuleID (i)) = copyLocally;
  580. }
  581. File EnabledModuleList::findDefaultModulesFolder (Project& project)
  582. {
  583. ModuleList available;
  584. available.scanAllKnownFolders (project);
  585. for (int i = available.modules.size(); --i >= 0;)
  586. {
  587. File f (available.modules.getUnchecked(i)->getFolder());
  588. if (f.isDirectory())
  589. return f.getParentDirectory();
  590. }
  591. return File::getCurrentWorkingDirectory();
  592. }
  593. void EnabledModuleList::addModuleFromUserSelectedFile()
  594. {
  595. static File lastLocation (findDefaultModulesFolder (project));
  596. FileChooser fc ("Select a module to add...", lastLocation, String::empty, false);
  597. if (fc.browseForDirectory())
  598. {
  599. lastLocation = fc.getResult();
  600. addModuleOfferingToCopy (lastLocation);
  601. }
  602. }
  603. void EnabledModuleList::addModuleInteractive (const String& moduleID)
  604. {
  605. ModuleList list;
  606. list.scanAllKnownFolders (project);
  607. if (const ModuleDescription* info = list.getModuleWithID (moduleID))
  608. addModule (info->moduleFolder, areMostModulesCopiedLocally());
  609. else
  610. addModuleFromUserSelectedFile();
  611. }
  612. void EnabledModuleList::addModuleOfferingToCopy (const File& f)
  613. {
  614. ModuleDescription m (f);
  615. if (! m.isValid())
  616. {
  617. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  618. "Add Module", "This wasn't a valid module folder!");
  619. return;
  620. }
  621. if (isModuleEnabled (m.getID()))
  622. {
  623. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  624. "Add Module", "The project already contains this module!");
  625. return;
  626. }
  627. addModule (m.moduleFolder, areMostModulesCopiedLocally());
  628. }
  629. bool isJuceFolder (const File& f)
  630. {
  631. return isJuceModulesFolder (f.getChildFile ("modules"));
  632. }
  633. bool isJuceModulesFolder (const File& f)
  634. {
  635. return f.isDirectory() && f.getChildFile ("juce_core").isDirectory();
  636. }