-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
util.cpp
53 lines (42 loc) · 1.1 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
#include <QDebug>
#include <QFileInfo>
#include <QProcessEnvironment>
#include <QString>
#include "util.h"
QProcessEnvironment Util::_env;
bool Util::_envInitialised;
void Util::initialiseEnvironment()
{
if (!_envInitialised) {
_env = QProcessEnvironment::systemEnvironment();
_envInitialised = true;
}
}
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) {
QFileInfo *qfi = new QFileInfo(entry.append(binary));
qDebug() << entry;
#ifdef WINDOWS
if (!qfi->exists()) {
QFileInfo qfi = new QFileInfo(entry.append(".exe"));
}
#endif
if (!qfi->isExecutable()) {
continue;
}
ret = qfi->absoluteFilePath();
break;
}
}
return ret;
}