-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupdate.cpp
More file actions
92 lines (82 loc) · 2.46 KB
/
update.cpp
File metadata and controls
92 lines (82 loc) · 2.46 KB
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
#include "widget.hpp"
void Window::updateReplyFinished(QNetworkReply *resp){
bool ok;
int code = resp->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
try
{
if(code == 200 && ok)
{
QByteArray buffer = resp->read(20971520);
float latestVersion = buffer.toFloat(&ok);
if(ok)
{
float currentVersion = appVersion.toFloat(&ok);
if(ok)
{
if(latestVersion > currentVersion)
{
goForUpdate(latestVersion);
}
else
{
return;
}
}
else
{
throw 1; // Ficher de version invalide
}
}
else
{
throw 2; // Dernière version invalide
}
}
else
{
throw 3; // Le fichier de la dernière version est indisponible
}
}
catch(const int err)
{
QMessageBox msgBox;
msgBox.setWindowIcon(QIcon(QDir::currentPath() + "/img/icon.png"));
switch(err)
{
case 1:
msgBox.setText("Le fichier de version est invalide, veuillez retélécharger l'application.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
break;
case 2:
msgBox.setText("La dernière version est invalide, veuillez avertir un administrateur.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
break;
case 3:
msgBox.setText("Le fichier contenant le tag de la dernière version est inaccessible.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
break;
}
return;
}
return;
}
void Window::goForUpdate(float newVersion)
{
QMessageBox msgBox;
msgBox.setWindowIcon(QIcon(QDir::currentPath() + "/img/icon.png"));
msgBox.setText("La nouvelle version " + QString::number(newVersion) + " est disponible !");
msgBox.setInformativeText("Voulez vous l'installer ?");
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if(ret == QMessageBox::No)
return;
QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath() + "/Update.bat"));
qApp->exit(0);
}