forked from Feeling97/t411ClientInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.cpp
781 lines (706 loc) · 28.7 KB
/
installer.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
/* This file is part of t411 Client Installer.
t411 Client Installer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
t411 Client Installer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with t411 Client Installer. If not, see <http://www.gnu.org/licenses/>. */
#include "installer.h"
Installer::Installer(MainWindow *argparent, QString argos) : QObject(argparent)
{
parent = argparent;
os = argos;
etape = 0;
isDownloaded = false;
isInstalled = false;
readyToInstall = false;
readyToConfig = false;
finished = false;
port = 50500;
QSettings regAccess("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", QSettings::NativeFormat);
downloadsPath = regAccess.value("{374DE290-123F-4565-9164-39C4925E467B}", QProcessEnvironment::systemEnvironment().value("USERPROFILE") + "/Downloads").toString();
if (!QDir(downloadsPath).exists())
QDir(downloadsPath).mkdir(downloadsPath);
torrentsPath = downloadsPath + "/Torrents";
if (!QDir(torrentsPath).exists())
QDir(torrentsPath).mkdir(torrentsPath);
connect(this, SIGNAL(finishedStage()), this, SLOT(doNextStage()), Qt::QueuedConnection);
connect(this, SIGNAL(setupConfig()), this, SLOT(makeConfig()), Qt::QueuedConnection);
options = new Options(this);
QPixmap t411(":/images/t411.png");
t411label = new QLabel;
t411label->setObjectName("t411label");
t411label->setPixmap(t411);
logolabel = new AboutLabel;
FileDownloader test;
if (!test.isConnected())
{
QMessageBox::critical(parent, "Erreur", "Vous n'êtes actuellement pas connecté à Internet<br />Veuillez vous connecter puis relancer le programme");
exit(1);
}
}
Installer::~Installer() {}
QGridLayout* Installer::nextStage(int incetape)
{
etape = etape + incetape;
QGridLayout *layout = new QGridLayout;
layout->addWidget(logolabel, 0, 0, 0, 0, Qt::AlignTop);
layout->addWidget(t411label, 0, 0, 0, 0, Qt::AlignRight | Qt::AlignTop);
if (etape == 0) // Choix du client
{
QVBoxLayout *centerlayout = new QVBoxLayout;
QVBoxLayout *boxlayout = new QVBoxLayout;
chosedClient = new QGroupBox("Choisissez le client que vous voulez installer :", parent);
utorrentButton = new QRadioButton("µTorrent 2.2.1", chosedClient);
qbittorrentButton = new QRadioButton("qBittorrent", chosedClient);
vuzeButton = new QRadioButton("Vuze", chosedClient);
delugeButton = new QRadioButton("Deluge", chosedClient);
if (client == "µTorrent 2.2.1")
utorrentButton->setChecked(true);
else if (client == "qBittorrent")
qbittorrentButton->setChecked(true);
else if (client == "Vuze")
vuzeButton->setChecked(true);
else if (client == "Deluge")
delugeButton->setChecked(true);
if (!(os == "Windows 8" || os == "Windows 8.1" || os == "Windows"))
boxlayout->addWidget(utorrentButton, Qt::AlignVCenter);
else
delete utorrentButton;
boxlayout->addWidget(qbittorrentButton, Qt::AlignVCenter);
boxlayout->addWidget(vuzeButton, Qt::AlignVCenter);
boxlayout->addWidget(delugeButton, Qt::AlignVCenter);
chosedClient->setLayout(boxlayout);
centerlayout->addWidget(chosedClient);
centerlayout->addStretch();
QPushButton *advancedOptions = new QPushButton("Avancé");
connect(advancedOptions, SIGNAL(released()), this, SLOT(openOptions()));
centerlayout->addWidget(advancedOptions);
centerlayout->setContentsMargins(0, 100, 0, 0);
layout->addLayout(centerlayout, 0, 0, 0, 0, Qt::AlignVCenter);
connect(utorrentButton, SIGNAL(released()), this, SLOT(clientChanged()));
connect(qbittorrentButton, SIGNAL(released()), this, SLOT(clientChanged()));
connect(vuzeButton, SIGNAL(released()), this, SLOT(clientChanged()));
connect(delugeButton, SIGNAL(released()), this, SLOT(clientChanged()));
}
else if (etape == 1) { // Etape 1: Présentation
QVBoxLayout *centerlayout = new QVBoxLayout;
QLabel *text = new QLabel("Ce programme va installer " + client + " pour " + os + " avec la configuration recommandée pour <a href=\"http://www.t411.io/\">t411.io</a><br /><br />"
"Configuration recommandée :"
"<ul>"
"<li>Port " + QString::number(port) + "</li>"
"<li>DHT/Recherche locale de pairs desactivée</li>"
"<li>Mises à jour automatiques désactivées</li>"
"<li>Aucune limite d'envoi et de réception</li>"
"<li>Pré-allocation de l'espace disque pour les nouveaux fichiers</li>"
"<li>Cryptage des échanges forcé</li>"
"</ul>");
text->setTextFormat(Qt::RichText);
text->setTextInteractionFlags(Qt::TextBrowserInteraction);
text->setOpenExternalLinks(true);
centerlayout->addWidget(text);
centerlayout->setContentsMargins(0, 100, 0, 0);
centerlayout->addStretch();
QPushButton *goToChoice = new QPushButton("Autres options");
centerlayout->addWidget(goToChoice, Qt::AlignCenter);
connect(goToChoice, SIGNAL(released()), this, SLOT(goToChoice()));
layout->addLayout(centerlayout, 0, 0, 0, 0, Qt::AlignVCenter);
parent->enableNext();
}
else if (etape == 2) { // Etape 2: Téléchargement
QVBoxLayout *centerlayout = new QVBoxLayout;
QProgressBar *dbar = new QProgressBar;
centerlayout->addWidget(new QLabel("Téléchargement de " + client + "..."));
if (!isDownloaded)
{
QUrl fileUrl;
if (client == "qBittorrent")
fileUrl.setUrl("http://88.198.168.163/logiciels/qbittorrent_3.1.11_setup.exe");
else if (client == "µTorrent 2.2.1")
fileUrl.setUrl("http://88.198.168.163/logiciels/2-2-1-build-25130-utorrent.exe");
else if (client == "Vuze")
fileUrl.setUrl("http://tuxange.org/t411ClientInstaller/installs/VuzeInstaller.exe");
else if (client == "Deluge")
fileUrl.setUrl("http://88.198.168.163/logiciels/deluge-1.3.5-win32-setup.exe");
else
{
QMessageBox::critical(parent, "Erreur", "Impossible de déterminer le lien de téléchargement de " + client + " pour " + os);
qApp->quit();
}
fileDownload = new FileDownloader(fileUrl, this);
filePath = qApp->applicationDirPath();
filePath += "/setup.exe";
connect(fileDownload, SIGNAL(downloaded()), this, SLOT(saveDownloadedFile()));
dbar->setValue(0);
}
else
{
isDownloaded = false;
finished = true;
dbar->setValue(33);
}
centerlayout->addWidget(dbar);
layout->addLayout(centerlayout, 0, 0, 0, 0, Qt::AlignCenter);
}
else if (etape == 3) { // Etape 3: Installation du client
QVBoxLayout *centerlayout = new QVBoxLayout;
QProgressBar *dbar = new QProgressBar;
centerlayout->addWidget(new QLabel("Installation de " + client + "..."));
if (!isInstalled)
{
if (client == "qBittorrent" || client == "Deluge")
{
killProcessByName(QString(client + ".exe").toLower().toUtf8().data());
QProcess *setup = new QProcess(this);
QStringList args;
args << "/S";
setup->start(qApp->applicationDirPath() + "/setup.exe", args);
connect(setup, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishedSetup(int, QProcess::ExitStatus)));
dbar->setValue(33);
}
else if (client == "Vuze")
{
killProcessByName("Azureus.exe");
QProcess *setup = new QProcess(this);
QStringList args;
args << "-q" << "-overwrite";
setup->start(qApp->applicationDirPath() + "/setup.exe", args);
connect(setup, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishedSetup(int, QProcess::ExitStatus)));
dbar->setValue(33);
}
else if (client == "µTorrent 2.2.1")
{
if (readyToInstall)
{
QString target = QProcessEnvironment::systemEnvironment().value("ProgramFiles");
if (target.isEmpty())
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Impossible d'accéder à la variable d'environnement %ProgramFiles%");
qApp->quit();
}
if (!QDir(target + "/uTorrent").exists()) { QDir().mkdir(target + "/uTorrent"); }
if (!QDir(QProcessEnvironment::systemEnvironment().value("AppData") + "/uTorrent").exists()) { QDir().mkdir(QProcessEnvironment::systemEnvironment().value("AppData") + "/uTorrent"); }
if (QFile(target + "/uTorrent/uTorrent.exe").exists()) { QFile::remove(target + "/uTorrent/uTorrent.exe"); }
copy(qApp->applicationDirPath() + "/setup.exe", target + "/uTorrent/uTorrent.exe");
QTimer::singleShot(50, this, SLOT(finishedSetup()));
dbar->setValue(33);
}
else
{
killProcessByName("uTorrent.exe");
QTimer::singleShot(2000, this, SLOT(installuTorrent()));
dbar->setValue(33);
}
}
else
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Contactez Feeling97 en indiquant votre OS et le client choisi");
qApp->quit();
}
}
else
{
dbar->setValue(66);
finished = true;
}
centerlayout->addWidget(dbar);
layout->addLayout(centerlayout, 0, 0, 0, 0, Qt::AlignCenter);
}
else if (etape == 4) { // Etape 4: Installation de la config
QVBoxLayout *centerlayout = new QVBoxLayout;
QProgressBar *dbar = new QProgressBar;
centerlayout->addWidget(new QLabel("Installation de la configuration recommandée pour " + client + "..."));
if (client == "qBittorrent")
{
QString target = QProcessEnvironment::systemEnvironment().value("AppData");
if (target.isEmpty())
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Impossible d'accéder à la variable d'environnement %AppData%");
qApp->quit();
}
target += "/qBittorrent";
configPath = target + "/qBittorrent.ini";
if (!readyToConfig)
{
bool replaceConfig = true;
if (QFile::exists(configPath))
{
if (!wannaReplace())
{
replaceConfig = false;
dbar->setValue(100);
finished = true;
}
}
if (replaceConfig)
{
killProcessByName("qBittorrent.exe");
QTimer::singleShot(2000, this, SLOT(installConfig()));
dbar->setValue(66);
}
}
else if (!isDownloaded)
{
if (!QDir(target).exists())
QDir().mkdir(target);
rename(configPath, target + "/qBittorrent.bak.ini");
QUrl fileUrl;
fileUrl.setUrl("http://tuxange.org/t411ClientInstaller/dynConfigs/qBittorrent.ini");
fileDownload = new FileDownloader(fileUrl, this);
filePath = configPath;
connect(fileDownload, SIGNAL(downloaded()), this, SLOT(saveDownloadedFile()));
dbar->setValue(66);
}
else
{
emit setupConfig();
dbar->setValue(100);
finished = true;
}
}
else if (client == "µTorrent 2.2.1")
{
QString target = QProcessEnvironment::systemEnvironment().value("AppData");
if (target.isNull())
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Impossible d'accéder à la variable d'environnement %AppData%");
qApp->quit();
}
target += "/uTorrent";
configPath = target + "/settings.dat";
if (!readyToConfig)
{
bool replaceConfig = true;
if (QFile::exists(configPath))
{
if (!wannaReplace())
{
replaceConfig = false;
dbar->setValue(100);
finished = true;
}
}
if (replaceConfig)
{
copy(target + "/resume.dat", target + "/resume.bak.dat");
killProcessByName("uTorrent.exe");
QTimer::singleShot(2000, this, SLOT(installConfig()));
dbar->setValue(66);
}
}
else if (!isDownloaded)
{
if (!QDir(target).exists())
QDir().mkdir(target);
remove(target + "/resume.dat");
rename(target + "/resume.bak.dat", target + "/resume.dat");
rename(configPath, target + "/settings.bak.dat");
rename(target + "/settings.dat.old", target + "/settings.bak.dat.old");
QUrl fileUrl;
fileUrl.setUrl("http://tuxange.org/t411ClientInstaller/dynConfigs/uTorrent.dat");
fileDownload = new FileDownloader(fileUrl, this);
filePath = configPath;
connect(fileDownload, SIGNAL(downloaded()), this, SLOT(saveDownloadedFile()));
dbar->setValue(66);
}
else
{
emit setupConfig();
dbar->setValue(100);
finished = true;
}
}
else if (client == "Vuze")
{
QString target = QProcessEnvironment::systemEnvironment().value("AppData");
if (target.isEmpty())
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Impossible d'accéder à la variable d'environnement %AppData%");
qApp->quit();
}
target += "/Azureus";
configPath = target + "/azureus.config";
if (!readyToConfig)
{
bool replaceConfig = true;
if (QFile::exists(configPath))
{
if (!wannaReplace())
{
replaceConfig = false;
dbar->setValue(100);
finished = true;
}
}
if (replaceConfig)
{
killProcessByName("Azureus.exe");
QTimer::singleShot(2000, this, SLOT(installConfig()));
dbar->setValue(66);
}
}
else if (!isDownloaded)
{
if (!QDir(target).exists())
QDir().mkdir(target);
rename(configPath, target + "/azureus.bak.config");
QUrl fileUrl;
fileUrl.setUrl("http://tuxange.org/t411ClientInstaller/dynConfigs/Vuze.config");
fileDownload = new FileDownloader(fileUrl, this);
filePath = configPath;
connect(fileDownload, SIGNAL(downloaded()), this, SLOT(saveDownloadedFile()));
dbar->setValue(66);
}
else
{
emit setupConfig();
dbar->setValue(100);
finished = true;
}
}
else if (client == "Deluge")
{
QString target = QProcessEnvironment::systemEnvironment().value("AppData");
if (target.isEmpty())
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Impossible d'accéder à la variable d'environnement %AppData%");
qApp->quit();
}
target += "/deluge";
configPath = target + "/core.conf";
if (!readyToConfig)
{
bool replaceConfig = true;
if (QFile::exists(configPath))
{
if (!wannaReplace())
{
replaceConfig = false;
dbar->setValue(100);
finished = true;
}
}
if (replaceConfig)
{
killProcessByName("deluge.exe");
QTimer::singleShot(2000, this, SLOT(installConfig()));
dbar->setValue(66);
}
}
else if (!isDownloaded)
{
if (!QDir(target).exists())
QDir().mkdir(target);
rename(configPath, target + "/core.bak.conf");
QUrl fileUrl;
fileUrl.setUrl("http://tuxange.org/t411ClientInstaller/dynConfigs/Deluge.conf");
fileDownload = new FileDownloader(fileUrl, this);
filePath = configPath;
connect(fileDownload, SIGNAL(downloaded()), this, SLOT(saveDownloadedFile()));
dbar->setValue(66);
}
else
{
emit setupConfig();
dbar->setValue(100);
finished = true;
}
}
else
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Contactez Feeling97 en indiquant votre OS et le client que le programme vous conseille");
qApp->quit();
}
centerlayout->addWidget(dbar);
layout->addLayout(centerlayout, 0, 0, 0, 0, Qt::AlignCenter);
}
else if (etape == 5) { // Etape 5: Fin
QVBoxLayout *centerlayout = new QVBoxLayout;
launchClient = new QCheckBox("Lancer " + client + " à la fermeture", parent);
createLink = new QCheckBox("Créer un raccourci pour " + client + " sur le bureau", parent);
launchClient->setChecked(true);
createLink->setChecked(true);
centerlayout->addWidget(new QLabel(client + " pour " + os + " est maintenant installé avec sa configuration recommandée"));
centerlayout->addWidget(launchClient);
if (client == "Vuze" || client == "Deluge")
createLink->setChecked(false);
else
centerlayout->addWidget(createLink);
layout->addLayout(centerlayout, 0, 0, 0, 0, Qt::AlignVCenter);
remove(qApp->applicationDirPath() + "/setup.exe");
parent->enableFinish();
}
if (etape < 5 && finished)
{
finished = false;
emit finishedStage();
}
if (etape > 1)
parent->disableQuit();
return layout;
}
void Installer::determineClient()
{
if (os == "Windows 8.1" || os == "Windows 8" || os == "Windows")
client = "qBittorrent";
else
client = "µTorrent 2.2.1";
}
void Installer::setOption(QString name, QVariant value)
{
if (name == "port")
port = value.toInt();
else if (name == "files")
downloadsPath = value.toString();
else
torrentsPath = value.toString();
}
QString Installer::getOption(QString name)
{
if (name == "port")
return QString::number(port);
else if (name == "files")
return QDir::toNativeSeparators(downloadsPath);
else
return QDir::toNativeSeparators(torrentsPath);
}
void Installer::makeConfig()
{
QFile *configFile = new QFile(configPath);
if (!configFile->open(QIODevice::ReadOnly))
{
QMessageBox::critical(parent, "Erreur", "Impossible de lire le fichier de configuration<br />" + configPath + "<br />Erreur : " + configFile->errorString());
qApp->quit();
}
QByteArray configBinary = configFile->readAll();
QByteArray dPath;
QByteArray tPath;
if (client == "µTorrent 2.2.1" || client == "Vuze")
{
dPath.append(downloadsPath.length() + ":" + QDir::toNativeSeparators(downloadsPath));
tPath.append(torrentsPath.length() + ":" + QDir::toNativeSeparators(torrentsPath));
configBinary.replace(QByteArray::number(50500), QByteArray::number(port));
configBinary.replace("13:DOWNLOADSHERE", dPath);
configBinary.replace("12:TORRENTSHERE", tPath);
}
else
{
dPath.append(QDir::toNativeSeparators(downloadsPath));
tPath.append(QDir::toNativeSeparators(torrentsPath));
configBinary.replace("PORTHERE", QByteArray::number(port));
configBinary.replace("DOWNLOADSHERE", dPath);
configBinary.replace("TORRENTSHERE", tPath);
}
configFile->close();
if (!configFile->open(QIODevice::WriteOnly | QIODevice::Truncate))
{
QMessageBox::critical(parent, "Erreur", "Impossible d'écrire dans le fichier de configuration<br />" + configPath + "<br />Erreur : " + configFile->errorString());
qApp->quit();
}
configFile->write(configBinary);
configFile->close();
}
void Installer::doRefreshLayout(QGridLayout *newlayout)
{
emit refreshLayout(newlayout);
}
void Installer::doNextStage(int incetape)
{
doRefreshLayout(nextStage(incetape));
}
void Installer::goToChoice()
{
doNextStage(-1);
}
void Installer::clientChanged()
{
if (utorrentButton->isChecked())
client = "µTorrent 2.2.1";
else if (qbittorrentButton->isChecked())
client = "qBittorrent";
else if (vuzeButton->isChecked())
client = "Vuze";
else if (delugeButton->isChecked())
client = "Deluge";
else
{
QMessageBox::critical(parent, "Erreur", "Imposible de mémoriser le client à installer");
qApp->quit();
}
}
void Installer::openOptions()
{
options->open();
}
bool Installer::wannaReplace()
{
QMessageBox wannaReplace(QMessageBox::Question, "Remplacer", "Une configuration existe déjà pour " + client + " pour " + os + "<br />Voulez-vous la remplacer ?<br />Il est conseillé de la remplacer sauf si vous savez ce que vous faites", QMessageBox::Yes | QMessageBox::No);
wannaReplace.setButtonText(QMessageBox::Yes, "Oui");
wannaReplace.setButtonText(QMessageBox::No, "Non");
wannaReplace.setDefaultButton(QMessageBox::Yes);
if (wannaReplace.exec() == QMessageBox::Yes)
return true;
else
return false;
}
void Installer::saveDownloadedFile()
{
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::critical(parent, "Erreur", "Impossible d'écrire dans le fichier <br />" + filePath + "<br />\
Erreur : " + file.errorString());
qApp->quit();
}
QDataStream out(&file);
out.writeRawData(fileDownload->downloadedData().data(), fileDownload->downloadedData().length());
isDownloaded = true;
doNextStage(0);
}
void Installer::finishedSetup()
{
isInstalled = true;
doNextStage(0);
}
void Installer::finishedSetup(int code, QProcess::ExitStatus status)
{
(void)code; // Ne fait rien, enlève juste le warning de variable inutilisée
if (status == QProcess::NormalExit)
{
if (client == "Vuze")
killProcessByName("Azureus.exe");
isInstalled = true;
doNextStage(0);
}
else
{
QMessageBox::critical(parent, "Erreur", "Une erreur est survenue pendant l'installation de " + client + " pour " + os + "<br />\
Vous pouvez demander de l'aide <a href=\"http://forum.t411.io/categories/info/\">sur le forum</a>");
qApp->quit();
}
}
void Installer::installuTorrent()
{
readyToInstall = true;
doNextStage(0);
}
void Installer::installConfig()
{
readyToConfig = true;
doNextStage(0);
}
void Installer::pressedFinish()
{
if (launchClient->isChecked())
{
QProcess *clientProcess = new QProcess;
QString path = client;
QString exeName = client;
if (client == "µTorrent 2.2.1")
{
path = "uTorrent";
exeName = "uTorrent";
}
else if (client == "Vuze")
{
exeName = "Azureus";
if (QDir(QProcessEnvironment::systemEnvironment().value("ProgramFiles") + "/Vuze").exists())
path = QProcessEnvironment::systemEnvironment().value("ProgramFiles") + "/Vuze";
else
{
path = QProcessEnvironment::systemEnvironment().value("ProgramFiles");
path.chop(6);
path += "/Vuze";
}
clientProcess->startDetached(QDir::toNativeSeparators(path + "/" + exeName + ".exe"), QStringList());
}
else if (client == "Deluge")
exeName = "deluge";
clientProcess->startDetached(QDir::toNativeSeparators(QProcessEnvironment::systemEnvironment().value("ProgramFiles") + "/" + path + "/" + exeName + ".exe"), QStringList());
}
if (createLink->isChecked())
{
if (client == "µTorrent 2.2.1")
QFile::link(QDir::toNativeSeparators(QProcessEnvironment::systemEnvironment().value("ProgramFiles") + "/uTorrent/uTorrent.exe"), QDir::toNativeSeparators(QProcessEnvironment::systemEnvironment().value("UserProfile") + "/Desktop/µTorrent.lnk"));
else if (client == "qBittorrent")
QFile::link(QDir::toNativeSeparators(QProcessEnvironment::systemEnvironment().value("ProgramFiles") + "/qBittorrent/qBittorrent.exe"), QDir::toNativeSeparators(QProcessEnvironment::systemEnvironment().value("UserProfile") + "/Desktop/" + client + ".lnk"));
}
qApp->quit();
}
void Installer::copy(QString argsource, QString argtarget)
{
argsource = QDir::toNativeSeparators(argsource);
argtarget = QDir::toNativeSeparators(argtarget);
if (QFile::exists(argsource))
{
if (QFile::copy(argsource, argtarget))
return;
else
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Avez-vous les droits d'accès à <br />" + argtarget + " ?");
qApp->quit();
}
}
}
void Installer::rename(QString argsource, QString argtarget)
{
argsource = QDir::toNativeSeparators(argsource);
argtarget = QDir::toNativeSeparators(argtarget);
if (QFile::exists(argsource))
{
if (QFile::rename(argsource, argtarget))
return;
else if (QFile::remove(argtarget) && QFile::rename(argsource, argtarget))
return;
else
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Avez-vous les droits d'accès à <br />" + argtarget + " ?");
qApp->quit();
}
}
}
void Installer::remove(QString argfile)
{
argfile = QDir::toNativeSeparators(argfile);
if (QFile::exists(argfile))
{
if (QFile::remove(argfile))
return;
else
{
QMessageBox::critical(parent, "Erreur", "Impossible d'installer " + client + " pour " + os + "<br />Avez-vous les droits d'accès à <br />" + argfile + " ?");
qApp->quit();
}
}
}
void Installer::killProcessByName(const char *filename)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof (pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
char mbstr[128];
std::wcstombs(mbstr, pEntry.szExeFile, 128);
if (strcmp(mbstr, filename) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0, (DWORD) pEntry.th32ProcessID);
if (hProcess != NULL)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
}
MainWindow* Installer::getParent()
{
return parent;
}