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.

122 lines
4.4KB

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