Skip to content

Commit

Permalink
fix GlobalSaveClicked() and checkCommonFiles(QList<int>* games)
Browse files Browse the repository at this point in the history
  • Loading branch information
noisecode3 committed Jan 30, 2025
1 parent 5603895 commit c1e9128
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
63 changes: 26 additions & 37 deletions src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,63 +31,52 @@ Model::Model() {

Model::~Model() {}

bool Model::setDirectory(const QString& level, const QString& game) {
bool status = false;
if (fileManager.setUpCamp(level, game) &&
downloader.setUpCamp(level) &&
data.initializeDatabase(level)) {
status = true;
}
return status;
}

void Model::setup(const QString& level, const QString& game) {
if (setDirectory(level, game) == true) {
QByteArray commonFiles(8, '\0');
QList<int> commonFiles;
checkCommonFiles(&commonFiles);
m_availableGames.clear();
for (int i = 1; i <= 5; i++) {
qint8 dirStatus = commonFiles[i];
if (dirStatus == 1) {
if (fileManager.checkDir(
QString("/Original.TR%1").arg(i), false) == true) {
m_availableGames.append(i);
}
// Iterate backward to avoid index shifting
for (int i = 4; i >= 0; i--) {
int dirStatus = commonFiles[i];
if (fileManager.checkDir(
QString("/Original.TR%1").arg(i + 1), false) == true) {
commonFiles[i] = i + 1;
} else if (dirStatus == 2) {
m_availableGames.append(-i);
// check if there is one of
// TOMBRAID/tomb.exe
// Tomb2.exe
// tomb3.exe
// tomb4.exe
// PCTomb5.exe
commonFiles[i] = -(i + 1);
} else {
if (fileManager.checkDir(
QString("/Original.TR%1").arg(i), false) == true) {
m_availableGames.append(i);
}
commonFiles.removeAt(i);
}
}
emit generateListSignal(m_availableGames);
emit generateListSignal(commonFiles);
QCoreApplication::processEvents();
} else {
// send signal to gui with error about setup fail
qDebug() << "setDirectory setup failed";
}
}

bool Model::setDirectory(const QString& level, const QString& game) {
bool status = false;
if (fileManager.setUpCamp(level, game) &&
downloader.setUpCamp(level) &&
data.initializeDatabase(level)) {
status = true;
}
return status;
}

void Model::checkCommonFiles(QByteArray* games) {
void Model::checkCommonFiles(QList<int>* games) {
for (int i = 1; i <= 5; i++) {
int dirStatus = checkGameDirectory(i);
if (dirStatus == 1) { // symbolic link
m_availableGames.append(1);
games->append(1);
} else if (dirStatus == 2) { // directory
m_availableGames.append(2);
games->append(2);
} else if (dirStatus == 3) {
m_availableGames.append(3);
games->append(3);
qDebug() << "File could be a broken link or a regular file";
} else {
m_availableGames.append(0);
games->append(0);
qDebug() << "File don't exist";
}
}
Expand Down Expand Up @@ -178,7 +167,7 @@ void Model::setupGame(int id) {
assert(s != (unsigned int)0);

const QString levelPath = QString("/Original.TR%1/").arg(id);
const QString gamePath = QString("%1/").arg(getGameDirectory(id));
const QString gamePath = QString("/%1/").arg(getGameDirectory(id));

for (size_t i = 0; i < s; i++) {
const QString levelFile = QString("%1%2").arg(levelPath, list[i].path);
Expand Down
3 changes: 1 addition & 2 deletions src/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Model : public QObject {
static Model instance;
return instance;
}
void checkCommonFiles(QByteArray* games);
void checkCommonFiles(QList<int>* games);
int checkGameDirectory(int id);
int checkLevelDirectory(int id);
void getList(QVector<ListItemData>* list);
Expand All @@ -84,7 +84,6 @@ class Model : public QObject {
bool unpackLevel(const int id, const QString& name);

Runner m_wineRunner = Runner("/usr/bin/wine");
QList<int> m_availableGames;
Data& data = Data::getInstance();
FileManager& fileManager = FileManager::getInstance();
Downloader& downloader = Downloader::getInstance();
Expand Down
15 changes: 13 additions & 2 deletions src/TombRaiderLinuxLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
}

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

Expand Down Expand Up @@ -599,8 +600,18 @@ void TombRaiderLinuxLauncher::downloadError(int status) {
}

void TombRaiderLinuxLauncher::GlobalSaveClicked() {
m_settings.setValue("gamePath" , ui->tableWidgetSetup->item(0, 0)->text());
m_settings.setValue("levelPath" , ui->tableWidgetSetup->item(1, 0)->text());
const QString newLevelPath = ui->tableWidgetSetup->item(1, 0)->text();
const QString newGamePath = ui->tableWidgetSetup->item(0, 0)->text();

const QString oldLevelPath = m_settings.value("levelPath").toString();
const QString oldGamePath = m_settings.value("gamePath").toString();

if ((newLevelPath != oldLevelPath) || (newGamePath != oldGamePath)) {
m_settings.setValue("levelPath" , newLevelPath);
m_settings.setValue("gamePath" , newGamePath);

controller.setup(newLevelPath, newGamePath);
}
}
void TombRaiderLinuxLauncher::GlobalResetClicked() {
ui->tableWidgetSetup->item(0, 0)->setText(
Expand Down

0 comments on commit c1e9128

Please sign in to comment.