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.

737 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. }
  289. else
  290. {
  291. // this should never happen!
  292. jassertfalse;
  293. }
  294. }
  295. }
  296. void writeAppConfig (MemoryOutputStream& out, const OwnedArray<LibraryModule>& modules, const String& userContent)
  297. {
  298. writeAutoGenWarningComment (out);
  299. out << " There's a section below where you can add your own custom code safely, and the" << newLine
  300. << " Projucer will preserve the contents of that block, but the best way to change" << newLine
  301. << " any of these definitions is by using the Projucer's project settings." << newLine
  302. << newLine
  303. << " Any commented-out settings will assume their default values." << newLine
  304. << newLine
  305. << "*/" << newLine
  306. << newLine;
  307. out << "#pragma once" << newLine
  308. << newLine
  309. << "//==============================================================================" << newLine
  310. << "// [BEGIN_USER_CODE_SECTION]" << newLine
  311. << userContent
  312. << "// [END_USER_CODE_SECTION]" << newLine;
  313. out << newLine
  314. << "/*" << newLine
  315. << " ==============================================================================" << newLine
  316. << newLine
  317. << " In accordance with the terms of the JUCE 5 End-Use License Agreement, the" << newLine
  318. << " JUCE Code in SECTION A cannot be removed, changed or otherwise rendered" << newLine
  319. << " ineffective unless you have a JUCE Indie or Pro license, or are using JUCE" << newLine
  320. << " under the GPL v3 license." << newLine
  321. << newLine
  322. << " End User License Agreement: www.juce.com/juce-5-licence" << newLine
  323. << " ==============================================================================" << newLine
  324. << "*/" << newLine
  325. << newLine
  326. << "// BEGIN SECTION A" << newLine
  327. << newLine
  328. << "#define JUCE_DISPLAY_SPLASH_SCREEN " << (project.shouldDisplaySplashScreen().getValue() ? "1" : "0") << newLine
  329. << "#define JUCE_REPORT_APP_USAGE " << (project.shouldReportAppUsage().getValue() ? "1" : "0") << newLine
  330. << newLine
  331. << "// END SECTION A" << newLine
  332. << newLine
  333. << "#define JUCE_USE_DARK_SPLASH_SCREEN " << (project.splashScreenColour().toString() == "Dark" ? "1" : "0") << newLine;
  334. out << newLine
  335. << "//==============================================================================" << newLine;
  336. const int longestName = findLongestModuleName (modules);
  337. for (int k = 0; k < modules.size(); ++k)
  338. {
  339. LibraryModule* const m = modules.getUnchecked(k);
  340. out << "#define JUCE_MODULE_AVAILABLE_" << m->getID()
  341. << String::repeatedString (" ", longestName + 5 - m->getID().length()) << " 1" << newLine;
  342. }
  343. out << newLine << "#define JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED 1" << newLine;
  344. for (int j = 0; j < modules.size(); ++j)
  345. {
  346. LibraryModule* const m = modules.getUnchecked(j);
  347. OwnedArray<Project::ConfigFlag> flags;
  348. m->getConfigFlags (project, flags);
  349. if (flags.size() > 0)
  350. {
  351. out << newLine
  352. << "//==============================================================================" << newLine
  353. << "// " << m->getID() << " flags:" << newLine;
  354. for (int i = 0; i < flags.size(); ++i)
  355. {
  356. flags.getUnchecked(i)->value.referTo (project.getConfigFlag (flags.getUnchecked(i)->symbol));
  357. const Project::ConfigFlag* const f = flags[i];
  358. const String value (project.getConfigFlag (f->symbol).toString());
  359. out << newLine
  360. << "#ifndef " << f->symbol << newLine;
  361. if (value == Project::configFlagEnabled)
  362. out << " #define " << f->symbol << " 1";
  363. else if (value == Project::configFlagDisabled)
  364. out << " #define " << f->symbol << " 0";
  365. else if (f->defaultValue.isEmpty())
  366. out << " //#define " << f->symbol << " 1";
  367. else
  368. out << " #define " << f->symbol << " " << f->defaultValue;
  369. out << newLine
  370. << "#endif" << newLine;
  371. }
  372. }
  373. }
  374. {
  375. int isStandaloneApplication = 1;
  376. const ProjectType& type = project.getProjectType();
  377. if (type.isAudioPlugin() || type.isDynamicLibrary())
  378. isStandaloneApplication = 0;
  379. out << "//==============================================================================" << newLine
  380. << "#ifndef JUCE_STANDALONE_APPLICATION" << newLine
  381. << " #if defined(JucePlugin_Name) && defined(JucePlugin_Build_Standalone)" << newLine
  382. << " #define JUCE_STANDALONE_APPLICATION JucePlugin_Build_Standalone" << newLine
  383. << " #else" << newLine
  384. << " #define JUCE_STANDALONE_APPLICATION " << isStandaloneApplication << newLine
  385. << " #endif" << newLine
  386. << "#endif" << newLine;
  387. }
  388. if (extraAppConfigContent.isNotEmpty())
  389. out << newLine << extraAppConfigContent.trimEnd() << newLine;
  390. }
  391. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent)
  392. {
  393. appConfigFile = getAppConfigFile();
  394. MemoryOutputStream mem;
  395. writeAppConfig (mem, modules, userContent);
  396. saveGeneratedFile (project.getAppConfigFilename(), mem);
  397. }
  398. void writeAppHeader (MemoryOutputStream& out, const OwnedArray<LibraryModule>& modules)
  399. {
  400. writeAutoGenWarningComment (out);
  401. out << " This is the header file that your files should include in order to get all the" << newLine
  402. << " JUCE library headers. You should avoid including the JUCE headers directly in" << newLine
  403. << " your own source files, because that wouldn't pick up the correct configuration" << newLine
  404. << " options for your app." << newLine
  405. << newLine
  406. << "*/" << newLine << newLine;
  407. out << "#pragma once" << newLine << newLine;
  408. if (appConfigFile.exists())
  409. out << CodeHelpers::createIncludeStatement (project.getAppConfigFilename()) << newLine;
  410. if (modules.size() > 0)
  411. {
  412. out << newLine;
  413. for (int i = 0; i < modules.size(); ++i)
  414. modules.getUnchecked(i)->writeIncludes (*this, out);
  415. out << newLine;
  416. }
  417. if (hasBinaryData && project.shouldIncludeBinaryInAppConfig().getValue())
  418. out << CodeHelpers::createIncludeStatement (project.getBinaryDataHeaderFile(), appConfigFile) << newLine;
  419. out << newLine
  420. << "#if ! DONT_SET_USING_JUCE_NAMESPACE" << newLine
  421. << " // If your code uses a lot of JUCE classes, then this will obviously save you" << newLine
  422. << " // a lot of typing, but can be disabled by setting DONT_SET_USING_JUCE_NAMESPACE." << newLine
  423. << " using namespace juce;" << newLine
  424. << "#endif" << newLine
  425. << newLine
  426. << "#if ! JUCE_DONT_DECLARE_PROJECTINFO" << newLine
  427. << "namespace ProjectInfo" << newLine
  428. << "{" << newLine
  429. << " const char* const projectName = " << CppTokeniserFunctions::addEscapeChars (project.getTitle()).quoted() << ";" << newLine
  430. << " const char* const versionString = " << CppTokeniserFunctions::addEscapeChars (project.getVersionString()).quoted() << ";" << newLine
  431. << " const int versionNumber = " << project.getVersionAsHex() << ";" << newLine
  432. << "}" << newLine
  433. << "#endif" << newLine;
  434. }
  435. void writeAppHeader (const OwnedArray<LibraryModule>& modules)
  436. {
  437. MemoryOutputStream mem;
  438. writeAppHeader (mem, modules);
  439. saveGeneratedFile (project.getJuceSourceHFilename(), mem);
  440. }
  441. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules)
  442. {
  443. for (auto* module : modules)
  444. {
  445. for (auto& cu : module->getAllCompileUnits())
  446. {
  447. MemoryOutputStream mem;
  448. writeAutoGenWarningComment (mem);
  449. mem << "*/" << newLine
  450. << newLine
  451. << "#include " << project.getAppConfigFilename().quoted() << newLine
  452. << "#include <";
  453. if (cu.file.getFileExtension() != ".r") // .r files are included without the path
  454. mem << module->getID() << "/";
  455. mem << cu.file.getFileName() << ">" << newLine;
  456. replaceFileIfDifferent (generatedCodeFolder.getChildFile (cu.getFilenameForProxyFile()), mem);
  457. }
  458. }
  459. }
  460. void writeBinaryDataFiles()
  461. {
  462. const File binaryDataH (project.getBinaryDataHeaderFile());
  463. ResourceFile resourceFile (project);
  464. if (resourceFile.getNumFiles() > 0)
  465. {
  466. auto dataNamespace = project.binaryDataNamespace().toString().trim();
  467. if (dataNamespace.isEmpty())
  468. dataNamespace = "BinaryData";
  469. resourceFile.setClassName (dataNamespace);
  470. Array<File> binaryDataFiles;
  471. int maxSize = project.getMaxBinaryFileSize().getValue();
  472. if (maxSize <= 0)
  473. maxSize = 10 * 1024 * 1024;
  474. Result r (resourceFile.write (binaryDataFiles, maxSize));
  475. if (r.wasOk())
  476. {
  477. hasBinaryData = true;
  478. for (int i = 0; i < binaryDataFiles.size(); ++i)
  479. {
  480. const File& f = binaryDataFiles.getReference(i);
  481. filesCreated.add (f);
  482. generatedFilesGroup.addFileRetainingSortOrder (f, ! f.hasFileExtension (".h"));
  483. }
  484. }
  485. else
  486. {
  487. addError (r.getErrorMessage());
  488. }
  489. }
  490. else
  491. {
  492. for (int i = 20; --i >= 0;)
  493. project.getBinaryDataCppFile (i).deleteFile();
  494. binaryDataH.deleteFile();
  495. }
  496. }
  497. void writeReadmeFile()
  498. {
  499. MemoryOutputStream out;
  500. out << newLine
  501. << " Important Note!!" << newLine
  502. << " ================" << newLine
  503. << newLine
  504. << "The purpose of this folder is to contain files that are auto-generated by the Projucer," << newLine
  505. << "and ALL files in this folder will be mercilessly DELETED and completely re-written whenever" << newLine
  506. << "the Projucer saves your project." << newLine
  507. << newLine
  508. << "Therefore, it's a bad idea to make any manual changes to the files in here, or to" << newLine
  509. << "put any of your own files in here if you don't want to lose them. (Of course you may choose" << newLine
  510. << "to add the folder's contents to your version-control system so that you can re-merge your own" << newLine
  511. << "modifications after the Projucer has saved its changes)." << newLine;
  512. replaceFileIfDifferent (generatedCodeFolder.getChildFile ("ReadMe.txt"), out);
  513. }
  514. void addError (const String& message)
  515. {
  516. const ScopedLock sl (errorLock);
  517. errors.add (message);
  518. }
  519. void writePluginCharacteristicsFile();
  520. void writeProjects (const OwnedArray<LibraryModule>& modules, const String& specifiedExporterToSave)
  521. {
  522. ThreadPool threadPool;
  523. // keep a copy of the basic generated files group, as each exporter may modify it.
  524. const ValueTree originalGeneratedGroup (generatedFilesGroup.state.createCopy());
  525. try
  526. {
  527. for (Project::ExporterIterator exporter (project); exporter.next();)
  528. {
  529. if (specifiedExporterToSave.isNotEmpty() && exporter->getName() != specifiedExporterToSave)
  530. continue;
  531. if (exporter->getTargetFolder().createDirectory())
  532. {
  533. exporter->copyMainGroupFromProject();
  534. exporter->settings = exporter->settings.createCopy();
  535. exporter->addToExtraSearchPaths (RelativePath ("JuceLibraryCode", RelativePath::projectFolder));
  536. generatedFilesGroup.state = originalGeneratedGroup.createCopy();
  537. exporter->addSettingsForProjectType (project.getProjectType());
  538. for (auto& module: modules)
  539. module->addSettingsForModuleToExporter (*exporter, *this);
  540. if (project.getProjectType().isAudioPlugin())
  541. writePluginCharacteristicsFile();
  542. generatedFilesGroup.sortAlphabetically (true, true);
  543. exporter->getAllGroups().add (generatedFilesGroup);
  544. threadPool.addJob (new ExporterJob (*this, exporter.exporter.release(), modules), true);
  545. }
  546. else
  547. {
  548. addError ("Can't create folder: " + exporter->getTargetFolder().getFullPathName());
  549. }
  550. }
  551. }
  552. catch (ProjectExporter::SaveError& saveError)
  553. {
  554. addError (saveError.message);
  555. }
  556. while (threadPool.getNumJobs() > 0)
  557. Thread::sleep (10);
  558. }
  559. class ExporterJob : public ThreadPoolJob
  560. {
  561. public:
  562. ExporterJob (ProjectSaver& ps, ProjectExporter* pe,
  563. const OwnedArray<LibraryModule>& moduleList)
  564. : ThreadPoolJob ("export"),
  565. owner (ps), exporter (pe), modules (moduleList)
  566. {
  567. }
  568. JobStatus runJob() override
  569. {
  570. try
  571. {
  572. exporter->create (modules);
  573. std::cout << "Finished saving: " << exporter->getName() << std::endl;
  574. }
  575. catch (ProjectExporter::SaveError& error)
  576. {
  577. owner.addError (error.message);
  578. }
  579. return jobHasFinished;
  580. }
  581. private:
  582. ProjectSaver& owner;
  583. ScopedPointer<ProjectExporter> exporter;
  584. const OwnedArray<LibraryModule>& modules;
  585. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterJob)
  586. };
  587. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  588. };