Skip to content

Commit a630212

Browse files
committed
fix database problem with original game file list
1 parent f0558dd commit a630212

File tree

6 files changed

+64
-64
lines changed

6 files changed

+64
-64
lines changed

src/Data.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,20 @@ ZipData Data::getDownload(const int id) {
151151
return ZipData();
152152
}
153153

154-
std::array<QVector<QString>, 2> Data::getFileList(const int id, bool trleList) {
154+
std::array<QVector<QString>, 2> Data::getFileList(const int id) {
155155
std::array<QVector<QString>, 2> list;
156156
QSqlQuery query(db);
157-
if (trleList) {
158-
query.prepare("SELECT Files.path, Files.md5sum "
159-
"FROM Files "
160-
"JOIN LevelFileList ON Files.FileID = LevelFileList.fileID "
161-
"JOIN Level ON LevelFileList.levelID = Level.LevelID "
162-
"WHERE Level.LevelID = :id");
163-
} else {
164-
query.prepare("SELECT Files.path, Files.md5sum "
165-
"FROM Files "
166-
"JOIN GameFileList ON Files.FileID = GameFileList.fileID "
167-
"JOIN Game ON GameFileList.gameID = Game.GameID "
168-
"WHERE Game.GameID = :id");
157+
if (!query.prepare("SELECT File.path, File.md5sum "
158+
"FROM File "
159+
"JOIN GameFileList ON File.FileID = GameFileList.fileID "
160+
"WHERE GameFileList.gameID = :id")) {
161+
qDebug() << "Error preparing query:" << query.lastError().text();
169162
}
170163
query.bindValue(":id", id);
171164
if (query.exec()) {
172165
while (query.next()) {
173-
list[0] << query.value("Files.path").toString();
174-
list[1] << query.value("Files.md5sum").toString();
166+
list[0] << query.value("path").toString();
167+
list[1] << query.value("md5sum").toString();
175168
}
176169
} else {
177170
qDebug() << "Error executing query:" << query.lastError().text();

src/Data.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Data : public QObject {
198198
QString getWalkthrough(int id);
199199
int getType(int id);
200200

201-
std::array<QVector<QString>, 2> getFileList(const int id, bool trleList);
201+
std::array<QVector<QString>, 2> getFileList(const int id);
202202
ZipData getDownload(int id);
203203

204204
private:

src/FileManager.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@
2323
#include "gameTree.hpp"
2424

2525
bool FileManager::setUpCamp(const QString& levelDir, const QString& gameDir) {
26+
bool status = true;
27+
2628
QDir levelDirPath(levelDir);
27-
if (!levelDirPath.exists()) {
28-
if (!levelDirPath.mkpath(levelDir)) {
29-
qWarning() << "Failed to create level directory:" << levelDir;
30-
return false;
31-
}
29+
if (!levelDirPath.exists() && !levelDirPath.mkpath(levelDir)) {
30+
qWarning() << "Failed to create level directory:" << levelDir;
31+
status = false;
32+
} else {
33+
m_levelDir.setPath(levelDir);
3234
}
33-
m_levelDir.setPath(levelDir);
3435

3536
QDir gameDirPath(gameDir);
36-
if (!gameDirPath.exists()) {
37-
if (!gameDirPath.mkpath(gameDir)) {
38-
qWarning() << "Failed to create game directory:" << gameDir;
39-
return false;
40-
}
37+
if (!gameDirPath.exists() && !gameDirPath.mkpath(gameDir)) {
38+
qWarning() << "Failed to create game directory:" << gameDir;
39+
status = false;
40+
} else {
41+
m_gameDir.setPath(gameDir);
4142
}
42-
m_gameDir.setPath(gameDir);
4343

44-
return true;
44+
return status;
4545
}
4646

4747
inline const QString FileManager::lookGameDir(
@@ -178,13 +178,13 @@ bool FileManager::extractZip(
178178
/**
179179
*
180180
*/
181-
bool FileManager::checkDir(const QString& file, bool lookGameDir ) {
181+
bool FileManager::checkDir(const QString& file, bool lookGameDir) {
182182
const QString path = FileManager::lookGameDir(file, lookGameDir);
183183
QDir directory(path);
184184
return directory.exists();
185185
}
186186

187-
bool FileManager::checkFile(const QString& file, bool lookGameDir ) {
187+
bool FileManager::checkFile(const QString& file, bool lookGameDir) {
188188
const QString path = FileManager::lookGameDir(file, lookGameDir);
189189
QFile fFile(path);
190190
return fFile.exists();
@@ -193,7 +193,7 @@ bool FileManager::checkFile(const QString& file, bool lookGameDir ) {
193193
int FileManager::checkFileInfo(const QString& file, bool lookGameDir) {
194194
const QString path = FileManager::lookGameDir(file, lookGameDir);
195195
QFileInfo fileInfo(path);
196-
if (fileInfo.isDir()) {
196+
if (fileInfo.isDir() == true) {
197197
qDebug() << "The path is a directory.";
198198
if (fileInfo.isSymLink() == true) {
199199
qDebug() << "return value 1:The path is a symbolic link.";
@@ -242,18 +242,18 @@ bool FileManager::makeRelativeLink(
242242
const QString& levelDir,
243243
const QString& from,
244244
const QString& to) {
245-
const QString& l = m_levelDir.absolutePath() + levelDir;
246-
const QString& f = l + from;
247-
const QString& t = l + to;
245+
const QString& levelPath = m_levelDir.absolutePath() + levelDir;
246+
const QString& fromPath = levelPath + from;
247+
const QString& toPath = levelPath + to;
248248

249-
if (QFile::link(f, t)) {
249+
if (QFile::link(fromPath, toPath)) {
250250
qDebug() << "Symbolic link created successfully.";
251251
return 0;
252252
} else {
253-
QFileInfo i(t);
253+
QFileInfo i(toPath);
254254
if (i.isSymLink()) {
255-
QFile::remove(t);
256-
if (QFile::link(f, t)) {
255+
QFile::remove(toPath);
256+
if (QFile::link(fromPath, toPath)) {
257257
qDebug() << "Symbolic link created successfully.";
258258
return 0;
259259
} else {
@@ -405,17 +405,18 @@ bool FileManager::moveFilesToDirectory(
405405
dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
406406

407407
// Move files and recursively move directories
408-
for (const QString& entry : entryFileList) {
408+
bool allMoved = std::all_of(
409+
entryFileList.cbegin(),
410+
entryFileList.cend(),
411+
[&](const QString& entry) {
409412
QString entryPath = directoryFromPath + m_sep + entry;
410-
411-
if (!QFile::rename(
412-
entryPath,
413-
directoryToPath + m_sep + entry)) {
413+
if (!QFile::rename(entryPath, directoryToPath + m_sep + entry)) {
414414
qWarning() << "Failed to move file:" << entryPath;
415415
return false;
416416
}
417-
}
418-
return true;
417+
return true;
418+
});
419+
return allMoved;
419420
}
420421

421422
bool FileManager::moveFilesToParentDirectory(

src/Model.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ Model::Model(QObject *parent) : QObject(parent), checkCommonFilesIndex_m(1) {
4141

4242
Model::~Model() {}
4343

44-
void Model::setup(const QString& level, const QString& game) {
45-
setDirectory(level, game);
46-
checkCommonFiles();
44+
bool Model::setup(const QString& level, const QString& game) {
45+
bool status = false;
46+
if (setDirectory(level, game)) {
47+
status = true;
48+
checkCommonFiles();
49+
}
50+
return status;
4751
}
4852

4953
bool Model::setDirectory(const QString& level, const QString& game) {
@@ -56,19 +60,24 @@ bool Model::setDirectory(const QString& level, const QString& game) {
5660
return false;
5761
}
5862

59-
void Model::checkCommonFiles() {
63+
// true if there was new original game
64+
// false if there was no new original games
65+
bool Model::checkCommonFiles() {
6066
int index = checkCommonFilesIndex_m;
6167
assert(index >= 1 && index <= 5);
6268
for (int i = index; i <= 5; i++) {
6369
if (checkGameDirectory(i) == 2) {
70+
// checkCommonFilesIndex_m this is becouse it should start here
71+
// becouse we use a return, we should only use 1 return...
6472
checkCommonFilesIndex_m = i+1;
6573
emit askGameSignal(i);
6674
QCoreApplication::processEvents();
67-
return;
75+
return true;
6876
}
6977
}
7078
emit generateListSignal();
7179
QCoreApplication::processEvents();
80+
return false;
7281
}
7382

7483
QString Model::getGameDirectory(int id) {
@@ -131,7 +140,7 @@ bool Model::setLink(int id) {
131140
}
132141

133142
void Model::setupGame(int id) {
134-
std::array<QVector<QString>, 2> list = data.getFileList(id, false);
143+
std::array<QVector<QString>, 2> list = data.getFileList(id);
135144
const size_t s = list[0].size();
136145
const size_t sm = list[1].size();
137146
if (s != sm) {
@@ -140,8 +149,9 @@ void Model::setupGame(int id) {
140149
<< " more or less checksums for the files\n";
141150
assert(false);
142151
}
143-
const QString& sd = "/Original.TR" + QString::number(id) +"/";
144-
const QString& sg = getGameDirectory(id) + "/";
152+
assert(s != 0);
153+
const QString sd = "/Original.TR" + QString::number(id) +"/";
154+
const QString sg = getGameDirectory(id) + "/";
145155
for (size_t i = 0; i < s; i++) {
146156
const QString& fFile = list[0][i];
147157
const QString& fMd5sum = list[1][i];
@@ -157,8 +167,8 @@ void Model::setupGame(int id) {
157167
}
158168
}
159169
if (fileManager.backupGameDir(sg)) {
160-
const QString& src = sd.chopped(1);
161-
const QString& des = sg.chopped(1);
170+
const QString src = sd.chopped(1);
171+
const QString des = sg.chopped(1);
162172
if (!fileManager.linkGameDir(src, des)) {
163173
checkCommonFiles();
164174
return;

src/Model.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Model : public QObject {
5454
static Model instance;
5555
return instance;
5656
}
57-
void checkCommonFiles();
57+
bool checkCommonFiles();
5858
int checkGameDirectory(int id);
5959
int checkLevelDirectory(int id);
6060
void getList(QVector<ListItemData>* list);
@@ -66,7 +66,7 @@ class Model : public QObject {
6666
const InfoData getInfo(int id);
6767
const QString getWalkthrough(int id);
6868
bool setDirectory(const QString& level, const QString& game);
69-
void setup(const QString& level, const QString& game);
69+
bool setup(const QString& level, const QString& game);
7070

7171
signals:
7272
void askGameSignal(int);

src/TombRaiderLinuxLauncher.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,9 @@ void TombRaiderLinuxLauncher::linkClicked() {
422422
QListWidgetItem *selectedItem = ui->listWidgetModds->currentItem();
423423
int id = selectedItem->data(Qt::UserRole).toInt();
424424
if (id) {
425-
if (!controller.link(id)) {
426-
qDebug() << "Sumo linko el la compleeteo";
427-
} else {
428-
qDebug() << "Problemo de link";
429-
}
425+
qint64 status = controller.link(id);
430426
} else {
431-
qDebug() << "Say no more";
427+
qDebug() << "id error";
432428
}
433429
QApplication::quit();
434430
}

0 commit comments

Comments
 (0)