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.

158 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "jucer_Module.h"
  19. #include "jucer_ProjectType.h"
  20. #include "jucer_ProjectExporter.h"
  21. #include "jucer_ProjectSaver.h"
  22. #include "jucer_AudioPluginModule.h"
  23. #include "jucer_JuceLibraryModule.h"
  24. //==============================================================================
  25. ModuleList::ModuleList()
  26. {
  27. rescan();
  28. }
  29. ModuleList& ModuleList::getInstance()
  30. {
  31. static ModuleList list;
  32. return list;
  33. }
  34. struct ModuleSorter
  35. {
  36. static int compareElements (const ModuleList::Module* m1, const ModuleList::Module* m2)
  37. {
  38. return m1->uid.compareIgnoreCase (m2->uid);
  39. }
  40. };
  41. void ModuleList::rescan()
  42. {
  43. modules.clear();
  44. moduleFolder = StoredSettings::getInstance()->getLastKnownJuceFolder().getChildFile ("modules");
  45. DirectoryIterator iter (moduleFolder, false, "*", File::findDirectories);
  46. while (iter.next())
  47. {
  48. const File moduleDef (iter.getFile().getChildFile ("juce_module_info"));
  49. if (moduleDef.exists())
  50. {
  51. ScopedPointer<JuceLibraryModule> m (new JuceLibraryModule (moduleDef));
  52. jassert (m->isValid());
  53. if (m->isValid())
  54. {
  55. Module* info = new Module();
  56. modules.add (info);
  57. info->uid = m->getID();
  58. info->name = m->moduleInfo ["name"];
  59. info->description = m->moduleInfo ["description"];
  60. info->file = moduleDef;
  61. }
  62. }
  63. }
  64. ModuleSorter sorter;
  65. modules.sort (sorter);
  66. }
  67. LibraryModule* ModuleList::Module::create() const
  68. {
  69. return new JuceLibraryModule (file);
  70. }
  71. LibraryModule* ModuleList::loadModule (const String& uid) const
  72. {
  73. const Module* const m = findModuleInfo (uid);
  74. return m != nullptr ? m->create() : nullptr;
  75. }
  76. const ModuleList::Module* ModuleList::findModuleInfo (const String& uid) const
  77. {
  78. for (int i = modules.size(); --i >= 0;)
  79. if (modules.getUnchecked(i)->uid == uid)
  80. return modules.getUnchecked(i);
  81. return nullptr;
  82. }
  83. void ModuleList::getDependencies (const String& moduleID, StringArray& dependencies) const
  84. {
  85. ScopedPointer<LibraryModule> lib (loadModule (moduleID));
  86. JuceLibraryModule* m = dynamic_cast<JuceLibraryModule*> (static_cast <LibraryModule*> (lib));
  87. if (m != nullptr)
  88. {
  89. const var depsArray (m->moduleInfo ["dependencies"]);
  90. const Array<var>* const deps = depsArray.getArray();
  91. for (int i = 0; i < deps->size(); ++i)
  92. {
  93. const var& d = deps->getReference(i);
  94. String uid (d ["id"].toString());
  95. String version (d ["version"].toString());
  96. if (! dependencies.contains (uid, true))
  97. {
  98. dependencies.add (uid);
  99. getDependencies (uid, dependencies);
  100. }
  101. }
  102. }
  103. }
  104. void ModuleList::createDependencies (const String& moduleID, OwnedArray<LibraryModule>& modules) const
  105. {
  106. ScopedPointer<LibraryModule> lib (loadModule (moduleID));
  107. JuceLibraryModule* m = dynamic_cast<JuceLibraryModule*> (static_cast <LibraryModule*> (lib));
  108. if (m != nullptr)
  109. {
  110. var depsArray (m->moduleInfo ["dependencies"]);
  111. const Array<var>* const deps = depsArray.getArray();
  112. for (int i = 0; i < deps->size(); ++i)
  113. {
  114. const var& d = deps->getReference(i);
  115. String uid (d ["id"].toString());
  116. String version (d ["version"].toString());
  117. //xxx to do - also need to find version conflicts
  118. jassertfalse
  119. }
  120. }
  121. }