forked from jackburton79/ocs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Softwares.cpp
98 lines (88 loc) · 2.3 KB
/
Softwares.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
/*
* Softwares.cpp
*
* Author: Jonathan ORSEL
*/
#include "Softwares.h"
#include "ProcReader.h"
#include "Support.h"
#include <iostream>
#include <istream>
Softwares::Softwares()
{
_ReadSoftwaresInfo();
}
void
Softwares::_ReadSoftwaresInfo()
{
try {
if (!CommandExists("rpm"))
return;
CommandStreamBuffer rpms("rpm -qai", "r");
std::istream iStreamRpms(&rpms);
std::string string;
std::string strtmp;
std::string comments = "";
std::string size = "";
std::string from = "";
std::string installdate = "";
std::string name = "";
std::string version = "";
while (std::getline(iStreamRpms, string)) {
if (string.find("Name :") != std::string::npos ) {
// new rpm, add last in defined
if (name != "") {
software_info info;
info.comments = comments;
info.size = size;
info.from = from;
info.installdate = installdate;
info.name = name;
info.version = version;
fItems.push_back(info);
}
// then update name
name = string.substr(13, 35);
trim(name);
} else if (string.find("Version :") != std::string::npos) {
version = string.substr(13, 35);
trim(version);
} else if (string.find("Architecture:") != std::string::npos) {
strtmp = string.substr(13, 35);
trim(strtmp);
name = name + '.' + strtmp;
} else if (string.find("Release :") != std::string::npos) {
strtmp = string.substr(13, 35);
trim(strtmp);
version = version + '-' + strtmp;
} else if (string.find("Install Date:") != std::string::npos) {
installdate = string.substr(13, 50);
trim(installdate);
} else if (string.find("Size :") != std::string::npos) {
size = string.substr(13, 35);
trim(size);
} else if (string.find("Summary :") != std::string::npos) {
comments = string.substr(13, 100);
trim(comments);
} else if (string.find("Vendor :") != std::string::npos) {
strtmp = string.substr(13, 35);
trim(strtmp);
from = "RPM-" + strtmp;
}
}
//last one ?
if (name != "") {
software_info info;
info.comments = comments;
info.size = size;
info.from = from;
info.installdate = installdate;
info.name = name;
info.version = version;
fItems.push_back(info);
}
} catch (...) {
std::cerr << "No software info" << std::endl;
}
Rewind();
}