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_FileSearchPath.h"
33 //==============================================================================
34 FileSearchPath::FileSearchPath()
38 FileSearchPath::FileSearchPath (const String
& path
)
43 FileSearchPath::FileSearchPath (const FileSearchPath
& other
)
44 : directories (other
.directories
)
48 FileSearchPath::~FileSearchPath()
52 FileSearchPath
& FileSearchPath::operator= (const String
& path
)
58 void FileSearchPath::init (const String
& path
)
61 directories
.addTokens (path
, ";", "\"");
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
)
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
);
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
147 for (int i
= 0; i
< directories
.size(); ++i
)
148 total
+= operator[] (i
).findChildFiles (results
,
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
))
170 if (fileToCheck
.getParentDirectory() == d
)