Skip to content

Commit c1e9128

Browse files
committed
fix GlobalSaveClicked() and checkCommonFiles(QList<int>* games)
1 parent 5603895 commit c1e9128

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

src/Model.cpp

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,63 +31,52 @@ Model::Model() {
3131

3232
Model::~Model() {}
3333

34+
bool Model::setDirectory(const QString& level, const QString& game) {
35+
bool status = false;
36+
if (fileManager.setUpCamp(level, game) &&
37+
downloader.setUpCamp(level) &&
38+
data.initializeDatabase(level)) {
39+
status = true;
40+
}
41+
return status;
42+
}
43+
3444
void Model::setup(const QString& level, const QString& game) {
3545
if (setDirectory(level, game) == true) {
36-
QByteArray commonFiles(8, '\0');
46+
QList<int> commonFiles;
3747
checkCommonFiles(&commonFiles);
38-
m_availableGames.clear();
39-
for (int i = 1; i <= 5; i++) {
40-
qint8 dirStatus = commonFiles[i];
41-
if (dirStatus == 1) {
42-
if (fileManager.checkDir(
43-
QString("/Original.TR%1").arg(i), false) == true) {
44-
m_availableGames.append(i);
45-
}
48+
// Iterate backward to avoid index shifting
49+
for (int i = 4; i >= 0; i--) {
50+
int dirStatus = commonFiles[i];
51+
if (fileManager.checkDir(
52+
QString("/Original.TR%1").arg(i + 1), false) == true) {
53+
commonFiles[i] = i + 1;
4654
} else if (dirStatus == 2) {
47-
m_availableGames.append(-i);
48-
// check if there is one of
49-
// TOMBRAID/tomb.exe
50-
// Tomb2.exe
51-
// tomb3.exe
52-
// tomb4.exe
53-
// PCTomb5.exe
55+
commonFiles[i] = -(i + 1);
5456
} else {
55-
if (fileManager.checkDir(
56-
QString("/Original.TR%1").arg(i), false) == true) {
57-
m_availableGames.append(i);
58-
}
57+
commonFiles.removeAt(i);
5958
}
6059
}
61-
emit generateListSignal(m_availableGames);
60+
emit generateListSignal(commonFiles);
6261
QCoreApplication::processEvents();
6362
} else {
6463
// send signal to gui with error about setup fail
6564
qDebug() << "setDirectory setup failed";
6665
}
6766
}
6867

69-
bool Model::setDirectory(const QString& level, const QString& game) {
70-
bool status = false;
71-
if (fileManager.setUpCamp(level, game) &&
72-
downloader.setUpCamp(level) &&
73-
data.initializeDatabase(level)) {
74-
status = true;
75-
}
76-
return status;
77-
}
78-
79-
void Model::checkCommonFiles(QByteArray* games) {
68+
void Model::checkCommonFiles(QList<int>* games) {
8069
for (int i = 1; i <= 5; i++) {
8170
int dirStatus = checkGameDirectory(i);
8271
if (dirStatus == 1) { // symbolic link
83-
m_availableGames.append(1);
72+
games->append(1);
8473
} else if (dirStatus == 2) { // directory
85-
m_availableGames.append(2);
74+
games->append(2);
8675
} else if (dirStatus == 3) {
87-
m_availableGames.append(3);
76+
games->append(3);
8877
qDebug() << "File could be a broken link or a regular file";
8978
} else {
90-
m_availableGames.append(0);
79+
games->append(0);
9180
qDebug() << "File don't exist";
9281
}
9382
}
@@ -178,7 +167,7 @@ void Model::setupGame(int id) {
178167
assert(s != (unsigned int)0);
179168

180169
const QString levelPath = QString("/Original.TR%1/").arg(id);
181-
const QString gamePath = QString("%1/").arg(getGameDirectory(id));
170+
const QString gamePath = QString("/%1/").arg(getGameDirectory(id));
182171

183172
for (size_t i = 0; i < s; i++) {
184173
const QString levelFile = QString("%1%2").arg(levelPath, list[i].path);

src/Model.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Model : public QObject {
5757
static Model instance;
5858
return instance;
5959
}
60-
void checkCommonFiles(QByteArray* games);
60+
void checkCommonFiles(QList<int>* games);
6161
int checkGameDirectory(int id);
6262
int checkLevelDirectory(int id);
6363
void getList(QVector<ListItemData>* list);
@@ -84,7 +84,6 @@ class Model : public QObject {
8484
bool unpackLevel(const int id, const QString& name);
8585

8686
Runner m_wineRunner = Runner("/usr/bin/wine");
87-
QList<int> m_availableGames;
8887
Data& data = Data::getInstance();
8988
FileManager& fileManager = FileManager::getInstance();
9089
Downloader& downloader = Downloader::getInstance();

src/TombRaiderLinuxLauncher.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
124124
}
125125

126126
void TombRaiderLinuxLauncher::generateList(const QList<int>& availableGames) {
127+
ui->listWidgetModds->clear();
127128
const QString pictures = ":/pictures/";
128129
OriginalGameData pictueData;
129130

@@ -599,8 +600,18 @@ void TombRaiderLinuxLauncher::downloadError(int status) {
599600
}
600601

601602
void TombRaiderLinuxLauncher::GlobalSaveClicked() {
602-
m_settings.setValue("gamePath" , ui->tableWidgetSetup->item(0, 0)->text());
603-
m_settings.setValue("levelPath" , ui->tableWidgetSetup->item(1, 0)->text());
603+
const QString newLevelPath = ui->tableWidgetSetup->item(1, 0)->text();
604+
const QString newGamePath = ui->tableWidgetSetup->item(0, 0)->text();
605+
606+
const QString oldLevelPath = m_settings.value("levelPath").toString();
607+
const QString oldGamePath = m_settings.value("gamePath").toString();
608+
609+
if ((newLevelPath != oldLevelPath) || (newGamePath != oldGamePath)) {
610+
m_settings.setValue("levelPath" , newLevelPath);
611+
m_settings.setValue("gamePath" , newGamePath);
612+
613+
controller.setup(newLevelPath, newGamePath);
614+
}
604615
}
605616
void TombRaiderLinuxLauncher::GlobalResetClicked() {
606617
ui->tableWidgetSetup->item(0, 0)->setText(

0 commit comments

Comments
 (0)