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.

198 lines
7.0KB

  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 "../Utility/Helpers/jucer_PresetIDs.h"
  15. //==============================================================================
  16. static void setExecutableNameForAllTargets (Project& project, const String& exeName)
  17. {
  18. for (Project::ExporterIterator exporter (project); exporter.next();)
  19. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  20. config->getValue (Ids::targetName) = exeName;
  21. }
  22. static Project::Item createSourceGroup (Project& project)
  23. {
  24. return project.getMainGroup().addNewSubGroup ("Source", 0);
  25. }
  26. static File& getLastWizardFolder()
  27. {
  28. if (getAppSettings().lastWizardFolder.isDirectory())
  29. return getAppSettings().lastWizardFolder;
  30. #if JUCE_WINDOWS
  31. static File lastFolderFallback (File::getSpecialLocation (File::userDocumentsDirectory));
  32. #else
  33. static File lastFolderFallback (File::getSpecialLocation (File::userHomeDirectory));
  34. #endif
  35. return lastFolderFallback;
  36. }
  37. //==============================================================================
  38. struct NewProjectWizard
  39. {
  40. NewProjectWizard() {}
  41. virtual ~NewProjectWizard() {}
  42. //==============================================================================
  43. virtual String getName() const = 0;
  44. virtual String getDescription() const = 0;
  45. virtual const char* getIcon() const = 0;
  46. virtual StringArray getFileCreationOptions() { return {}; }
  47. virtual Result processResultsFromSetupItems (WizardComp&) { return Result::ok(); }
  48. virtual bool initialiseProject (Project& project) = 0;
  49. virtual StringArray getDefaultModules()
  50. {
  51. return
  52. {
  53. "juce_audio_basics",
  54. "juce_audio_devices",
  55. "juce_audio_formats",
  56. "juce_audio_processors",
  57. "juce_core",
  58. "juce_cryptography",
  59. "juce_data_structures",
  60. "juce_events",
  61. "juce_graphics",
  62. "juce_gui_basics",
  63. "juce_gui_extra",
  64. "juce_opengl",
  65. };
  66. }
  67. String appTitle;
  68. File targetFolder, projectFile, modulesFolder;
  69. WizardComp* ownerWizardComp;
  70. StringArray failedFiles;
  71. bool selectJuceFolder()
  72. {
  73. return ModulesFolderPathBox::selectJuceFolder (modulesFolder);
  74. }
  75. //==============================================================================
  76. Project* runWizard (WizardComp& wc,
  77. const String& projectName,
  78. const File& target,
  79. bool useGlobalPath)
  80. {
  81. ownerWizardComp = &wc;
  82. appTitle = projectName;
  83. targetFolder = target;
  84. if (! targetFolder.exists())
  85. {
  86. if (! targetFolder.createDirectory())
  87. failedFiles.add (targetFolder.getFullPathName());
  88. }
  89. else if (FileHelpers::containsAnyNonHiddenFiles (targetFolder))
  90. {
  91. if (! AlertWindow::showOkCancelBox (AlertWindow::InfoIcon,
  92. TRANS("New JUCE Project"),
  93. TRANS("You chose the folder:\n\nXFLDRX\n\n").replace ("XFLDRX", targetFolder.getFullPathName())
  94. + TRANS("This folder isn't empty - are you sure you want to create the project there?")
  95. + "\n\n"
  96. + TRANS("Any existing files with the same names may be overwritten by the new files.")))
  97. return nullptr;
  98. }
  99. projectFile = targetFolder.getChildFile (File::createLegalFileName (appTitle))
  100. .withFileExtension (Project::projectFileExtension);
  101. auto project = std::make_unique<Project> (projectFile);
  102. if (failedFiles.size() == 0)
  103. {
  104. project->setTitle (appTitle);
  105. if (! initialiseProject (*project))
  106. return nullptr;
  107. project->getConfigFlag ("JUCE_STRICT_REFCOUNTEDPOINTER") = true;
  108. project->getProjectValue (Ids::useAppConfig) = false;
  109. project->getProjectValue (Ids::addUsingNamespaceToJuceHeader) = false;
  110. if (! ProjucerApplication::getApp().getLicenseController().getCurrentState().isPaidOrGPL())
  111. project->getProjectValue (Ids::displaySplashScreen) = true;
  112. addExporters (*project, wc);
  113. addDefaultModules (*project, useGlobalPath);
  114. if (project->save (false, true) != FileBasedDocument::savedOk)
  115. return nullptr;
  116. project->setChangedFlag (false);
  117. }
  118. if (failedFiles.size() > 0)
  119. {
  120. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  121. TRANS("Errors in Creating Project!"),
  122. TRANS("The following files couldn't be written:")
  123. + "\n\n"
  124. + failedFiles.joinIntoString ("\n", 0, 10));
  125. return nullptr;
  126. }
  127. return project.release();
  128. }
  129. //==============================================================================
  130. File getSourceFilesFolder() const
  131. {
  132. return projectFile.getSiblingFile ("Source");
  133. }
  134. void createSourceFolder()
  135. {
  136. if (! getSourceFilesFolder().createDirectory())
  137. failedFiles.add (getSourceFilesFolder().getFullPathName());
  138. }
  139. void addDefaultModules (Project& project, bool useGlobalPath)
  140. {
  141. auto defaultModules = getDefaultModules();
  142. AvailableModulesList list;
  143. list.scanPaths ({ modulesFolder });
  144. for (auto& mod : list.getAllModules())
  145. if (defaultModules.contains (mod.first))
  146. project.getEnabledModules().addModule (mod.second, false, useGlobalPath);
  147. }
  148. void addExporters (Project& project, WizardComp& wizardComp)
  149. {
  150. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  151. for (int i = 0; i < types.size(); ++i)
  152. project.addNewExporter (types[i]);
  153. if (project.getNumExporters() == 0)
  154. project.createExporterForCurrentPlatform();
  155. }
  156. };