mirror of
https://github.com/debauchee/barrier.git
synced 2024-11-23 20:12:39 +03:00
Check OS info from GUI #4933
This commit is contained in:
parent
a4c799c285
commit
d4d5d83bb6
@ -18,17 +18,46 @@
|
||||
#include "CommandProcess.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <stdexcept>
|
||||
|
||||
CommandProcess::CommandProcess(QString cmd, QStringList arguments) :
|
||||
CommandProcess::CommandProcess(QString cmd, QStringList arguments, QString input) :
|
||||
m_Command(cmd),
|
||||
m_Arguments(arguments)
|
||||
m_Arguments(arguments),
|
||||
m_Input(input)
|
||||
{
|
||||
}
|
||||
|
||||
void CommandProcess::run()
|
||||
QString CommandProcess::run()
|
||||
{
|
||||
QProcess process;
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.start(m_Command, m_Arguments);
|
||||
process.waitForFinished();
|
||||
bool success = process.waitForFinished();
|
||||
|
||||
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
|
||||
|
||||
public:
|
||||
CommandProcess(QString cmd, QStringList arguments);
|
||||
CommandProcess(QString cmd, QStringList arguments, QString input = "");
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
public slots:
|
||||
void run();
|
||||
QString run();
|
||||
|
||||
private:
|
||||
QString m_Command;
|
||||
QStringList m_Arguments;
|
||||
QString m_Input;
|
||||
};
|
||||
|
||||
#endif // COMMANDTHREAD_H
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "PluginManager.h"
|
||||
|
||||
#include "CoreInterface.h"
|
||||
#include "CommandProcess.h"
|
||||
#include "DataDownloader.h"
|
||||
#include "QUtility.h"
|
||||
#include "ProcessorArch.h"
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "QUtility.h"
|
||||
|
||||
#include "ProcessorArch.h"
|
||||
#include "CommandProcess"
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include <QProcess>
|
||||
@ -90,3 +91,21 @@ qProcessorArch getProcessorArch()
|
||||
|
||||
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 getFirstMacAddress();
|
||||
qProcessorArch getProcessorArch();
|
||||
QString getOSInformation();
|
||||
|
Loading…
Reference in New Issue
Block a user