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.

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