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.

1920 lines
70KB

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