Skip to content

Commit 84769ed

Browse files
committed
Add Path
1 parent 01a0075 commit 84769ed

File tree

12 files changed

+237
-106
lines changed

12 files changed

+237
-106
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ set(SOURCES_MC
9595
src/Model.cpp
9696
src/Network.hpp
9797
src/Network.cpp
98+
src/Path.cpp
99+
src/Path.hpp
98100
src/PyRunner.cpp
99101
src/PyRunner.hpp
100102
src/Runner.cpp

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ This project is my passion for Tomb Raider classics combined with learning C++,
66

77
## Features
88

9-
- Run level wine/proton from app
10-
- Search trle.net with a fast offline indexing
9+
- Run level with Wine/Proton from app
10+
- Search trle.net with fast offline indexing
1111
- Lazy loading trle.net level info (runtime scraping)
1212
- Integrates with Linux other launchers (Steam, Lutris, etc.)
1313
- Controller mapper support using uinput
@@ -148,7 +148,7 @@ sudo modprobe ntsync
148148

149149
```
150150

151-
I listed some open source modes that work well with proton/wine.
151+
I listed some open source modes that work well with Proton/Wine.
152152

153153
### TR1
154154

src/Data.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ void Data::setDownloadMd5(const int id, const QString& newMd5sum) {
267267
}
268268
}
269269

270-
QVector<File> Data::getFileList(const int id) {
270+
QVector<FileListItem> Data::getFileList(const int id) {
271271
QSqlQuery query(db);
272-
QVector<File> list;
272+
QVector<FileListItem> list;
273273

274274
if (!query.prepare(
275275
"SELECT File.path, File.md5sum "

src/Data.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
#include <QSqlError>
2626
#include <QSqlQuery>
2727

28-
2928
/**
30-
* @struct File
29+
* @struct FileListItem
3130
* @brief Files object to keep track of files.
3231
*
3332
*/
34-
struct File {
33+
struct FileListItem {
3534
QString path;
3635
QString md5sum;
3736
};
@@ -459,28 +458,33 @@ class Data : public QObject {
459458
* @return The number of Level records
460459
*/
461460
qint64 getListRowCount();
461+
462462
/**
463463
* @brief Get the main list of levels, without the picture
464464
* @return The QVector ListItemData is all the level metadata
465465
*/
466466
QVector<ListItemData> getListItems();
467+
467468
/**
468469
* @brief Add Cover Pictures to ListItemData pointers
469470
* @param Cache like used QVector for holding ListItemData pointers
470471
*/
471472
void getCoverPictures(QVector<ListItemData*>* items);
473+
472474
/**
473475
* @brief Get the info page, this is HTML and picture data you see on trel.net
474476
* @param trle.net lid
475477
* @return The InfoData is a struct of QString and QVector<QPixmap>
476478
*/
477479
InfoData getInfo(int id);
480+
478481
/**
479482
* @brief Get the walkthrough HTML page
480483
* @param trle.net lid
481484
* @return HTML and Qt picture data
482485
*/
483486
QString getWalkthrough(int id);
487+
484488
/**
485489
* @brief Get the type of a level
486490
* @param trle.net lid
@@ -493,13 +497,15 @@ class Data : public QObject {
493497
* @param Id number for original game
494498
* @return File vector list (path and md5sum)
495499
*/
496-
QVector<File> getFileList(const int id);
500+
QVector<FileListItem> getFileList(const int id);
501+
497502
/**
498503
* @brief Get download info for a level
499504
* @param trle.net lid
500505
* @return zip data, url, filename, size, etc...
501506
*/
502507
ZipData getDownload(const int id);
508+
503509
/**
504510
* @brief Record new md5sum to database.
505511
* @param trle.net lid

src/File.cpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/File.hpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/FileManager.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "../miniz/miniz_zip.h"
2525
#include "../src/gameFileTreeData.hpp"
2626
#include "../src/binary.hpp"
27+
#include "../src/Path.hpp"
2728

2829
bool FileManager::backupGameDir(const QString &gameDir) {
2930
bool status = false;
@@ -68,17 +69,6 @@ const QString FileManager::calculateMD5(
6869
return result;
6970
}
7071

71-
bool FileManager::checkDir(const QString& file, bool lookGameDir) {
72-
const QString path = FileManager::getFullPath(file, lookGameDir);
73-
QDir directory(path);
74-
return directory.exists();
75-
}
76-
77-
bool FileManager::checkFile(const QString& file, bool lookGameDir) {
78-
const QString path = FileManager::getFullPath(file, lookGameDir);
79-
QFile fFile(path);
80-
return fFile.exists();
81-
}
8272

8373
int FileManager::checkFileInfo(const QString& file, bool lookGameDir) {
8474
int status = 0;

src/FileManager.hpp

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QByteArray>
2222
#include <QCryptographicHash>
2323
#include <QDebug>
24+
#include "../src/Path.hpp"
2425

2526
class FileManager : public QObject {
2627
Q_OBJECT
@@ -61,38 +62,6 @@ class FileManager : public QObject {
6162
*/
6263
const QString calculateMD5(const QString& file, bool lookGameDir);
6364

64-
/**
65-
* @brief Checks if a given directory exists.
66-
*
67-
* This function constructs the full path of a directory based on the given
68-
* filename and the specified directory type (game directory or level directory).
69-
* It then verifies whether the directory exists.
70-
*
71-
* @param file The name of the directory to check.
72-
* @param lookGameDir If `true`, the directory is checked in the game directory;
73-
* otherwise, it is checked in the level directory.
74-
* @return `true` if the directory exists, otherwise `false`.
75-
*
76-
* @note This function does not check if the path is actually a directory.
77-
*/
78-
bool checkDir(const QString& file, bool lookGameDir);
79-
80-
/**
81-
* @brief Checks if a given file exists.
82-
*
83-
* This function constructs the full path of a file based on the given filename
84-
* and the specified directory type (game directory or level directory).
85-
* It then verifies whether the file exists.
86-
*
87-
* @param file The name of the file to check.
88-
* @param lookGameDir If `true`, the file is checked in the game directory;
89-
* otherwise, it is checked in the level directory.
90-
* @return `true` if the file exists, otherwise `false`.
91-
*
92-
* @note This function does not check if the path is a regular file.
93-
*/
94-
bool checkFile(const QString& file, bool lookGameDir);
95-
9665
/**
9766
* @brief Checks the type of a file path and returns a status code.
9867
*

src/Model.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
*/
1313

1414
#include "../src/Model.hpp"
15+
#include "../src/Data.hpp"
16+
#include "../src/Path.hpp"
1517

1618
Model::Model() {}
1719
Model::~Model() {}
1820

1921
bool Model::setupDirectories(const QString& level, const QString& game) {
2022
bool status = false;
23+
2124
if (fileManager.setUpCamp(level, game) &&
2225
downloader.setUpCamp(level) &&
2326
data.initializeDatabase(level) &&
2427
m_pyRunner.setUpCamp(level)) {
28+
Path::setProgramFilesPath();
29+
Path::setResourcePath();
2530
status = true;
2631
}
2732
return status;
@@ -34,8 +39,10 @@ void Model::setup(const QString& level, const QString& game) {
3439
// Iterate backward to avoid index shifting
3540
for (int i = 4; i >= 0; i--) {
3641
int dirStatus = commonFiles[i];
37-
if (fileManager.checkDir(
38-
QString("/Original.TR%1").arg(i + 1), false) == true) {
42+
43+
Path p(Path::resource);
44+
p << QString("Original.TR%1").arg(i + 1);
45+
if (p.isDir()) {
3946
commonFiles[i] = i + 1;
4047
} else if (dirStatus == 2) {
4148
commonFiles[i] = -(i + 1);
@@ -111,16 +118,19 @@ void Model::getCoverList(QVector<ListItemData*>* items) {
111118

112119
int Model::getItemState(int id) {
113120
int status = 0;
121+
122+
Path path(Path::resource);
114123
if (id < 0) {
115-
QString dir = QString("Original.TR%1").arg(id);
116-
if (fileManager.checkDir(dir, false)) {
124+
path << QString("Original.TR%1").arg(id);
125+
if (path.isDir()) {
117126
status = 2;
118127
} else {
119128
status = 1;
120129
}
121130
} else if (id > 0) {
122-
QString dir = QString("%1.TRLE").arg(id);
123-
if (fileManager.checkDir(dir, false)) {
131+
path << QString("%1.TRLE").arg(id);
132+
qDebug() << "getItemState: path is " << path.get();
133+
if (path.isDir()) {
124134
status = 2;
125135
} else {
126136
status = 0;
@@ -175,8 +185,8 @@ bool Model::runUmu(const int id) {
175185
}
176186

177187

178-
void Model::setUmuEnv(const QVector<QPair<QString, QString>>& env) {
179-
for (const QPair<QString, QString>& e : env) {
188+
void Model::setUmuEnv(const QVector<QPair<QString, QString>>& environment) {
189+
for (const QPair<QString, QString>& e : environment) {
180190
m_umuRunner.insertProcessEnvironment(e);
181191
}
182192
}
@@ -224,8 +234,8 @@ bool Model::runWine(const qint64 id) {
224234
return status;
225235
}
226236

227-
void Model::setWineEnv(const QVector<QPair<QString, QString>>& env) {
228-
for (const QPair<QString, QString>& e : env) {
237+
void Model::setWineEnv(const QVector<QPair<QString, QString>>& environment) {
238+
for (const QPair<QString, QString>& e : environment) {
229239
m_wineRunner.insertProcessEnvironment(e);
230240
}
231241
}
@@ -236,19 +246,22 @@ void Model::setWineSetup() {
236246

237247
bool Model::setLink(int id) {
238248
bool status = false;
249+
Path path(Path::resource);
239250
if (id < 0) { // we use original game id as negative number
240251
int orgId = (-1)*id;
241-
const QString s = QString("/Original.TR%1").arg(orgId);
242-
if (fileManager.checkDir(s, false )) {
252+
path << QString("Original.TR%1").arg(orgId);
253+
const QString s = path.get();
254+
if (path.isDir()) {
243255
status = fileManager.linkGameDir(s, getGameDirectory(orgId));
244256
} else {
245257
qDebug() << "Dirr: " << s << " seems to bee missing";
246258
}
247259
} else {
248-
const QString s = QString("/%1.TRLE").arg(id);
260+
path << QString("%1.TRLE").arg(id);
261+
const QString s = path.get();
249262
const int t = data.getType(id);
250263

251-
if (fileManager.checkDir(s, false )) {
264+
if (path.isDir()) {
252265
status = fileManager.linkGameDir(s, getGameDirectory(t));
253266
} else {
254267
qDebug() << "Dirr: " << s << " seems to bee missing";
@@ -258,7 +271,7 @@ bool Model::setLink(int id) {
258271
}
259272

260273
void Model::setupGame(int id) {
261-
QVector<File> list = data.getFileList(id);
274+
QVector<FileListItem> list = data.getFileList(id);
262275
const size_t s = list.size();
263276
assert(s != (unsigned int)0);
264277

@@ -363,7 +376,11 @@ void Model::getLevel(int id) {
363376
downloader.setUrl(zipData.m_URL);
364377
downloader.setSaveFile(zipData.m_fileName);
365378
// this if just slips up execution but has nothing to do with the error
366-
if (fileManager.checkFile(zipData.m_fileName, false)) {
379+
380+
Path path(Path::resource);
381+
path << zipData.m_fileName;
382+
383+
if (path.isFile()) {
367384
qWarning() << "File exists:" << zipData.m_fileName;
368385
status = getLevelHaveFile(id, zipData.m_MD5sum, zipData.m_fileName);
369386
} else {

src/Model.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <cassert>
2525

26+
#include "../src/Path.hpp"
2627
#include "../src/Data.hpp"
2728
#include "../src/FileManager.hpp"
2829
#include "../src/Network.hpp"
@@ -68,10 +69,10 @@ class Model : public QObject {
6869
void getCoverList(QVector<ListItemData*>* tiems);
6970
int getItemState(int id);
7071
bool runUmu(const int id);
71-
void setUmuEnv(const QVector<QPair<QString, QString>>& env);
72+
void setUmuEnv(const QVector<QPair<QString, QString>>& environment);
7273
void setUmuSetup();
7374
bool runWine(const qint64 id);
74-
void setWineEnv(const QVector<QPair<QString, QString>>& env);
75+
void setWineEnv(const QVector<QPair<QString, QString>>& environment);
7576
void setWineSetup();
7677
bool runLutris(const QStringList& arg);
7778
bool runSteam(const int id);

0 commit comments

Comments
 (0)