LMMS
Loading...
Searching...
No Matches
juce_FileSearchPath.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
27{
28 init (path);
29}
30
35
36FileSearchPath& FileSearchPath::operator= (const FileSearchPath& other)
37{
39 return *this;
40}
41
42FileSearchPath& FileSearchPath::operator= (const String& path)
43{
44 init (path);
45 return *this;
46}
47
48void FileSearchPath::init (const String& path)
49{
50 directories.clear();
51 directories.addTokens (path, ";", "\"");
52 directories.trim();
53 directories.removeEmptyStrings();
54
55 for (auto& d : directories)
56 d = d.unquoted();
57}
58
60{
61 return directories.size();
62}
63
64File FileSearchPath::operator[] (int index) const
65{
66 return File (directories[index]);
67}
68
70{
71 auto dirs = directories;
72
73 for (auto& d : dirs)
74 if (d.containsChar (';'))
75 d = d.quoted();
76
77 return dirs.joinIntoString (";");
78}
79
80void FileSearchPath::add (const File& dir, int insertIndex)
81{
82 directories.insert (insertIndex, dir.getFullPathName());
83}
84
86{
87 for (auto& d : directories)
88 if (File (d) == dir)
89 return false;
90
91 add (dir);
92 return true;
93}
94
95void FileSearchPath::remove (int index)
96{
97 directories.remove (index);
98}
99
101{
102 for (int i = 0; i < other.getNumPaths(); ++i)
103 addIfNotAlreadyThere (other[i]);
104}
105
107{
108 for (int i = directories.size(); --i >= 0;)
109 {
110 const File d1 (directories[i]);
111
112 for (int j = directories.size(); --j >= 0;)
113 {
114 const File d2 (directories[j]);
115
116 if (i != j && (d1.isAChildOf (d2) || d1 == d2))
117 {
118 directories.remove (i);
119 break;
120 }
121 }
122 }
123}
124
126{
127 for (int i = directories.size(); --i >= 0;)
128 if (! File (directories[i]).isDirectory())
129 directories.remove (i);
130}
131
132Array<File> FileSearchPath::findChildFiles (int whatToLookFor, bool recurse, const String& wildcard) const
133{
134 Array<File> results;
135 findChildFiles (results, whatToLookFor, recurse, wildcard);
136 return results;
137}
138
139int FileSearchPath::findChildFiles (Array<File>& results, int whatToLookFor,
140 bool recurse, const String& wildcard) const
141{
142 int total = 0;
143
144 for (auto& d : directories)
145 total += File (d).findChildFiles (results, whatToLookFor, recurse, wildcard);
146
147 return total;
148}
149
150bool FileSearchPath::isFileInPath (const File& fileToCheck,
151 const bool checkRecursively) const
152{
153 for (auto& d : directories)
154 {
155 if (checkRecursively)
156 {
157 if (fileToCheck.isAChildOf (File (d)))
158 return true;
159 }
160 else
161 {
162 if (fileToCheck.getParentDirectory() == File (d))
163 return true;
164 }
165 }
166
167 return false;
168}
169
170} // namespace juce
Definition juce_Array.h:56
Definition juce_File.h:45
Array< File > findChildFiles(int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*", FollowSymlinks followSymlinks=FollowSymlinks::yes) const
Definition juce_File.cpp:564
const String & getFullPathName() const noexcept
Definition juce_File.h:153
File getParentDirectory() const
Definition juce_File.cpp:358
bool isAChildOf(const File &potentialParentDirectory) const
Definition juce_File.cpp:380
bool isFileInPath(const File &fileToCheck, bool checkRecursively) const
Definition juce_FileSearchPath.cpp:150
void add(const File &directoryToAdd, int insertIndex=-1)
Definition juce_FileSearchPath.cpp:80
void remove(int indexToRemove)
Definition juce_FileSearchPath.cpp:95
void init(const String &)
Definition juce_FileSearchPath.cpp:48
void removeNonExistentPaths()
Definition juce_FileSearchPath.cpp:125
void addPath(const FileSearchPath &)
Definition juce_FileSearchPath.cpp:100
String toString() const
Definition juce_FileSearchPath.cpp:69
int getNumPaths() const
Definition juce_FileSearchPath.cpp:59
StringArray directories
Definition juce_FileSearchPath.h:164
void removeRedundantPaths()
Definition juce_FileSearchPath.cpp:106
FileSearchPath()=default
bool addIfNotAlreadyThere(const File &directoryToAdd)
Definition juce_FileSearchPath.cpp:85
Array< File > findChildFiles(int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*") const
Definition juce_FileSearchPath.cpp:132
Definition juce_String.h:53
register unsigned j
Definition inflate.c:1576
unsigned d
Definition inflate.c:940
register unsigned i
Definition inflate.c:1575
Definition carla_juce.cpp:31
ZCONST uch * init
Definition extract.c:2392