-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
util.cpp
67 lines (55 loc) · 1.42 KB
/
util.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
#include <QDebug>
#include <QFileInfo>
#include <QProcessEnvironment>
#include <QString>
#include <QDir>
#include "util.h"
QProcessEnvironment Util::_env;
bool Util::_envInitialised;
void Util::initialiseEnvironment()
{
if (!_envInitialised) {
_env = QProcessEnvironment::systemEnvironment();
_envInitialised = true;
}
}
QString Util::findPasswordStore()
{
QString path;
initialiseEnvironment();
if (_env.contains("PASSWORD_STORE_DIR")) {
path = _env.value("PASSWORD_STORE_DIR");
} else {
/* @TODO checks */
path = QDir::homePath()+"/.password-store/";
}
return path;
}
QString Util::findBinaryInPath(QString binary)
{
initialiseEnvironment();
QString ret = "";
binary.prepend("/");
if (_env.contains("PATH")) {
QString path = _env.value("PATH");
QStringList entries = path.split(':');
if (entries.length() < 2) {
entries = path.split(';');
}
foreach(QString entry, entries) {
QScopedPointer<QFileInfo> qfi(new QFileInfo(entry.append(binary)));
qDebug() << entry;
#ifdef Q_OS_WIN
if (!qfi->exists()) {
qfi.reset(new QFileInfo(entry.append(".exe")));
}
#endif
if (!qfi->isExecutable()) {
continue;
}
ret = qfi->absoluteFilePath();
break;
}
}
return ret;
}