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.

200 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->getTargetBinaryName() = 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 JUCE_WINDOWS
  34. static File lastFolder (File::getSpecialLocation (File::userDocumentsDirectory));
  35. #else
  36. static File lastFolder (File::getSpecialLocation (File::userHomeDirectory));
  37. #endif
  38. return lastFolder;
  39. }
  40. //==============================================================================
  41. struct NewProjectWizard
  42. {
  43. NewProjectWizard() {}
  44. virtual ~NewProjectWizard() {}
  45. //==============================================================================
  46. virtual String getName() const = 0;
  47. virtual String getDescription() const = 0;
  48. virtual const char* getIcon() const = 0;
  49. virtual StringArray getFileCreationOptions() { return {}; }
  50. virtual Result processResultsFromSetupItems (WizardComp&) { return Result::ok(); }
  51. virtual bool initialiseProject (Project& project) = 0;
  52. virtual StringArray getDefaultModules()
  53. {
  54. static const char* mods[] =
  55. {
  56. "juce_core",
  57. "juce_events",
  58. "juce_graphics",
  59. "juce_data_structures",
  60. "juce_gui_basics",
  61. "juce_gui_extra",
  62. "juce_cryptography",
  63. "juce_video",
  64. "juce_opengl",
  65. "juce_audio_basics",
  66. "juce_audio_devices",
  67. "juce_audio_formats",
  68. "juce_audio_processors",
  69. nullptr
  70. };
  71. return StringArray (mods);
  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. project->getBundleIdentifier() = project->getDefaultBundleIdentifier();
  113. if (! initialiseProject (*project))
  114. return nullptr;
  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. return project.release();
  131. }
  132. //==============================================================================
  133. File getSourceFilesFolder() const
  134. {
  135. return projectFile.getSiblingFile ("Source");
  136. }
  137. void createSourceFolder()
  138. {
  139. if (! getSourceFilesFolder().createDirectory())
  140. failedFiles.add (getSourceFilesFolder().getFullPathName());
  141. }
  142. void addDefaultModules (Project& project, bool useGlobalPath)
  143. {
  144. StringArray mods (getDefaultModules());
  145. ModuleList list;
  146. list.addAllModulesInFolder (modulesFolder);
  147. for (int i = 0; i < mods.size(); ++i)
  148. if (const ModuleDescription* info = list.getModuleWithID (mods[i]))
  149. project.getModules().addModule (info->moduleFolder, false, useGlobalPath);
  150. }
  151. void addExporters (Project& project, WizardComp& wizardComp)
  152. {
  153. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  154. for (int i = 0; i < types.size(); ++i)
  155. project.addNewExporter (types[i]);
  156. if (project.getNumExporters() == 0)
  157. project.createExporterForCurrentPlatform();
  158. }
  159. };