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.

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