-
Notifications
You must be signed in to change notification settings - Fork 4
/
protocol_fu.cpp
58 lines (44 loc) · 1.54 KB
/
protocol_fu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <QVector>
#include <QJsonDocument>
#include <QJsonObject>
#include "protocol_fu.h"
Protocol_FU::Protocol_FU(int currentVersion, const QByteArray &msg)
{
QJsonDocument doc = QJsonDocument::fromJson(msg);
if(doc.isNull() || !doc.isObject())
return;
QJsonObject mainObj = doc.object();
if(mainObj.isEmpty() || !mainObj.contains("versions"))
return;
if(mainObj.contains(_keys.programName))
_programName = mainObj.value(_keys.programName).toString();
if(mainObj.contains(_keys.actualVersion))
_beautyVersion = mainObj.value(_keys.actualVersion).toString();
QJsonObject versionsObj = mainObj.value("versions").toObject();
QVector<int> versSortList;
for(QString k : versionsObj.keys())
{
int version = k.toInt();
if(currentVersion < version)
versSortList << k.toInt();
}
qSort(versSortList);
for(int v : versSortList)
{
_version = v;
QJsonObject itemObj = versionsObj.value(QString::number(v)).toObject();
if(itemObj.contains(_keys.desc))
_description += itemObj.value(_keys.desc).toString();
if(itemObj.contains(_keys.updateFiles))
{
QJsonObject urlListObj = itemObj.value(_keys.updateFiles).toObject();
for(QString key : urlListObj.keys())
{
QString url = urlListObj.value(key).toString().trimmed();
if(!url.isEmpty())
_fileNameUrlList.insert(key, url);
}
}
}
_isValid = true;
}