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.

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