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.

126 lines
4.8KB

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