-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.cpp
60 lines (52 loc) · 2.08 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
#include "updater.h"
Updater::Updater(){
manager = new QNetworkAccessManager(this);
//Timer to download signatures every ten seconds.
fileDownloader = new QTimer();
connect(fileDownloader, SIGNAL(timeout()), this, SLOT(downloadSignatures()));
fileDownloader->start(10000);
}
void Updater::replyFinished(){
//qDebug() << networkResponse;
}
//Get the data size
void Updater::slotReadyRead(){
incomingDataSize = static_cast<int>(networkResponse->size());
}
void Updater::updateDownloadProgress(qint64 bytesRead, qint64 bytesTotal){
emit state("Downloading");
emit currentProgress(bytesRead, bytesTotal);
}
//Process the data and write to file
void Updater::processIncomingData(){
emit dataSize(incomingDataSize);
QFile file("C:/Program Files/Naoris_Antivirus/signatures/viruslist.txt");
if (file.open(QIODevice::WriteOnly)){
int size = 0;
while(size <= incomingDataSize){
QTextStream out(&file);
out << networkResponse->readLine(256);
//qDebug() << networkResponse->readLine(256);
size += 256;
emit currentProgressFiles(size);
emit state("Installing");
if(size >= incomingDataSize){
emit currentProgressFiles(incomingDataSize);
emit state("Complete");
}
}
}else{
qDebug() << "File Error";
return;
}
}
void Updater::downloadSignatures(){
//These links were returning the html and not the text list on the page
//request.setUrl(QUrl("http://filesamples.com/samples/document/txt/sample3.txt"));
//request.setUrl(QUrl("http://manubrial-hour.000webhostapp.com/viruslist.txt"));
request.setUrl(QUrl("http://25.io/toau/audio/sample.txt"));
networkResponse = manager->get(request);
connect(networkResponse, &QNetworkReply::finished, this, &Updater::processIncomingData);
connect(networkResponse, &QIODevice::readyRead, this, &Updater::slotReadyRead);
connect(networkResponse, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64)));
}