| 1 |
#ifndef CLFILESCOLLECTOR_H |
| 2 |
#define CLFILESCOLLECTOR_H |
| 3 |
|
| 4 |
#include "codelite_exports.h" |
| 5 |
#include "macros.h" |
| 6 |
|
| 7 |
#include <functional> |
| 8 |
#include <vector> |
| 9 |
#include <wx/filename.h> |
| 10 |
#include <wx/string.h> |
| 11 |
|
| 12 |
class WXDLLIMPEXP_CL clFilesScanner |
| 13 |
{ |
| 14 |
public: |
| 15 |
struct EntryData { |
| 16 |
size_t flags = 0; |
| 17 |
wxString fullpath; |
| 18 |
typedef std::vector<EntryData> Vec_t; |
| 19 |
}; |
| 20 |
|
| 21 |
enum eFileAttributes { |
| 22 |
kInvalid = 0, |
| 23 |
kIsFile = (1 << 0), |
| 24 |
kIsFolder = (1 << 1), |
| 25 |
kIsHidden = (1 << 2), |
| 26 |
kIsSymlink = (1 << 3), |
| 27 |
}; |
| 28 |
|
| 29 |
enum eSearchFlags { |
| 30 |
SF_NONE = 0, |
| 31 |
SF_EXCLUDE_HIDDEN_DIRS = (1 << 0), |
| 32 |
SF_DONT_FOLLOW_SYMLINKS = (1 << 1), |
| 33 |
SF_DEFAULT = SF_EXCLUDE_HIDDEN_DIRS | SF_DONT_FOLLOW_SYMLINKS, |
| 34 |
}; |
| 35 |
|
| 36 |
public: |
| 37 |
clFilesScanner(); |
| 38 |
virtual ~clFilesScanner(); |
| 39 |
|
| 40 |
/** |
| 41 |
* @brief collect all files matching a given pattern from a root folder |
| 42 |
* @param rootFolder the scan root folder |
| 43 |
* @param filesOutput [output] output result full path entries |
| 44 |
* @param filespec files spec |
| 45 |
* @param excludeFolders list of folder to exclude from the search |
| 46 |
* @return number of files found |
| 47 |
*/ |
| 48 |
size_t Scan(const wxString& rootFolder, std::vector<wxString>& filesOutput, const wxString& filespec = "*", |
| 49 |
const wxString& excludeFilespec = "", const wxStringSet_t& excludeFolders = wxStringSet_t()); |
| 50 |
/** |
| 51 |
* @brief same as above, but accepts the ignore directories list in a spec format |
| 52 |
*/ |
| 53 |
size_t Scan(const wxString& rootFolder, std::vector<wxFileName>& filesOutput, const wxString& filespec, |
| 54 |
const wxString& excludeFilespec, const wxString& excludeFoldersSpec); |
| 55 |
size_t Scan(const wxString& rootFolder, wxArrayString& filesOutput, const wxString& filespec, |
| 56 |
const wxString& excludeFilespec, const wxString& excludeFoldersSpec); |
| 57 |
/** |
| 58 |
* @brief similar to the above, however, whenever a method is found, collect_cb is invoked |
| 59 |
*/ |
| 60 |
size_t Scan(const wxString& rootFolder, const wxString& filespec, const wxString& excludeFilespec, |
| 61 |
const wxString& excludeFoldersSpec, std::function<bool(const wxString&)>&& collect_cb); |
| 62 |
/** |
| 63 |
* @brief scan folder for files and folders. This function does not recurse into folders. Everything that matches |
| 64 |
* "matchSpec" will get collected. |
| 65 |
*/ |
| 66 |
size_t ScanNoRecurse(const wxString& rootFolder, clFilesScanner::EntryData::Vec_t& results, |
| 67 |
const wxString& matchSpec = "*"); |
| 68 |
|
| 69 |
/** |
| 70 |
* @brief a raw version for scanning files |
| 71 |
* @param rootFolder the root folder |
| 72 |
* @param on_folder_cb called whenever a folder is found. return true to traverse into this folder or false to skip |
| 73 |
* it |
| 74 |
* @param on_file_cb called when a file is found. |
| 75 |
*/ |
| 76 |
void ScanWithCallbacks(const wxString& rootFolder, std::function<bool(const wxString&)>&& on_folder_cb, |
| 77 |
std::function<void(const wxArrayString&)>&& on_file_cb, size_t search_flags = SF_DEFAULT); |
| 78 |
}; |
| 79 |
|
| 80 |
#endif // CLFILESCOLLECTOR_H |