Check OS info from GUI #4933
This commit is contained in:
parent
a4c799c285
commit
d4d5d83bb6
|
@ -18,17 +18,46 @@
|
||||||
#include "CommandProcess.h"
|
#include "CommandProcess.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
CommandProcess::CommandProcess(QString cmd, QStringList arguments) :
|
CommandProcess::CommandProcess(QString cmd, QStringList arguments, QString input) :
|
||||||
m_Command(cmd),
|
m_Command(cmd),
|
||||||
m_Arguments(arguments)
|
m_Arguments(arguments),
|
||||||
|
m_Input(input)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandProcess::run()
|
QString CommandProcess::run()
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
|
process.setReadChannel(QProcess::StandardOutput);
|
||||||
process.start(m_Command, m_Arguments);
|
process.start(m_Command, m_Arguments);
|
||||||
process.waitForFinished();
|
bool success = process.waitForFinished();
|
||||||
emit finished();
|
|
||||||
|
QString output, error;
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
if (!m_Input.isEmpty()) {
|
||||||
|
process.write(m_Input.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.waitForFinished()) {
|
||||||
|
output = process.readAllStandardOutput().trimmed();
|
||||||
|
error = process.readAllStandardError().trimmed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int code = process.exitCode();
|
||||||
|
if (!error.isEmpty() || !success || code != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
QString("Code: %1\nError: %2")
|
||||||
|
.arg(process.exitCode())
|
||||||
|
.arg(error.isEmpty() ? "Unknown" : error)
|
||||||
|
.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
emit finished();
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,17 +25,18 @@ class CommandProcess : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandProcess(QString cmd, QStringList arguments);
|
CommandProcess(QString cmd, QStringList arguments, QString input = "");
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void run();
|
QString run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_Command;
|
QString m_Command;
|
||||||
QStringList m_Arguments;
|
QStringList m_Arguments;
|
||||||
|
QString m_Input;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMMANDTHREAD_H
|
#endif // COMMANDTHREAD_H
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include "PluginManager.h"
|
#include "PluginManager.h"
|
||||||
|
|
||||||
#include "CoreInterface.h"
|
#include "CoreInterface.h"
|
||||||
#include "CommandProcess.h"
|
|
||||||
#include "DataDownloader.h"
|
#include "DataDownloader.h"
|
||||||
#include "QUtility.h"
|
#include "QUtility.h"
|
||||||
#include "ProcessorArch.h"
|
#include "ProcessorArch.h"
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "QUtility.h"
|
#include "QUtility.h"
|
||||||
|
|
||||||
#include "ProcessorArch.h"
|
#include "ProcessorArch.h"
|
||||||
|
#include "CommandProcess"
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
@ -90,3 +91,21 @@ qProcessorArch getProcessorArch()
|
||||||
|
|
||||||
return kProcessorArchUnknown;
|
return kProcessorArchUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getOSInformation()
|
||||||
|
{
|
||||||
|
QString output;
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
CommandProcess cp("/bin/cat", "/etc/os-release");
|
||||||
|
QString output = cp.run();
|
||||||
|
|
||||||
|
QRegExp resultRegex(".*PRETTY_NAME=\".*\".*");
|
||||||
|
if (resultRegex.exactMatch(output)) {
|
||||||
|
QString OSInfo = resultRegex.cap(1);
|
||||||
|
output = OSInfo;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
|
@ -28,3 +28,4 @@ void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData);
|
||||||
QString hash(const QString& string);
|
QString hash(const QString& string);
|
||||||
QString getFirstMacAddress();
|
QString getFirstMacAddress();
|
||||||
qProcessorArch getProcessorArch();
|
qProcessorArch getProcessorArch();
|
||||||
|
QString getOSInformation();
|
||||||
|
|
Loading…
Reference in New Issue