Skip to content

Commit 63c8d30

Browse files
committed
remove zip or level files
1 parent c835eae commit 63c8d30

13 files changed

+150
-30
lines changed

src/Controller.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,18 @@ const InfoData Controller::getInfo(int id) {
142142
return model.getInfo(id);
143143
}
144144

145+
const bool Controller::checkZip(int id) {
146+
return model.checkZip(id);
147+
}
148+
145149
const bool Controller::deleteZip(int id) {
146150
return model.deleteZip(id);
147151
}
148152

153+
const bool Controller::deleteLevel(int id) {
154+
return model.deleteLevel(id);
155+
}
156+
149157
const QString Controller::getWalkthrough(int id) {
150158
return model.getWalkthrough(id);
151159
}

src/Controller.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class Controller : public QObject {
4343
int checkGameDirectory(int id);
4444
void getList(QVector<QSharedPointer<ListItemData>>* list);
4545
const InfoData getInfo(int id);
46+
const bool checkZip(int id);
4647
const bool deleteZip(int id);
48+
const bool deleteLevel(int id);
4749
const QString getWalkthrough(int id);
4850
bool link(int id);
4951
int getItemState(int id);

src/Dialog.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ void Dialog::setOptions(const QStringList &options) {
8989

9090
if (options.isEmpty()) {
9191
m_optionContainer->hide();
92+
} else if (options.size() == 1) {
93+
m_optionContainer->hide();
94+
m_oneOptionHolder = options.at(0);
9295
} else {
9396
m_optionContainer->show();
97+
m_oneOptionHolder.clear();
9498
for (quint64 i = 0; i < options.size(); i++) {
9599
QRadioButton *rb = new QRadioButton(options.at(i));
96100
if (i == 0) {
@@ -100,12 +104,18 @@ void Dialog::setOptions(const QStringList &options) {
100104
m_optionLayout->addWidget(rb);
101105
}
102106
}
103-
104107
this->adjustSize();
108+
this->updateGeometry();
105109
}
106110

107111
QString Dialog::selectedOption() const {
108-
auto btn = m_buttonGroup->checkedButton();
109-
return btn ? btn->text() : QString();
112+
QString result;
113+
if (m_oneOptionHolder.isEmpty()) {
114+
auto btn = m_buttonGroup->checkedButton();
115+
result = btn ? btn->text() : QString();
116+
} else {
117+
result = m_oneOptionHolder;
118+
}
119+
return result;
110120
}
111121

src/Dialog.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Dialog : public QWidget {
4141
QVBoxLayout* m_optionLayout;
4242
QButtonGroup* m_buttonGroup;
4343
QPushButton* m_okButton;
44+
QString m_oneOptionHolder;
4445
};
4546

4647
#endif // SRC_DIALOG_HPP_

src/FileManager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,19 @@ void FileManager::addLevelDir(Path& path, quint64 id) {
351351
path << QString("%1.TRLE").arg(id);
352352
}
353353
}
354+
355+
QStringList FileManager::getSaveFiles(Path& path) {
356+
QStringList result;
357+
QRegularExpression re("savegame\\.\\d+", QRegularExpression::CaseInsensitiveOption);
358+
359+
QDirIterator it(path.get(), QDir::Files, QDirIterator::Subdirectories);
360+
while (it.hasNext()) {
361+
it.next();
362+
QFileInfo fi = it.fileInfo();
363+
if (re.match(fi.fileName()).hasMatch()) {
364+
result << fi.filePath();
365+
}
366+
}
367+
368+
return result;
369+
}

src/FileManager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class FileManager : public QObject {
202202
qint64 removeFileOrDirectory(Path path);
203203

204204
void addLevelDir(Path& path, quint64 id);
205+
QStringList getSaveFiles(Path& path);
205206

206207
signals:
207208
void fileWorkTickSignal();

src/LevelViewList.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ void LevelListModel::setInstalled(const QModelIndex &index) {
9090
item.m_installed = true;
9191
}
9292

93+
void LevelListModel::clearInstalled(const QModelIndex &index) {
94+
ListItemData &item = *m_levels[index.row()];
95+
item.m_installed = false;
96+
}
97+
9398
QVariant LevelListModel::data(const QModelIndex &index, int role) const {
9499
QVariant result;
95100

@@ -190,58 +195,65 @@ bool LevelListProxy::getInstalled(const QModelIndex &i) const {
190195
}
191196

192197
void LevelListProxy::setClassFilter(const QString &c) {
198+
beginFilterChange();
193199
if (c == m_all) {
194200
m_class = 0;
195201
} else {
196202
m_class = StaticData::getClassID().at(c);
197203
}
198-
invalidateFilter();
204+
endFilterChange();
199205
}
200206

201207
void LevelListProxy::setTypeFilter(const QString &t) {
208+
beginFilterChange();
202209
if (t == m_all) {
203210
m_type = 0;
204211
} else {
205212
m_type = StaticData::getTypeID().at(t);
206213
}
207-
invalidateFilter();
214+
endFilterChange();
208215
}
209216

210217
void LevelListProxy::setDifficultyFilter(const QString &d) {
218+
beginFilterChange();
211219
if (d == m_all) {
212220
m_difficulty = 0;
213221
} else {
214222
m_difficulty = StaticData::getDifficultyID().at(d);
215223
}
216-
invalidateFilter();
224+
endFilterChange();
217225
}
218226

219227
void LevelListProxy::setDurationFilter(const QString &d) {
228+
beginFilterChange();
220229
if(d == m_all) {
221230
m_duration = 0;
222231
} else {
223232
m_duration = StaticData::getDurationID().at(d);
224233
}
225-
invalidateFilter();
234+
endFilterChange();
226235
}
227236

228237
void LevelListProxy::setSearchFilter(const QString &s) {
238+
beginFilterChange();
229239
m_search = s;
230-
invalidateFilter();
240+
endFilterChange();
231241
}
232242

233243
void LevelListProxy::setSearchType(const QString &t) {
244+
beginFilterChange();
234245
if (t == "Level") {
235246
m_searchType = 0;
236247
} else if (t == "Author") {
237248
m_searchType = 1;
238249
}
239-
invalidateFilter();
250+
endFilterChange();
240251
}
241252

242253
void LevelListProxy::setInstalledFilter(bool on) {
254+
beginFilterChange();
243255
m_installed = on;
244-
invalidateFilter();
256+
endFilterChange();
245257
}
246258

247259
void LevelListProxy::setSortMode(SortMode mode) {

src/LevelViewList.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class LevelListModel : public QAbstractListModel {
7474
void setScrollChanged(QModelIndexList list);
7575
void setInstalled(const QModelIndex &index);
7676

77+
void clearInstalled(const QModelIndex &index);
7778
quint64 indexInBounds(quint64 index) const;
7879
bool stop() const;
7980
void updateCovers(quint64 a, quint64 b);

src/Model.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ void Model::setupGame(int id) {
254254
}
255255
}
256256

257+
bool Model::checkZip(int id) {
258+
bool status = false;
259+
ZipData zipData = data.getDownload(id);
260+
Path path(Path::resource);
261+
path << zipData.m_fileName;
262+
if (path.isFile()) {
263+
status = true;
264+
}
265+
return status;
266+
}
267+
257268
bool Model::deleteZip(int id) {
258269
bool status = false;
259270
ZipData zipData = data.getDownload(id);
@@ -265,8 +276,38 @@ bool Model::deleteZip(int id) {
265276
return status;
266277
}
267278

268-
bool backupSaveFiles(int id) {
279+
bool Model::deleteLevel(int id) {
280+
bool status = false;
281+
if (id != 0) {
282+
Path path = Path(Path::resource);
283+
fileManager.addLevelDir(path, id);
284+
Path testPath = Path(Path::resource);
285+
Q_ASSERT_WITH_TRACE(path.get() != testPath.get());
286+
287+
quint64 error = fileManager.removeFileOrDirectory(path);
288+
if (error == 0) {
289+
status = true;
290+
}
291+
292+
if (id<0) {
293+
g_settings.setValue(
294+
QString("installed/game%1").arg(-id),
295+
"fales");
296+
} else {
297+
g_settings.setValue(
298+
QString("installed/level%1").arg(id),
299+
"false");
300+
}
301+
}
302+
303+
return status;
304+
}
305+
306+
bool Model::backupSaveFiles(int id) {
269307
bool status = false;
308+
Path path = Path(Path::resource);
309+
fileManager.addLevelDir(path, id);
310+
QStringList list = fileManager.getSaveFiles(path);
270311
return status;
271312
}
272313

src/Model.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ class Model : public QObject {
6767
void checkCommonFiles(QList<int>* games);
6868
int checkGameDirectory(int id);
6969
int checkLevelDirectory(int id);
70+
bool checkZip(int id);
7071
bool deleteZip(int id);
72+
bool deleteLevel(int id);
7173
bool backupSaveFiles(int id);
7274
void getList(QVector<QSharedPointer<ListItemData>>* list);
7375
void getCoverList(QVector<QSharedPointer<ListItemData>> tiems);

0 commit comments

Comments
 (0)