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.

137 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. static StringArray readDeadMansPedalFile (const File& file)
  18. {
  19. StringArray lines;
  20. file.readLines (lines);
  21. lines.removeEmptyStrings();
  22. return lines;
  23. }
  24. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  25. AudioPluginFormat& formatToLookFor,
  26. FileSearchPath directoriesToSearch,
  27. const bool recursive,
  28. const File& deadMansPedal)
  29. : list (listToAddTo),
  30. format (formatToLookFor),
  31. deadMansPedalFile (deadMansPedal),
  32. progress (0)
  33. {
  34. directoriesToSearch.removeRedundantPaths();
  35. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  36. // If any plugins have crashed recently when being loaded, move them to the
  37. // end of the list to give the others a chance to load correctly..
  38. const StringArray crashedPlugins (readDeadMansPedalFile (deadMansPedalFile));
  39. for (int i = 0; i < crashedPlugins.size(); ++i)
  40. {
  41. const String f = crashedPlugins[i];
  42. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  43. if (f == filesOrIdentifiersToScan[j])
  44. filesOrIdentifiersToScan.move (j, -1);
  45. }
  46. applyBlacklistingsFromDeadMansPedal (listToAddTo, deadMansPedalFile);
  47. nextIndex.set (filesOrIdentifiersToScan.size());
  48. }
  49. PluginDirectoryScanner::~PluginDirectoryScanner()
  50. {
  51. list.scanFinished();
  52. }
  53. //==============================================================================
  54. String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const
  55. {
  56. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex.get() - 1]);
  57. }
  58. void PluginDirectoryScanner::updateProgress()
  59. {
  60. progress = (1.0f - nextIndex.get() / (float) filesOrIdentifiersToScan.size());
  61. }
  62. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList,
  63. String& nameOfPluginBeingScanned)
  64. {
  65. const int index = --nextIndex;
  66. if (index >= 0)
  67. {
  68. const String file (filesOrIdentifiersToScan [index]);
  69. if (file.isNotEmpty() && ! list.isListingUpToDate (file, format))
  70. {
  71. nameOfPluginBeingScanned = format.getNameOfPluginFromIdentifier (file);
  72. OwnedArray <PluginDescription> typesFound;
  73. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  74. StringArray crashedPlugins (readDeadMansPedalFile (deadMansPedalFile));
  75. crashedPlugins.removeString (file);
  76. crashedPlugins.add (file);
  77. setDeadMansPedalFile (crashedPlugins);
  78. list.scanAndAddFile (file, dontRescanIfAlreadyInList, typesFound, format);
  79. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  80. crashedPlugins.removeString (file);
  81. setDeadMansPedalFile (crashedPlugins);
  82. if (typesFound.size() == 0 && ! list.getBlacklistedFiles().contains (file))
  83. failedFiles.add (file);
  84. }
  85. }
  86. updateProgress();
  87. return index > 0;
  88. }
  89. bool PluginDirectoryScanner::skipNextFile()
  90. {
  91. updateProgress();
  92. return --nextIndex > 0;
  93. }
  94. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents)
  95. {
  96. if (deadMansPedalFile.getFullPathName().isNotEmpty())
  97. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  98. }
  99. void PluginDirectoryScanner::applyBlacklistingsFromDeadMansPedal (KnownPluginList& list, const File& file)
  100. {
  101. // If any plugins have crashed recently when being loaded, move them to the
  102. // end of the list to give the others a chance to load correctly..
  103. const StringArray crashedPlugins (readDeadMansPedalFile (file));
  104. for (int i = 0; i < crashedPlugins.size(); ++i)
  105. list.addToBlacklist (crashedPlugins[i]);
  106. }