Merge branch 'main' into includes

This commit is contained in:
edisionnano
2024-06-22 19:55:09 +03:00
committed by GitHub
9 changed files with 95 additions and 86 deletions

View File

@@ -22,7 +22,7 @@ void utils::clearButtonGroup(QButtonGroup* buttonGroup, QHBoxLayout* horizontalL
menuDisk->clear();
}
QString utils::getSmartctlPath(bool initializing) {
QString utils::getSmartctlPath() {
QStringList paths = QString::fromLocal8Bit(qgetenv("PATH")).split(QDir::listSeparator(), Qt::SkipEmptyParts);
paths << "/usr/sbin" << "/usr/local/sbin";
@@ -45,10 +45,10 @@ QString utils::getSmartctlOutput(const QStringList &arguments, bool root, bool i
if (root) {
command = "pkexec";
} else {
command = getSmartctlPath(initializing);
command = getSmartctlPath();
}
if (!getSmartctlPath(initializing).isEmpty()) {
if (!getSmartctlPath().isEmpty()) {
process.start(command, arguments);
process.waitForFinished(-1);
}
@@ -75,14 +75,14 @@ QPair<QStringList, QJsonArray> utils::scanDevices(bool initializing)
QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8());
QJsonObject jsonObj = doc.object();
QJsonArray devices = jsonObj["devices"].toArray();
QString smartctlPath = getSmartctlPath(initializing);
QString smartctlPath = getSmartctlPath();
QStringList commandList;
QStringList deviceOutputs;
for (const QJsonValue &value : std::as_const(devices)) {
QJsonObject device = value.toObject();
QString deviceName = device["name"].toString();
commandList.append(QString(smartctlPath + " --all --json=o %1").arg(deviceName));
commandList.append((smartctlPath + " --all --json=o %1").arg(deviceName));
}
QString command = commandList.join(" ; ");
@@ -93,8 +93,8 @@ QPair<QStringList, QJsonArray> utils::scanDevices(bool initializing)
QString allDevicesOutput = getSmartctlOutput({"sh", "-c", command}, true, initializing);
int startIndex = 0;
int endIndex = 0;
qsizetype startIndex = 0;
qsizetype endIndex = 0;
static const QRegularExpression regex("\\}\\n\\{");
@@ -120,7 +120,7 @@ QPair<QStringList, QJsonArray> utils::scanDevices(bool initializing)
QString utils::initiateSelfTest(const QString &testType, const QString &deviceNode)
{
QProcess process;
QString command = getSmartctlPath(false);
QString command = getSmartctlPath();
QStringList arguments;
arguments << command << "--json=o" << "-t" << testType << deviceNode;
@@ -137,7 +137,7 @@ QString utils::initiateSelfTest(const QString &testType, const QString &deviceNo
void utils::cancelSelfTest(const QString &deviceNode)
{
QProcess process;
QString command = getSmartctlPath(false);
QString command = getSmartctlPath();
QStringList arguments;
arguments << command << "-X" << deviceNode;
@@ -161,8 +161,6 @@ void utils::selfTestHandler(const QString &mode, const QString &name, const QStr
QJsonDocument testDoc = QJsonDocument::fromJson(output.toUtf8());
QJsonObject testObj = testDoc.object();
QJsonObject smartctlObj = testObj.value("smartctl").toObject();
QJsonObject deviceObj = testObj.value("device").toObject();
QString name = deviceObj.value("name").toString();
int exitStatus = smartctlObj.value("exit_status").toInt();
QJsonArray outputArray = smartctlObj["output"].toArray();