Commit b0435f21501a980c7d9e8c701d6bc989a953b2f5
1 parent
9f6a985d
Exists in
master
Consulta WMI quase pronta, só falta colocar quais classes é pra pesquisar
Showing
9 changed files
with
132 additions
and
21 deletions
Show diff stats
cacic-teste/testcacic.cpp
... | ... | @@ -228,7 +228,7 @@ void CTestCacic::testColetaSoftware() |
228 | 228 | void CTestCacic::testColetaHardware() |
229 | 229 | { |
230 | 230 | OCacicHardware.iniciaColeta(); |
231 | - QVERIFY(false); | |
231 | + QVERIFY(!OCacicHardware.toJsonObject().isEmpty()); | |
232 | 232 | } |
233 | 233 | void CTestCacic::testConvertDouble() |
234 | 234 | { | ... | ... |
gercols/gercols.pro
install-cacic/install-cacic.pro.user
src/cacic_hardware.cpp
... | ... | @@ -14,13 +14,101 @@ void cacic_hardware::iniciaColeta() |
14 | 14 | #ifdef Q_OS_WIN |
15 | 15 | QJsonObject cacic_hardware::coletaWin() |
16 | 16 | { |
17 | + QJsonObject hardware; | |
18 | + QStringList params; | |
19 | + QJsonObject wmi; | |
20 | + // Win32_ComputerSystem (Caption, Description, Domain, DNSHostName, Manufacturer, | |
21 | + // Model, Name, PrimaryOwnerName, TotalPhysicalMemory, Workgroup) | |
22 | + params << "Caption" << "Description" << "Domain" << "DNSHostName" << "Manufacturer" << "Model" | |
23 | + << "Name" << "PrimaryOwnerName" << "TotalPhysicalMemory" << "Workgroup"; | |
24 | + wmi = wmiSearch("Win32_ComputerSystem", params); | |
25 | + if (!wmi.isEmpty()) | |
26 | + hardware["ComputerSystem"] = wmiSearch("Win32_ComputerSystem", params); | |
27 | + //Win32_PortableBattery | |
28 | + // (Verifica se é notebook) | |
29 | + params.clear(); | |
30 | + hardware["IsNotebook"] = QJsonValue::fromVariant(!wmiSearch("Win32_PortableBattery", params).isEmpty()); | |
31 | + //Win32_Bios | |
32 | + // (Manufacturer, SMBIOSBIOSVersion, BIOSVersion, Version, SerialNumber, ReleaseDate) | |
33 | + params.clear(); | |
34 | + params << "Manufacturer" << "SMBIOSBIOSVersion" << "BIOSVersion" << "Version" << "SerialNumber" << "ReleaseDate"; | |
35 | + wmi = wmiSearch("Win32_Bios", params); | |
36 | + if (!wmi.isEmpty()) | |
37 | + hardware["Bios"] = wmi; | |
38 | + //Win32_BaseBoard | |
39 | + // (Manufacturer, Model, SerialNumber) | |
40 | + params.clear(); | |
41 | + params << "Manufacturer" << "Model" << "SerialNumber"; | |
42 | + wmi = wmiSearch("Win32_Baseboard", params); | |
43 | + if (!wmi.isEmpty()) | |
44 | + hardware["BaseBoard"] = wmi; | |
45 | + //Win32_SystemEnclosure | |
46 | + // (Manufacturer, ChassisTypes, SerialNumber, SMBIOSAssetTag) | |
47 | + //Win32_FloppyDrive | |
48 | + // (Manufacturer, Caption, Description, Name, MediaType, Size) | |
49 | + //Win32_DiskDrive | |
50 | + // (Manufacturer, Caption, Description, Name, MediaType, Size, SerialNumber, Model, FirmwareRevision) | |
51 | + //Win32_CDROMDrive | |
52 | + // (Manufacturer, Caption, Description, Name, MediaType, Size) | |
53 | + //Win32_FloppyController | |
54 | + // (Manufacturer, Caption, Description, Name) | |
55 | + //Win32_SCSIController | |
56 | + // (Manufacturer, Caption, Description, Name, HardwareVersion) | |
57 | + //Win32_InfraredDevice | |
58 | + // (Manufacturer, Caption, Description, Name) | |
59 | + //Win32_USBController | |
60 | + // (Manufacturer, Caption, Description, Name) | |
61 | + //Win32_PCMCIAController | |
62 | + // (Manufacturer, Caption, Description, Name) | |
63 | + //Win32_VideoController | |
64 | + // (Description, VideoProcessor, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution) | |
65 | + //Win32_DesktopMonitor | |
66 | + // (MonitorManufacturer, Caption, Description, MonitorType) | |
67 | + //Win32_Printer | |
68 | + // (Name, DriverName, PortName, ServerName, ShareName, HorizontalResolution, VerticalResolution, Comment, Shared, Network) | |
69 | + //Win32_PortConnector | |
70 | + // (ExternalReferenceDesignator, PortType, ConnectorType) | |
71 | + //Win32_SerialPort | |
72 | + // (Name, Caption, Description, StatusInfo) | |
73 | + //Win32_Processor | |
74 | + // (MaxClockSpeed, Name, Architecture, NumberOfCores, SocketDesignation, Manufacturer, Name, Architecture, NumberOfCores | |
75 | + // CurrentClockSpeed, MaxClockSpeed, L2CacheSize, AddressWidth, DataWidth, VoltageCaps, CpuStatus, | |
76 | + // ProcessorId || UniqueId, AddressWidth) | |
77 | + //Win32_OperatingSystem | |
78 | + // (Name, Version, CSDVersion, Description, InstallDate, Organization, RegisteredUser, SerialNumber) | |
79 | + //Win32_SystemSlot | |
80 | + // (Name, Description, SlotDesignation, CurrentUsage, Status, Shared) | |
81 | + //Win32_LogicalDisk | |
82 | + // (Caption, DriveType, Filesystem, VolumeName, ProviderName, Filesystem, VolumeName, Size, FreeSpace) | |
83 | + //Win32_PhysicalMemory | |
84 | + // (Caption, Description, BankLabel, DeviceLocator, Capacity, Speed, MemoryTypem, SerialNumber) | |
85 | + //Win32_Keyboard | |
86 | + // (Manufacturer, Caption, Description) | |
87 | + //Win32_PointingDevice | |
88 | + // (Manufacturer, Caption, Description, PointingType, DeviceInterface) | |
89 | + //Win32_PnPSignedDriver | |
90 | + // (Manufacturer, DeviceName, Description, Location, DeviceClass) | |
91 | + qDebug() << hardware; | |
92 | + return hardware; | |
93 | +} | |
94 | + | |
95 | +QJsonObject cacic_hardware::wmiSearch(QString classe, QStringList params) | |
96 | +{ | |
97 | + QJsonObject wmiReturn; | |
98 | + QString paramsString; | |
99 | + if (!params.empty()){ | |
100 | + for(int i = 0; i!=params.size();i++) | |
101 | + paramsString.append(params.at(i) + ((i != params.size() - 1) ? "," : "")); | |
102 | + } | |
17 | 103 | QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); |
18 | 104 | QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)", |
19 | 105 | QString("."), |
20 | 106 | QString("root\\CIMV2") |
21 | 107 | ); |
22 | 108 | QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", |
23 | - QString("SELECT * FROM Win32_ComputerSystem") | |
109 | + QString("SELECT " + ((!paramsString.isEmpty()) ? | |
110 | + paramsString : "*") + | |
111 | + " FROM " + classe) | |
24 | 112 | ); |
25 | 113 | QAxObject *enum1 = returnList->querySubObject("_NewEnum"); |
26 | 114 | //ui->textBrowser_4->setHtml(enum1->generateDocumentation()); |
... | ... | @@ -36,17 +124,45 @@ QJsonObject cacic_hardware::coletaWin() |
36 | 124 | VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); |
37 | 125 | if (enumInterface->Next(1,theItem,NULL) != S_FALSE){ |
38 | 126 | QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); |
39 | - | |
40 | 127 | if(item){ |
41 | - qDebug() <<" string is "<<item->dynamicCall("ProcessorId").toString(); | |
42 | - qDebug() <<" string is "<<item->dynamicCall("GetText_(WbemObjectTextFormatEnum)", QVariant(1)).toString(); | |
128 | + //pega o retorno da query | |
129 | + QString instance = item->dynamicCall("GetObjectText_(int)", QVariant(0)).toString(); | |
130 | + QStringList instanceList = instance.split("\n\t"); | |
131 | + //Pra cada linha grava no json os valores com cada tag | |
132 | + foreach(QString value, instanceList){ | |
133 | + qDebug() << value; | |
134 | + QStringList valueList = value.split("="); | |
135 | + if (valueList.size() > 1){ | |
136 | + QString tag = valueList.at(0).trimmed(); | |
137 | + QString aux = valueList.at(1).trimmed(); | |
138 | + aux.remove("\""); | |
139 | + aux.remove(";"); | |
140 | + aux.remove("\n"); | |
141 | + //verifica se é lista | |
142 | + qDebug() << aux; | |
143 | + if(aux.contains("{") && aux.contains("}")){ | |
144 | + QStringList auxList = aux.split(","); | |
145 | + QJsonArray jList; | |
146 | + foreach(QString valueList, auxList){ | |
147 | + if (valueList.contains("{")) | |
148 | + valueList.remove("{"); | |
149 | + else if (valueList.contains("}")) | |
150 | + valueList.remove("}"); | |
151 | + jList.append(valueList.trimmed()); | |
152 | + } | |
153 | + wmiReturn[tag] = jList; | |
154 | + } else { | |
155 | + //O último valor sempre volta com "}" no final. | |
156 | + if (aux.contains("}")) | |
157 | + aux.remove("}"); | |
158 | + wmiReturn[tag] = QJsonValue::fromVariant(aux.trimmed()); | |
159 | + } | |
160 | + } | |
161 | + } | |
43 | 162 | } |
44 | - // item-> | |
45 | - //QString val = | |
46 | - qDebug()<<"item name is "<< item->property("objectName").toString(); | |
47 | 163 | } |
48 | 164 | } |
49 | - return QJsonObject(); | |
165 | + return wmiReturn; | |
50 | 166 | } |
51 | 167 | #elif defined(Q_OS_LINUX) |
52 | 168 | QJsonObject cacic_hardware::coletaLinux() | ... | ... |
src/cacic_hardware.h
... | ... | @@ -22,12 +22,9 @@ public: |
22 | 22 | private: |
23 | 23 | #ifdef Q_OS_WIN |
24 | 24 | QJsonObject coletaWin(); |
25 | + QJsonObject wmiSearch(QString classe, QStringList params); | |
25 | 26 | |
26 | 27 | #elif defined(Q_OS_LINUX) |
27 | -/* Thiago aqui: | |
28 | - * Ao menos nos elif's tem que deixar com o "defined()". | |
29 | - * Por isso antes eu preferia deixar todas essas verificações com ele, mesmo tendo o ifdef. | |
30 | - */ | |
31 | 28 | QJsonObject coletaLinux(); |
32 | 29 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); |
33 | 30 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); | ... | ... |
src/vqtconvert.cpp
src/vqtconvert.h
src/vregistry.cpp