-
Notifications
You must be signed in to change notification settings - Fork 4
/
mainwindow.cpp
200 lines (158 loc) · 5.14 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QFutureWatcher>
#include <QtConcurrent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
refTask(NULL)
{
ui->setupUi(this);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint);
setAcceptDrops(true);
ui->animation->initialize(":/img/animation/progress", 15, 3, 14);
ui->animation->setVisible(false);
if (!QFile::exists("..\\element"))
{
QMessageBox::critical(0, "INVALID PATH", "Sepertinya kamu salah extract, deh.\nKok gak ada folder 'element'?!!");
exit(EXIT_FAILURE);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {
move(event->globalPos() - dragPosition);
event->accept();
}
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent *event)
{
event->acceptProposedAction();
if (event->mimeData()->urls().count() != 1)
{
QMessageBox::warning(0, "ERROR", "Sabar kk, file patch nya satu - persatu yah...");
return;
}
QUrl url = event->mimeData()->urls().at(0);
if (!url.isLocalFile())
{
QMessageBox::critical(0, "NON LOCAL FILE", "URL IS NON LOCAL FILE");
return;
}
QString path = QDir::toNativeSeparators(url.toLocalFile());
if (!path.endsWith(".sempack"))
{
QMessageBox::critical(0, "INVALID FORMAT", "Sepertinya ini bukan file patch PWScarlet, deh");
return;
}
applyPatch(path);
}
void MainWindow::on_btnExit_clicked()
{
if (refTask && refTask->processId() != 0)
refTask->kill();
QApplication::quit();
}
void MainWindow::on_btnStart_clicked()
{
QStringList args;
args << "startbypatcher";
QProcess::startDetached("..\\element\\elementclient.exe", args, "..\\element\\");
QThread::sleep(3);
QApplication::quit();
}
void MainWindow::on_btnPatch_clicked()
{
QFileDialog dlg(this);
dlg.setAcceptMode(QFileDialog::AcceptOpen);
dlg.setFileMode(QFileDialog::ExistingFile);
dlg.setNameFilter("PWScarlet Patch (*.sempack)");
if (dlg.exec())
{
QString fileName = dlg.selectedFiles().at(0);
if (!fileName.endsWith(".sempack"))
{
QMessageBox::critical(0, "INVALID FORMAT", "Sepertinya ini bukan file patch PWScarlet, deh");
return;
}
applyPatch(fileName);
}
}
void MainWindow::applyPatch(const QString &fileName)
{
ui->btnPatch->setEnabled(false);
ui->btnStart->setEnabled(false);
ui->animation->start();
QFutureWatcher<void> *future = new QFutureWatcher<void>();
connect(future, &QFutureWatcher<void>::finished, [this,future]() {
ui->animation->stop();
ui->btnStart->setEnabled(true);
ui->btnPatch->setEnabled(true);
refTask = NULL;
future->deleteLater();
});
future->setFuture(QtConcurrent::run([=](const QString &fileName) {
QStringList args;
QProcess task; refTask = &task;
args << "x" << fileName << "-y" << "-o..\\";
task.start("bin\\7za.exe", args);
task.waitForFinished(-1);
args.clear(); args << "*.pck.b64.files";
QDir elementDir("..\\element");
QStringList packs = elementDir.entryList(args, QDir::Dirs);
for (int i = 0; i < packs.size(); i++)
{
QString source = packs.at(i).toLocal8Bit().constData();
QString dest = source.left(source.indexOf('.'));
QString pck = dest + ".pck";
QString pkx = dest + ".pkx";
QString originalWorkingDir = QDir::current().dirName();
QDir::setCurrent("..\\element");
if (QFile::exists(pkx))
{
// TODO: merge *.pck and *.pkx
args.clear(); args << "/c" << "copy" << "/b" << pck+"+"+pkx << pck;
task.start("cmd.exe", args);
task.waitForFinished(-1);
QFile::remove(pkx);
}
// TODO: merge source folder into *.pck
args.clear(); args << "-pw" << "-ap" << source;
task.start("bin\\sPCK.exe", args);
task.waitForFinished(-1);
// TODO: split *.pck into *.pkx
if (QFile(pck).size() > 2147483392)
{
args.clear(); args << pck << "2147483392";
task.start("bin\\split.exe", args);
task.waitForFinished(-1);
QFile::remove(pck);
QFile::rename(pck + ".1", pck);
QFile::rename(pck + ".2", pkx);
}
// TODO: delete source folder recursive
QDir(source).removeRecursively();
QDir::setCurrent(originalWorkingDir);
}
}, fileName));
}