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.

206 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_video",
  66. "juce_opengl",
  67. "juce_audio_basics",
  68. "juce_audio_devices",
  69. "juce_audio_formats",
  70. "juce_audio_processors"
  71. };
  72. }
  73. String appTitle;
  74. File targetFolder, projectFile, modulesFolder;
  75. WizardComp* ownerWizardComp;
  76. StringArray failedFiles;
  77. bool selectJuceFolder()
  78. {
  79. return ModulesFolderPathBox::selectJuceFolder (modulesFolder);
  80. }
  81. //==============================================================================
  82. Project* runWizard (WizardComp& wc,
  83. const String& projectName,
  84. const File& target,
  85. bool useGlobalPath)
  86. {
  87. ownerWizardComp = &wc;
  88. appTitle = projectName;
  89. targetFolder = target;
  90. if (! targetFolder.exists())
  91. {
  92. if (! targetFolder.createDirectory())
  93. failedFiles.add (targetFolder.getFullPathName());
  94. }
  95. else if (FileHelpers::containsAnyNonHiddenFiles (targetFolder))
  96. {
  97. if (! AlertWindow::showOkCancelBox (AlertWindow::InfoIcon,
  98. TRANS("New JUCE Project"),
  99. TRANS("You chose the folder:\n\nXFLDRX\n\n").replace ("XFLDRX", targetFolder.getFullPathName())
  100. + TRANS("This folder isn't empty - are you sure you want to create the project there?")
  101. + "\n\n"
  102. + TRANS("Any existing files with the same names may be overwritten by the new files.")))
  103. return nullptr;
  104. }
  105. projectFile = targetFolder.getChildFile (File::createLegalFileName (appTitle))
  106. .withFileExtension (Project::projectFileExtension);
  107. std::unique_ptr<Project> project (new Project (projectFile));
  108. if (failedFiles.size() == 0)
  109. {
  110. project->setFile (projectFile);
  111. project->setTitle (appTitle);
  112. if (! initialiseProject (*project))
  113. return nullptr;
  114. project->getConfigFlag ("JUCE_STRICT_REFCOUNTEDPOINTER") = true;
  115. addExporters (*project, wc);
  116. addDefaultModules (*project, useGlobalPath);
  117. if (project->save (false, true) != FileBasedDocument::savedOk)
  118. return nullptr;
  119. project->setChangedFlag (false);
  120. }
  121. if (failedFiles.size() > 0)
  122. {
  123. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  124. TRANS("Errors in Creating Project!"),
  125. TRANS("The following files couldn't be written:")
  126. + "\n\n"
  127. + failedFiles.joinIntoString ("\n", 0, 10));
  128. return nullptr;
  129. }
  130. StringPairArray data;
  131. data.set ("label", "Project Type = " + project->getProjectTypeString());
  132. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  133. return project.release();
  134. }
  135. //==============================================================================
  136. File getSourceFilesFolder() const
  137. {
  138. return projectFile.getSiblingFile ("Source");
  139. }
  140. void createSourceFolder()
  141. {
  142. if (! getSourceFilesFolder().createDirectory())
  143. failedFiles.add (getSourceFilesFolder().getFullPathName());
  144. }
  145. void addDefaultModules (Project& project, bool useGlobalPath)
  146. {
  147. StringArray mods (getDefaultModules());
  148. ModuleList list;
  149. list.addAllModulesInFolder (modulesFolder);
  150. for (int i = 0; i < mods.size(); ++i)
  151. if (const ModuleDescription* info = list.getModuleWithID (mods[i]))
  152. project.getModules().addModule (info->moduleFolder, false, useGlobalPath, false);
  153. }
  154. void addExporters (Project& project, WizardComp& wizardComp)
  155. {
  156. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  157. for (int i = 0; i < types.size(); ++i)
  158. project.addNewExporter (types[i]);
  159. if (project.getNumExporters() == 0)
  160. project.createExporterForCurrentPlatform();
  161. }
  162. };