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.

832 lines
26KB

  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. static void findWildcardMatches (const File& folder, Array<File>& result)
  388. {
  389. Array<File> tempList;
  390. FileSorter sorter;
  391. DirectoryIterator iter (folder, false, "*");
  392. bool isHiddenFile;
  393. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  394. if (! isHiddenFile)
  395. tempList.addSorted (sorter, iter.getFile());
  396. result.addArray (tempList);
  397. }
  398. void LibraryModule::findBrowseableFiles (const File& localModuleFolder, Array<File>& filesFound) const
  399. {
  400. DirectoryIterator iter (localModuleFolder, true, "*", File::findDirectories);
  401. bool isHiddenFile;
  402. while (iter.next (nullptr, &isHiddenFile, nullptr, nullptr, nullptr, nullptr))
  403. if (! isHiddenFile)
  404. findWildcardMatches (iter.getFile(), filesFound);
  405. }
  406. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  407. {
  408. if (sourceFiles.size() == 0)
  409. findBrowseableFiles (localModuleFolder, sourceFiles);
  410. Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false));
  411. const RelativePath moduleFromProject (exporter.getModuleFolderRelativeToProject (getID()));
  412. for (int i = 0; i < sourceFiles.size(); ++i)
  413. {
  414. const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder));
  415. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  416. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  417. if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i)))
  418. addFileWithGroups (sourceGroup,
  419. moduleFromProject.getChildFile (pathWithinModule),
  420. pathWithinModule);
  421. }
  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. if (info.isValid())
  547. {
  548. const var depsArray (info.moduleInfo ["dependencies"]);
  549. if (const Array<var>* const deps = depsArray.getArray())
  550. {
  551. for (int i = 0; i < deps->size(); ++i)
  552. {
  553. const var& d = deps->getReference(i);
  554. String uid (d [Ids::ID].toString());
  555. String version (d [Ids::version].toString());
  556. if (! dependencies.contains (uid, true))
  557. {
  558. dependencies.add (uid);
  559. getDependencies (project, uid, dependencies);
  560. }
  561. }
  562. }
  563. }
  564. }
  565. StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const
  566. {
  567. StringArray dependencies, extraDepsNeeded;
  568. getDependencies (project, moduleID, dependencies);
  569. for (int i = 0; i < dependencies.size(); ++i)
  570. if ((! isModuleEnabled (dependencies[i])) && dependencies[i] != moduleID)
  571. extraDepsNeeded.add (dependencies[i]);
  572. return extraDepsNeeded;
  573. }
  574. bool EnabledModuleList::areMostModulesCopiedLocally() const
  575. {
  576. int numYes = 0, numNo = 0;
  577. for (int i = getNumModules(); --i >= 0;)
  578. {
  579. if (shouldCopyModuleFilesLocally (getModuleID (i)).getValue())
  580. ++numYes;
  581. else
  582. ++numNo;
  583. }
  584. return numYes > numNo;
  585. }
  586. void EnabledModuleList::setLocalCopyModeForAllModules (bool copyLocally)
  587. {
  588. for (int i = getNumModules(); --i >= 0;)
  589. shouldCopyModuleFilesLocally (project.getModules().getModuleID (i)) = copyLocally;
  590. }
  591. File EnabledModuleList::findDefaultModulesFolder (Project& project)
  592. {
  593. ModuleList available;
  594. available.scanAllKnownFolders (project);
  595. for (int i = available.modules.size(); --i >= 0;)
  596. {
  597. File f (available.modules.getUnchecked(i)->getFolder());
  598. if (f.isDirectory())
  599. return f.getParentDirectory();
  600. }
  601. return File::getCurrentWorkingDirectory();
  602. }
  603. void EnabledModuleList::addModuleFromUserSelectedFile()
  604. {
  605. static File lastLocation (findDefaultModulesFolder (project));
  606. FileChooser fc ("Select a module to add...", lastLocation, String::empty, false);
  607. if (fc.browseForDirectory())
  608. {
  609. lastLocation = fc.getResult();
  610. addModuleOfferingToCopy (lastLocation);
  611. }
  612. }
  613. void EnabledModuleList::addModuleInteractive (const String& moduleID)
  614. {
  615. ModuleList list;
  616. list.scanAllKnownFolders (project);
  617. if (const ModuleDescription* info = list.getModuleWithID (moduleID))
  618. addModule (info->moduleFolder, areMostModulesCopiedLocally());
  619. else
  620. addModuleFromUserSelectedFile();
  621. }
  622. void EnabledModuleList::addModuleOfferingToCopy (const File& f)
  623. {
  624. ModuleDescription m (f);
  625. if (! m.isValid())
  626. {
  627. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  628. "Add Module", "This wasn't a valid module folder!");
  629. return;
  630. }
  631. if (isModuleEnabled (m.getID()))
  632. {
  633. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  634. "Add Module", "The project already contains this module!");
  635. return;
  636. }
  637. addModule (m.moduleFolder, areMostModulesCopiedLocally());
  638. }
  639. bool isJuceFolder (const File& f)
  640. {
  641. return isJuceModulesFolder (f.getChildFile ("modules"));
  642. }
  643. bool isJuceModulesFolder (const File& f)
  644. {
  645. return f.isDirectory() && f.getChildFile ("juce_core").isDirectory();
  646. }