2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 static StringArray
readDeadMansPedalFile (const File
& file
)
32 file
.readLines (lines
);
33 lines
.removeEmptyStrings();
37 PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList
& listToAddTo
,
38 AudioPluginFormat
& formatToLookFor
,
39 FileSearchPath directoriesToSearch
,
41 const File
& deadMansPedal
,
42 bool allowPluginsWhichRequireAsynchronousInstantiation
)
44 format (formatToLookFor
),
45 deadMansPedalFile (deadMansPedal
),
46 allowAsync (allowPluginsWhichRequireAsynchronousInstantiation
)
48 directoriesToSearch
.removeRedundantPaths();
49 setFilesOrIdentifiersToScan (format
.searchPathsForPlugins (directoriesToSearch
, recursive
, allowAsync
));
52 PluginDirectoryScanner::~PluginDirectoryScanner()
57 //==============================================================================
58 void PluginDirectoryScanner::setFilesOrIdentifiersToScan (const StringArray
& filesOrIdentifiers
)
60 filesOrIdentifiersToScan
= filesOrIdentifiers
;
62 // If any plugins have crashed recently when being loaded, move them to the
63 // end of the list to give the others a chance to load correctly..
64 for (auto& crashed
: readDeadMansPedalFile (deadMansPedalFile
))
65 for (int j
= filesOrIdentifiersToScan
.size(); --j
>= 0;)
66 if (crashed
== filesOrIdentifiersToScan
[j
])
67 filesOrIdentifiersToScan
.move (j
, -1);
69 applyBlacklistingsFromDeadMansPedal (list
, deadMansPedalFile
);
70 nextIndex
.set (filesOrIdentifiersToScan
.size());
73 String
PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const
75 return format
.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan
[nextIndex
.get() - 1]);
78 void PluginDirectoryScanner::updateProgress()
80 progress
= (1.0f
- (float) nextIndex
.get() / (float) filesOrIdentifiersToScan
.size());
83 bool PluginDirectoryScanner::scanNextFile (bool dontRescanIfAlreadyInList
,
84 String
& nameOfPluginBeingScanned
)
86 const int index
= --nextIndex
;
90 auto file
= filesOrIdentifiersToScan
[index
];
92 if (file
.isNotEmpty() && ! (dontRescanIfAlreadyInList
&& list
.isListingUpToDate (file
, format
)))
94 nameOfPluginBeingScanned
= format
.getNameOfPluginFromIdentifier (file
);
96 OwnedArray
<PluginDescription
> typesFound
;
98 // Add this plugin to the end of the dead-man's pedal list in case it crashes...
99 auto crashedPlugins
= readDeadMansPedalFile (deadMansPedalFile
);
100 crashedPlugins
.removeString (file
);
101 crashedPlugins
.add (file
);
102 setDeadMansPedalFile (crashedPlugins
);
104 list
.scanAndAddFile (file
, dontRescanIfAlreadyInList
, typesFound
, format
);
106 // Managed to load without crashing, so remove it from the dead-man's-pedal..
107 crashedPlugins
.removeString (file
);
108 setDeadMansPedalFile (crashedPlugins
);
110 if (typesFound
.size() == 0 && ! list
.getBlacklistedFiles().contains (file
))
111 failedFiles
.add (file
);
119 bool PluginDirectoryScanner::skipNextFile()
122 return --nextIndex
> 0;
125 void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray
& newContents
)
127 if (deadMansPedalFile
.getFullPathName().isNotEmpty())
128 deadMansPedalFile
.replaceWithText (newContents
.joinIntoString ("\n"), true, true);
131 void PluginDirectoryScanner::applyBlacklistingsFromDeadMansPedal (KnownPluginList
& list
, const File
& file
)
133 // If any plugins have crashed recently when being loaded, move them to the
134 // end of the list to give the others a chance to load correctly..
135 for (auto& crashedPlugin
: readDeadMansPedalFile (file
))
136 list
.addToBlacklist (crashedPlugin
);