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.

205 lines
7.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. static void setExecutableNameForAllTargets (Project& project, const String& exeName)
  22. {
  23. for (Project::ExporterIterator exporter (project); exporter.next();)
  24. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  25. config->getValue (Ids::targetName) = exeName;
  26. }
  27. static Project::Item createSourceGroup (Project& project)
  28. {
  29. return project.getMainGroup().addNewSubGroup ("Source", 0);
  30. }
  31. static File& getLastWizardFolder()
  32. {
  33. if (getAppSettings().lastWizardFolder.isDirectory())
  34. return getAppSettings().lastWizardFolder;
  35. #if JUCE_WINDOWS
  36. static File lastFolderFallback (File::getSpecialLocation (File::userDocumentsDirectory));
  37. #else
  38. static File lastFolderFallback (File::getSpecialLocation (File::userHomeDirectory));
  39. #endif
  40. return lastFolderFallback;
  41. }
  42. //==============================================================================
  43. struct NewProjectWizard
  44. {
  45. NewProjectWizard() {}
  46. virtual ~NewProjectWizard() {}
  47. //==============================================================================
  48. virtual String getName() const = 0;
  49. virtual String getDescription() const = 0;
  50. virtual const char* getIcon() const = 0;
  51. virtual StringArray getFileCreationOptions() { return {}; }
  52. virtual Result processResultsFromSetupItems (WizardComp&) { return Result::ok(); }
  53. virtual bool initialiseProject (Project& project) = 0;
  54. virtual StringArray getDefaultModules()
  55. {
  56. return
  57. {
  58. "juce_core",
  59. "juce_events",
  60. "juce_graphics",
  61. "juce_data_structures",
  62. "juce_gui_basics",
  63. "juce_gui_extra",
  64. "juce_cryptography",
  65. "juce_opengl",
  66. "juce_audio_basics",
  67. "juce_audio_devices",
  68. "juce_audio_formats",
  69. "juce_audio_processors"
  70. };
  71. }
  72. String appTitle;
  73. File targetFolder, projectFile, modulesFolder;
  74. WizardComp* ownerWizardComp;
  75. StringArray failedFiles;
  76. bool selectJuceFolder()
  77. {
  78. return ModulesFolderPathBox::selectJuceFolder (modulesFolder);
  79. }
  80. //==============================================================================
  81. Project* runWizard (WizardComp& wc,
  82. const String& projectName,
  83. const File& target,
  84. bool useGlobalPath)
  85. {
  86. ownerWizardComp = &wc;
  87. appTitle = projectName;
  88. targetFolder = target;
  89. if (! targetFolder.exists())
  90. {
  91. if (! targetFolder.createDirectory())
  92. failedFiles.add (targetFolder.getFullPathName());
  93. }
  94. else if (FileHelpers::containsAnyNonHiddenFiles (targetFolder))
  95. {
  96. if (! AlertWindow::showOkCancelBox (AlertWindow::InfoIcon,
  97. TRANS("New JUCE Project"),
  98. TRANS("You chose the folder:\n\nXFLDRX\n\n").replace ("XFLDRX", targetFolder.getFullPathName())
  99. + TRANS("This folder isn't empty - are you sure you want to create the project there?")
  100. + "\n\n"
  101. + TRANS("Any existing files with the same names may be overwritten by the new files.")))
  102. return nullptr;
  103. }
  104. projectFile = targetFolder.getChildFile (File::createLegalFileName (appTitle))
  105. .withFileExtension (Project::projectFileExtension);
  106. std::unique_ptr<Project> project (new Project (projectFile));
  107. if (failedFiles.size() == 0)
  108. {
  109. project->setFile (projectFile);
  110. project->setTitle (appTitle);
  111. if (! initialiseProject (*project))
  112. return nullptr;
  113. project->getConfigFlag ("JUCE_STRICT_REFCOUNTEDPOINTER") = true;
  114. addExporters (*project, wc);
  115. addDefaultModules (*project, useGlobalPath);
  116. if (project->save (false, true) != FileBasedDocument::savedOk)
  117. return nullptr;
  118. project->setChangedFlag (false);
  119. }
  120. if (failedFiles.size() > 0)
  121. {
  122. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  123. TRANS("Errors in Creating Project!"),
  124. TRANS("The following files couldn't be written:")
  125. + "\n\n"
  126. + failedFiles.joinIntoString ("\n", 0, 10));
  127. return nullptr;
  128. }
  129. StringPairArray data;
  130. data.set ("label", "Project Type = " + project->getProjectTypeString());
  131. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  132. return project.release();
  133. }
  134. //==============================================================================
  135. File getSourceFilesFolder() const
  136. {
  137. return projectFile.getSiblingFile ("Source");
  138. }
  139. void createSourceFolder()
  140. {
  141. if (! getSourceFilesFolder().createDirectory())
  142. failedFiles.add (getSourceFilesFolder().getFullPathName());
  143. }
  144. void addDefaultModules (Project& project, bool useGlobalPath)
  145. {
  146. auto defaultModules = getDefaultModules();
  147. AvailableModuleList list;
  148. list.scanPaths ({ modulesFolder });
  149. for (auto& mod : list.getAllModules())
  150. if (defaultModules.contains (mod.first))
  151. project.getEnabledModules().addModule (mod.second, false, useGlobalPath, false);
  152. }
  153. void addExporters (Project& project, WizardComp& wizardComp)
  154. {
  155. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  156. for (int i = 0; i < types.size(); ++i)
  157. project.addNewExporter (types[i]);
  158. if (project.getNumExporters() == 0)
  159. project.createExporterForCurrentPlatform();
  160. }
  161. };