|
2 | 2 | #include "system/commandrunner.h" |
3 | 3 |
|
4 | 4 | #include <QFile> |
5 | | -#include <QTextStream> |
6 | 5 | #include <QRegularExpression> |
| 6 | +#include <QTextStream> |
7 | 7 |
|
8 | | -NvidiaDetector::NvidiaDetector(QObject *parent) |
9 | | - : QObject(parent) |
10 | | -{} |
| 8 | +NvidiaDetector::NvidiaDetector(QObject *parent) : QObject(parent) {} |
11 | 9 |
|
12 | | -NvidiaDetector::GpuInfo NvidiaDetector::detect() const |
13 | | -{ |
14 | | - GpuInfo info; |
| 10 | +NvidiaDetector::GpuInfo NvidiaDetector::detect() const { |
| 11 | + GpuInfo info; |
15 | 12 |
|
16 | | - info.name = detectGpuName(); |
17 | | - info.found = !info.name.isEmpty(); |
18 | | - info.driverVersion = detectDriverVersion(); |
19 | | - info.driverLoaded = isModuleLoaded(QStringLiteral("nvidia")); |
20 | | - info.nouveauActive = isModuleLoaded(QStringLiteral("nouveau")); |
21 | | - info.secureBootEnabled = detectSecureBoot(); |
| 13 | + info.name = detectGpuName(); |
| 14 | + info.found = !info.name.isEmpty(); |
| 15 | + info.driverVersion = detectDriverVersion(); |
| 16 | + info.driverLoaded = isModuleLoaded(QStringLiteral("nvidia")); |
| 17 | + info.nouveauActive = isModuleLoaded(QStringLiteral("nouveau")); |
| 18 | + info.secureBootEnabled = detectSecureBoot(); |
22 | 19 |
|
23 | | - return info; |
| 20 | + return info; |
24 | 21 | } |
25 | 22 |
|
26 | | -bool NvidiaDetector::hasNvidiaGpu() const |
27 | | -{ |
28 | | - return !detectGpuName().isEmpty(); |
| 23 | +bool NvidiaDetector::hasNvidiaGpu() const { return !detectGpuName().isEmpty(); } |
| 24 | + |
| 25 | +bool NvidiaDetector::isDriverInstalled() const { |
| 26 | + return !detectDriverVersion().isEmpty(); |
29 | 27 | } |
30 | 28 |
|
31 | | -bool NvidiaDetector::isDriverInstalled() const |
32 | | -{ |
33 | | - return !detectDriverVersion().isEmpty(); |
| 29 | +QString NvidiaDetector::installedDriverVersion() const { |
| 30 | + return detectDriverVersion(); |
34 | 31 | } |
35 | 32 |
|
36 | | -QString NvidiaDetector::installedDriverVersion() const |
37 | | -{ |
38 | | - return detectDriverVersion(); |
| 33 | +QString NvidiaDetector::verificationReport() const { |
| 34 | + const QString gpuText = m_info.found ? m_info.name : QStringLiteral("Yok"); |
| 35 | + const QString driverText = |
| 36 | + m_info.driverVersion.isEmpty() ? QStringLiteral("Yok") : m_info.driverVersion; |
| 37 | + const QString secureBootText = m_info.secureBootEnabled ? QStringLiteral("Acik") |
| 38 | + : QStringLiteral("Kapali/Bilinmiyor"); |
| 39 | + |
| 40 | + return QStringLiteral("GPU: %1\nSurucu Versiyonu: %2\nSecure Boot: %3\nNVIDIA Modulu: %4\nNouveau: %5") |
| 41 | + .arg(gpuText, driverText, secureBootText, |
| 42 | + m_info.driverLoaded ? QStringLiteral("Yuklu") : QStringLiteral("Yuklu degil"), |
| 43 | + m_info.nouveauActive ? QStringLiteral("Aktif") : QStringLiteral("Aktif degil")); |
39 | 44 | } |
40 | 45 |
|
41 | | -QString NvidiaDetector::detectGpuName() const |
42 | | -{ |
43 | | - CommandRunner runner; |
44 | | - |
45 | | - // lspci ile PCI cihazlarını listele, NVIDIA olanı filtrele |
46 | | - const auto result = runner.run( |
47 | | - QStringLiteral("lspci"), |
48 | | - { QStringLiteral("-mm") } |
49 | | - ); |
50 | | - |
51 | | - if (!result.success()) |
52 | | - return {}; |
53 | | - |
54 | | - // lspci -mm çıktısında NVIDIA GPU satırını ara |
55 | | - const QStringList lines = result.stdout.split(QLatin1Char('\n')); |
56 | | - for (const QString &line : lines) { |
57 | | - if (line.contains(QStringLiteral("NVIDIA"), Qt::CaseInsensitive) && |
58 | | - line.contains(QStringLiteral("VGA"), Qt::CaseInsensitive)) |
59 | | - { |
60 | | - // Tırnak işaretleri arasındaki model adını çıkar |
61 | | - static const QRegularExpression re(QStringLiteral("\"([^\"]+)\"")); |
62 | | - auto it = re.globalMatch(line); |
63 | | - QStringList parts; |
64 | | - while (it.hasNext()) |
65 | | - parts << it.next().captured(1); |
66 | | - |
67 | | - if (parts.size() >= 3) |
68 | | - return parts[2]; // Model adı 3. tırnak grubunda |
69 | | - } |
70 | | - } |
| 46 | +QString NvidiaDetector::detectGpuName() const { |
| 47 | + CommandRunner runner; |
| 48 | + |
| 49 | + // lspci ile PCI cihazlarını listele, NVIDIA olanı filtrele |
| 50 | + const auto result = |
| 51 | + runner.run(QStringLiteral("lspci"), {QStringLiteral("-mm")}); |
71 | 52 |
|
| 53 | + if (!result.success()) |
72 | 54 | return {}; |
73 | | -} |
74 | 55 |
|
75 | | -QString NvidiaDetector::detectDriverVersion() const |
76 | | -{ |
77 | | - CommandRunner runner; |
78 | | - |
79 | | - // nvidia-smi varsa sürücü versiyonunu döner |
80 | | - const auto result = runner.run( |
81 | | - QStringLiteral("nvidia-smi"), |
82 | | - { QStringLiteral("--query-gpu=driver_version"), |
83 | | - QStringLiteral("--format=csv,noheader") } |
84 | | - ); |
85 | | - |
86 | | - if (result.success()) |
87 | | - return result.stdout.trimmed(); |
88 | | - |
89 | | - // nvidia-smi yoksa modinfo'dan dene |
90 | | - const auto modinfo = runner.run( |
91 | | - QStringLiteral("modinfo"), |
92 | | - { QStringLiteral("nvidia") } |
93 | | - ); |
94 | | - |
95 | | - if (modinfo.success()) { |
96 | | - static const QRegularExpression re(QStringLiteral("^version:\\s+(.+)$"), |
97 | | - QRegularExpression::MultilineOption); |
98 | | - const auto match = re.match(modinfo.stdout); |
99 | | - if (match.hasMatch()) |
100 | | - return match.captured(1).trimmed(); |
| 56 | + // lspci -mm çıktısında NVIDIA GPU satırını ara |
| 57 | + const QStringList lines = result.stdout.split(QLatin1Char('\n')); |
| 58 | + for (const QString &line : lines) { |
| 59 | + if (line.contains(QStringLiteral("NVIDIA"), Qt::CaseInsensitive) && |
| 60 | + line.contains(QStringLiteral("VGA"), Qt::CaseInsensitive)) { |
| 61 | + // Tırnak işaretleri arasındaki model adını çıkar |
| 62 | + static const QRegularExpression re(QStringLiteral("\"([^\"]+)\"")); |
| 63 | + auto it = re.globalMatch(line); |
| 64 | + QStringList parts; |
| 65 | + while (it.hasNext()) |
| 66 | + parts << it.next().captured(1); |
| 67 | + |
| 68 | + if (parts.size() >= 3) |
| 69 | + return parts[2]; // Model adı 3. tırnak grubunda |
101 | 70 | } |
| 71 | + } |
102 | 72 |
|
103 | | - return {}; |
| 73 | + return {}; |
104 | 74 | } |
105 | 75 |
|
106 | | -bool NvidiaDetector::isModuleLoaded(const QString &moduleName) const |
107 | | -{ |
108 | | - // /proc/modules dosyasını oku — yüklü kernel modüllerini listeler |
109 | | - QFile modules(QStringLiteral("/proc/modules")); |
110 | | - if (!modules.open(QIODevice::ReadOnly | QIODevice::Text)) |
111 | | - return false; |
112 | | - |
113 | | - QTextStream stream(&modules); |
114 | | - while (!stream.atEnd()) { |
115 | | - const QString line = stream.readLine(); |
116 | | - if (line.startsWith(moduleName + QLatin1Char(' '))) |
117 | | - return true; |
118 | | - } |
| 76 | +QString NvidiaDetector::detectDriverVersion() const { |
| 77 | + CommandRunner runner; |
| 78 | + |
| 79 | + // nvidia-smi varsa sürücü versiyonunu döner |
| 80 | + const auto result = runner.run(QStringLiteral("nvidia-smi"), |
| 81 | + {QStringLiteral("--query-gpu=driver_version"), |
| 82 | + QStringLiteral("--format=csv,noheader")}); |
| 83 | + |
| 84 | + if (result.success()) |
| 85 | + return result.stdout.trimmed(); |
119 | 86 |
|
| 87 | + // nvidia-smi yoksa modinfo'dan dene |
| 88 | + const auto modinfo = |
| 89 | + runner.run(QStringLiteral("modinfo"), {QStringLiteral("nvidia")}); |
| 90 | + |
| 91 | + if (modinfo.success()) { |
| 92 | + static const QRegularExpression re(QStringLiteral("^version:\\s+(.+)$"), |
| 93 | + QRegularExpression::MultilineOption); |
| 94 | + const auto match = re.match(modinfo.stdout); |
| 95 | + if (match.hasMatch()) |
| 96 | + return match.captured(1).trimmed(); |
| 97 | + } |
| 98 | + |
| 99 | + return {}; |
| 100 | +} |
| 101 | + |
| 102 | +bool NvidiaDetector::isModuleLoaded(const QString &moduleName) const { |
| 103 | + // /proc/modules dosyasını oku — yüklü kernel modüllerini listeler |
| 104 | + QFile modules(QStringLiteral("/proc/modules")); |
| 105 | + if (!modules.open(QIODevice::ReadOnly | QIODevice::Text)) |
120 | 106 | return false; |
| 107 | + |
| 108 | + QTextStream stream(&modules); |
| 109 | + while (!stream.atEnd()) { |
| 110 | + const QString line = stream.readLine(); |
| 111 | + if (line.startsWith(moduleName + QLatin1Char(' '))) |
| 112 | + return true; |
| 113 | + } |
| 114 | + |
| 115 | + return false; |
121 | 116 | } |
122 | 117 |
|
123 | | -bool NvidiaDetector::detectSecureBoot() const |
124 | | -{ |
125 | | - // mokutil --sb-state: Secure Boot durumunu raporlar |
126 | | - // "SecureBoot enabled" veya "SecureBoot disabled" döner |
127 | | - CommandRunner runner; |
128 | | - const auto result = runner.run( |
129 | | - QStringLiteral("mokutil"), |
130 | | - { QStringLiteral("--sb-state") } |
131 | | - ); |
132 | | - |
133 | | - if (result.success() || result.exitCode == 1) { |
134 | | - // mokutil çıktısı "enabled" içeriyorsa Secure Boot açık |
135 | | - return result.stdout.contains(QStringLiteral("enabled"), |
136 | | - Qt::CaseInsensitive); |
137 | | - } |
| 118 | +bool NvidiaDetector::detectSecureBoot() const { |
| 119 | + CommandRunner runner; |
| 120 | + const auto result = |
| 121 | + runner.run(QStringLiteral("mokutil"), {QStringLiteral("--sb-state")}); |
138 | 122 |
|
139 | | - // mokutil yoksa durum bilinmez — kullanıcıyı uyarmayız |
140 | | - return false; |
| 123 | + if (result.success() || result.exitCode == 1) { |
| 124 | + return result.stdout.contains(QStringLiteral("enabled"), Qt::CaseInsensitive); |
| 125 | + } |
| 126 | + |
| 127 | + return false; |
141 | 128 | } |
142 | 129 |
|
143 | | -void NvidiaDetector::refresh() |
144 | | -{ |
145 | | - m_info = detect(); |
146 | | - emit infoChanged(); |
| 130 | +void NvidiaDetector::refresh() { |
| 131 | + m_info = detect(); |
| 132 | + emit infoChanged(); |
147 | 133 | } |
0 commit comments