-
Notifications
You must be signed in to change notification settings - Fork 0
/
localappscanner.cpp
54 lines (40 loc) · 1.39 KB
/
localappscanner.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 "localappscanner.h"
#include <QBuffer>
LocalAppScanner* LocalAppScanner::_instance = NULL;
void LocalAppScanner::scanLocalApps() {
QDirIterator it("/Applications");
while (it.hasNext()) {
it.next();
if (!it.fileInfo().isDir())
continue;
if (!it.fileName().compare(".") || !it.fileName().compare(".."))
continue;
LocalApp l;
l.name = it.fileName();
l.version = getAppVersion(it.filePath());
localAppList.append(l);
}
emit finished();
}
QString LocalAppScanner::getAppVersion(QString appPath) {
QString version;
QString fileName = appPath + "/Contents/Info.plist";
//prepare file
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
//transfer file content to buffer
QByteArray data = file.readAll();
QBuffer buffer(&data);
if (buffer.open(QIODevice::ReadOnly)) {
//create query
QXmlQuery query(QXmlQuery::XQuery10);
query.bindVariable("file", &buffer);
query.setQuery("declare variable $file external; doc($file)/plist/dict/key[node()='CFBundleShortVersionString']/following-sibling::string[1]/node()");
//execute query
query.evaluateTo(&version);
buffer.close();
}
file.close();
}
return version.remove(QChar('\n'), Qt::CaseInsensitive);
}