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.

1896 lines
69KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../Application/jucer_Headers.h"
  20. #include "jucer_Project.h"
  21. #include "../ProjectSaving/jucer_ProjectSaver.h"
  22. #include "../Application/jucer_Application.h"
  23. namespace
  24. {
  25. String makeValid4CC (const String& seed)
  26. {
  27. auto s = CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx";
  28. return s.substring (0, 1).toUpperCase()
  29. + s.substring (1, 4).toLowerCase();
  30. }
  31. }
  32. //==============================================================================
  33. Project::Project (const File& f)
  34. : FileBasedDocument (projectFileExtension,
  35. String ("*") + projectFileExtension,
  36. "Choose a Jucer project to load",
  37. "Save Jucer project")
  38. {
  39. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  40. setFile (f);
  41. removeDefunctExporters();
  42. updateOldModulePaths();
  43. updateOldStyleConfigList();
  44. setCppVersionFromOldExporterSettings();
  45. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  46. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  47. initialiseProjectValues();
  48. initialiseMainGroup();
  49. initialiseAudioPluginValues();
  50. coalescePluginFormatValues();
  51. coalescePluginCharacteristicsValues();
  52. updatePluginCategories();
  53. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  54. getModules().sortAlphabetically();
  55. projectRoot.addListener (this);
  56. setChangedFlag (false);
  57. modificationTime = getFile().getLastModificationTime();
  58. }
  59. Project::~Project()
  60. {
  61. projectRoot.removeListener (this);
  62. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  63. }
  64. const char* Project::projectFileExtension = ".jucer";
  65. //==============================================================================
  66. void Project::setTitle (const String& newTitle)
  67. {
  68. projectNameValue = newTitle;
  69. updateTitle();
  70. }
  71. void Project::updateTitle()
  72. {
  73. auto projectName = getProjectNameString();
  74. getMainGroup().getNameValue() = projectName;
  75. pluginNameValue.setDefault (projectName);
  76. pluginDescriptionValue.setDefault (projectName);
  77. bundleIdentifierValue.setDefault (getDefaultBundleIdentifierString());
  78. pluginAUExportPrefixValue.setDefault (CodeHelpers::makeValidIdentifier (projectName, false, true, false) + "AU");
  79. pluginAAXIdentifierValue.setDefault (getDefaultAAXIdentifierString());
  80. }
  81. String Project::getDocumentTitle()
  82. {
  83. return getProjectNameString();
  84. }
  85. void Project::updateProjectSettings()
  86. {
  87. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  88. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  89. }
  90. bool Project::setCppVersionFromOldExporterSettings()
  91. {
  92. auto highestLanguageStandard = -1;
  93. for (Project::ExporterIterator exporter (*this); exporter.next();)
  94. {
  95. if (exporter->isXcode()) // cpp version was per-build configuration for xcode exporters
  96. {
  97. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  98. {
  99. auto cppLanguageStandard = config->getValue (Ids::cppLanguageStandard).getValue();
  100. if (cppLanguageStandard != var())
  101. {
  102. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  103. if (versionNum > highestLanguageStandard)
  104. highestLanguageStandard = versionNum;
  105. }
  106. }
  107. }
  108. else
  109. {
  110. auto cppLanguageStandard = exporter->getSetting (Ids::cppLanguageStandard).getValue();
  111. if (cppLanguageStandard != var())
  112. {
  113. if (cppLanguageStandard.toString().containsIgnoreCase ("latest"))
  114. {
  115. cppStandardValue = "latest";
  116. return true;
  117. }
  118. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  119. if (versionNum > highestLanguageStandard)
  120. highestLanguageStandard = versionNum;
  121. }
  122. }
  123. }
  124. if (highestLanguageStandard != -1 && highestLanguageStandard >= 11)
  125. {
  126. cppStandardValue = highestLanguageStandard;
  127. return true;
  128. }
  129. return false;
  130. }
  131. void Project::updateDeprecatedProjectSettingsInteractively()
  132. {
  133. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  134. for (Project::ExporterIterator exporter (*this); exporter.next();)
  135. exporter->updateDeprecatedProjectSettingsInteractively();
  136. }
  137. void Project::initialiseMainGroup()
  138. {
  139. // Create main file group if missing
  140. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  141. {
  142. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  143. projectRoot.addChild (mainGroup.state, 0, 0);
  144. }
  145. getMainGroup().initialiseMissingProperties();
  146. }
  147. void Project::initialiseProjectValues()
  148. {
  149. projectNameValue.referTo (projectRoot, Ids::name, getUndoManager(), "JUCE Project");
  150. projectUIDValue.referTo (projectRoot, Ids::ID, getUndoManager(), createAlphaNumericUID());
  151. projectTypeValue.referTo (projectRoot, Ids::projectType, getUndoManager(), ProjectType_GUIApp::getTypeName());
  152. versionValue.referTo (projectRoot, Ids::version, getUndoManager(), "1.0.0");
  153. bundleIdentifierValue.referTo (projectRoot, Ids::bundleIdentifier, getUndoManager(), getDefaultBundleIdentifierString());
  154. companyNameValue.referTo (projectRoot, Ids::companyName, getUndoManager());
  155. companyCopyrightValue.referTo (projectRoot, Ids::companyCopyright, getUndoManager());
  156. companyWebsiteValue.referTo (projectRoot, Ids::companyWebsite, getUndoManager());
  157. companyEmailValue.referTo (projectRoot, Ids::companyEmail, getUndoManager());
  158. displaySplashScreenValue.referTo (projectRoot, Ids::displaySplashScreen, getUndoManager(), ! ProjucerApplication::getApp().isPaidOrGPL());
  159. splashScreenColourValue.referTo (projectRoot, Ids::splashScreenColour, getUndoManager(), "Dark");
  160. reportAppUsageValue.referTo (projectRoot, Ids::reportAppUsage, getUndoManager());
  161. if (ProjucerApplication::getApp().isPaidOrGPL())
  162. {
  163. reportAppUsageValue.setDefault (ProjucerApplication::getApp().licenseController->getState().applicationUsageDataState
  164. == LicenseState::ApplicationUsageData::enabled);
  165. }
  166. else
  167. {
  168. reportAppUsageValue.setDefault (true);
  169. }
  170. cppStandardValue.referTo (projectRoot, Ids::cppLanguageStandard, getUndoManager(), "14");
  171. headerSearchPathsValue.referTo (projectRoot, Ids::headerPath, getUndoManager());
  172. preprocessorDefsValue.referTo (projectRoot, Ids::defines, getUndoManager());
  173. userNotesValue.referTo (projectRoot, Ids::userNotes, getUndoManager());
  174. maxBinaryFileSizeValue.referTo (projectRoot, Ids::maxBinaryFileSize, getUndoManager(), 10240 * 1024);
  175. includeBinaryDataInAppConfigValue.referTo (projectRoot, Ids::includeBinaryInAppConfig, getUndoManager(), true);
  176. binaryDataNamespaceValue.referTo (projectRoot, Ids::binaryDataNamespace, getUndoManager(), "BinaryData");
  177. }
  178. void Project::initialiseAudioPluginValues()
  179. {
  180. pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(), Array<var> (Ids::buildVST.toString(), Ids::buildAU.toString()), ",");
  181. pluginCharacteristicsValue.referTo (projectRoot, Ids::pluginCharacteristicsValue, getUndoManager(), Array<var> (), ",");
  182. pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString());
  183. pluginDescriptionValue.referTo (projectRoot, Ids::pluginDesc, getUndoManager(), getProjectNameString());
  184. pluginManufacturerValue.referTo (projectRoot, Ids::pluginManufacturer, getUndoManager(), "yourcompany");
  185. pluginManufacturerCodeValue.referTo (projectRoot, Ids::pluginManufacturerCode, getUndoManager(), "Manu");
  186. pluginCodeValue.referTo (projectRoot, Ids::pluginCode, getUndoManager(), makeValid4CC (getProjectUIDString() + getProjectUIDString()));
  187. pluginChannelConfigsValue.referTo (projectRoot, Ids::pluginChannelConfigs, getUndoManager());
  188. pluginAAXIdentifierValue.referTo (projectRoot, Ids::aaxIdentifier, getUndoManager(), getDefaultAAXIdentifierString());
  189. pluginAUExportPrefixValue.referTo (projectRoot, Ids::pluginAUExportPrefix, getUndoManager(),
  190. CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false) + "AU");
  191. pluginAUMainTypeValue.referTo (projectRoot, Ids::pluginAUMainType, getUndoManager());
  192. pluginVSTCategoryValue.referTo (projectRoot, Ids::pluginVSTCategory, getUndoManager(), getDefaultVSTCategories(), ",");
  193. pluginVST3CategoryValue.referTo (projectRoot, Ids::pluginVST3Category, getUndoManager(), getDefaultVST3Categories(), ",");
  194. pluginRTASCategoryValue.referTo (projectRoot, Ids::pluginRTASCategory, getUndoManager(), getDefaultRTASCategories(), ",");
  195. pluginAAXCategoryValue.referTo (projectRoot, Ids::pluginAAXCategory, getUndoManager(), getDefaultAAXCategories(), ",");
  196. }
  197. void Project::updateOldStyleConfigList()
  198. {
  199. auto deprecatedConfigsList = projectRoot.getChildWithName (Ids::CONFIGURATIONS);
  200. if (deprecatedConfigsList.isValid())
  201. {
  202. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  203. for (Project::ExporterIterator exporter (*this); exporter.next();)
  204. {
  205. if (exporter->getNumConfigurations() == 0)
  206. {
  207. auto newConfigs = deprecatedConfigsList.createCopy();
  208. if (! exporter->isXcode())
  209. {
  210. for (auto j = newConfigs.getNumChildren(); --j >= 0;)
  211. {
  212. auto config = newConfigs.getChild (j);
  213. config.removeProperty (Ids::osxSDK, nullptr);
  214. config.removeProperty (Ids::osxCompatibility, nullptr);
  215. config.removeProperty (Ids::osxArchitecture, nullptr);
  216. }
  217. }
  218. exporter->settings.addChild (newConfigs, 0, nullptr);
  219. }
  220. }
  221. }
  222. }
  223. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  224. {
  225. if (projectRoot.hasProperty (name))
  226. {
  227. for (Project::ExporterIterator exporter (*this); exporter.next();)
  228. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  229. projectRoot.removeProperty (name, nullptr);
  230. }
  231. }
  232. void Project::removeDefunctExporters()
  233. {
  234. auto exporters = projectRoot.getChildWithName (Ids::EXPORTFORMATS);
  235. StringPairArray oldExporters;
  236. oldExporters.set ("ANDROID", "Android Ant Exporter");
  237. oldExporters.set ("MSVC6", "MSVC6");
  238. oldExporters.set ("VS2010", "Visual Studio 2010");
  239. oldExporters.set ("VS2012", "Visual Studio 2012");
  240. for (auto& key : oldExporters.getAllKeys())
  241. {
  242. auto oldExporter = exporters.getChildWithName (key);
  243. if (oldExporter.isValid())
  244. {
  245. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  246. TRANS (oldExporters[key]),
  247. TRANS ("The " + oldExporters[key] + " Exporter is deprecated. The exporter will be removed from this project."));
  248. exporters.removeChild (oldExporter, nullptr);
  249. }
  250. }
  251. }
  252. void Project::updateOldModulePaths()
  253. {
  254. for (Project::ExporterIterator exporter (*this); exporter.next();)
  255. exporter->updateOldModulePaths();
  256. }
  257. Array<Identifier> Project::getLegacyPluginFormatIdentifiers() noexcept
  258. {
  259. static Array<Identifier> legacyPluginFormatIdentifiers { Ids::buildVST, Ids::buildVST3, Ids::buildAU, Ids::buildAUv3,
  260. Ids::buildRTAS, Ids::buildAAX, Ids::buildStandalone, Ids::enableIAA };
  261. return legacyPluginFormatIdentifiers;
  262. }
  263. Array<Identifier> Project::getLegacyPluginCharacteristicsIdentifiers() noexcept
  264. {
  265. static Array<Identifier> legacyPluginCharacteristicsIdentifiers { Ids::pluginIsSynth, Ids::pluginWantsMidiIn, Ids::pluginProducesMidiOut,
  266. Ids::pluginIsMidiEffectPlugin, Ids::pluginEditorRequiresKeys, Ids::pluginRTASDisableBypass,
  267. Ids::pluginRTASDisableMultiMono, Ids::pluginAAXDisableBypass, Ids::pluginAAXDisableMultiMono };
  268. return legacyPluginCharacteristicsIdentifiers;
  269. }
  270. void Project::coalescePluginFormatValues()
  271. {
  272. Array<var> formatsToBuild;
  273. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  274. {
  275. if (projectRoot.getProperty (formatIdentifier, false))
  276. formatsToBuild.add (formatIdentifier.toString());
  277. }
  278. if (formatsToBuild.size() > 0)
  279. {
  280. pluginFormatsValue = formatsToBuild;
  281. shouldWriteLegacyPluginFormatSettings = true;
  282. }
  283. }
  284. void Project::coalescePluginCharacteristicsValues()
  285. {
  286. Array<var> pluginCharacteristics;
  287. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  288. {
  289. if (projectRoot.getProperty (characteristicIdentifier, false))
  290. pluginCharacteristics.add (characteristicIdentifier.toString());
  291. }
  292. if (pluginCharacteristics.size() > 0)
  293. {
  294. pluginCharacteristicsValue = pluginCharacteristics;
  295. shouldWriteLegacyPluginCharacteristicsSettings = true;
  296. }
  297. }
  298. void Project::updatePluginCategories()
  299. {
  300. {
  301. auto aaxCategory = projectRoot.getProperty (Ids::pluginAAXCategory, {}).toString();
  302. if (aaxCategory.isNotEmpty())
  303. pluginAAXCategoryValue = Array<var> (getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf (aaxCategory)]);
  304. }
  305. {
  306. auto rtasCategory = projectRoot.getProperty (Ids::pluginRTASCategory, {}).toString();
  307. if (rtasCategory.isNotEmpty())
  308. pluginRTASCategoryValue = Array<var> (getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf (rtasCategory)]);
  309. }
  310. {
  311. auto vstCategory = projectRoot.getProperty (Ids::pluginVSTCategory, {}).toString();
  312. if (vstCategory.isNotEmpty() && getAllVSTCategoryStrings().contains (vstCategory))
  313. pluginVSTCategoryValue = Array<var> (vstCategory);
  314. }
  315. }
  316. void Project::writeLegacyPluginFormatSettings()
  317. {
  318. if (pluginFormatsValue.isUsingDefault())
  319. {
  320. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  321. projectRoot.removeProperty (formatIdentifier, nullptr);
  322. }
  323. else
  324. {
  325. auto formatVar = pluginFormatsValue.get();
  326. if (auto* arr = formatVar.getArray())
  327. {
  328. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  329. projectRoot.setProperty (formatIdentifier, arr->contains (formatIdentifier.toString()), nullptr);
  330. }
  331. }
  332. }
  333. void Project::writeLegacyPluginCharacteristicsSettings()
  334. {
  335. if (pluginFormatsValue.isUsingDefault())
  336. {
  337. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  338. projectRoot.removeProperty (characteristicIdentifier, nullptr);
  339. }
  340. else
  341. {
  342. auto characteristicsVar = pluginCharacteristicsValue.get();
  343. if (auto* arr = characteristicsVar.getArray())
  344. {
  345. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  346. projectRoot.setProperty (characteristicIdentifier, arr->contains (characteristicIdentifier.toString()), nullptr);
  347. }
  348. }
  349. }
  350. //==============================================================================
  351. static int getVersionElement (StringRef v, int index)
  352. {
  353. StringArray parts = StringArray::fromTokens (v, "., ", {});
  354. return parts [parts.size() - index - 1].getIntValue();
  355. }
  356. static int getJuceVersion (const String& v)
  357. {
  358. return getVersionElement (v, 2) * 100000
  359. + getVersionElement (v, 1) * 1000
  360. + getVersionElement (v, 0);
  361. }
  362. static int getBuiltJuceVersion()
  363. {
  364. return JUCE_MAJOR_VERSION * 100000
  365. + JUCE_MINOR_VERSION * 1000
  366. + JUCE_BUILDNUMBER;
  367. }
  368. static bool isAnyModuleNewerThanProjucer (const OwnedArray<ModuleDescription>& modules)
  369. {
  370. for (auto i = modules.size(); --i >= 0;)
  371. {
  372. auto* m = modules.getUnchecked(i);
  373. if (m->getID().startsWith ("juce_")
  374. && getJuceVersion (m->getVersion()) > getBuiltJuceVersion())
  375. return true;
  376. }
  377. return false;
  378. }
  379. void Project::warnAboutOldProjucerVersion()
  380. {
  381. ModuleList available;
  382. available.scanGlobalJuceModulePath();
  383. if (! isAnyModuleNewerThanProjucer (available.modules))
  384. available.scanGlobalUserModulePath();
  385. if (! isAnyModuleNewerThanProjucer (available.modules))
  386. available.scanProjectExporterModulePaths (*this);
  387. if (! isAnyModuleNewerThanProjucer (available.modules))
  388. return;
  389. // Projucer is out of date!
  390. if (ProjucerApplication::getApp().isRunningCommandLine)
  391. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  392. else
  393. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  394. "Projucer",
  395. "This version of the Projucer is out-of-date!"
  396. "\n\n"
  397. "Always make sure that you're running the very latest version, "
  398. "preferably compiled directly from the JUCE repository that you're working with!");
  399. }
  400. //==============================================================================
  401. static File lastDocumentOpened;
  402. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  403. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  404. static void registerRecentFile (const File& file)
  405. {
  406. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  407. getAppSettings().recentFiles.addFile (file);
  408. getAppSettings().flush();
  409. }
  410. static void forgetRecentFile (const File& file)
  411. {
  412. RecentlyOpenedFilesList::forgetRecentFileNatively (file);
  413. getAppSettings().recentFiles.removeFile (file);
  414. getAppSettings().flush();
  415. }
  416. //==============================================================================
  417. Result Project::loadDocument (const File& file)
  418. {
  419. ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  420. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  421. return Result::fail ("Not a valid Jucer project!");
  422. auto newTree = ValueTree::fromXml (*xml);
  423. if (! newTree.hasType (Ids::JUCERPROJECT))
  424. return Result::fail ("The document contains errors and couldn't be parsed!");
  425. registerRecentFile (file);
  426. enabledModulesList.reset();
  427. projectRoot = newTree;
  428. initialiseProjectValues();
  429. initialiseMainGroup();
  430. initialiseAudioPluginValues();
  431. coalescePluginFormatValues();
  432. coalescePluginCharacteristicsValues();
  433. updatePluginCategories();
  434. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  435. removeDefunctExporters();
  436. updateOldModulePaths();
  437. setChangedFlag (false);
  438. if (! ProjucerApplication::getApp().isRunningCommandLine)
  439. warnAboutOldProjucerVersion();
  440. return Result::ok();
  441. }
  442. Result Project::saveDocument (const File& file)
  443. {
  444. return saveProject (file, false);
  445. }
  446. Result Project::saveProject (const File& file, bool isCommandLineApp)
  447. {
  448. if (isSaving)
  449. return Result::ok();
  450. if (isTemporaryProject())
  451. {
  452. askUserWhereToSaveProject();
  453. return Result::ok();
  454. }
  455. updateProjectSettings();
  456. if (! isCommandLineApp && ! isTemporaryProject())
  457. registerRecentFile (file);
  458. const ScopedValueSetter<bool> vs (isSaving, true, false);
  459. ProjectSaver saver (*this, file);
  460. return saver.save (! isCommandLineApp, shouldWaitAfterSaving, specifiedExporterToSave);
  461. }
  462. Result Project::saveResourcesOnly (const File& file)
  463. {
  464. ProjectSaver saver (*this, file);
  465. return saver.saveResourcesOnly();
  466. }
  467. //==============================================================================
  468. void Project::setTemporaryDirectory (const File& dir) noexcept
  469. {
  470. tempDirectory = dir;
  471. // remove this file from the recent documents list as it is a temporary project
  472. forgetRecentFile (getFile());
  473. }
  474. void Project::askUserWhereToSaveProject()
  475. {
  476. FileChooser fc ("Save Project");
  477. fc.browseForDirectory();
  478. if (fc.getResult().exists())
  479. moveTemporaryDirectory (fc.getResult());
  480. }
  481. void Project::moveTemporaryDirectory (const File& newParentDirectory)
  482. {
  483. auto newDirectory = newParentDirectory.getChildFile (tempDirectory.getFileName());
  484. auto oldJucerFileName = getFile().getFileName();
  485. saveProjectRootToFile();
  486. tempDirectory.copyDirectoryTo (newDirectory);
  487. tempDirectory.deleteRecursively();
  488. tempDirectory = File();
  489. // reload project from new location
  490. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  491. {
  492. Component::SafePointer<MainWindow> safeWindow (window);
  493. MessageManager::callAsync ([safeWindow, newDirectory, oldJucerFileName]
  494. {
  495. if (safeWindow != nullptr)
  496. safeWindow.getComponent()->moveProject (newDirectory.getChildFile (oldJucerFileName));
  497. });
  498. }
  499. }
  500. bool Project::saveProjectRootToFile()
  501. {
  502. ScopedPointer<XmlElement> xml (projectRoot.createXml());
  503. if (xml == nullptr)
  504. {
  505. jassertfalse;
  506. return false;
  507. }
  508. MemoryOutputStream mo;
  509. xml->writeToStream (mo, {});
  510. return FileHelpers::overwriteFileWithNewDataIfDifferent (getFile(), mo);
  511. }
  512. //==============================================================================
  513. static void sendProjectSettingAnalyticsEvent (StringRef label)
  514. {
  515. StringPairArray data;
  516. data.set ("label", label);
  517. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  518. }
  519. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  520. {
  521. if (tree.getRoot() == tree)
  522. {
  523. if (property == Ids::projectType)
  524. {
  525. sendChangeMessage();
  526. sendProjectSettingAnalyticsEvent ("Project Type = " + projectTypeValue.get().toString());
  527. }
  528. else if (property == Ids::name)
  529. {
  530. updateTitle();
  531. }
  532. else if (property == Ids::defines)
  533. {
  534. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  535. }
  536. else if (property == Ids::cppLanguageStandard)
  537. {
  538. sendProjectSettingAnalyticsEvent ("C++ Standard = " + cppStandardValue.get().toString());
  539. }
  540. else if (property == Ids::pluginFormats)
  541. {
  542. if (shouldWriteLegacyPluginFormatSettings)
  543. writeLegacyPluginFormatSettings();
  544. }
  545. else if (property == Ids::pluginCharacteristicsValue)
  546. {
  547. pluginVSTCategoryValue.setDefault (getDefaultVSTCategories());
  548. pluginVST3CategoryValue.setDefault (getDefaultVST3Categories());
  549. pluginRTASCategoryValue.setDefault (getDefaultRTASCategories());
  550. pluginAAXCategoryValue.setDefault (getDefaultAAXCategories());
  551. if (shouldWriteLegacyPluginCharacteristicsSettings)
  552. writeLegacyPluginCharacteristicsSettings();
  553. }
  554. changed();
  555. }
  556. }
  557. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  558. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  559. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  560. void Project::valueTreeParentChanged (ValueTree&) {}
  561. //==============================================================================
  562. bool Project::hasProjectBeenModified()
  563. {
  564. auto oldModificationTime = modificationTime;
  565. modificationTime = getFile().getLastModificationTime();
  566. return (modificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  567. }
  568. //==============================================================================
  569. File Project::resolveFilename (String filename) const
  570. {
  571. if (filename.isEmpty())
  572. return {};
  573. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  574. #if ! JUCE_WINDOWS
  575. if (filename.startsWith ("~"))
  576. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  577. #endif
  578. if (FileHelpers::isAbsolutePath (filename))
  579. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  580. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  581. }
  582. String Project::getRelativePathForFile (const File& file) const
  583. {
  584. auto filename = file.getFullPathName();
  585. auto relativePathBase = getFile().getParentDirectory();
  586. auto p1 = relativePathBase.getFullPathName();
  587. auto p2 = file.getFullPathName();
  588. while (p1.startsWithChar (File::getSeparatorChar()))
  589. p1 = p1.substring (1);
  590. while (p2.startsWithChar (File::getSeparatorChar()))
  591. p2 = p2.substring (1);
  592. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  593. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  594. {
  595. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  596. }
  597. return filename;
  598. }
  599. //==============================================================================
  600. const ProjectType& Project::getProjectType() const
  601. {
  602. if (auto* type = ProjectType::findType (getProjectTypeString()))
  603. return *type;
  604. auto* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  605. jassert (guiType != nullptr);
  606. return *guiType;
  607. }
  608. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  609. {
  610. auto& projectType = getProjectType();
  611. if (! projectType.supportsTargetType (targetType))
  612. return false;
  613. switch (targetType)
  614. {
  615. case ProjectType::Target::VSTPlugIn:
  616. return shouldBuildVST();
  617. case ProjectType::Target::VST3PlugIn:
  618. return shouldBuildVST3();
  619. case ProjectType::Target::AAXPlugIn:
  620. return shouldBuildAAX();
  621. case ProjectType::Target::RTASPlugIn:
  622. return shouldBuildRTAS();
  623. case ProjectType::Target::AudioUnitPlugIn:
  624. return shouldBuildAU();
  625. case ProjectType::Target::AudioUnitv3PlugIn:
  626. return shouldBuildAUv3();
  627. case ProjectType::Target::StandalonePlugIn:
  628. return shouldBuildStandalonePlugin();
  629. case ProjectType::Target::AggregateTarget:
  630. case ProjectType::Target::SharedCodeTarget:
  631. return projectType.isAudioPlugin();
  632. case ProjectType::Target::unspecified:
  633. return false;
  634. default:
  635. break;
  636. }
  637. return true;
  638. }
  639. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  640. {
  641. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  642. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  643. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  644. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  645. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  646. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  647. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  648. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  649. }
  650. const char* ProjectType::Target::getName() const noexcept
  651. {
  652. switch (type)
  653. {
  654. case GUIApp: return "App";
  655. case ConsoleApp: return "ConsoleApp";
  656. case StaticLibrary: return "Static Library";
  657. case DynamicLibrary: return "Dynamic Library";
  658. case VSTPlugIn: return "VST";
  659. case VST3PlugIn: return "VST3";
  660. case AudioUnitPlugIn: return "AU";
  661. case StandalonePlugIn: return "Standalone Plugin";
  662. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  663. case AAXPlugIn: return "AAX";
  664. case RTASPlugIn: return "RTAS";
  665. case SharedCodeTarget: return "Shared Code";
  666. case AggregateTarget: return "All";
  667. default: return "undefined";
  668. }
  669. }
  670. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  671. {
  672. switch (type)
  673. {
  674. case GUIApp: return executable;
  675. case ConsoleApp: return executable;
  676. case StaticLibrary: return staticLibrary;
  677. case DynamicLibrary: return sharedLibraryOrDLL;
  678. case VSTPlugIn: return pluginBundle;
  679. case VST3PlugIn: return pluginBundle;
  680. case AudioUnitPlugIn: return pluginBundle;
  681. case StandalonePlugIn: return executable;
  682. case AudioUnitv3PlugIn: return macOSAppex;
  683. case AAXPlugIn: return pluginBundle;
  684. case RTASPlugIn: return pluginBundle;
  685. case SharedCodeTarget: return staticLibrary;
  686. default:
  687. break;
  688. }
  689. return unknown;
  690. }
  691. //==============================================================================
  692. void Project::createPropertyEditors (PropertyListBuilder& props)
  693. {
  694. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  695. "The name of the project.");
  696. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  697. "The project's version number, This should be in the format major.minor.point[.point]");
  698. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  699. "Your company name, which will be added to the properties of the binary where possible");
  700. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  701. "Your company copyright, which will be added to the properties of the binary where possible");
  702. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  703. "Your company website, which will be added to the properties of the binary where possible");
  704. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  705. "Your company e-mail, which will be added to the properties of the binary where possible");
  706. {
  707. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  708. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  709. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  710. "license, or are using JUCE under the GPL v3 license.");
  711. StringPairArray description;
  712. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  713. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  714. if (ProjucerApplication::getApp().isPaidOrGPL())
  715. {
  716. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  717. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  718. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  719. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  720. }
  721. else
  722. {
  723. StringArray options;
  724. Array<var> vars;
  725. options.add (licenseRequiredTagline);
  726. vars.add (var());
  727. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  728. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  729. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  730. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  731. }
  732. }
  733. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  734. { "Dark", "Light" },
  735. { "Dark", "Light" }),
  736. "Choose the colour of the JUCE splash screen.");
  737. {
  738. StringArray projectTypeNames;
  739. Array<var> projectTypeCodes;
  740. auto types = ProjectType::getAllTypes();
  741. for (int i = 0; i < types.size(); ++i)
  742. {
  743. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  744. projectTypeCodes.add (types.getUnchecked(i)->getType());
  745. }
  746. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  747. "The project type for which settings should be shown.");
  748. }
  749. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  750. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  751. if (getProjectType().isAudioPlugin())
  752. createAudioPluginPropertyEditors (props);
  753. {
  754. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  755. StringArray maxSizeNames;
  756. Array<var> maxSizeCodes;
  757. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  758. {
  759. auto sizeInBytes = maxSizes[i] * 1024;
  760. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  761. maxSizeCodes.add (sizeInBytes);
  762. }
  763. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  764. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  765. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  766. }
  767. props.add (new ChoicePropertyComponent (includeBinaryDataInAppConfigValue, "Include BinaryData in AppConfig"),
  768. "Include BinaryData.h in the AppConfig.h file");
  769. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  770. "The namespace containing the binary assests.");
  771. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  772. { "C++11", "C++14", "C++17", "Use Latest" },
  773. { "11", "14", "17", "latest" }),
  774. "The standard of the C++ language that will be used for compilation.");
  775. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  776. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  777. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  778. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  779. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  780. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  781. }
  782. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  783. {
  784. props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats",
  785. { "VST", "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Enable IAA" },
  786. { Ids::buildVST.toString(), Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(),
  787. Ids::buildRTAS.toString(), Ids::buildAAX.toString(), Ids::buildStandalone.toString(), Ids::enableIAA.toString() }),
  788. "Plugin formats to build.");
  789. props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics",
  790. { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus",
  791. "Disable RTAS Bypass", "Disable AAX Bypass", "Disable RTAS Multi-Mono", "Disable AAX Multi-Mono" },
  792. { Ids::pluginIsSynth.toString(), Ids::pluginWantsMidiIn.toString(), Ids::pluginProducesMidiOut.toString(),
  793. Ids::pluginIsMidiEffectPlugin.toString(), Ids::pluginEditorRequiresKeys.toString(), Ids::pluginRTASDisableBypass.toString(),
  794. Ids::pluginAAXDisableBypass.toString(), Ids::pluginRTASDisableMultiMono.toString(), Ids::pluginAAXDisableMultiMono.toString() }),
  795. "Some characteristics of your plugin such as whether it is a synth, produces MIDI messages, accepts MIDI messages etc.");
  796. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  797. "The name of your plugin (keep it short!)");
  798. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  799. "A short description of your plugin.");
  800. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  801. "The name of your company (cannot be blank).");
  802. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  803. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  804. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  805. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  806. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  807. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  808. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  809. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  810. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  811. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  812. "The value to use for the JucePlugin_AAXIdentifier setting");
  813. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  814. "A prefix for the names of exported entry-point functions that the component exposes - typically this will be a version of your plugin's name that can be used as part of a C++ token.");
  815. props.add (new TextPropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", 128, false),
  816. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  817. {
  818. Array<var> vstCategoryVars;
  819. for (auto s : getAllVSTCategoryStrings())
  820. vstCategoryVars.add (s);
  821. props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST Category", getAllVSTCategoryStrings(), vstCategoryVars, 1),
  822. "VST category");
  823. }
  824. {
  825. Array<var> vst3CategoryVars;
  826. for (auto s : getAllVST3CategoryStrings())
  827. vst3CategoryVars.add (s);
  828. props.add (new MultiChoicePropertyComponent (pluginVST3CategoryValue, "Plugin VST3 Category", getAllVST3CategoryStrings(), vst3CategoryVars),
  829. "VST3 category");
  830. }
  831. props.add (new MultiChoicePropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", getAllRTASCategoryStrings(), getAllRTASCategoryVars()),
  832. "RTAS category");
  833. props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()),
  834. "AAX category");
  835. }
  836. //==============================================================================
  837. static StringArray getVersionSegments (const Project& p)
  838. {
  839. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  840. segments.trim();
  841. segments.removeEmptyStrings();
  842. return segments;
  843. }
  844. int Project::getVersionAsHexInteger() const
  845. {
  846. auto segments = getVersionSegments (*this);
  847. auto value = (segments[0].getIntValue() << 16)
  848. + (segments[1].getIntValue() << 8)
  849. + segments[2].getIntValue();
  850. if (segments.size() >= 4)
  851. value = (value << 8) + segments[3].getIntValue();
  852. return value;
  853. }
  854. String Project::getVersionAsHex() const
  855. {
  856. return "0x" + String::toHexString (getVersionAsHexInteger());
  857. }
  858. File Project::getBinaryDataCppFile (int index) const
  859. {
  860. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  861. if (index > 0)
  862. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  863. .withFileExtension (cpp.getFileExtension());
  864. return cpp;
  865. }
  866. Project::Item Project::getMainGroup()
  867. {
  868. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  869. }
  870. PropertiesFile& Project::getStoredProperties() const
  871. {
  872. return getAppSettings().getProjectProperties (getProjectUIDString());
  873. }
  874. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  875. {
  876. if (item.isImageFile())
  877. {
  878. found.add (new Project::Item (item));
  879. }
  880. else if (item.isGroup())
  881. {
  882. for (int i = 0; i < item.getNumChildren(); ++i)
  883. findImages (item.getChild (i), found);
  884. }
  885. }
  886. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  887. {
  888. findImages (getMainGroup(), items);
  889. }
  890. //==============================================================================
  891. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  892. : project (p), state (s), belongsToModule (isModuleCode)
  893. {
  894. }
  895. Project::Item::Item (const Item& other)
  896. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  897. {
  898. }
  899. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  900. String Project::Item::getID() const { return state [Ids::ID]; }
  901. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  902. Drawable* Project::Item::loadAsImageFile() const
  903. {
  904. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  905. if (! mml.lockWasGained())
  906. return nullptr;
  907. return isValid() ? Drawable::createFromImageFile (getFile())
  908. : nullptr;
  909. }
  910. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  911. {
  912. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  913. group.setID (uid);
  914. group.initialiseMissingProperties();
  915. group.getNameValue() = name;
  916. return group;
  917. }
  918. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  919. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  920. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  921. bool Project::Item::isImageFile() const
  922. {
  923. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  924. || getFile().hasFileExtension ("svg"));
  925. }
  926. Project::Item Project::Item::findItemWithID (const String& targetId) const
  927. {
  928. if (state [Ids::ID] == targetId)
  929. return *this;
  930. if (isGroup())
  931. {
  932. for (auto i = getNumChildren(); --i >= 0;)
  933. {
  934. auto found = getChild(i).findItemWithID (targetId);
  935. if (found.isValid())
  936. return found;
  937. }
  938. }
  939. return Item (project, ValueTree(), false);
  940. }
  941. bool Project::Item::canContain (const Item& child) const
  942. {
  943. if (isFile())
  944. return false;
  945. if (isGroup())
  946. return child.isFile() || child.isGroup();
  947. jassertfalse;
  948. return false;
  949. }
  950. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  951. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  952. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  953. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  954. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  955. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  956. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  957. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  958. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  959. bool Project::Item::isModuleCode() const { return belongsToModule; }
  960. String Project::Item::getFilePath() const
  961. {
  962. if (isFile())
  963. return state [Ids::file].toString();
  964. return {};
  965. }
  966. File Project::Item::getFile() const
  967. {
  968. if (isFile())
  969. return project.resolveFilename (state [Ids::file].toString());
  970. return {};
  971. }
  972. void Project::Item::setFile (const File& file)
  973. {
  974. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  975. jassert (getFile() == file);
  976. }
  977. void Project::Item::setFile (const RelativePath& file)
  978. {
  979. jassert (isFile());
  980. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  981. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  982. }
  983. bool Project::Item::renameFile (const File& newFile)
  984. {
  985. auto oldFile = getFile();
  986. if (oldFile.moveFileTo (newFile)
  987. || (newFile.exists() && ! oldFile.exists()))
  988. {
  989. setFile (newFile);
  990. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  991. return true;
  992. }
  993. return false;
  994. }
  995. bool Project::Item::containsChildForFile (const RelativePath& file) const
  996. {
  997. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  998. }
  999. Project::Item Project::Item::findItemForFile (const File& file) const
  1000. {
  1001. if (getFile() == file)
  1002. return *this;
  1003. if (isGroup())
  1004. {
  1005. for (auto i = getNumChildren(); --i >= 0;)
  1006. {
  1007. auto found = getChild(i).findItemForFile (file);
  1008. if (found.isValid())
  1009. return found;
  1010. }
  1011. }
  1012. return Item (project, ValueTree(), false);
  1013. }
  1014. File Project::Item::determineGroupFolder() const
  1015. {
  1016. jassert (isGroup());
  1017. File f;
  1018. for (int i = 0; i < getNumChildren(); ++i)
  1019. {
  1020. f = getChild(i).getFile();
  1021. if (f.exists())
  1022. return f.getParentDirectory();
  1023. }
  1024. auto parent = getParent();
  1025. if (parent != *this)
  1026. {
  1027. f = parent.determineGroupFolder();
  1028. if (f.getChildFile (getName()).isDirectory())
  1029. f = f.getChildFile (getName());
  1030. }
  1031. else
  1032. {
  1033. f = project.getProjectFolder();
  1034. if (f.getChildFile ("Source").isDirectory())
  1035. f = f.getChildFile ("Source");
  1036. }
  1037. return f;
  1038. }
  1039. void Project::Item::initialiseMissingProperties()
  1040. {
  1041. if (! state.hasProperty (Ids::ID))
  1042. setID (createAlphaNumericUID());
  1043. if (isFile())
  1044. {
  1045. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  1046. }
  1047. else if (isGroup())
  1048. {
  1049. for (auto i = getNumChildren(); --i >= 0;)
  1050. getChild(i).initialiseMissingProperties();
  1051. }
  1052. }
  1053. Value Project::Item::getNameValue()
  1054. {
  1055. return state.getPropertyAsValue (Ids::name, getUndoManager());
  1056. }
  1057. String Project::Item::getName() const
  1058. {
  1059. return state [Ids::name];
  1060. }
  1061. void Project::Item::addChild (const Item& newChild, int insertIndex)
  1062. {
  1063. state.addChild (newChild.state, insertIndex, getUndoManager());
  1064. }
  1065. void Project::Item::removeItemFromProject()
  1066. {
  1067. state.getParent().removeChild (state, getUndoManager());
  1068. }
  1069. Project::Item Project::Item::getParent() const
  1070. {
  1071. if (isMainGroup() || ! isGroup())
  1072. return *this;
  1073. return { project, state.getParent(), belongsToModule };
  1074. }
  1075. struct ItemSorter
  1076. {
  1077. static int compareElements (const ValueTree& first, const ValueTree& second)
  1078. {
  1079. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1080. }
  1081. };
  1082. struct ItemSorterWithGroupsAtStart
  1083. {
  1084. static int compareElements (const ValueTree& first, const ValueTree& second)
  1085. {
  1086. auto firstIsGroup = first.hasType (Ids::GROUP);
  1087. auto secondIsGroup = second.hasType (Ids::GROUP);
  1088. if (firstIsGroup == secondIsGroup)
  1089. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1090. return firstIsGroup ? -1 : 1;
  1091. }
  1092. };
  1093. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  1094. {
  1095. if (keepGroupsAtStart)
  1096. {
  1097. ItemSorterWithGroupsAtStart sorter;
  1098. state.sort (sorter, undoManager, true);
  1099. }
  1100. else
  1101. {
  1102. ItemSorter sorter;
  1103. state.sort (sorter, undoManager, true);
  1104. }
  1105. }
  1106. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  1107. {
  1108. if (state.getNumChildren() == 0)
  1109. return false;
  1110. if (state.getNumChildren() == 1)
  1111. return true;
  1112. auto stateCopy = state.createCopy();
  1113. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  1114. return stateCopy.isEquivalentTo (state);
  1115. }
  1116. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  1117. {
  1118. sortGroup (state, keepGroupsAtStart, getUndoManager());
  1119. if (recursive)
  1120. for (auto i = getNumChildren(); --i >= 0;)
  1121. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  1122. }
  1123. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1124. {
  1125. for (auto i = state.getNumChildren(); --i >= 0;)
  1126. {
  1127. auto child = state.getChild (i);
  1128. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1129. return { project, child, belongsToModule };
  1130. }
  1131. return addNewSubGroup (name, -1);
  1132. }
  1133. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1134. {
  1135. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1136. int n = 0;
  1137. while (project.getMainGroup().findItemWithID (newID).isValid())
  1138. newID = createGUID (newID + String (++n));
  1139. auto group = createGroup (project, name, newID, belongsToModule);
  1140. jassert (canContain (group));
  1141. addChild (group, insertIndex);
  1142. return group;
  1143. }
  1144. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1145. {
  1146. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1147. return false;
  1148. if (file.isDirectory())
  1149. {
  1150. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1151. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1152. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1153. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1154. }
  1155. else if (file.existsAsFile())
  1156. {
  1157. if (! project.getMainGroup().findItemForFile (file).isValid())
  1158. addFileUnchecked (file, insertIndex, shouldCompile);
  1159. }
  1160. else
  1161. {
  1162. jassertfalse;
  1163. }
  1164. return true;
  1165. }
  1166. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1167. {
  1168. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1169. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1170. if (! addFileAtIndex (file, 0, shouldCompile))
  1171. return false;
  1172. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1173. sortAlphabetically (wasSortedGroupsFirst, false);
  1174. return true;
  1175. }
  1176. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1177. {
  1178. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1179. item.initialiseMissingProperties();
  1180. item.getNameValue() = file.getFileName();
  1181. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1182. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1183. if (canContain (item))
  1184. {
  1185. item.setFile (file);
  1186. addChild (item, insertIndex);
  1187. }
  1188. }
  1189. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1190. {
  1191. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1192. item.initialiseMissingProperties();
  1193. item.getNameValue() = file.getFileName();
  1194. item.getShouldCompileValue() = shouldCompile;
  1195. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1196. if (canContain (item))
  1197. {
  1198. item.setFile (file);
  1199. addChild (item, insertIndex);
  1200. return true;
  1201. }
  1202. return false;
  1203. }
  1204. Icon Project::Item::getIcon (bool isOpen) const
  1205. {
  1206. auto& icons = getIcons();
  1207. if (isFile())
  1208. {
  1209. if (isImageFile())
  1210. return Icon (icons.imageDoc, Colours::transparentBlack);
  1211. return { icons.file, Colours::transparentBlack };
  1212. }
  1213. if (isMainGroup())
  1214. return { icons.juceLogo, Colours::orange };
  1215. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1216. }
  1217. bool Project::Item::isIconCrossedOut() const
  1218. {
  1219. return isFile()
  1220. && ! (shouldBeCompiled()
  1221. || shouldBeAddedToBinaryResources()
  1222. || getFile().hasFileExtension (headerFileExtensions));
  1223. }
  1224. //==============================================================================
  1225. ValueTree Project::getConfigNode()
  1226. {
  1227. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1228. }
  1229. ValueWithDefault Project::getConfigFlag (const String& name)
  1230. {
  1231. auto configNode = getConfigNode();
  1232. return { configNode, name, getUndoManagerFor (configNode) };
  1233. }
  1234. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1235. {
  1236. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1237. if (configValue == "default")
  1238. return defaultIsEnabled;
  1239. return configValue;
  1240. }
  1241. //==============================================================================
  1242. String Project::getVSTCategoryString() const noexcept
  1243. {
  1244. auto v = pluginVSTCategoryValue.get();
  1245. if (auto* arr = v.getArray())
  1246. return arr->getFirst().toString();
  1247. return {};
  1248. }
  1249. static String getVST3CategoryStringFromSelection (Array<var> selected) noexcept
  1250. {
  1251. StringArray categories;
  1252. for (auto& category : selected)
  1253. categories.add (category);
  1254. return categories.joinIntoString ("|");
  1255. }
  1256. String Project::getVST3CategoryString() const noexcept
  1257. {
  1258. auto v = pluginVST3CategoryValue.get();
  1259. if (auto* arr = v.getArray())
  1260. return getVST3CategoryStringFromSelection (*arr);
  1261. return {};
  1262. }
  1263. int Project::getAAXCategory() const noexcept
  1264. {
  1265. int res = 0;
  1266. auto v = pluginAAXCategoryValue.get();
  1267. if (auto* arr = v.getArray())
  1268. {
  1269. for (auto c : *arr)
  1270. res |= static_cast<int> (c);
  1271. }
  1272. return res;
  1273. }
  1274. int Project::getRTASCategory() const noexcept
  1275. {
  1276. int res = 0;
  1277. auto v = pluginRTASCategoryValue.get();
  1278. if (auto* arr = v.getArray())
  1279. {
  1280. for (auto c : *arr)
  1281. res |= static_cast<int> (c);
  1282. }
  1283. return res;
  1284. }
  1285. String Project::getAUMainTypeString()
  1286. {
  1287. auto s = getPluginAUMainTypeString();
  1288. if (s.isEmpty())
  1289. {
  1290. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  1291. // Use aumi instead.
  1292. if (isPluginMidiEffect()) s = "'aumi'";
  1293. else if (isPluginSynth()) s = "kAudioUnitType_MusicDevice";
  1294. else if (pluginWantsMidiInput()) s = "kAudioUnitType_MusicEffect";
  1295. else s = "kAudioUnitType_Effect";
  1296. }
  1297. return s;
  1298. }
  1299. String Project::getAUMainTypeCode()
  1300. {
  1301. auto s = getPluginAUMainTypeString();
  1302. if (s.isEmpty())
  1303. {
  1304. if (isPluginMidiEffect()) s = "aumi";
  1305. else if (isPluginSynth()) s = "aumu";
  1306. else if (pluginWantsMidiInput()) s = "aumf";
  1307. else s = "aufx";
  1308. }
  1309. return s;
  1310. }
  1311. String Project::getIAATypeCode()
  1312. {
  1313. String s;
  1314. if (pluginWantsMidiInput())
  1315. {
  1316. if (isPluginSynth())
  1317. s = "auri";
  1318. else
  1319. s = "aurm";
  1320. }
  1321. else
  1322. {
  1323. if (isPluginSynth())
  1324. s = "aurg";
  1325. else
  1326. s = "aurx";
  1327. }
  1328. return s;
  1329. }
  1330. String Project::getIAAPluginName()
  1331. {
  1332. auto s = getPluginManufacturerString();
  1333. s << ": ";
  1334. s << getPluginNameString();
  1335. return s;
  1336. }
  1337. //==============================================================================
  1338. bool Project::isAUPluginHost()
  1339. {
  1340. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1341. }
  1342. bool Project::isVSTPluginHost()
  1343. {
  1344. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1345. }
  1346. bool Project::isVST3PluginHost()
  1347. {
  1348. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1349. }
  1350. //==============================================================================
  1351. StringArray Project::getAllVSTCategoryStrings() noexcept
  1352. {
  1353. static StringArray vstCategoryStrings { "kPlugCategUnknown", "kPlugCategEffect", "kPlugCategSynth", "kPlugCategAnalysis", "kPlugCategMastering",
  1354. "kPlugCategSpacializer", "kPlugCategRoomFx", "kPlugSurroundFx", "kPlugCategRestoration", "kPlugCategOfflineProcess",
  1355. "kPlugCategShell", "kPlugCategGenerator" };
  1356. return vstCategoryStrings;
  1357. }
  1358. Array<var> Project::getDefaultVSTCategories() const noexcept
  1359. {
  1360. if (isPluginSynth())
  1361. return { "kPlugCategSynth" };
  1362. return { "kPlugCategEffect" };
  1363. }
  1364. StringArray Project::getAllVST3CategoryStrings() noexcept
  1365. {
  1366. static StringArray vst3CategoryStrings { "Fx", "Instrument", "Spatial", "Analyzer", "Delay", "Distortion", "EQ", "Filter", "Generator", "Mastering",
  1367. "Modulation", "Pitch Shift", "Restoration", "Reverb", "Surround", "Tools", "Network", "Drum", "Sampler",
  1368. "Synth", "External", "OnlyRT", "OnlyOfflineProcess", "NoOfflineProcess", "Up-Downmix" };
  1369. return vst3CategoryStrings;
  1370. }
  1371. Array<var> Project::getDefaultVST3Categories() const noexcept
  1372. {
  1373. if (isPluginSynth())
  1374. return { "Instrument", "Synth" };
  1375. return { "Fx" };
  1376. }
  1377. StringArray Project::getAllAAXCategoryStrings() noexcept
  1378. {
  1379. static StringArray aaxCategoryStrings { "AAX_ePlugInCategory_None", "AAX_ePlugInCategory_EQ", "AAX_ePlugInCategory_Dynamics", "AAX_ePlugInCategory_PitchShift",
  1380. "AAX_ePlugInCategory_Reverb", "AAX_ePlugInCategory_Delay", "AAX_ePlugInCategory_Modulation", "AAX_ePlugInCategory_Harmonic",
  1381. "AAX_ePlugInCategory_NoiseReduction", "AAX_ePlugInCategory_Dither", "AAX_ePlugInCategory_SoundField", "AAX_ePlugInCategory_HWGenerators",
  1382. "AAX_ePlugInCategory_SWGenerators", "AAX_ePlugInCategory_WrappedPlugin", "AAX_EPlugInCategory_Effect" };
  1383. return aaxCategoryStrings;
  1384. }
  1385. Array<var> Project::getAllAAXCategoryVars() noexcept
  1386. {
  1387. static Array<var> aaxCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1388. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1389. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1390. 0x00000800, 0x00001000, 0x00002000 };
  1391. return aaxCategoryVars;
  1392. }
  1393. Array<var> Project::getDefaultAAXCategories() const noexcept
  1394. {
  1395. if (isPluginSynth())
  1396. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_SWGenerators")];
  1397. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_None")];
  1398. }
  1399. StringArray Project::getAllRTASCategoryStrings() noexcept
  1400. {
  1401. static StringArray rtasCategoryStrings { "ePlugInCategory_None", "ePlugInCategory_EQ", "ePlugInCategory_Dynamics", "ePlugInCategory_PitchShift",
  1402. "ePlugInCategory_Reverb", "ePlugInCategory_Delay", "ePlugInCategory_Modulation", "ePlugInCategory_Harmonic",
  1403. "ePlugInCategory_NoiseReduction", "ePlugInCategory_Dither", "ePlugInCategory_SoundField", "ePlugInCategory_HWGenerators",
  1404. "ePlugInCategory_SWGenerators", "ePlugInCategory_WrappedPlugin", "ePlugInCategory_Effect" };
  1405. return rtasCategoryStrings;
  1406. }
  1407. Array<var> Project::getAllRTASCategoryVars() noexcept
  1408. {
  1409. static Array<var> rtasCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1410. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1411. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1412. 0x00000800, 0x00001000, 0x00002000 };
  1413. return rtasCategoryVars;
  1414. }
  1415. Array<var> Project::getDefaultRTASCategories() const noexcept
  1416. {
  1417. if (isPluginSynth())
  1418. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_SWGenerators")];
  1419. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_None")];
  1420. }
  1421. //==============================================================================
  1422. EnabledModuleList& Project::getModules()
  1423. {
  1424. if (enabledModulesList == nullptr)
  1425. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  1426. return *enabledModulesList;
  1427. }
  1428. //==============================================================================
  1429. ValueTree Project::getExporters()
  1430. {
  1431. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1432. }
  1433. int Project::getNumExporters()
  1434. {
  1435. return getExporters().getNumChildren();
  1436. }
  1437. ProjectExporter* Project::createExporter (int index)
  1438. {
  1439. jassert (index >= 0 && index < getNumExporters());
  1440. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1441. }
  1442. void Project::addNewExporter (const String& exporterName)
  1443. {
  1444. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1445. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1446. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1447. auto exportersTree = getExporters();
  1448. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1449. }
  1450. void Project::createExporterForCurrentPlatform()
  1451. {
  1452. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1453. }
  1454. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1455. {
  1456. StringArray buildFolders;
  1457. auto exportersTree = getExporters();
  1458. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1459. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1460. {
  1461. auto exporterNode = exportersTree.getChild (i);
  1462. if (exporterNode.getType() == Identifier (type))
  1463. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1464. }
  1465. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1466. return {};
  1467. buildFolders.remove (buildFolders.indexOf (base));
  1468. int num = 1;
  1469. for (auto f : buildFolders)
  1470. {
  1471. if (! f.endsWith ("_" + String (num)))
  1472. break;
  1473. ++num;
  1474. }
  1475. return "_" + String (num);
  1476. }
  1477. //==============================================================================
  1478. bool Project::shouldSendGUIBuilderAnalyticsEvent() noexcept
  1479. {
  1480. if (! hasSentGUIBuilderAnalyticsEvent)
  1481. {
  1482. hasSentGUIBuilderAnalyticsEvent = true;
  1483. return true;
  1484. }
  1485. return false;
  1486. }
  1487. //==============================================================================
  1488. String Project::getFileTemplate (const String& templateName)
  1489. {
  1490. int dataSize;
  1491. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1492. return String::fromUTF8 (data, dataSize);
  1493. jassertfalse;
  1494. return {};
  1495. }
  1496. //==============================================================================
  1497. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1498. Project::ExporterIterator::~ExporterIterator() {}
  1499. bool Project::ExporterIterator::next()
  1500. {
  1501. if (++index >= project.getNumExporters())
  1502. return false;
  1503. exporter = project.createExporter (index);
  1504. if (exporter == nullptr)
  1505. {
  1506. jassertfalse; // corrupted project file?
  1507. return next();
  1508. }
  1509. return true;
  1510. }