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.

145 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "../Application/jucer_Headers.h"
  15. #include "jucer_ResourceFile.h"
  16. #include "../Project/Modules/jucer_Modules.h"
  17. #include "jucer_ProjectExporter.h"
  18. //==============================================================================
  19. class ProjectSaver
  20. {
  21. public:
  22. ProjectSaver (Project& projectToSave);
  23. Result save (ProjectExporter* exporterToSave = nullptr);
  24. Result saveResourcesOnly();
  25. void saveBasicProjectItems (const OwnedArray<LibraryModule>& modules, const String& appConfigUserContent);
  26. Result saveContentNeededForLiveBuild();
  27. Project& getProject() { return project; }
  28. Project::Item addFileToGeneratedGroup (const File& file);
  29. bool copyFolder (const File& source, const File& dest);
  30. static String getJuceCodeGroupName() { return "JUCE Library Code"; }
  31. private:
  32. //==============================================================================
  33. struct SaveThreadWithProgressWindow : public ThreadWithProgressWindow
  34. {
  35. public:
  36. SaveThreadWithProgressWindow (ProjectSaver& ps, ProjectExporter* exporterToSave)
  37. : ThreadWithProgressWindow ("Saving...", true, false),
  38. saver (ps),
  39. specifiedExporterToSave (exporterToSave)
  40. {}
  41. void run() override
  42. {
  43. setProgress (-1);
  44. result = saver.saveProject (specifiedExporterToSave);
  45. }
  46. ProjectSaver& saver;
  47. Result result = Result::ok();
  48. ProjectExporter* specifiedExporterToSave;
  49. JUCE_DECLARE_NON_COPYABLE (SaveThreadWithProgressWindow)
  50. };
  51. class ExporterJob : public ThreadPoolJob
  52. {
  53. public:
  54. ExporterJob (ProjectSaver& ps, ProjectExporter& pe, const OwnedArray<LibraryModule>& modulesList)
  55. : ThreadPoolJob ("export"),
  56. owner (ps),
  57. exporter (pe),
  58. modules (modulesList)
  59. {
  60. }
  61. JobStatus runJob() override
  62. {
  63. owner.saveExporter (exporter, modules);
  64. return jobHasFinished;
  65. }
  66. private:
  67. ProjectSaver& owner;
  68. ProjectExporter& exporter;
  69. const OwnedArray<LibraryModule>& modules;
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterJob)
  71. };
  72. //==============================================================================
  73. Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData);
  74. bool replaceFileIfDifferent (const File& f, const MemoryOutputStream& newData);
  75. bool deleteUnwantedFilesIn (const File& parent);
  76. void addError (const String& message);
  77. File getAppConfigFile() const;
  78. File getPluginDefinesFile() const;
  79. String loadUserContentFromAppConfig() const;
  80. String getAudioPluginDefines() const;
  81. OwnedArray<LibraryModule> getModules();
  82. Result saveProject (ProjectExporter* specifiedExporterToSave);
  83. template <typename WriterCallback>
  84. void writeOrRemoveGeneratedFile (const String& name, WriterCallback&& writerCallback);
  85. void writePluginDefines (MemoryOutputStream& outStream) const;
  86. void writePluginDefines();
  87. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent);
  88. void writeMainProjectFile();
  89. void writeAppConfig (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules, const String& userContent);
  90. void writeAppHeader (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules);
  91. void writeAppHeader (const OwnedArray<LibraryModule>& modules);
  92. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules);
  93. void writeBinaryDataFiles();
  94. void writeReadmeFile();
  95. void writePluginCharacteristicsFile();
  96. void writeUnityScriptFile();
  97. void writeProjects (const OwnedArray<LibraryModule>&, ProjectExporter*);
  98. void runPostExportScript();
  99. void saveExporter (ProjectExporter& exporter, const OwnedArray<LibraryModule>& modules);
  100. //==============================================================================
  101. Project& project;
  102. File generatedCodeFolder;
  103. Project::Item generatedFilesGroup;
  104. SortedSet<File> filesCreated;
  105. String projectLineFeed;
  106. CriticalSection errorLock;
  107. StringArray errors;
  108. bool hasBinaryData = false;
  109. //==============================================================================
  110. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  111. };