-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectoryIndex.cpp
65 lines (53 loc) · 1.11 KB
/
DirectoryIndex.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "DirectoryIndex.h"
using namespace std;
DirectoryIndex::DirectoryIndex(const String pathToIndex)
{
Path = pathToIndex;
GenerateIndex();
}
String DirectoryIndex::GetPath()
{
return Path;
}
void DirectoryIndex::GenerateIndex()
{
IOfunction::FolderMap(
GetPath(),
(void*)&Index,
[](String path, String fileName, unsigned long long lastModifiedDate, unsigned long long fileSize, bool isDirectory, void* ptr)
{
priority_queue<File>* index = ((priority_queue<File>*)ptr);
// Pushing at the end of the index every file from the folder
index->emplace(File(path, fileName, lastModifiedDate, fileSize, isDirectory));
}
);
}
int DirectoryIndex::FindNext(File* resultFile)
{
if (Index.size() == 0)
{
return 1;
}
*resultFile = Index.top();
Index.pop();
return 0;
}
int DirectoryIndex::FindNext(File* resultFile, Filter condition)
{
if (Index.size() == 0)
{
return 1;
}
File indexTop = Index.top();
Index.pop();
if (!condition.TestString(indexTop.Path + BACKSLASH + indexTop.Name))
{
// File is ignored
FindNext(resultFile, condition);
}
else
{
*resultFile = indexTop;
}
return 0;
}