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.

133 lines
4.7KB

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