-
Notifications
You must be signed in to change notification settings - Fork 3
/
qldd.h
executable file
·109 lines (90 loc) · 2.5 KB
/
qldd.h
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
101
102
103
104
105
106
107
108
109
#ifndef QLDD_H
#define QLDD_H
#include <QString>
#include <QTreeWidget>
#include <QListWidget>
#include <QFileInfo>
#include <QFont>
#include <QTextStream>
#include <memory>
#include <functional>
#include <future>
#include "customtypes.h"
struct QMOD {
bool read;
bool write;
bool execute;
};
class QLdd {
public:
QLdd(QString fileName, QString lddDirPath, RulesMap demangleRules);
QLdd(const QLdd &) = delete;
QLdd(QLdd &&) = delete;
QLdd operator=(const QLdd &) = delete;
QLdd operator=(QLdd &&) = delete;
virtual ~QLdd();
int64_t getFileSize() const;
const QString &getStringFileSize() const;
void fillDependency(QTreeWidget &treeWidget);
void fillExportTable(QListWidget &listWidget, const QString &filter);
QString getPathOfBinary();
QString getBinaryName();
const QString &getCreatedTime();
const QString &getAccessTime();
const QString &getModifyTime();
QString getInfo();
const QMOD &getOwnerMod() const;
void setOwnerMod(const QMOD &ownerMod);
const QMOD &getGroupMod() const;
void setGroupMod(const QMOD &groupMod);
const QMOD &getOtherMod() const;
void setOtherMod(const QMOD &otherMod);
const QString &getOwnerName() const;
void setOwnerName(const QString &ownerName);
const QString &getGroupName() const;
void setGroupName(const QString &groupName);
private:
QString _fileName;
QFileInfo _fileInfo;
bool _link;
QString _tmCreate;
QString _tmAccess;
QString _tmModify;
QString _lddDirPath;
QString _fileSize;
QMOD _ownerMod{};
QMOD _groupMod{};
QMOD _otherMod{};
QString _ownerName;
QString _groupName;
RulesMap _demangleRules;
QString getHumanReadableDataSize() const;
};
enum class Exec { SYNC = 0, ASYNC = 1 };
template <typename Action>
void execAndDoOnEveryLine(const std::string &execString, const Action &action, Exec exec = Exec::SYNC) {
std::unique_ptr<FILE, std::function<int(FILE *)>> cmdStream(popen(execString.c_str(), "r"), pclose);
QTextStream nmOutStream(cmdStream.get());
QString line;
using returnType = typename std::result_of<Action(const QString &)>::type;
std::list<std::future<returnType>> retList;
do {
line = nmOutStream.readLine();
if (line.isNull()) {
break;
}
line = line.trimmed();
if (line.isEmpty()) {
break;
}
if (exec == Exec::ASYNC) {
retList.emplace_back(std::async(std::launch::async, action, QString(line)));
} else {
action(line);
}
} while (!line.isNull());
for (auto &l : retList) {
l.wait();
}
}
#endif // QLDD_H