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.

134 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - 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 the technical preview this file cannot be licensed commercially.
  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. void save (Async async, ProjectExporter* exporterToSave, std::function<void (Result)> onCompletion);
  24. Result saveResourcesOnly();
  25. void saveBasicProjectItems (const OwnedArray<LibraryModule>& modules, const String& appConfigUserContent);
  26. Project& getProject() { return project; }
  27. Project::Item addFileToGeneratedGroup (const File& file);
  28. bool copyFolder (const File& source, const File& dest);
  29. static String getJuceCodeGroupName() { return "JUCE Library Code"; }
  30. private:
  31. //==============================================================================
  32. struct SaveThreadWithProgressWindow : public ThreadWithProgressWindow
  33. {
  34. public:
  35. SaveThreadWithProgressWindow (ProjectSaver& ps,
  36. ProjectExporter* exporterToSave,
  37. std::function<void (Result)> onCompletionIn)
  38. : ThreadWithProgressWindow ("Saving...", true, false),
  39. saver (ps),
  40. specifiedExporterToSave (exporterToSave),
  41. onCompletion (std::move (onCompletionIn))
  42. {
  43. jassert (onCompletion != nullptr);
  44. }
  45. void run() override
  46. {
  47. setProgress (-1);
  48. const auto result = saver.saveProject (specifiedExporterToSave);
  49. const auto callback = onCompletion;
  50. MessageManager::callAsync ([callback, result] { callback (result); });
  51. }
  52. private:
  53. ProjectSaver& saver;
  54. ProjectExporter* specifiedExporterToSave;
  55. std::function<void (Result)> onCompletion;
  56. JUCE_DECLARE_NON_COPYABLE (SaveThreadWithProgressWindow)
  57. };
  58. //==============================================================================
  59. Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData);
  60. bool replaceFileIfDifferent (const File& f, const MemoryOutputStream& newData);
  61. bool deleteUnwantedFilesIn (const File& parent);
  62. void addError (const String& message);
  63. File getAppConfigFile() const;
  64. File getPluginDefinesFile() const;
  65. String loadUserContentFromAppConfig() const;
  66. String getAudioPluginDefines() const;
  67. OwnedArray<LibraryModule> getModules();
  68. Result saveProject (ProjectExporter* specifiedExporterToSave);
  69. void saveProjectAsync (ProjectExporter* exporterToSave, std::function<void (Result)> onCompletion);
  70. template <typename WriterCallback>
  71. void writeOrRemoveGeneratedFile (const String& name, WriterCallback&& writerCallback);
  72. void writePluginDefines (MemoryOutputStream& outStream) const;
  73. void writePluginDefines();
  74. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent);
  75. void writeLV2Defines (MemoryOutputStream&);
  76. void writeProjectFile();
  77. void writeAppConfig (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules, const String& userContent);
  78. void writeAppHeader (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules);
  79. void writeAppHeader (const OwnedArray<LibraryModule>& modules);
  80. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules);
  81. void writeBinaryDataFiles();
  82. void writeReadmeFile();
  83. void writePluginCharacteristicsFile();
  84. void writeUnityScriptFile();
  85. void writeProjects (const OwnedArray<LibraryModule>&, ProjectExporter*);
  86. void writeLV2DefinesFile();
  87. void runPostExportScript();
  88. void saveExporter (ProjectExporter& exporter, const OwnedArray<LibraryModule>& modules);
  89. //==============================================================================
  90. Project& project;
  91. File generatedCodeFolder;
  92. Project::Item generatedFilesGroup;
  93. SortedSet<File> filesCreated;
  94. String projectLineFeed;
  95. CriticalSection errorLock;
  96. StringArray errors;
  97. std::unique_ptr<SaveThreadWithProgressWindow> saveThread;
  98. bool hasBinaryData = false;
  99. //==============================================================================
  100. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  101. JUCE_DECLARE_WEAK_REFERENCEABLE (ProjectSaver)
  102. };