-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiisEnvironment.cpp
executable file
·152 lines (125 loc) · 3.56 KB
/
iisEnvironment.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* iisEnvironment.cpp
*
* Created on: 07.08.2008
*/
#include "iisEnvironment.h"
#ifdef Q_OS_WIN32
#include <windows.h>
#include <shlobj.h>
#endif
#include <QtWidgets>
iisEnvironment::iisEnvironment()
{
}
iisEnvironment::~iisEnvironment()
{
}
QString iisEnvironment::systemVariable(const QString &varname)
{
QStringList env = QProcess::systemEnvironment();
QString pat = varname + "=";
foreach (QString s, env) {
if (s.startsWith(pat, Qt::CaseInsensitive))
return s.right(s.length()-pat.length());
}
return QString();
}
QStringList iisEnvironment::systemPath()
{
QString s = systemVariable("PATH");
#ifdef Q_OS_WIN32
QStringList sl = s.split(";", QString::SkipEmptyParts);
#else
QStringList sl = s.split(":", QString::SkipEmptyParts);
#endif
return sl;
}
QStringList iisEnvironment::availableInPath(const QString &filename, const QStringList &pathlist, bool expandSymLinks)
{
QStringList files;
if (filename.isEmpty())
return files;
if (QDir::isAbsolutePath(filename)) {
if (QFile::exists(filename))
files << filename;
#ifdef Q_OS_WIN32
else
if (!filename.endsWith(".exe")) {
QString tmp = filename + ".exe";
if (QFile::exists(tmp))
files << tmp;
}
#endif
return files;
}
foreach (QString path, pathlist) {
path = path.replace("\\","/");
path += "/" + filename;
if (QFile::exists(path)) {
if (!expandSymLinks) {
files << path;
} else {
QFileInfo fi(path);
path = fi.canonicalFilePath();
if (!files.contains(path))
files << path;
}
}
#ifdef Q_OS_WIN32
else
if (!path.endsWith(".exe")) {
QString tmp = path + ".exe";
if (QFile::exists(tmp))
files << tmp;
}
#endif
}
return files;
}
QStringList iisEnvironment::availableInPath(const QString &filename, bool expandSymLinks)
{
return availableInPath(filename, systemPath(), expandSymLinks);
}
void iisEnvironment::openFileDir(const QString &name)
{
QString outDir = QDir::cleanPath(name);
// Qt can not open URLs with spaces unless file:/// is not specified in front of.
if (!QDesktopServices::openUrl(QUrl(QString("file:///") + outDir)))
{
// last chance on Windows
#ifdef Q_OS_WIN32
ShellExecuteA(NULL, "open", outDir.toLatin1().data(), NULL, NULL, SW_SHOW);
#endif
}
}
#include <QDebug>
QStringList iisEnvironment::matchInPath(const QString &baseDir, const QString &filter)
{
QStringList result;
QStringList filt = filter.split("/", QString::SkipEmptyParts);
QString dir = QFileInfo(baseDir).canonicalFilePath();
//qDebug() << dir << filter << filt.count();
foreach(QString s, filt) {
QDir progDir(dir);
QStringList sfilt; sfilt << s;
result = progDir.entryList(sfilt, QDir::Dirs | QDir::Files);
//qDebug() << s << result.count();
if (result.isEmpty())
return result;
dir += "/" + result.first();
//qDebug() << dir;
}
result.clear(); result << dir;
return result;
}
QString iisEnvironment::applicationsPath()
{
#ifdef Q_OS_WIN32
char path[1024];
SHGetFolderPathA(0, CSIDL_PROGRAM_FILES, NULL, 0, path);
return QString(path);
#else
return "/usr/bin";
#endif
}