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.

199 lines
6.9KB

  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. ScopedPointer<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. 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. return project.release();
  130. }
  131. //==============================================================================
  132. File getSourceFilesFolder() const
  133. {
  134. return projectFile.getSiblingFile ("Source");
  135. }
  136. void createSourceFolder()
  137. {
  138. if (! getSourceFilesFolder().createDirectory())
  139. failedFiles.add (getSourceFilesFolder().getFullPathName());
  140. }
  141. void addDefaultModules (Project& project, bool useGlobalPath)
  142. {
  143. StringArray mods (getDefaultModules());
  144. ModuleList list;
  145. list.addAllModulesInFolder (modulesFolder);
  146. for (int i = 0; i < mods.size(); ++i)
  147. if (const ModuleDescription* info = list.getModuleWithID (mods[i]))
  148. project.getModules().addModule (info->moduleFolder, false, useGlobalPath);
  149. }
  150. void addExporters (Project& project, WizardComp& wizardComp)
  151. {
  152. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  153. for (int i = 0; i < types.size(); ++i)
  154. project.addNewExporter (types[i]);
  155. if (project.getNumExporters() == 0)
  156. project.createExporterForCurrentPlatform();
  157. }
  158. };