forked from projectM-visualizer/projectm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileScanner.hpp
48 lines (38 loc) · 981 Bytes
/
FileScanner.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// FileScanner.hpp
// libprojectM
//
// Cross-platform directory traversal with filtering by extension
#ifndef FileScanner_hpp
#define FileScanner_hpp
#include <string>
#include <vector>
#include <iostream>
#include <functional>
#include "Common.hpp"
#include <string.h>
#ifdef HAVE_FTS_H
#include <fts.h>
extern "C"
{
#include <errno.h>
#include <dirent.h>
}
#else
#include "dirent.h"
#endif
typedef std::function<void (std::string &path, std::string &name)> ScanCallback;
class FileScanner {
public:
FileScanner();
FileScanner(std::vector<std::string> &rootDirs, std::vector<std::string> &extensions);
void scan(ScanCallback cb);
std::string extensionMatches(std::string &filename);
private:
std::vector<std::string> _rootDirs;
std::vector<std::string> _extensions;
void scanGeneric(ScanCallback cb, const char *dir);
void scanPosix(ScanCallback cb);
void handleDirectoryError(std::string dir);
};
#endif /* FileScanner_hpp */