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.

134 lines
4.9KB

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