OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_FileSearchPath.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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
23 namespace juce
24{
25
26 FileSearchPath::FileSearchPath() {}
27 FileSearchPath::~FileSearchPath() {}
28
29 FileSearchPath::FileSearchPath (const String& path)
30{
31 init (path);
32}
33
34 FileSearchPath::FileSearchPath (const FileSearchPath& other)
35 : directories (other.directories)
36{
37}
38
39 FileSearchPath& FileSearchPath::operator= (const FileSearchPath& other)
40{
41 directories = other.directories;
42 return *this;
43}
44
45 FileSearchPath& FileSearchPath::operator= (const String& path)
46{
47 init (path);
48 return *this;
49}
50
51 void FileSearchPath::init (const String& path)
52{
53 directories.clear();
54 directories.addTokens (path, ";", "\"");
55 directories.trim();
56 directories.removeEmptyStrings();
57
58 for (auto& d : directories)
59 d = d.unquoted();
60}
61
62 int FileSearchPath::getNumPaths() const
63{
64 return directories.size();
65}
66
67 File FileSearchPath::operator[] (int index) const
68{
69 return File (directories[index]);
70}
71
72 String FileSearchPath::toString() const
73{
74 auto dirs = directories;
75
76 for (auto& d : dirs)
77 if (d.containsChar (';'))
78 d = d.quoted();
79
80 return dirs.joinIntoString (";");
81}
82
83 void FileSearchPath::add (const File& dir, int insertIndex)
84{
85 directories.insert (insertIndex, dir.getFullPathName());
86}
87
88 bool FileSearchPath::addIfNotAlreadyThere (const File& dir)
89{
90 for (auto& d : directories)
91 if (File (d) == dir)
92 return false;
93
94 add (dir);
95 return true;
96}
97
98 void FileSearchPath::remove (int index)
99{
100 directories.remove (index);
101}
102
103 void FileSearchPath::addPath (const FileSearchPath& other)
104{
105 for (int i = 0; i < other.getNumPaths(); ++i)
106 addIfNotAlreadyThere (other[i]);
107}
108
109 void FileSearchPath::removeRedundantPaths()
110{
111 for (int i = directories.size(); --i >= 0;)
112 {
113 const File d1 (directories[i]);
114
115 for (int j = directories.size(); --j >= 0;)
116 {
117 const File d2 (directories[j]);
118
119 if (i != j && (d1.isAChildOf (d2) || d1 == d2))
120 {
121 directories.remove (i);
122 break;
123 }
124 }
125 }
126}
127
128 void FileSearchPath::removeNonExistentPaths()
129{
130 for (int i = directories.size(); --i >= 0;)
131 if (! File (directories[i]).isDirectory())
132 directories.remove (i);
133}
134
135 Array<File> FileSearchPath::findChildFiles (int whatToLookFor, bool recurse, const String& wildcard) const
136{
137 Array<File> results;
138 findChildFiles (results, whatToLookFor, recurse, wildcard);
139 return results;
140}
141
142 int FileSearchPath::findChildFiles (Array<File>& results, int whatToLookFor,
143 bool recurse, const String& wildcard) const
144{
145 int total = 0;
146
147 for (auto& d : directories)
148 total += File (d).findChildFiles (results, whatToLookFor, recurse, wildcard);
149
150 return total;
151}
152
153 bool FileSearchPath::isFileInPath (const File& fileToCheck,
154 const bool checkRecursively) const
155{
156 for (auto& d : directories)
157 {
158 if (checkRecursively)
159 {
160 if (fileToCheck.isAChildOf (File (d)))
161 return true;
162 }
163 else
164 {
165 if (fileToCheck.getParentDirectory() == File (d))
166 return true;
167 }
168 }
169
170 return false;
171}
172
173} // namespace juce
juce::Array
Definition: juce_Array.h:56
juce::FileSearchPath
Definition: juce_FileSearchPath.h:35
juce::FileSearchPath::~FileSearchPath
~FileSearchPath()
Definition: juce_FileSearchPath.cpp:27
juce::FileSearchPath::isFileInPath
bool isFileInPath(const File &fileToCheck, bool checkRecursively) const
Definition: juce_FileSearchPath.cpp:153
juce::FileSearchPath::add
void add(const File &directoryToAdd, int insertIndex=-1)
Definition: juce_FileSearchPath.cpp:83
juce::FileSearchPath::remove
void remove(int indexToRemove)
Definition: juce_FileSearchPath.cpp:98
juce::FileSearchPath::removeNonExistentPaths
void removeNonExistentPaths()
Definition: juce_FileSearchPath.cpp:128
juce::FileSearchPath::operator=
FileSearchPath & operator=(const FileSearchPath &)
Definition: juce_FileSearchPath.cpp:39
juce::FileSearchPath::addPath
void addPath(const FileSearchPath &)
Definition: juce_FileSearchPath.cpp:103
juce::FileSearchPath::toString
String toString() const
Definition: juce_FileSearchPath.cpp:72
juce::FileSearchPath::getNumPaths
int getNumPaths() const
Definition: juce_FileSearchPath.cpp:62
juce::FileSearchPath::operator[]
File operator[](int index) const
Definition: juce_FileSearchPath.cpp:67
juce::FileSearchPath::removeRedundantPaths
void removeRedundantPaths()
Definition: juce_FileSearchPath.cpp:109
juce::FileSearchPath::addIfNotAlreadyThere
bool addIfNotAlreadyThere(const File &directoryToAdd)
Definition: juce_FileSearchPath.cpp:88
juce::FileSearchPath::FileSearchPath
FileSearchPath()
Definition: juce_FileSearchPath.cpp:26
juce::FileSearchPath::findChildFiles
Array< File > findChildFiles(int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*") const
Definition: juce_FileSearchPath.cpp:135
juce::File
Definition: juce_File.h:41
juce::File::getFullPathName
const String & getFullPathName() const noexcept
Definition: juce_File.h:149
juce::File::findChildFiles
Array< File > findChildFiles(int whatToLookFor, bool searchRecursively, const String &wildCardPattern="*") const
Definition: juce_File.cpp:566
juce::File::getParentDirectory
File getParentDirectory() const
Definition: juce_File.cpp:360
juce::File::isAChildOf
bool isAChildOf(const File &potentialParentDirectory) const
Definition: juce_File.cpp:382
juce::StringArray::removeEmptyStrings
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Definition: juce_StringArray.cpp:249
juce::StringArray::clear
void clear()
Definition: juce_StringArray.cpp:111
juce::StringArray::trim
void trim()
Definition: juce_StringArray.cpp:265
juce::StringArray::addTokens
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Definition: juce_StringArray.cpp:328
juce::String
Definition: juce_String.h:39
juce::String::quoted
String quoted(juce_wchar quoteCharacter='"') const
Definition: juce_String.cpp:1635