-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexation.cpp
100 lines (86 loc) · 2.56 KB
/
indexation.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "indexation.h"
#include "Serializer.h"
#include <QFileDialog>
IndexatorRunnable::IndexatorRunnable()
{
canTerminate = false;
getDrivesLetters();
}
IndexatorRunnable::~IndexatorRunnable()
{
}
void IndexatorRunnable::getDrivesLetters()
{
wchar_t driveStrings[MAX_PATH];
DWORD result = GetLogicalDriveStrings(MAX_PATH, driveStrings);
if(result > 0 && result <= MAX_PATH)
{
wchar_t* singleDrive = driveStrings;
while(*singleDrive)
{
drivesLetters.push_back(std::wstring(singleDrive));
singleDrive += wcslen(singleDrive) + 1;
}
}
}
void IndexatorRunnable::iterateAllFilesInDirectory(const wchar_t* dirPath)
{
if(!canTerminate)
{
std::wostringstream directoryPath;
directoryPath << dirPath;
directoryPath << "\\*";
WIN32_FIND_DATA foundFileData;
HANDLE foundFileHandler = FindFirstFile(directoryPath.str().c_str(), &foundFileData);
if (foundFileHandler == INVALID_HANDLE_VALUE)
{
return;
}
do
{
if(!(foundFileData.dwFileAttributes & (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
&& !(foundFileData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM))
&& (foundFileData.cFileName[wcslen(foundFileData.cFileName)-1] != '.'))
{
std::wostringstream absolutePath;
absolutePath << dirPath << "\\";
absolutePath << foundFileData.cFileName;
if (foundFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
textChanged(QString::fromStdWString(absolutePath.str()));
iterateAllFilesInDirectory(absolutePath.str().c_str());
}
else
{
filesData.push_back(FileInfo(foundFileData, absolutePath.str()));
}
}
}
while (FindNextFile(foundFileHandler, &foundFileData) != 0);
FindClose(foundFileHandler);
}
else
{
return;
}
}
void* IndexatorRunnable::run()
{
textChanged("Initializing...");
indexationCompleted(false);
drivesLetters.resize(2);
for(auto i : drivesLetters)
{
iterateAllFilesInDirectory(i.c_str());
}
Serializer<std::deque<FileInfo>> xml("C:\\res.xml");
textChanged("Serializing...");
xml.serialize(filesData);
textChanged("Done");
indexationCompleted(true);
return 0;
}
void IndexatorRunnable::terminate()
{
canTerminate = true;
}