LMMS
Loading...
Searching...
No Matches
DirectoryIterator.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the Water library.
5 Copyright (c) 2016 ROLI Ltd.
6 Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
7
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
10
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 OF THIS SOFTWARE.
22
23 ==============================================================================
24*/
25
26#include "DirectoryIterator.h"
27#include "../text/StringArray.h"
28
29namespace water {
30
31DirectoryIterator::DirectoryIterator (const File& directory, bool recursive,
32 const String& pattern, const int type)
34 fileFinder (directory, (recursive || wildCards.size() > 1) ? "*" : pattern),
36 path (File::addTrailingSeparator (directory.getFullPathName())),
37 index (-1),
38 totalNumFiles (-1),
40 isRecursive (recursive),
42{
43 // you have to specify the type of files you're looking for!
45 wassert (type > 0 && type <= 7);
46}
47
51
53{
55 s.addTokens (pattern, ";,", "\"'");
56 s.trim();
57 s.removeEmptyStrings();
58 return s;
59}
60
62{
63 for (int i = 0; i < wildCards.size(); ++i)
64 if (filename.matchesWildcard (wildCards[i], ! File::areFileNamesCaseSensitive()))
65 return true;
66
67 return false;
68}
69
71{
72 return next (nullptr, nullptr, nullptr);
73}
74
75bool DirectoryIterator::next (bool* const isDirResult, int64* const fileSize, bool* const isReadOnly)
76{
77 for (;;)
78 {
79 hasBeenAdvanced = true;
80
81 if (subIterator != nullptr)
82 {
83 if (subIterator->next (isDirResult, fileSize, isReadOnly))
84 return true;
85
86 subIterator = nullptr;
87 }
88
90 bool isDirectory, shouldContinue = false;
91
92 while (fileFinder.next (filename, &isDirectory, fileSize, isReadOnly))
93 {
94 ++index;
95
96 if (! filename.containsOnly ("."))
97 {
98 bool matches = false;
99
100 if (isDirectory)
101 {
102 if (isRecursive)
104 true, wildCard, whatToLookFor);
105
106 matches = (whatToLookFor & File::findDirectories) != 0;
107 }
108 else
109 {
110 matches = (whatToLookFor & File::findFiles) != 0;
111 }
112
113 // if we're not relying on the OS iterator to do the wildcard match, do it now..
114 if (matches && (isRecursive || wildCards.size() > 1))
115 matches = fileMatches (wildCards, filename);
116
117 if (matches)
118 {
120 if (isDirResult != nullptr) *isDirResult = isDirectory;
121
122 return true;
123 }
124
125 if (subIterator != nullptr)
126 {
127 shouldContinue = true;
128 break;
129 }
130 }
131 }
132
133 if (! shouldContinue)
134 return false;
135 }
136}
137
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
150{
151 if (totalNumFiles < 0)
153
154 if (totalNumFiles <= 0)
155 return 0.0f;
156
157 const float detailedIndex = (subIterator != nullptr) ? index + subIterator->getEstimatedProgress()
158 : (float) index;
159
160 return detailedIndex / totalNumFiles;
161}
162
163}
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
static StringArray parseWildcards(const String &pattern)
Definition DirectoryIterator.cpp:52
float getEstimatedProgress() const
Definition DirectoryIterator.cpp:149
int index
Definition DirectoryIterator.h:142
~DirectoryIterator()
Definition DirectoryIterator.cpp:48
DirectoryIterator(const File &directory, bool isRecursive, const String &wildCard="*", int whatToLookFor=File::findFiles)
Definition DirectoryIterator.cpp:31
int totalNumFiles
Definition DirectoryIterator.h:143
CarlaScopedPointer< DirectoryIterator > subIterator
Definition DirectoryIterator.h:147
const int whatToLookFor
Definition DirectoryIterator.h:144
String path
Definition DirectoryIterator.h:141
StringArray wildCards
Definition DirectoryIterator.h:139
File currentFile
Definition DirectoryIterator.h:148
static bool fileMatches(const StringArray &wildCards, const String &filename)
Definition DirectoryIterator.cpp:61
bool next()
Definition DirectoryIterator.cpp:70
NativeIterator fileFinder
Definition DirectoryIterator.h:140
const File & getFile() const
Definition DirectoryIterator.cpp:138
const bool isRecursive
Definition DirectoryIterator.h:145
String wildCard
Definition DirectoryIterator.h:141
bool hasBeenAdvanced
Definition DirectoryIterator.h:146
Definition File.h:50
static File createFileWithoutCheckingPath(const String &absolutePath) noexcept
Definition File.cpp:65
uint getNumberOfChildFiles(int whatToLookFor, const String &wildCardPattern="*") const
Definition File.cpp:597
@ findDirectories
Definition File.h:461
@ findFiles
Definition File.h:462
@ findFilesAndDirectories
Definition File.h:463
static bool areFileNamesCaseSensitive()
Definition File.cpp:236
Definition StringArray.h:41
Definition String.h:48
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
static char filename[]
Definition features.c:5
#define wassert(expression)
Definition AudioSampleBuffer.h:33
long long int64
Definition water.h:100
#define false
Definition ordinals.h:83
ulg size
Definition extract.c:2350
int * pattern
Definition match.c:126