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.

126 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. Result save (ProjectExporter* exporterToSave = nullptr);
  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, ProjectExporter* exporterToSave)
  41. : ThreadWithProgressWindow ("Saving...", true, false),
  42. saver (ps),
  43. specifiedExporterToSave (exporterToSave)
  44. {}
  45. void run() override
  46. {
  47. setProgress (-1);
  48. result = saver.saveProject (specifiedExporterToSave);
  49. }
  50. ProjectSaver& saver;
  51. Result result = Result::ok();
  52. ProjectExporter* specifiedExporterToSave;
  53. JUCE_DECLARE_NON_COPYABLE (SaveThreadWithProgressWindow)
  54. };
  55. //==============================================================================
  56. Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData);
  57. bool replaceFileIfDifferent (const File& f, const MemoryOutputStream& newData);
  58. bool deleteUnwantedFilesIn (const File& parent);
  59. void addError (const String& message);
  60. File getAppConfigFile() const;
  61. File getPluginDefinesFile() const;
  62. String loadUserContentFromAppConfig() const;
  63. String getAudioPluginDefines() const;
  64. OwnedArray<LibraryModule> getModules();
  65. Result saveProject (ProjectExporter* specifiedExporterToSave);
  66. template <typename WriterCallback>
  67. void writeOrRemoveGeneratedFile (const String& name, WriterCallback&& writerCallback);
  68. void writePluginDefines (MemoryOutputStream& outStream) const;
  69. void writePluginDefines();
  70. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent);
  71. void writeProjectFile();
  72. void writeAppConfig (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules, const String& userContent);
  73. void writeAppHeader (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules);
  74. void writeAppHeader (const OwnedArray<LibraryModule>& modules);
  75. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules);
  76. void writeBinaryDataFiles();
  77. void writeReadmeFile();
  78. void writePluginCharacteristicsFile();
  79. void writeUnityScriptFile();
  80. void writeProjects (const OwnedArray<LibraryModule>&, ProjectExporter*);
  81. void runPostExportScript();
  82. void saveExporter (ProjectExporter& exporter, const OwnedArray<LibraryModule>& modules);
  83. //==============================================================================
  84. Project& project;
  85. File generatedCodeFolder;
  86. Project::Item generatedFilesGroup;
  87. SortedSet<File> filesCreated;
  88. String projectLineFeed;
  89. CriticalSection errorLock;
  90. StringArray errors;
  91. bool hasBinaryData = false;
  92. //==============================================================================
  93. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  94. };