-
Notifications
You must be signed in to change notification settings - Fork 17
/
Common.cpp
114 lines (105 loc) · 3.45 KB
/
Common.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
/*
* QEstEidCommon
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "Common.h"
#include <QtCore/QOperatingSystemVersion>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#include <Regstr.h>
#include <Setupapi.h>
#elif defined(Q_OS_MAC)
#include <PCSC/wintypes.h>
#include <PCSC/winscard.h>
#include <arpa/inet.h>
#else
#include <wintypes.h>
#include <winscard.h>
#include <arpa/inet.h>
#endif
QString Common::applicationOs()
{
#if defined(Q_OS_MAC)
const auto version = QOperatingSystemVersion::current();
return QLatin1String("%1 %2.%3.%4 (%5/%6)")
.arg(version.name())
.arg(version.majorVersion())
.arg(version.minorVersion())
.arg(version.microVersion())
.arg(QSysInfo::buildCpuArchitecture())
.arg(QSysInfo::currentCpuArchitecture());
#elif defined(Q_OS_WIN)
QString product = QSysInfo::productType();
product[0] = product[0].toUpper();
QString version = QSysInfo::productVersion();
version.replace(QLatin1String("server"), QLatin1String("Server "));
return QStringLiteral("%1 %2 %3 (%4/%5)")
.arg(product)
.arg(version)
.arg(QOperatingSystemVersion::current().microVersion())
.arg(QSysInfo::buildCpuArchitecture())
.arg(QSysInfo::currentCpuArchitecture());
#else
return QStringLiteral("%1 (%2/%3)").arg(
QSysInfo::prettyProductName(),
QSysInfo::buildCpuArchitecture(),
QSysInfo::currentCpuArchitecture());
#endif
}
QStringList Common::drivers()
{
QStringList list;
#ifdef Q_OS_WIN
GUID guid {0x50dd5230L, 0xba8a, 0x11d1, 0xbf, 0x5d, 0x00, 0x00, 0xf8, 0x05, 0xf5, 0x30}; // SmartCardReader
HDEVINFO h = SetupDiGetClassDevs(&guid, nullptr, 0, DIGCF_PRESENT);
if(!h)
return list;
SP_DEVINFO_DATA info { sizeof(SP_DEVINFO_DATA) };
DWORD size = 0;
WCHAR data[1024];
for(DWORD i = 0; SetupDiEnumDeviceInfo(h, i, &info); ++i)
{
DWORD conf = 0;
SetupDiGetDeviceRegistryPropertyW(h, &info,
SPDRP_CONFIGFLAGS, 0, LPBYTE(&conf), sizeof(conf), &size);
if(conf & CONFIGFLAG_DISABLED)
continue;
SetupDiGetDeviceRegistryPropertyW(h, &info,
SPDRP_DEVICEDESC, 0, LPBYTE(data), sizeof(data), &size);
QString name = QString::fromWCharArray(data);
SetupDiGetDeviceRegistryPropertyW(h, &info,
SPDRP_HARDWAREID, 0, LPBYTE(data), sizeof(data), &size);
list.append(QStringLiteral("%1 (%2)").arg(name, QString::fromWCharArray(data)));
}
SetupDiDestroyDeviceInfoList(h);
#else
SCARDCONTEXT context{};
SCardEstablishContext(DWORD(SCARD_SCOPE_USER), nullptr, nullptr, &context);
if(!context)
return list;
DWORD size{};
if(SCardListReaders(context, nullptr, nullptr, &size) != SCARD_S_SUCCESS || !size)
return list;
QByteArray data(int(size), 0);
if(SCardListReaders(context, nullptr, data.data(), &size) != SCARD_S_SUCCESS)
data.clear();
SCardReleaseContext(context);
list = QString::fromLatin1(data).split('\0');
list.removeAll({});
#endif
return list;
}