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.

139 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. bool allowPluginsWhichRequireAsynchronousInstantiation)
  30. : list (listToAddTo),
  31. format (formatToLookFor),
  32. deadMansPedalFile (deadMansPedal),
  33. progress (0),
  34. allowAsync (allowPluginsWhichRequireAsynchronousInstantiation)
  35. {
  36. directoriesToSearch.removeRedundantPaths();
  37. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive, allowAsync);
  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. nextIndex.set (filesOrIdentifiersToScan.size());
  50. }
  51. PluginDirectoryScanner::~PluginDirectoryScanner()
  52. {
  53. list.scanFinished();
  54. }
  55. //==============================================================================
  56. String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const
  57. {
  58. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex.get() - 1]);
  59. }
  60. void PluginDirectoryScanner::updateProgress()
  61. {
  62. progress = (1.0f - nextIndex.get() / (float) filesOrIdentifiersToScan.size());
  63. }
  64. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList,
  65. String& nameOfPluginBeingScanned)
  66. {
  67. const int index = --nextIndex;
  68. if (index >= 0)
  69. {
  70. const String file (filesOrIdentifiersToScan [index]);
  71. if (file.isNotEmpty() && ! list.isListingUpToDate (file, format))
  72. {
  73. nameOfPluginBeingScanned = format.getNameOfPluginFromIdentifier (file);
  74. OwnedArray <PluginDescription> typesFound;
  75. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  76. StringArray crashedPlugins (readDeadMansPedalFile (deadMansPedalFile));
  77. crashedPlugins.removeString (file);
  78. crashedPlugins.add (file);
  79. setDeadMansPedalFile (crashedPlugins);
  80. list.scanAndAddFile (file, dontRescanIfAlreadyInList, typesFound, format);
  81. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  82. crashedPlugins.removeString (file);
  83. setDeadMansPedalFile (crashedPlugins);
  84. if (typesFound.size() == 0 && ! list.getBlacklistedFiles().contains (file))
  85. failedFiles.add (file);
  86. }
  87. }
  88. updateProgress();
  89. return index > 0;
  90. }
  91. bool PluginDirectoryScanner::skipNextFile()
  92. {
  93. updateProgress();
  94. return --nextIndex > 0;
  95. }
  96. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents)
  97. {
  98. if (deadMansPedalFile.getFullPathName().isNotEmpty())
  99. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  100. }
  101. void PluginDirectoryScanner::applyBlacklistingsFromDeadMansPedal (KnownPluginList& list, const File& file)
  102. {
  103. // If any plugins have crashed recently when being loaded, move them to the
  104. // end of the list to give the others a chance to load correctly..
  105. const StringArray crashedPlugins (readDeadMansPedalFile (file));
  106. for (int i = 0; i < crashedPlugins.size(); ++i)
  107. list.addToBlacklist (crashedPlugins[i]);
  108. }