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.

127 lines
4.7KB

  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. Result saveContentNeededForLiveBuild();
  32. Project& getProject() { return project; }
  33. Project::Item addFileToGeneratedGroup (const File& file);
  34. bool copyFolder (const File& source, const File& dest);
  35. static String getJuceCodeGroupName() { return "JUCE Library Code"; }
  36. private:
  37. //==============================================================================
  38. struct SaveThreadWithProgressWindow : public ThreadWithProgressWindow
  39. {
  40. public:
  41. SaveThreadWithProgressWindow (ProjectSaver& ps, ProjectExporter* exporterToSave)
  42. : ThreadWithProgressWindow ("Saving...", true, false),
  43. saver (ps),
  44. specifiedExporterToSave (exporterToSave)
  45. {}
  46. void run() override
  47. {
  48. setProgress (-1);
  49. result = saver.saveProject (specifiedExporterToSave);
  50. }
  51. ProjectSaver& saver;
  52. Result result = Result::ok();
  53. ProjectExporter* specifiedExporterToSave;
  54. JUCE_DECLARE_NON_COPYABLE (SaveThreadWithProgressWindow)
  55. };
  56. //==============================================================================
  57. Project::Item saveGeneratedFile (const String& filePath, const MemoryOutputStream& newData);
  58. bool replaceFileIfDifferent (const File& f, const MemoryOutputStream& newData);
  59. bool deleteUnwantedFilesIn (const File& parent);
  60. void addError (const String& message);
  61. File getAppConfigFile() const;
  62. File getPluginDefinesFile() const;
  63. String loadUserContentFromAppConfig() const;
  64. String getAudioPluginDefines() const;
  65. OwnedArray<LibraryModule> getModules();
  66. Result saveProject (ProjectExporter* specifiedExporterToSave);
  67. template <typename WriterCallback>
  68. void writeOrRemoveGeneratedFile (const String& name, WriterCallback&& writerCallback);
  69. void writePluginDefines (MemoryOutputStream& outStream) const;
  70. void writePluginDefines();
  71. void writeAppConfigFile (const OwnedArray<LibraryModule>& modules, const String& userContent);
  72. void writeProjectFile();
  73. void writeAppConfig (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules, const String& userContent);
  74. void writeAppHeader (MemoryOutputStream& outStream, const OwnedArray<LibraryModule>& modules);
  75. void writeAppHeader (const OwnedArray<LibraryModule>& modules);
  76. void writeModuleCppWrappers (const OwnedArray<LibraryModule>& modules);
  77. void writeBinaryDataFiles();
  78. void writeReadmeFile();
  79. void writePluginCharacteristicsFile();
  80. void writeUnityScriptFile();
  81. void writeProjects (const OwnedArray<LibraryModule>&, ProjectExporter*);
  82. void runPostExportScript();
  83. void saveExporter (ProjectExporter& exporter, const OwnedArray<LibraryModule>& modules);
  84. //==============================================================================
  85. Project& project;
  86. File generatedCodeFolder;
  87. Project::Item generatedFilesGroup;
  88. SortedSet<File> filesCreated;
  89. String projectLineFeed;
  90. CriticalSection errorLock;
  91. StringArray errors;
  92. bool hasBinaryData = false;
  93. //==============================================================================
  94. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProjectSaver)
  95. };