2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../core/juce_StandardHeader.h"
30 #include "juce_PluginDirectoryScanner.h"
31 #include "juce_AudioPluginFormat.h"
32 #include "../../io/files/juce_DirectoryIterator.h"
35 //==============================================================================
36 PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList
& listToAddTo
,
37 AudioPluginFormat
& formatToLookFor
,
38 FileSearchPath directoriesToSearch
,
40 const File
& deadMansPedalFile_
)
42 format (formatToLookFor
),
43 deadMansPedalFile (deadMansPedalFile_
),
47 directoriesToSearch
.removeRedundantPaths();
49 filesOrIdentifiersToScan
= format
.searchPathsForPlugins (directoriesToSearch
, recursive
);
51 // If any plugins have crashed recently when being loaded, move them to the
52 // end of the list to give the others a chance to load correctly..
53 const StringArray
crashedPlugins (getDeadMansPedalFile());
55 for (int i
= 0; i
< crashedPlugins
.size(); ++i
)
57 const String f
= crashedPlugins
[i
];
59 for (int j
= filesOrIdentifiersToScan
.size(); --j
>= 0;)
60 if (f
== filesOrIdentifiersToScan
[j
])
61 filesOrIdentifiersToScan
.move (j
, -1);
65 PluginDirectoryScanner::~PluginDirectoryScanner()
69 //==============================================================================
70 const String
PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const
72 return format
.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan
[nextIndex
]);
75 bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList
)
77 String
file (filesOrIdentifiersToScan
[nextIndex
]);
79 if (file
.isNotEmpty() && ! list
.isListingUpToDate (file
))
81 OwnedArray
<PluginDescription
> typesFound
;
83 // Add this plugin to the end of the dead-man's pedal list in case it crashes...
84 StringArray
crashedPlugins (getDeadMansPedalFile());
85 crashedPlugins
.removeString (file
);
86 crashedPlugins
.add (file
);
87 setDeadMansPedalFile (crashedPlugins
);
89 list
.scanAndAddFile (file
,
90 dontRescanIfAlreadyInList
,
94 // Managed to load without crashing, so remove it from the dead-man's-pedal..
95 crashedPlugins
.removeString (file
);
96 setDeadMansPedalFile (crashedPlugins
);
98 if (typesFound
.size() == 0)
99 failedFiles
.add (file
);
102 return skipNextFile();
105 bool PluginDirectoryScanner::skipNextFile()
107 if (nextIndex
>= filesOrIdentifiersToScan
.size())
110 progress
= ++nextIndex
/ (float) filesOrIdentifiersToScan
.size();
111 return nextIndex
< filesOrIdentifiersToScan
.size();
114 StringArray
PluginDirectoryScanner::getDeadMansPedalFile()
118 if (deadMansPedalFile
!= File::nonexistent
)
120 lines
.addLines (deadMansPedalFile
.loadFileAsString());
121 lines
.removeEmptyStrings();
127 void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray
& newContents
)
129 if (deadMansPedalFile
!= File::nonexistent
)
130 deadMansPedalFile
.replaceWithText (newContents
.joinIntoString ("\n"), true, true);