JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_DirectoryIterator.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
26StringArray DirectoryIterator::parseWildcards (const String& pattern)
27{
28 StringArray s;
29 s.addTokens (pattern, ";,", "\"'");
30 s.trim();
31 s.removeEmptyStrings();
32 return s;
33}
34
35bool DirectoryIterator::fileMatches (const StringArray& wildcards, const String& filename)
36{
37 for (auto& w : wildcards)
38 if (filename.matchesWildcard (w, ! File::areFileNamesCaseSensitive()))
40
41 return false;
42}
43
44bool DirectoryIterator::next()
45{
46 return next (nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
47}
48
49JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations")
50JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
51
52bool DirectoryIterator::next (bool* isDirResult, bool* isHiddenResult, int64* fileSize,
53 Time* modTime, Time* creationTime, bool* isReadOnly)
54{
55 for (;;)
56 {
57 hasBeenAdvanced = true;
58
59 if (subIterator != nullptr)
60 {
61 if (subIterator->next (isDirResult, isHiddenResult, fileSize, modTime, creationTime, isReadOnly))
62 return true;
63
64 subIterator.reset();
65 }
66
67 String filename;
68 bool isDirectory, isHidden = false, shouldContinue = false;
69
70 while (fileFinder.next (filename, &isDirectory,
71 (isHiddenResult != nullptr || (whatToLookFor & File::ignoreHiddenFiles) != 0) ? &isHidden : nullptr,
72 fileSize, modTime, creationTime, isReadOnly))
73 {
74 ++index;
75
76 if (! filename.containsOnly ("."))
77 {
78 const auto fullPath = File::createFileWithoutCheckingPath (path + filename);
79 bool matches = false;
80
81 if (isDirectory)
82 {
83 const auto mayRecurseIntoPossibleHiddenDir = [this, &isHidden]
84 {
85 return (whatToLookFor & File::ignoreHiddenFiles) == 0 || ! isHidden;
86 };
87
88 const auto mayRecurseIntoPossibleSymlink = [this, &fullPath]
89 {
91 || ! fullPath.isSymbolicLink()
93 && knownPaths->find (fullPath.getLinkedTarget()) == knownPaths->end());
94 };
95
97 subIterator.reset (new DirectoryIterator (fullPath, true, wildCard, whatToLookFor, followSymlinks, knownPaths));
98
99 matches = (whatToLookFor & File::findDirectories) != 0;
100 }
101 else
102 {
103 matches = (whatToLookFor & File::findFiles) != 0;
104 }
105
106 // if we're not relying on the OS iterator to do the wildcard match, do it now..
107 if (matches && (isRecursive || wildCards.size() > 1))
108 matches = fileMatches (wildCards, filename);
109
110 if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0)
111 matches = ! isHidden;
112
113 if (matches)
114 {
115 currentFile = fullPath;
116 if (isHiddenResult != nullptr) *isHiddenResult = isHidden;
117 if (isDirResult != nullptr) *isDirResult = isDirectory;
118
119 return true;
120 }
121
122 if (subIterator != nullptr)
123 {
124 shouldContinue = true;
125 break;
126 }
127 }
128 }
129
130 if (! shouldContinue)
131 return false;
132 }
133}
134
135JUCE_END_IGNORE_WARNINGS_GCC_LIKE
136JUCE_END_IGNORE_WARNINGS_MSVC
137
138const File& DirectoryIterator::getFile() const
139{
140 if (subIterator != nullptr && subIterator->hasBeenAdvanced)
141 return subIterator->getFile();
142
143 // You need to call DirectoryIterator::next() before asking it for the file that it found!
145
146 return currentFile;
147}
148
149float DirectoryIterator::getEstimatedProgress() const
150{
151 if (totalNumFiles < 0)
152 totalNumFiles = File (path).getNumberOfChildFiles (File::findFilesAndDirectories);
153
154 if (totalNumFiles <= 0)
155 return 0.0f;
156
157 auto detailedIndex = (subIterator != nullptr) ? (float) index + subIterator->getEstimatedProgress()
158 : (float) index;
159
160 return jlimit (0.0f, 1.0f, detailedIndex / (float) totalNumFiles);
161}
162
163} // namespace juce
@ ignoreHiddenFiles
Add this flag to avoid returning any hidden files in the results.
Definition juce_File.h:568
@ findDirectories
Use this flag to indicate that you want to find directories.
Definition juce_File.h:565
@ findFilesAndDirectories
Use this flag to indicate that you want to find both files and directories.
Definition juce_File.h:567
@ findFiles
Use this flag to indicate that you want to find files.
Definition juce_File.h:566
@ yes
Requests that a file system traversal follow all symbolic links.
@ noCycles
Requests that a file system traversal may follow symbolic links, but should attempt to skip any symbo...
static File createFileWithoutCheckingPath(const String &absolutePath) noexcept
Creates a file that simply contains this string, without doing the sanity-checking that the normal co...
Definition juce_File.cpp:31
#define jassert(expression)
Platform-independent assertion macro.
typedef float
JUCE Namespace.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
long long int64
A platform-independent 64-bit integer type.
T next(T... args)