支持从apt源获取包名
This commit is contained in:
parent
aee6385e10
commit
cbb7510d99
@ -1,12 +1,45 @@
|
||||
#include "kernelinformation.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
KernelInformation::KernelInformation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QStringList KernelInformation::GetAptPackageList(QString name)
|
||||
{
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert("LANG", "en");
|
||||
QString data = GetCommandResult("apt", QStringList() << "list" << name, env);
|
||||
QStringList lineData = data.split("\n");
|
||||
QStringList result = {};
|
||||
for(QString i: lineData) {
|
||||
if(i.contains("Listing...")) {
|
||||
continue;
|
||||
}
|
||||
result.append(i.split("/").at(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray KernelInformation::GetCommandResult(QString command, QStringList argv, QProcessEnvironment env)
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessEnvironment(env);
|
||||
process.start(command, argv);
|
||||
process.waitForStarted();
|
||||
process.waitForFinished();
|
||||
QByteArray result = process.readAllStandardOutput();
|
||||
process.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
void KernelInformation::LoadInfo()
|
||||
{
|
||||
// 从 apt 获取信息
|
||||
qDebug() << this->GetAptPackageList("linux-*");
|
||||
// 从 Github 拉取信息
|
||||
QUrl url(this->url);
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("format", "j1");
|
||||
|
@ -42,9 +42,13 @@ signals:
|
||||
void loadFinished(QNetworkReply *reply);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
QString url = "http://info.kernel.gxde.gfdgdxi.top/information.json";
|
||||
QJsonArray listData;
|
||||
|
||||
QStringList GetAptPackageList(QString name);
|
||||
QByteArray GetCommandResult(QString command, QStringList argv, QProcessEnvironment env = QProcessEnvironment::systemEnvironment());
|
||||
};
|
||||
|
||||
#endif // KERNELINFORMATION_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user