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.

751 lines
27KB

  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. #pragma once
  20. #include "jucer_ResourceFile.h"
  21. #include "../Project/jucer_Module.h"
  22. #include "jucer_ProjectExporter.h"
  23. //==============================================================================
  24. class ProjectSaver
  25. {
  26. public:
  27. ProjectSaver (Project& p, const File& file)
  28. : project (p),
  29. projectFile (file),
  30. generatedCodeFolder (project.getGeneratedCodeFolder()),
  31. generatedFilesGroup (Project::Item::createGroup (project, getJuceCodeGroupName(), "__generatedcode__", true)),
  32. hasBinaryData (false)
  33. {
  34. generatedFilesGroup.setID (getGeneratedGroupID());
  35. }
  36. struct SaveThread : public ThreadWithProgressWindow
  37. {
  38. public:
  39. SaveThread (ProjectSaver& ps, bool wait, const String& exp)
  40. : ThreadWithProgressWindow ("Saving...", true, false),
  41. saver (ps), result (Result::ok()),
  42. shouldWaitAfterSaving (wait),
  43. specifiedExporterToSave (exp)
  44. {}
  45. void run() override
  46. {
  47. setProgress (-1);
  48. result = saver.save (false, shouldWaitAfterSaving, specifiedExporterToSave);
  49. }
  50. ProjectSaver& saver;
  51. Result result;
  52. bool shouldWaitAfterSaving;
  53. String specifiedExporterToSave;
  54. JUCE_DECLARE_NON_COPYABLE (SaveThread)
  55. };
  56. Result save (bool showProgressBox, bool waitAfterSaving, const String& specifiedExporterToSave)
  57. {
  58. if (showProgressBox)
  59. {
  60. SaveThread thread (*this, waitAfterSaving, specifiedExporterToSave);
  61. thread.runThread();
  62. return thread.result;
  63. }
  64. const String appConfigUserContent (loadUserContentFromAppConfig());
  65. const File oldFile (project.getFile());
  66. project.setFile (projectFile);
  67. OwnedArray<LibraryModule> modules;
  68. project.getModules().createRequiredModules (modules);
  69. checkModuleValidity (modules);
  70. if (errors.size() == 0)
  71. {
  72. writeMainProjectFile();
  73. project.updateModificationTime();
  74. writeAppConfigFile (modules, appConfigUserContent);
  75. writeBinaryDataFiles();
  76. writeAppHeader (modules);
  77. writeModuleCppWrappers (modules);
  78. writeProjects (modules, specifiedExporterToSave);
  79. writeAppConfigFile (modules, appConfigUserContent); // (this is repeated in case the projects added anything to it)
  80. if (generatedCodeFolder.exists())
  81. writeReadmeFile();
  82. }
  83. if (generatedCodeFolder.exists())
  84. deleteUnwantedFilesIn (generatedCodeFolder);
  85. if (errors.size() > 0)
  86. {
  87. project.setFile (oldFile);
  88. return Result::fail (errors[0]);
  89. }
  90. // Workaround for a bug where Xcode thinks the project is invalid if opened immedietely
  91. // after writing
  92. if (waitAfterSaving)
  93. Thread::sleep (2000);
  94. return Result::ok();
  95. }
  96. Result saveResourcesOnly()
  97. {
  98. writeBinaryDataFiles();
  99. if (errors.size() > 0)
  100. return Result::fail (errors[0]);
  101. return Result::ok();
  102. }
  103. Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData)
  104. {
  105. if (! generatedCodeFolder.createDirectory())
  106. {
  107. addError ("Couldn't create folder: " + generatedCodeFolder.getFullPathName());
  108. return Project::Item (project, ValueTree(), false);
  109. }
  110. const File file (generatedCodeFolder.getChildFile (filePath));
  111. if (replaceFileIfDifferent (file, newData))
  112. return addFileToGeneratedGroup (file);
  113. return Project::Item (project, ValueTree(), true);
  114. }
  115. Project::Item addFileToGeneratedGroup (const File& file)
  116. {
  117. Project::Item item (generatedFilesGroup.findItemForFile (file));
  118. if (item.isValid())
  119. return item;
  120. generatedFilesGroup.addFileAtIndex (file, -1, true);
  121. return generatedFilesGroup.findItemForFile (file);
  122. }
  123. void setExtraAppConfigFileContent (const String& content)
  124. {
  125. extraAppConfigContent = content;
  126. }
  127. static void writeAutoGenWarningComment (OutputStream& out)
  128. {
  129. out << "/*" << newLine << newLine
  130. << " IMPORTANT! This file is auto-generated each time you save your" << newLine
  131. << " project - if you alter its contents, your changes may be overwritten!" << newLine
  132. << newLine;
  133. }
  134. static const char* getGeneratedGroupID() noexcept { return "__jucelibfiles"; }
  135. Project::Item& getGeneratedCodeGroup() { return generatedFilesGroup; }
  136. static String getJuceCodeGroupName() { return "Juce Library Code"; }
  137. File getGeneratedCodeFolder() const { return generatedCodeFolder; }
  138. bool replaceFileIfDifferent (const File& f, const MemoryOutputStream& newData)
  139. {
  140. filesCreated.add (f);
  141. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (f, newData))
  142. {
  143. addError ("Can't write to file: " + f.getFullPathName());
  144. return false;
  145. }
  146. return true;
  147. }
  148. static bool shouldFolderBeIgnoredWhenCopying (const File& f)
  149. {
  150. return f.getFileName() == ".git" || f.getFileName() == ".svn" || f.getFileName() == ".cvs";
  151. }
  152. bool copyFolder (const File& source, const File& dest)
  153. {
  154. if (source.isDirectory() && dest.createDirectory())
  155. {
  156. Array<File> subFiles;
  157. source.findChildFiles (subFiles, File::findFiles, false);
  158. for (int i = 0; i < subFiles.size(); ++i)
  159. {
  160. const File f (subFiles.getReference(i));
  161. const File target (dest.getChildFile (f.getFileName()));
  162. filesCreated.add (target);
  163. if (! f.copyFileTo (target))
  164. return false;
  165. }
  166. Array<File> subFolders;
  167. source.findChildFiles (subFolders, File::findDirectories, false);
  168. for (int i = 0; i < subFolders.size(); ++i)
  169. {
  170. const File f (subFolders.getReference(i));
  171. if (! shouldFolderBeIgnoredWhenCopying (f))
  172. if (! copyFolder (f, dest.getChildFile (f.getFileName())))
  173. return false;
  174. }
  175. return true;
  176. }
  177. return false;
  178. }
  179. Project& project;
  180. SortedSet<File> filesCreated;
  181. private:
  182. const File projectFile, generatedCodeFolder;
  183. Project::Item generatedFilesGroup;
  184. String extraAppConfigContent;
  185. StringArray errors;
  186. CriticalSection errorLock;
  187. File appConfigFile;
  188. bool hasBinaryData;
  189. // Recursively clears out any files in a folder that we didn't create, but avoids
  190. // any folders containing hidden files that might be used by version-control systems.
  191. bool deleteUnwantedFilesIn (const File& parent)
  192. {
  193. bool folderIsNowEmpty = true;
  194. DirectoryIterator i (parent, false, "*", File::findFilesAndDirectories);
  195. Array<File> filesToDelete;
  196. bool isFolder;
  197. while (i.next (&isFolder, nullptr, nullptr, nullptr, nullptr, nullptr))
  198. {
  199. const File f (i.getFile());
  200. if (filesCreated.contains (f) || shouldFileBeKept (f.getFileName()))
  201. {
  202. folderIsNowEmpty = false;
  203. }
  204. else if (isFolder)
  205. {
  206. if (deleteUnwantedFilesIn (f))
  207. filesToDelete.add (f);
  208. else
  209. folderIsNowEmpty = false;
  210. }
  211. else
  212. {
  213. filesToDelete.add (f);
  214. }
  215. }
  216. for (int j = filesToDelete.size(); --j >= 0;)
  217. filesToDelete.getReference(j).deleteRecursively();
  218. return folderIsNowEmpty;
  219. }
  220. static bool shouldFileBeKept (const String& filename)
  221. {
  222. static const char* filesToKeep[] = { ".svn", ".cvs", "CMakeLists.txt" };
  223. for (int i = 0; i < numElementsInArray (filesToKeep); ++i)
  224. if (filename == filesToKeep[i])
  225. return true;
  226. return false;
  227. }
  228. void writeMainProjectFile()
  229. {
  230. ScopedPointer<XmlElement> xml (project.getProjectRoot().createXml());
  231. jassert (xml != nullptr);
  232. if (xml != nullptr)
  233. {
  234. MemoryOutputStream mo;
  235. xml->writeToStream (mo, String());
  236. replaceFileIfDifferent (projectFile, mo);
  237. }
  238. }
  239. static int findLongestModuleName (const OwnedArray<LibraryModule>& modules)
  240. {
  241. int longest = 0;
  242. for (int i = modules.size(); --i >= 0;)
  243. longest = jmax (longest, modules.getUnchecked(i)->getID().length());
  244. return longest;
  245. }
  246. File getAppConfigFile() const { return generatedCodeFolder.getChildFile (project.getAppConfigFilename()); }
  247. String loadUserContentFromAppConfig() const
  248. {
  249. StringArray lines, userContent;
  250. lines.addLines (getAppConfigFile().loadFileAsString());
  251. bool foundCodeSection = false;
  252. for (int i = 0; i < lines.size(); ++i)
  253. {
  254. if (lines[i].contains ("[BEGIN_USER_CODE_SECTION]"))
  255. {
  256. for (int j = i + 1; j < lines.size() && ! lines[j].contains ("[END_USER_CODE_SECTION]"); ++j)
  257. userContent.add (lines[j]);
  258. foundCodeSection = true;
  259. break;
  260. }
  261. }
  262. if (! foundCodeSection)
  263. {
  264. userContent.add (String());
  265. userContent.add ("// (You can add your own code in this section, and the Projucer will not overwrite it)");
  266. userContent.add (String());
  267. }
  268. return userContent.joinIntoString (newLine) + newLine;
  269. }
  270. void checkModuleValidity (OwnedArray<LibraryModule>& modules)
  271. {
  272. if (project.getNumExporters() == 0)
  273. {
  274. addError ("No exporters found!\n"
  275. "Please add an exporter before saving.");
  276. return;
  277. }
  278. for (LibraryModule** moduleIter = modules.begin(); moduleIter != modules.end(); ++moduleIter)
  279. {
  280. if (const LibraryModule* const module = *moduleIter)
  281. {
  282. if (! module->isValid())
  283. {
  284. addError ("At least one of your JUCE module paths is invalid!\n"
  285. "Please go to the Modules settings page and ensure each path points to the correct JUCE modules folder.");
  286. return;
  287. }
  288. if (project.getModules().getExtraDependenciesNeeded (module->getID()).size() > 0)
  289. {
  290. addError ("At least one of your modules has missing dependencies!\n"
  291. "Please go to the settings page of the highlighted modules and add the required dependencies.");
  292. return;
  293. }
  294. }
  295. else
  296. {
  297. // this should never happen!
  298. jassertfalse;
  299. }
  300. }
  301. }
  302. void writeAppConfig (MemoryOutputStream& out, const OwnedArray<LibraryModule>& modules, const String& userContent)
  303. {
  304. writeAutoGenWarningComment (out);
  305. out << " There's a section below where you can add your own custom code safely, and the" << newLine
  306. << " Projucer will preserve the contents of that block, but the best way to change" << newLine
  307. << " any of these definitions is by using the Projucer's project settings." << newLine
  308. << newLine
  309. << " Any commented-out settings will assume their default values." << newLine
  310. << newLine
  311. << "*/" << newLine
  312. << newLine;
  313. out << "#pragma once" << newLine
  314. << newLine
  315. << "//==============================================================================" << newLine
  316. << "// [BEGIN_USER_CODE_SECTION]" << newLine
  317. << userContent
  318. << "// [END_USER_CODE_SECTION]" << newLine;
  319. out << newLine
  320. << "/*" << newLine
  321. << " ==============================================================================" << newLine
  322. << newLine
  323. << " In accordance with the terms of the JUCE 5 End-Use License Agreement, the" << newLine
  324. << " JUCE Code in SECTION A cannot be removed, changed or otherwise rendered" << newLine
  325. << " ineffective unless you have a JUCE Indie or Pro license, or are using JUCE" << newLine
  326. << " under the GPL v3 license." << newLine
  327. << newLine
  328. << " End User License Agreement: www.juce.com/juce-5-licence" << newLine
  329. << " ==============================================================================" << newLine
  330. << "*/" << newLine
  331. << newLine
  332. << "// BEGIN SECTION A" << newLine
  333. << newLine
  334. << "#ifndef JUCE_DISPLAY_SPLASH_SCREEN" << newLine
  335. << " #define JUCE_DISPLAY_SPLASH_SCREEN " << (project.shouldDisplaySplashScreen().getValue() ? "1" : "0") << newLine
  336. << "#endif" << newLine << newLine
  337. << "#ifndef JUCE_REPORT_APP_USAGE" << newLine
  338. << " #define JUCE_REPORT_APP_USAGE " << (project.shouldReportAppUsage().getValue() ? "1" : "0") << newLine
  339. << "#endif" << newLine << newLine
  340. << newLine
  341. << "// END SECTION A" << newLine
  342. << newLine
  343. << "#define JUCE_USE_DARK_SPLASH_SCREEN " << (project.splashScreenColour().toString() == "Dark" ? "1" : "0") << newLine;
  344. out << newLine
  345. << "//==============================================================================" << newLine;
  346. const int longestName = findLongestModuleName (modules);
  347. for (int k = 0; k < modules.size(); ++k)
  348. {
  349. LibraryModule* const m = modules.getUnchecked(k);
  350. out << "#define JUCE_MODULE_AVAILABLE_" << m->getID()
  351. << String::repeatedString (" ", longestName + 5 - m->getID().length()) << " 1" << newLine;
  352. }
  353. out << newLine << "#define JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED 1" << newLine;
  354. for (int j = 0; j < modules.size(); ++j)
  355. {
  356. LibraryModule* const m = modules.getUnchecked(j);
  357. OwnedArray<Project::ConfigFlag> flags;
  358. m->getConfigFlags (project, flags);
  359. if (flags.size() > 0)
  360. {
  361. out << newLine
  362. << "//==============================================================================" << newLine
  363. << "// " << m->getID() << " flags:" << newLine;
  364. for (int i = 0; i < flags.size(); ++i)
  365. {
  366. flags.getUnchecked(i)->value.referTo (project.getConfigFlag (flags.getUnchecked(i)->symbol));
  367. const Project::ConfigFlag* const f = flags[i];
  368. const String value (project.getConfigFlag (f->symbol).toString());
  369. out << newLine
  370. << "#ifndef " << f->symbol << newLine;
  371. if (value == Project::configFlagEnabled)
  372. out << " #define " << f->symbol << " 1";
  373. else if (value == Project::configFlagDisabled)
  374. out << " #define " << f->symbol << " 0";
  375. else if (f->defaultValue.isEmpty())
  376. out << " //#define " << f->symbol << " 1";
  377. else
  378. out << " #define " << f->symbol << " " << f->defaultValue;
  379. out << newLine
  380. << "#endif" << newLine;
  381. }
  382. }
  383. }
  384. {
  385. int isStandaloneApplication = 1;
  386. const ProjectType& type = project.getProjectType();
  387. if (type.isAudioPlugin() || type.isDynamicLibrary())
  388. isStandaloneApplication = 0;
  389. out << "//==============================================================================" << newLine
  390. << "#ifndef JUCE_STANDALONE_APPLICATION" << newLine
  391. << " #if defined(JucePlugin_Name) && defined(JucePlugin_Build_Standalone)" << newLine
  392. << " #define JUCE_STANDALONE_APPLICATION JucePlugin_Build_Standalone" << newLine
  393. << " #else" << newLine
  394. << " #define JUCE_STANDALONE_APPLICATION " << isStandaloneApplication << newLine
  395. << " #endif" << newLine
  396. << "#endif" << newLine;
  397. }
  398. if (extraAppConfigContent.isNotEmpty())
  399. out << newLine << extraAppConfigContent.trimEnd() << newLine;
  400. }
  401. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent)
  402. {
  403. appConfigFile = getAppConfigFile();
  404. MemoryOutputStream mem;
  405. writeAppConfig (mem, modules, userContent);
  406. saveGeneratedFile (project.getAppConfigFilename(), mem);
  407. }
  408. void writeAppHeader (MemoryOutputStream& out, const OwnedArray<LibraryModule>& modules)
  409. {
  410. writeAutoGenWarningComment (out);
  411. out << " This is the header file that your files should include in order to get all the" << newLine
  412. << " JUCE library headers. You should avoid including the JUCE headers directly in" << newLine
  413. << " your own source files, because that wouldn't pick up the correct configuration" << newLine
  414. << " options for your app." << newLine
  415. << newLine
  416. << "*/" << newLine << newLine;
  417. out << "#pragma once" << newLine << newLine;
  418. if (appConfigFile.exists())
  419. out << CodeHelpers::createIncludeStatement (project.getAppConfigFilename()) << newLine;
  420. if (modules.size() > 0)
  421. {
  422. out << newLine;
  423. for (int i = 0; i < modules.size(); ++i)
  424. modules.getUnchecked(i)->writeIncludes (*this, out);
  425. out << newLine;
  426. }
  427. if (hasBinaryData && project.shouldIncludeBinaryInAppConfig().getValue())
  428. out << CodeHelpers::createIncludeStatement (project.getBinaryDataHeaderFile(), appConfigFile) << newLine;
  429. out << newLine
  430. << "#if ! DONT_SET_USING_JUCE_NAMESPACE" << newLine
  431. << " // If your code uses a lot of JUCE classes, then this will obviously save you" << newLine
  432. << " // a lot of typing, but can be disabled by setting DONT_SET_USING_JUCE_NAMESPACE." << newLine
  433. << " using namespace juce;" << newLine
  434. << "#endif" << newLine
  435. << newLine
  436. << "#if ! JUCE_DONT_DECLARE_PROJECTINFO" << newLine
  437. << "namespace ProjectInfo" << newLine
  438. << "{" << newLine
  439. << " const char* const projectName = " << CppTokeniserFunctions::addEscapeChars (project.getTitle()).quoted() << ";" << newLine
  440. << " const char* const versionString = " << CppTokeniserFunctions::addEscapeChars (project.getVersionString()).quoted() << ";" << newLine
  441. << " const int versionNumber = " << project.getVersionAsHex() << ";" << newLine
  442. << "}" << newLine
  443. << "#endif" << newLine;
  444. }
  445. void writeAppHeader (const OwnedArray<LibraryModule>& modules)
  446. {
  447. MemoryOutputStream mem;
  448. writeAppHeader (mem, modules);
  449. saveGeneratedFile (project.getJuceSourceHFilename(), mem);
  450. }
  451. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules)
  452. {
  453. for (auto* module : modules)
  454. {
  455. for (auto& cu : module->getAllCompileUnits())
  456. {
  457. MemoryOutputStream mem;
  458. writeAutoGenWarningComment (mem);
  459. mem << "*/" << newLine
  460. << newLine
  461. << "#include " << project.getAppConfigFilename().quoted() << newLine
  462. << "#include <";
  463. if (cu.file.getFileExtension() != ".r") // .r files are included without the path
  464. mem << module->getID() << "/";
  465. mem << cu.file.getFileName() << ">" << newLine;
  466. replaceFileIfDifferent (generatedCodeFolder.getChildFile (cu.getFilenameForProxyFile()), mem);
  467. }
  468. }
  469. }
  470. void writeBinaryDataFiles()
  471. {
  472. const File binaryDataH (project.getBinaryDataHeaderFile());
  473. ResourceFile resourceFile (project);
  474. if (resourceFile.getNumFiles() > 0)
  475. {
  476. auto dataNamespace = project.binaryDataNamespace().toString().trim();
  477. if (dataNamespace.isEmpty())
  478. dataNamespace = "BinaryData";
  479. resourceFile.setClassName (dataNamespace);
  480. Array<File> binaryDataFiles;
  481. int maxSize = project.getMaxBinaryFileSize().getValue();
  482. if (maxSize <= 0)
  483. maxSize = 10 * 1024 * 1024;
  484. Result r (resourceFile.write (binaryDataFiles, maxSize));
  485. if (r.wasOk())
  486. {
  487. hasBinaryData = true;
  488. for (int i = 0; i < binaryDataFiles.size(); ++i)
  489. {
  490. const File& f = binaryDataFiles.getReference(i);
  491. filesCreated.add (f);
  492. generatedFilesGroup.addFileRetainingSortOrder (f, ! f.hasFileExtension (".h"));
  493. }
  494. }
  495. else
  496. {
  497. addError (r.getErrorMessage());
  498. }
  499. }
  500. else
  501. {
  502. for (int i = 20; --i >= 0;)
  503. project.getBinaryDataCppFile (i).deleteFile();
  504. binaryDataH.deleteFile();
  505. }
  506. }
  507. void writeReadmeFile()
  508. {
  509. MemoryOutputStream out;
  510. out << newLine
  511. << " Important Note!!" << newLine
  512. << " ================" << newLine
  513. << newLine
  514. << "The purpose of this folder is to contain files that are auto-generated by the Projucer," << newLine
  515. << "and ALL files in this folder will be mercilessly DELETED and completely re-written whenever" << newLine
  516. << "the Projucer saves your project." << newLine
  517. << newLine
  518. << "Therefore, it's a bad idea to make any manual changes to the files in here, or to" << newLine
  519. << "put any of your own files in here if you don't want to lose them. (Of course you may choose" << newLine
  520. << "to add the folder's contents to your version-control system so that you can re-merge your own" << newLine
  521. << "modifications after the Projucer has saved its changes)." << newLine;
  522. replaceFileIfDifferent (generatedCodeFolder.getChildFile ("ReadMe.txt"), out);
  523. }
  524. void addError (const String& message)
  525. {
  526. const ScopedLock sl (errorLock);
  527. errors.add (message);
  528. }
  529. void writePluginCharacteristicsFile();
  530. void writeProjects (const OwnedArray<LibraryModule>& modules, const String& specifiedExporterToSave)
  531. {
  532. ThreadPool threadPool;
  533. // keep a copy of the basic generated files group, as each exporter may modify it.
  534. const ValueTree originalGeneratedGroup (generatedFilesGroup.state.createCopy());
  535. try
  536. {
  537. for (Project::ExporterIterator exporter (project); exporter.next();)
  538. {
  539. if (specifiedExporterToSave.isNotEmpty() && exporter->getName() != specifiedExporterToSave)
  540. continue;
  541. exporter->initialiseDependencyPathValues();
  542. if (exporter->getTargetFolder().createDirectory())
  543. {
  544. exporter->copyMainGroupFromProject();
  545. exporter->settings = exporter->settings.createCopy();
  546. exporter->addToExtraSearchPaths (RelativePath ("JuceLibraryCode", RelativePath::projectFolder));
  547. generatedFilesGroup.state = originalGeneratedGroup.createCopy();
  548. exporter->addSettingsForProjectType (project.getProjectType());
  549. for (auto& module: modules)
  550. module->addSettingsForModuleToExporter (*exporter, *this);
  551. if (project.getProjectType().isAudioPlugin())
  552. writePluginCharacteristicsFile();
  553. generatedFilesGroup.sortAlphabetically (true, true);
  554. exporter->getAllGroups().add (generatedFilesGroup);
  555. threadPool.addJob (new ExporterJob (*this, exporter.exporter.release(), modules), true);
  556. }
  557. else
  558. {
  559. addError ("Can't create folder: " + exporter->getTargetFolder().getFullPathName());
  560. }
  561. }
  562. }
  563. catch (ProjectExporter::SaveError& saveError)
  564. {
  565. addError (saveError.message);
  566. }
  567. while (threadPool.getNumJobs() > 0)
  568. Thread::sleep (10);
  569. }
  570. class ExporterJob : public ThreadPoolJob
  571. {
  572. public:
  573. ExporterJob (ProjectSaver& ps, ProjectExporter* pe,
  574. const OwnedArray<LibraryModule>& moduleList)
  575. : ThreadPoolJob ("export"),
  576. owner (ps), exporter (pe), modules (moduleList)
  577. {
  578. }
  579. JobStatus runJob() override
  580. {
  581. try
  582. {
  583. exporter->create (modules);
  584. std::cout << "Finished saving: " << exporter->getName() << std::endl;
  585. }
  586. catch (ProjectExporter::SaveError& error)
  587. {
  588. owner.addError (error.message);
  589. }
  590. return jobHasFinished;
  591. }
  592. private:
  593. ProjectSaver& owner;
  594. ScopedPointer<ProjectExporter> exporter;
  595. const OwnedArray<LibraryModule>& modules;
  596. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterJob)
  597. };
  598. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  599. };