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.

128 lines
4.5KB

  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. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  21. AudioPluginFormat& formatToLookFor,
  22. FileSearchPath directoriesToSearch,
  23. const bool recursive,
  24. const File& deadMansPedalFile_)
  25. : list (listToAddTo),
  26. format (formatToLookFor),
  27. deadMansPedalFile (deadMansPedalFile_),
  28. nextIndex (0),
  29. progress (0)
  30. {
  31. directoriesToSearch.removeRedundantPaths();
  32. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  33. // If any plugins have crashed recently when being loaded, move them to the
  34. // end of the list to give the others a chance to load correctly..
  35. const StringArray crashedPlugins (getDeadMansPedalFile());
  36. for (int i = 0; i < crashedPlugins.size(); ++i)
  37. {
  38. const String f = crashedPlugins[i];
  39. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  40. if (f == filesOrIdentifiersToScan[j])
  41. filesOrIdentifiersToScan.move (j, -1);
  42. }
  43. }
  44. PluginDirectoryScanner::~PluginDirectoryScanner()
  45. {
  46. }
  47. //==============================================================================
  48. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const
  49. {
  50. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  51. }
  52. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  53. {
  54. String file (filesOrIdentifiersToScan [nextIndex]);
  55. if (file.isNotEmpty() && ! list.isListingUpToDate (file))
  56. {
  57. OwnedArray <PluginDescription> typesFound;
  58. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  59. StringArray crashedPlugins (getDeadMansPedalFile());
  60. crashedPlugins.removeString (file);
  61. crashedPlugins.add (file);
  62. setDeadMansPedalFile (crashedPlugins);
  63. list.scanAndAddFile (file,
  64. dontRescanIfAlreadyInList,
  65. typesFound,
  66. format);
  67. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  68. crashedPlugins.removeString (file);
  69. setDeadMansPedalFile (crashedPlugins);
  70. if (typesFound.size() == 0)
  71. failedFiles.add (file);
  72. }
  73. return skipNextFile();
  74. }
  75. bool PluginDirectoryScanner::skipNextFile()
  76. {
  77. if (nextIndex >= filesOrIdentifiersToScan.size())
  78. return false;
  79. progress = ++nextIndex / (float) filesOrIdentifiersToScan.size();
  80. return nextIndex < filesOrIdentifiersToScan.size();
  81. }
  82. StringArray PluginDirectoryScanner::getDeadMansPedalFile()
  83. {
  84. StringArray lines;
  85. if (deadMansPedalFile != File::nonexistent)
  86. {
  87. deadMansPedalFile.readLines (lines);
  88. lines.removeEmptyStrings();
  89. }
  90. return lines;
  91. }
  92. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents)
  93. {
  94. if (deadMansPedalFile != File::nonexistent)
  95. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  96. }
  97. END_JUCE_NAMESPACE