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.

141 lines
5.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. #include "../Application/jucer_Headers.h"
  20. #include "jucer_ResourceFile.h"
  21. #include "../Project/Modules/jucer_Modules.h"
  22. #include "jucer_ProjectExporter.h"
  23. //==============================================================================
  24. class ProjectSaver
  25. {
  26. public:
  27. ProjectSaver (Project& projectToSave);
  28. void save (Async async, ProjectExporter* exporterToSave, std::function<void (Result)> onCompletion);
  29. Result saveResourcesOnly();
  30. void saveBasicProjectItems (const OwnedArray<LibraryModule>& modules, const String& appConfigUserContent);
  31. Project& getProject() { return project; }
  32. Project::Item addFileToGeneratedGroup (const File& file);
  33. bool copyFolder (const File& source, const File& dest);
  34. static String getJuceCodeGroupName() { return "JUCE Library Code"; }
  35. private:
  36. //==============================================================================
  37. struct SaveThreadWithProgressWindow : public ThreadWithProgressWindow
  38. {
  39. public:
  40. SaveThreadWithProgressWindow (ProjectSaver& ps,
  41. ProjectExporter* exporterToSave,
  42. std::function<void (Result)> onCompletionIn)
  43. : ThreadWithProgressWindow ("Saving...", true, false),
  44. saver (ps),
  45. specifiedExporterToSave (exporterToSave),
  46. onCompletion (std::move (onCompletionIn))
  47. {
  48. jassert (onCompletion != nullptr);
  49. }
  50. void run() override
  51. {
  52. setProgress (-1);
  53. const auto result = saver.saveProject (specifiedExporterToSave);
  54. const auto callback = onCompletion;
  55. MessageManager::callAsync ([callback, result] { callback (result); });
  56. }
  57. private:
  58. ProjectSaver& saver;
  59. ProjectExporter* specifiedExporterToSave;
  60. std::function<void (Result)> onCompletion;
  61. JUCE_DECLARE_NON_COPYABLE (SaveThreadWithProgressWindow)
  62. };
  63. //==============================================================================
  64. Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData);
  65. bool replaceFileIfDifferent (const File& f, const MemoryOutputStream& newData);
  66. bool deleteUnwantedFilesIn (const File& parent);
  67. void addError (const String& message);
  68. File getAppConfigFile() const;
  69. File getPluginDefinesFile() const;
  70. String loadUserContentFromAppConfig() const;
  71. String getAudioPluginDefines() const;
  72. OwnedArray<LibraryModule> getModules();
  73. Result saveProject (ProjectExporter* specifiedExporterToSave);
  74. void saveProjectAsync (ProjectExporter* exporterToSave, std::function<void (Result)> onCompletion);
  75. template <typename WriterCallback>
  76. void writeOrRemoveGeneratedFile (const String& name, WriterCallback&& writerCallback);
  77. void writePluginDefines (MemoryOutputStream& outStream) const;
  78. void writePluginDefines();
  79. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent);
  80. void writeLV2Defines (MemoryOutputStream&);
  81. void writeProjectFile();
  82. void writeAppConfig (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules, const String& userContent);
  83. void writeAppHeader (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules);
  84. void writeAppHeader (const OwnedArray<LibraryModule>& modules);
  85. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules);
  86. void writeBinaryDataFiles();
  87. void writeReadmeFile();
  88. void writePluginCharacteristicsFile();
  89. void writeUnityScriptFile();
  90. void writeProjects (const OwnedArray<LibraryModule>&, ProjectExporter*);
  91. void writeLV2DefinesFile();
  92. void runPostExportScript();
  93. void saveExporter (ProjectExporter& exporter, const OwnedArray<LibraryModule>& modules);
  94. //==============================================================================
  95. Project& project;
  96. File generatedCodeFolder;
  97. Project::Item generatedFilesGroup;
  98. SortedSet<File> filesCreated;
  99. String projectLineFeed;
  100. CriticalSection errorLock;
  101. StringArray errors;
  102. std::unique_ptr<SaveThreadWithProgressWindow> saveThread;
  103. bool hasBinaryData = false;
  104. //==============================================================================
  105. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  106. JUCE_DECLARE_WEAK_REFERENCEABLE (ProjectSaver)
  107. };