mirror of
https://github.com/edisionnano/QDiskInfo.git
synced 2026-04-16 13:11:28 +03:00
Add an error if smartctl does not exist or if pkexec is cancelled
This commit is contained in:
@@ -630,11 +630,24 @@ void MainWindow::addSmartAttributesTable(const QJsonArray &attributes)
|
|||||||
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool commandExists(const QString &command) {
|
||||||
|
QStringList paths = QString::fromLocal8Bit(qgetenv("PATH")).split(QDir::listSeparator(), Qt::SkipEmptyParts);
|
||||||
|
for (const QString &path : paths) {
|
||||||
|
QString absolutePath = QDir(path).absoluteFilePath(command);
|
||||||
|
if (QFile::exists(absolutePath) && QFileInfo(absolutePath).isExecutable()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QString MainWindow::getSmartctlOutput(const QStringList &arguments, bool root)
|
QString MainWindow::getSmartctlOutput(const QStringList &arguments, bool root)
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QString command;
|
QString command;
|
||||||
QStringList commandArgs;
|
QStringList commandArgs;
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
command = "pkexec";
|
command = "pkexec";
|
||||||
commandArgs = QStringList();
|
commandArgs = QStringList();
|
||||||
@@ -643,9 +656,20 @@ QString MainWindow::getSmartctlOutput(const QStringList &arguments, bool root)
|
|||||||
commandArgs = QStringList();
|
commandArgs = QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
commandArgs.append(arguments);
|
if (!commandExists("smartctl")) {
|
||||||
process.start(command, commandArgs);
|
QMessageBox::critical(nullptr, tr("KDiskInfo Error"), tr("smartctl was not found, please install it!"));
|
||||||
process.waitForFinished();
|
QTimer::singleShot(0, qApp, &QApplication::quit);
|
||||||
|
} else {
|
||||||
|
commandArgs.append(arguments);
|
||||||
|
process.start(command, commandArgs);
|
||||||
|
process.waitForFinished(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.exitCode() == 127) {
|
||||||
|
QMessageBox::critical(nullptr, tr("KDiskInfo Error"), tr("KDiskInfo needs root access in order to read S.M.A.R.T. data!"));
|
||||||
|
QTimer::singleShot(0, qApp, &QApplication::quit);
|
||||||
|
}
|
||||||
|
|
||||||
return process.readAllStandardOutput();
|
return process.readAllStandardOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QTimer>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "statusdot.h"
|
#include "statusdot.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user