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.

1936 lines
71KB

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