-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
134 lines (120 loc) · 4.92 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
#include "mainwindow.h"
#include "include/bsdifflib/bsdifflib.h"
#include "include/bsdifflib/bspatchlib.h"
#include "ui_mainwindow.h"
#include <QCoreApplication>
#include <QMessageBox>
static QString *create_sourceFilePath = new QString();
static QString *create_newFilePath = new QString();
static QString *create_patchFilePath = new QString();
static QString *apply_oldFilePath = new QString();
static QString *apply_patchFilePath = new QString();
static QString *apply_newFilePath = new QString();
static Page_Elements *createElements = new Page_Elements();
static Page_Elements *applyElements = new Page_Elements();
void clickFileDialogButton(MainWindow *w, bool existingFile, QLabel *label,
QString *path) {
QFileDialog dialog(w);
if (existingFile)
dialog.setFileMode(QFileDialog::ExistingFile);
else
dialog.setFileMode(QFileDialog::AnyFile);
if (dialog.exec())
*path = dialog.selectedFiles()[0];
label->setText(*path);
}
void initCreatePatch(QString *oldPath, QString *newPath, QString *patchPath) {
QMessageBox res;
char *errs =
bsdiff(oldPath->toUtf8(), newPath->toUtf8(), patchPath->toUtf8());
if (errs)
res.setText(errs);
else
res.setText(patchPath->toUtf8() + " created successfully!");
res.exec();
}
void initApplyPatch(QString *oldPath, QString *newPath, QString *patchPath) {
QMessageBox res;
char *errs =
bspatch(oldPath->toUtf8(), newPath->toUtf8(), patchPath->toUtf8());
if (errs)
res.setText(errs);
else
res.setText(newPath->toUtf8() + " created successfully!");
res.exec();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
// set about page label
QLabel *aboutLabel = this->findChild<QLabel *>("aboutLabel");
aboutLabel->setOpenExternalLinks(true);
aboutLabel->setText(
"<a href=\"https://github.com/Raflos10/PatchGUI \">PatchGUI Utility</a>");
// assign pointer elements (create)
createElements->oldFileButton =
findChild<QPushButton *>("create_sourceFileButton");
createElements->newFileButton =
findChild<QPushButton *>("create_newFileButton");
createElements->patchFileButton =
findChild<QPushButton *>("create_patchFileButton");
createElements->initButton = findChild<QPushButton *>("create_initButton");
createElements->oldFileLabel = findChild<QLabel *>("create_sourceFileLabel");
createElements->newFileLabel = findChild<QLabel *>("create_newFileLabel");
createElements->patchFileLabel = findChild<QLabel *>("create_patchFileLabel");
// assign pointer elements (apply)
applyElements->oldFileButton =
findChild<QPushButton *>("apply_oldFileButton");
applyElements->patchFileButton =
findChild<QPushButton *>("apply_patchFileButton");
applyElements->newFileButton =
findChild<QPushButton *>("apply_newFileButton");
applyElements->initButton = findChild<QPushButton *>("apply_initButton");
applyElements->oldFileLabel = findChild<QLabel *>("apply_oldFileLabel");
applyElements->patchFileLabel = findChild<QLabel *>("apply_patchFileLabel");
applyElements->newFileLabel = findChild<QLabel *>("apply_newFileLabel");
// connect functions to buttons (create)
connect(createElements->oldFileButton, &QPushButton::clicked, [&] {
clickFileDialogButton(this, true, createElements->oldFileLabel,
create_sourceFilePath);
});
connect(createElements->newFileButton, &QPushButton::clicked, [&] {
clickFileDialogButton(this, true, createElements->newFileLabel,
create_newFilePath);
});
connect(createElements->patchFileButton, &QPushButton::clicked, [&] {
clickFileDialogButton(this, false, createElements->patchFileLabel,
create_patchFilePath);
});
connect(createElements->initButton, &QPushButton::clicked, [&] {
initCreatePatch(create_sourceFilePath, create_newFilePath,
create_patchFilePath);
});
// connect functions to buttons (apply)
connect(applyElements->oldFileButton, &QPushButton::clicked, [&] {
clickFileDialogButton(this, true, applyElements->oldFileLabel,
apply_oldFilePath);
});
connect(applyElements->patchFileButton, &QPushButton::clicked, [&] {
clickFileDialogButton(this, true, applyElements->patchFileLabel,
apply_patchFilePath);
});
connect(applyElements->newFileButton, &QPushButton::clicked, [&] {
clickFileDialogButton(this, false, applyElements->newFileLabel,
apply_newFilePath);
});
connect(applyElements->initButton, &QPushButton::clicked, [&] {
initApplyPatch(apply_oldFilePath, apply_newFilePath, apply_patchFilePath);
});
}
MainWindow::~MainWindow() {
delete ui;
delete create_newFilePath;
delete create_sourceFilePath;
delete create_patchFilePath;
delete apply_newFilePath;
delete apply_oldFilePath;
delete apply_patchFilePath;
delete createElements;
delete applyElements;
}