-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings.cpp
207 lines (171 loc) · 6.4 KB
/
settings.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
#include "settings.h"
#include "ui_settings.h"
#include <QDir>
#include <QFileDialog>
Settings::Settings(QWidget* parent) :
QDialog(parent),
ui(new Ui::Settings)
{
ui->setupUi(this);
}
Settings::~Settings()
{
delete ui;
}
void Settings::fromWindowToVars()
{
pathWcc = ui->lineEditWcc->text();
pathUncooked = ui->lineEditUncooked->text();
pathCooked = ui->lineEditCooked->text();
pathPacked = ui->lineEditPacked->text();
mergedModName = ui->lineEditModName->text();
cmdUncook = ui->lineCmdUncook->text();
cmdCook = ui->lineCmdCook->text();
cmdCache = ui->lineCmdCache->text();
cmdPack = ui->lineCmdPack->text();
cmdMetadata = ui->lineCmdMetadata->text();
isWccSpecified = pathWcc.endsWith(Constants::EXE_NAME, Qt::CaseInsensitive);
autoInstallEnabled = ui->checkBoxAutoInstall->isChecked();
autoCleanEnabled = ui->checkBoxCleanDirs->isChecked();
skipErrors = ui->checkBoxSkipErrors->isChecked();
dumpSwf = ui->checkBoxSwf->isChecked();
saveMergingOrder = ui->checkBoxMergingOrder->isChecked();
showPauseMessage = ui->checkBoxShowPause->isChecked();
}
void Settings::fromVarsToWindow()
{
ui->lineEditWcc->setText(pathWcc);
ui->lineEditUncooked->setText(pathUncooked);
ui->lineEditCooked->setText(pathCooked);
ui->lineEditPacked->setText(pathPacked);
ui->lineEditModName->setText(mergedModName);
ui->lineCmdUncook->setText(cmdUncook);
ui->lineCmdCook->setText(cmdCook);
ui->lineCmdCache->setText(cmdCache);
ui->lineCmdPack->setText(cmdPack);
ui->lineCmdMetadata->setText(cmdMetadata);
ui->checkBoxAutoInstall->setChecked(autoInstallEnabled);
ui->checkBoxCleanDirs->setChecked(autoCleanEnabled);
ui->checkBoxSkipErrors->setChecked(skipErrors);
ui->checkBoxSwf->setChecked(dumpSwf);
ui->checkBoxMergingOrder->setChecked(saveMergingOrder);
ui->checkBoxShowPause->setChecked(showPauseMessage);
// Some additional checks
if ( pathWcc.contains(' ') ) {
toLog( tr("WARNING: path to wcc_lite.exe contains spaces. This may cause problems with wcc.", "Log warning message.") );
ui->lineEditWcc->setStyleSheet("QLineEdit { background: rgb(255, 0, 0); }");
}
else {
ui->lineEditWcc->setStyleSheet("QLineEdit { background: rgb(0, 255, 0); }");
}
checkFolderLength("Uncooked", pathUncooked, ui->lineEditUncooked);
checkFolderLength("Cooked", pathCooked, ui->lineEditCooked);
checkFolderLength("Packed", pathPacked, ui->lineEditPacked);
}
QString Settings::currentDir() const
{
QDir dir;
return QDir::toNativeSeparators( dir.absolutePath() );
}
QString Settings::rebuildCmd()
{
QString result = Constants::DEFAULT_UNCOOK;
result.remove(" -skiperrors -dumpswf");
if (skipErrors) {
result += " -skiperrors";
}
if (dumpSwf) {
result += " -dumpswf";
}
return result;
}
void Settings::checkFolderLength(const QString& name, const QString& path, QLineEdit* widget)
{
if ( path.length() > Constants::PATH_LENGTH_LIMIT ) {
toLog( tr( "WARNING: path to %1 folder exceeds %2 symbols. This may cause problems with wcc.", "Log warning message.").arg(name).arg(QString::number(Constants::PATH_LENGTH_LIMIT)) );
widget->setStyleSheet("QLineEdit { background: rgb(255, 0, 0); }");
}
else {
widget->setStyleSheet("QLineEdit { background: rgb(0, 255, 0); }");
}
}
void Settings::on_buttonReset_clicked()
{
using namespace Constants;
//pathWcc = "";
pathUncooked = currentDir() + DIR_UNCOOKED;
pathCooked = currentDir() + DIR_COOKED;
pathPacked = currentDir() + DIR_PACKED;
mergedModName = DEFAULT_NAME;
cmdUncook = DEFAULT_UNCOOK;
cmdCook = DEFAULT_COOK;
cmdCache = DEFAULT_CACHE;
cmdPack = DEFAULT_PACK;
cmdMetadata = DEFAULT_META;
isWccSpecified = pathWcc.endsWith(EXE_NAME, Qt::CaseInsensitive);
autoInstallEnabled = true;
autoCleanEnabled = true;
skipErrors = true;
dumpSwf = true;
saveMergingOrder = true;
showPauseMessage = false;
mergingOrder.clear();
hiddenMods.clear();
fromVarsToWindow();
}
void Settings::on_buttonWcc_clicked()
{
QString directory = QFileDialog::getOpenFileName( this, tr("wcc_lite.exe location:", "File selection dialog title."), QDir::currentPath(), Constants::EXE_NAME );
if ( !directory.isEmpty() ) {
pathWcc = QDir::toNativeSeparators(directory);
ui->lineEditWcc->setText(pathWcc);
}
}
void Settings::on_buttonUncooked_clicked()
{
QString directory = QFileDialog::getExistingDirectory(this, tr("Uncooked folder path:", "Folder selection dialog title."), QDir::currentPath() );
if ( !directory.isEmpty() ) {
pathUncooked = QDir::toNativeSeparators(directory);
ui->lineEditUncooked->setText(pathUncooked);
}
}
void Settings::on_buttonCooked_clicked()
{
QString directory = QFileDialog::getExistingDirectory(this, tr("Cooked folder path:", "Folder selection dialog title."), QDir::currentPath() );
if ( !directory.isEmpty() ) {
pathCooked = QDir::toNativeSeparators(directory);
ui->lineEditCooked->setText(pathCooked);
}
}
void Settings::on_buttonPacked_clicked()
{
QString directory = QFileDialog::getExistingDirectory(this, tr("Packed folder path:", "Folder selection dialog title."), QDir::currentPath() );
if ( !directory.isEmpty() ) {
pathPacked = QDir::toNativeSeparators(directory);
ui->lineEditPacked->setText(pathPacked);
}
}
void Settings::on_lineEditWcc_textChanged(const QString& arg1)
{
pathWcc = arg1;
isWccSpecified = pathWcc.endsWith(Constants::EXE_NAME, Qt::CaseInsensitive);
ui->buttonOk->setEnabled( isWccSpecified );
if ( isWccSpecified ) {
ui->lineEditWcc->setStyleSheet("QLineEdit { background: rgb(0, 255, 0); }");
}
else {
ui->lineEditWcc->setStyleSheet("QLineEdit { background: rgb(255, 0, 0); }");
}
}
void Settings::on_checkBoxSkipErrors_clicked()
{
skipErrors = ui->checkBoxSkipErrors->isChecked();
cmdUncook = rebuildCmd();
fromVarsToWindow();
}
void Settings::on_checkBoxSwf_clicked()
{
dumpSwf = ui->checkBoxSwf->isChecked();
cmdUncook = rebuildCmd();
fromVarsToWindow();
}