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.

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