20 qputenv(
"QT_BEARER_POLL_TIMEOUT", QByteArray::number(-1));
29 quint64 now = QDateTime::currentMSecsSinceEpoch();
42 if(reply->error() != QNetworkReply::NoError)
46 QByteArray data = reply->readAll();
48 QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Sha256);
55 gpg.start(
"gpg", QStringList(
"--version"));
56 gpg.waitForFinished();
57 if(gpg.error() == QProcess::FailedToStart)
61 QString output = QString::fromUtf8(gpg.readAll());
63 if(output.contains(
"RSA", Qt::CaseInsensitive) && output.contains(
"SHA256", Qt::CaseInsensitive))
69 qDebug() <<
"No GPG detected, signature verification disabled";
73 QDir tmp = QDir::temp();
75 qint64 pid = QCoreApplication::applicationPid();
76 QString fwPath = tmp.absoluteFilePath(QString(
"ckb-%1-firmware").arg(pid));
77 QFile firmware(fwPath);
78 if(!firmware.open(QIODevice::WriteOnly)
79 || firmware.write(data) != data.length()){
80 qDebug() <<
"Failed to write firmware file to temporary location, aborting firmware check";
85 QString keyPath = tmp.absoluteFilePath(QString(
"ckb-%1-key.gpg").arg(pid));
86 if(!QFile::copy(
":/bin/ckb-next-key.gpg", keyPath)){
88 qDebug() <<
"Failed to write GPG key to temporary location, aborting firmware check";
93 gpg.start(
"gpg", QStringList(
"--no-default-keyring") <<
"--keyring" << keyPath <<
"--verify" << fwPath);
94 gpg.waitForFinished();
98 if(gpg.error() != QProcess::UnknownError || gpg.exitCode() != 0){
99 qDebug() <<
"GPG couldn't verify firmware signature:";
100 qDebug() << gpg.readAllStandardOutput();
101 qDebug() << gpg.readAllStandardError();
107 QStringList lines = QString::fromUtf8(data).split(
"\n");
109 foreach(QString line, lines){
111 line.replace(QRegExp(
"\\s+"),
" ").remove(QRegExp(
"^\\s")).remove(QRegExp(
"\\s$"));
113 if(line.length() == 0 || line.at(0) ==
'#')
117 if(line ==
"!BEGIN FW ENTRIES")
122 if(line ==
"!END FW ENTRIES")
124 QStringList components = line.split(
" ");
125 if(components.length() != 7)
128 QString device = components[0].toUpper() +
"-" + components[1].toUpper();
131 fw.
url = QUrl::fromPercentEncoding(components[3].toLatin1());
133 fw.
fileName = QUrl::fromPercentEncoding(components[5].toLatin1());
134 fw.
hash = QByteArray::fromHex(components[6].toLatin1());
138 qDebug() <<
"Downloaded new firmware list." <<
fwTable.count() <<
"entries found.";
151 QStringList components = features.split(
" ");
152 if(components.length() < 2)
155 QString vendorModel = components[0].toUpper() +
"-" + components[1].toUpper();
157 if(features.contains(
"rgb") && !features.contains(
"monochrome"))
158 vendorModel +=
"RGB";
165 QEventLoop loop(
this);
172 if(info.
hash.isEmpty())
183 if(info.
hash.isEmpty())
187 QEventLoop loop(
this);
188 connect(reply, SIGNAL(finished()), &loop, SLOT(
quit()));
191 if(reply->error() != QNetworkReply::NoError)
193 QByteArray zipData = reply->readAll();
194 QBuffer buffer(&zipData);
203 if(!binFile.
open(QIODevice::ReadOnly))
205 QByteArray binary = binFile.readAll();
207 if(QCryptographicHash::hash(binary, QCryptographicHash::Sha256) != info.
hash)
static KbFirmware instance
QNetworkAccessManager * networkManager
void processDownload(QNetworkReply *reply)
static void quit()
quit Stop working the daemon. function is called if the daemon received a sigterm In this case...
static float parseVersionString(QString version)
static float ckbDaemonVersionF()
static const quint64 AUTO_CHECK_TIME
float _latestForBoard(const QString &features, bool waitForComplete)
static float ckbGuiVersionF()
enum KbFirmware::@1 hasGPG
bool setCurrentFile(const QString &fileName, CaseSensitivity cs=csDefault)
Sets current file by its name.
ZIP file is open for reading files inside it.
QMap< QString, FW > fwTable
static bool checkUpdates()
static QString tableName(const QString &features)
A file inside ZIP archive.
virtual bool open(OpenMode mode)
Opens a file for reading.
QNetworkReply * tableDownload
bool open(Mode mode, zlib_filefunc_def *ioApi=NULL)
Opens ZIP file.
QByteArray _fileForBoard(const QString &features)