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.

128 lines
5.5KB

  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. #ifndef __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__
  18. #define __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__
  19. #include "juce_KnownPluginList.h"
  20. #include "../format/juce_AudioPluginFormatManager.h"
  21. //==============================================================================
  22. /**
  23. Scans a directory for plugins, and adds them to a KnownPluginList.
  24. To use one of these, create it and call scanNextFile() repeatedly, until
  25. it returns false.
  26. */
  27. class JUCE_API PluginDirectoryScanner
  28. {
  29. public:
  30. //==============================================================================
  31. /**
  32. Creates a scanner.
  33. @param listToAddResultsTo this will get the new types added to it.
  34. @param formatToLookFor this is the type of format that you want to look for
  35. @param directoriesToSearch the path to search
  36. @param searchRecursively true to search recursively
  37. @param deadMansPedalFile if this isn't File::nonexistent, then it will
  38. be used as a file to store the names of any plugins
  39. that crash during initialisation. If there are
  40. any plugins listed in it, then these will always
  41. be scanned after all other possible files have
  42. been tried - in this way, even if there's a few
  43. dodgy plugins in your path, then a couple of rescans
  44. will still manage to find all the proper plugins.
  45. It's probably best to choose a file in the user's
  46. application data directory (alongside your app's
  47. settings file) for this. The file format it uses
  48. is just a list of filenames of the modules that
  49. failed.
  50. */
  51. PluginDirectoryScanner (KnownPluginList& listToAddResultsTo,
  52. AudioPluginFormat& formatToLookFor,
  53. FileSearchPath directoriesToSearch,
  54. bool searchRecursively,
  55. const File& deadMansPedalFile);
  56. /** Destructor. */
  57. ~PluginDirectoryScanner();
  58. //==============================================================================
  59. /** Tries the next likely-looking file.
  60. If dontRescanIfAlreadyInList is true, then the file will only be loaded and
  61. re-tested if it's not already in the list, or if the file's modification
  62. time has changed since the list was created. If dontRescanIfAlreadyInList is
  63. false, the file will always be reloaded and tested.
  64. Returns false when there are no more files to try.
  65. */
  66. bool scanNextFile (bool dontRescanIfAlreadyInList);
  67. /** Skips over the next file without scanning it.
  68. Returns false when there are no more files to try.
  69. */
  70. bool skipNextFile();
  71. /** Returns the description of the plugin that will be scanned during the next
  72. call to scanNextFile().
  73. This is handy if you want to show the user which file is currently getting
  74. scanned.
  75. */
  76. String getNextPluginFileThatWillBeScanned() const;
  77. /** Returns the estimated progress, between 0 and 1. */
  78. float getProgress() const { return progress; }
  79. /** This returns a list of all the filenames of things that looked like being
  80. a plugin file, but which failed to open for some reason.
  81. */
  82. const StringArray& getFailedFiles() const noexcept { return failedFiles; }
  83. /** Reads the given dead-mans-pedal file and applies its contents to the list. */
  84. static void applyBlacklistingsFromDeadMansPedal (KnownPluginList& listToApplyTo,
  85. const File& deadMansPedalFile);
  86. private:
  87. //==============================================================================
  88. KnownPluginList& list;
  89. AudioPluginFormat& format;
  90. StringArray filesOrIdentifiersToScan;
  91. File deadMansPedalFile;
  92. StringArray failedFiles;
  93. Atomic<int> nextIndex;
  94. float progress;
  95. void updateProgress();
  96. void setDeadMansPedalFile (const StringArray& newContents);
  97. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginDirectoryScanner)
  98. };
  99. #endif // __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__