Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / src / io / files / juce_FileSearchPath.cpp
blob8e0affc13ce42832c62b392408b2495517aad7fd
1 /*
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"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_FileSearchPath.h"
33 //==============================================================================
34 FileSearchPath::FileSearchPath()
38 FileSearchPath::FileSearchPath (const String& path)
40 init (path);
43 FileSearchPath::FileSearchPath (const FileSearchPath& other)
44 : directories (other.directories)
48 FileSearchPath::~FileSearchPath()
52 FileSearchPath& FileSearchPath::operator= (const String& path)
54 init (path);
55 return *this;
58 void FileSearchPath::init (const String& path)
60 directories.clear();
61 directories.addTokens (path, ";", "\"");
62 directories.trim();
63 directories.removeEmptyStrings();
65 for (int i = directories.size(); --i >= 0;)
66 directories.set (i, directories[i].unquoted());
69 int FileSearchPath::getNumPaths() const
71 return directories.size();
74 File FileSearchPath::operator[] (const int index) const
76 return File (directories [index]);
79 String FileSearchPath::toString() const
81 StringArray directories2 (directories);
82 for (int i = directories2.size(); --i >= 0;)
83 if (directories2[i].containsChar (';'))
84 directories2.set (i, directories2[i].quoted());
86 return directories2.joinIntoString (";");
89 void FileSearchPath::add (const File& dir, const int insertIndex)
91 directories.insert (insertIndex, dir.getFullPathName());
94 void FileSearchPath::addIfNotAlreadyThere (const File& dir)
96 for (int i = 0; i < directories.size(); ++i)
97 if (File (directories[i]) == dir)
98 return;
100 add (dir);
103 void FileSearchPath::remove (const int index)
105 directories.remove (index);
108 void FileSearchPath::addPath (const FileSearchPath& other)
110 for (int i = 0; i < other.getNumPaths(); ++i)
111 addIfNotAlreadyThere (other[i]);
114 void FileSearchPath::removeRedundantPaths()
116 for (int i = directories.size(); --i >= 0;)
118 const File d1 (directories[i]);
120 for (int j = directories.size(); --j >= 0;)
122 const File d2 (directories[j]);
124 if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
126 directories.remove (i);
127 break;
133 void FileSearchPath::removeNonExistentPaths()
135 for (int i = directories.size(); --i >= 0;)
136 if (! File (directories[i]).isDirectory())
137 directories.remove (i);
140 int FileSearchPath::findChildFiles (Array<File>& results,
141 const int whatToLookFor,
142 const bool searchRecursively,
143 const String& wildCardPattern) const
145 int total = 0;
147 for (int i = 0; i < directories.size(); ++i)
148 total += operator[] (i).findChildFiles (results,
149 whatToLookFor,
150 searchRecursively,
151 wildCardPattern);
153 return total;
156 bool FileSearchPath::isFileInPath (const File& fileToCheck,
157 const bool checkRecursively) const
159 for (int i = directories.size(); --i >= 0;)
161 const File d (directories[i]);
163 if (checkRecursively)
165 if (fileToCheck.isAChildOf (d))
166 return true;
168 else
170 if (fileToCheck.getParentDirectory() == d)
171 return true;
175 return false;
178 END_JUCE_NAMESPACE