-
Notifications
You must be signed in to change notification settings - Fork 10
/
updater.cpp
executable file
·126 lines (116 loc) · 3.91 KB
/
updater.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "updater.h"
#include <QUrlQuery>
#include "aboutdialog.h"
Updater::Updater(QObject *parent) :
QObject(parent)
{
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
}
Updater::~Updater()
{
delete manager;
}
void Updater::checkForUpdates(void)
{
QNetworkRequest appUpdateCheckReq;
appUpdateCheckReq.setUrl(QUrl("https://omniedge.io/install/download/check_version.xml"));
manager->get(appUpdateCheckReq);
}
void Updater::showUpdateNotificationDialog()
{
INFO(tr("There is a new verision available (") + latestVersion + ")");
//Show update message
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Update available"));
msgBox.setIcon(QMessageBox::Information);
// QPushButton changelogBtn(tr("Changelog"));
#ifdef Q_OS_WIN
msgBox.addButton(QMessageBox::Yes);
msgBox.addButton(QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setText(tr("There's a new version ")+ latestVersion + (tr(" available.\n Do you want to update now?")));
#endif
connect(this, SIGNAL(updateDialogsRejected()), &msgBox, SLOT(reject()));
int selection = msgBox.exec();
if(selection == QMessageBox::Yes)
{
DownloadUpdateDialog dialog;
dialog.startDownload(latestVersion);
dialog.exec();
}
}
void Updater::showNoUpdateNotificationDialog()
{
//Show no update message
QMessageBox msgBox;
msgBox.setWindowTitle(tr("No Update"));
msgBox.setIcon(QMessageBox::Information);
msgBox.addButton(QMessageBox::Yes);
msgBox.setText(tr("Congrats! You are using the latest version."));
msgBox.exec();
}
void Updater::rejectNotificationDialogs()
{
Q_EMIT updateDialogsRejected();
}
void Updater::showChangelog()
{
// ChangelogDialog changelog;
// connect(this, SIGNAL(updateDialogsRejected()), &changelog, SLOT(reject()));
// changelog.exec();
}
void Updater::progressUpdate(int)
{
Q_EMIT updateProgessRange(0, numPluginsUpdating * 4);
}
void Updater::replyFinished(QNetworkReply *reply)
{
QString replyText = reply->readAll();
if(reply->error() != QNetworkReply::NoError)
{
//Parse servers response
QDomDocument doc("error");
if (!doc.setContent(replyText)) {
//No XML to parse, user is probably disconnected
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Failed to check for updates"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(tr("Check version XML response ERROR!"));
msgBox.exec();
}else
{
QDomElement docElem = doc.documentElement();
QDomElement message = docElem.firstChildElement("message");
if(!message.text().isEmpty())
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Failed to check for updates"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(tr("Failed to check for updates.\nError was: ") + message.text());
msgBox.exec();
}
}
}else
{
//This is check_version.xml
QDomDocument doc("reply");
if (!doc.setContent(replyText)) {
return;
}
QDomElement docElem = doc.documentElement();
QDomElement versionElem = docElem.firstChildElement("current_version");
QDomElement outdatedElem = docElem.firstChildElement("outdated");
latestVersion = versionElem.text();
bool outdated = QVariant(outdatedElem.text()).toBool();
if(outdated && ( QString::compare(latestVersion, APPVERSION ) > 0 ))
{
showUpdateNotificationDialog();
}
else
{
showNoUpdateNotificationDialog();
}
}
}