-
Notifications
You must be signed in to change notification settings - Fork 2
/
modinstaller.cpp
85 lines (65 loc) · 2.3 KB
/
modinstaller.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
#include "modinstaller.h"
#include <QDir>
#include <QThread>
#include <QProgressDialog>
#include <QProgressBar>
Installer::Installer(QString src, QString dest, bool over) : source(src), destination(dest), overwrite(over)
{
}
void Installer::run()
{
QProgressDialog* progress = new QProgressDialog( tr("Installation, please wait...", "Installation progressbar text."), 0, 0, 0);
progress->setWindowModality(Qt::WindowModal);
progress->setMinimumWidth(250);
progress->setWindowFlags(Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
QProgressBar* bar = new QProgressBar();
bar->setTextVisible(false);
bar->setRange(0,0);
progress->setBar(bar);
progress->show();
connect(this, &Installer::finished, progress, &QProgressDialog::close);
connect(this, &Installer::finished, bar, &QProgressBar::deleteLater);
connect(this, &Installer::finished, progress, &QProgressDialog::deleteLater);
progress->show();
QThread* thread = new QThread;
moveToThread(thread);
connect(thread, &QThread::started, this, &Installer::startCopying);
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start();
}
void Installer::startCopying()
{
folderCopy(source, destination, overwrite);
emit finished();
}
// Some stuff from stackoverflow
bool Installer::folderCopy(QString src, QString dest, bool over)
{
QDir originDirectory(src);
if (! originDirectory.exists()) {
return false;
}
QDir destinationDirectory(dest);
if(destinationDirectory.exists() && !over) {
return false;
}
else if(destinationDirectory.exists() && over) {
destinationDirectory.removeRecursively();
}
originDirectory.mkpath(dest);
foreach (QString directoryName, originDirectory.entryList(QDir::Dirs | \
QDir::NoDotAndDotDot)) {
QString destinationPath = dest + "/" + directoryName;
originDirectory.mkpath(destinationPath);
folderCopy(src + "/" + directoryName, destinationPath, over);
}
foreach (QString fileName, originDirectory.entryList(QDir::Files)) {
QFile::copy(src + "/" + fileName, dest + "/" + fileName);
}
QDir finalDestination(destination);
finalDestination.refresh();
if(finalDestination.exists()) {
return true;
}
return false;
}