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.

739 lines
26KB

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