-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.cpp
52 lines (49 loc) · 1.3 KB
/
utils.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
#include "utils.h"
#include <QtOpenGL/QGL>
bool verifyOrCreateTargetDirectory(QString targetDirectory)
{
QDir *qDir = new QDir();
if (qDir->exists(targetDirectory))
{
return true;
}
else
{
return qDir->mkpath(targetDirectory);
}
}
const QString getHash(const QString& filePath)
{
QString md5;
QFile file(filePath);
if(file.open(QIODevice::ReadOnly))
{
QByteArray bArray = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md5);
md5 = QString(bArray.toHex()).toUpper();
}
file.close();
return md5;
}
QList<QString> getFullDirectory(QString target)
{
QList<QString> result;
QDir *dir = new QDir(target);
QStringList filter;
QList<QFileInfo> *fileInfo = new QList<QFileInfo>(dir->entryInfoList(filter));
for (int i = 0;i < fileInfo->length();++i)
{
if (fileInfo->at(i).absoluteFilePath().length() <= target.length())
{
continue;
}
if (fileInfo->at(i).isDir())
{
result.append(getFullDirectory(fileInfo->at(i).absoluteFilePath()));
}
else if (fileInfo->at(i).isFile())
{
result.append(fileInfo->at(i).absoluteFilePath());
}
}
return result;
}