-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.cpp
executable file
·123 lines (96 loc) · 3.84 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
#include "updater.h"
#include "ui_updater.h"
updater::updater(QWidget *parent) :
QWidget(parent),
ui(new Ui::updater)
{
logThread::addLog("Constructor of updater attack GUI", logInfo::MAIN);
ui->setupUi(this);
//connect button check updates
connect(this->ui->pushButtonCheckUpdates, SIGNAL(clicked()), this, SLOT(checkUpdates()));
//connect to download
connect(this->ui->pushButtonDownload, SIGNAL(clicked()), this, SLOT(downloadUpdate()));
//connect to show the window when update is available
connect(this, SIGNAL(updateAvailable()), this, SLOT(show()));
}
updater::~updater()
{
logThread::addLog("Destructor of updater attack GUI", logInfo::MAIN);
delete ui;
}
void updater::downloadUpdate()
{
QDesktopServices::openUrl(QUrl("http://code.google.com/p/aircrackgui-m4/downloads/list"));
}
void updater::checkUpdates(){
logThread::addLog("Updater: checking for updates", logInfo::MAIN);
QFile::remove("index.html");
this->ui->textEditLog->clear();
//move cursor to end
this->ui->textEditLog->moveCursor(QTextCursor::End);
//getting current version
this->ui->lineEditCurrentVersion->setText(VERSION);
//getting latest version
QProcess p;
p.start("wget http://code.google.com/p/aircrackgui-m4/");
if (!p.waitForFinished(5000)) {
this->ui->textEditLog->append(utils::htmlRojo("Imposible to execute correctly wget to update"));
return;
}
QFile f("index.html");
if (!f.open(QIODevice::ReadOnly)) {
this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
return;
}
QString pageText = f.readAll();
f.close();
int preIndex = pageText.indexOf("[{-]");
if (preIndex == -1) {
this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
return;
}
pageText.remove(preIndex, 4);
int postIndex = pageText.indexOf("[-}]");
if (postIndex == -1) {
this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
return;
}
//set latest version
this->ui->lineEditLatestVersion->setText(pageText.mid(preIndex, postIndex-preIndex).replace('_', ' '));
//getting changelog
preIndex = pageText.indexOf("[*CHANGELOG*]");
if (preIndex == -1) {
this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
return;
}
pageText.remove(preIndex, 13);
postIndex = pageText.indexOf("[/*CHANGELOG*]");
if (postIndex == -1) {
this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
return;
}
const QString changelog = pageText.mid(preIndex, postIndex-preIndex);
//UPDATED?
//yes
if (this->ui->lineEditCurrentVersion->text().remove(' ')
== this->ui->lineEditLatestVersion->text().remove(' ')) {
if (this->isVisible())
this->ui->textEditLog->append(utils::htmlVerde("Program is Up-To-Date"));
}
//no
else {
emit updateAvailable();
this->ui->textEditLog->append(utils::htmlVerde("*****************************"));
this->ui->textEditLog->append(utils::htmlVerde("UPDATE AVAILABLE"));
this->ui->textEditLog->append(utils::htmlVerde("*****************************"));
//enabling download button
this->ui->pushButtonDownload->setEnabled(true);
}
//anyway showing changelog
this->ui->textEditLog->append(utils::htmlVerde("\n-----------------------------"));
this->ui->textEditLog->append(utils::htmlVerde("Changelog"));
this->ui->textEditLog->append(utils::htmlVerde("-----------------------------"));
this->ui->textEditLog->append(changelog);
//move cursor to start
this->ui->textEditLog->moveCursor(QTextCursor::Start);
}