blob: a87c0a3a3dd509770216424a09ad2279081a2cb1 (
plain)
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
|
#ifndef FILESYSTEM_H
#define FILESYSTEM_H 1
#include <magic.h>
#include <inja/inja.hpp>
#include <string>
#include <unordered_map>
#include <vector>
using FilesDict = std::unordered_map<std::string, struct file_data>;
using Data = std::vector<unsigned char>;
struct file_data
{
std::string mime;
Data data;
};
class Filesystem
{
public:
Filesystem()
{
MagicInit();
}
~Filesystem()
{
MagicClose();
}
bool Scan(std::string root = "./wwwroot");
bool Scan(std::string root, std::vector<std::string> extensions, bool exclude_extensions = false);
FilesDict & GetFiles();
void GetFilenamesSorted(std::vector<std::string> & sortedFilenames);
private:
bool AddSingleFile(std::string path, std::string root);
void MagicInit();
void MagicClose();
FilesDict m_Files;
magic_t m_Magic;
};
#endif
|