Skip to content

Commit 080765b

Browse files
committed
fix trle id number references(lid)
1 parent eaae4cd commit 080765b

File tree

3 files changed

+141
-31
lines changed

3 files changed

+141
-31
lines changed

src/Data.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void Data::getCoverPictures(QVector<ListItemData*>* items) {
8686
QSqlQuery query(db);
8787

8888
bool status = query.prepare(
89-
"SELECT Info.trleID, Picture.data "
89+
"SELECT Picture.data "
9090
"FROM Level "
9191
"JOIN Info ON Level.infoID = Info.InfoID "
9292
"JOIN Screens ON Level.LevelID = Screens.levelID "
@@ -121,18 +121,19 @@ InfoData Data::getInfo(const int id) {
121121
status = query.prepare(
122122
"SELECT Level.body, Picture.data "
123123
"FROM Level "
124+
"JOIN Info ON Level.infoID = Info.InfoID "
124125
"JOIN Screens ON Level.LevelID = Screens.levelID "
125126
"JOIN Picture ON Screens.pictureID = Picture.PictureID "
126-
"WHERE Level.LevelID = :id");
127+
"WHERE Info.trleID = :id AND Screens.position > 0 "
128+
"ORDER BY Screens.position ASC");
127129
query.bindValue(":id", id);
128130

129131
if (status) {
130132
if (query.exec() == true) {
131133
if (query.next() == true) {
132134
QVector<QByteArray> imageList;
133135
QString body = query.value("body").toString();
134-
// notice that we jump over the fist image
135-
// the first image is the cover image
136+
imageList.push_back(query.value("Picture.data").toByteArray());
136137
while (query.next() == true) {
137138
imageList.push_back(
138139
query.value("Picture.data").toByteArray());
@@ -154,7 +155,8 @@ QString Data::getWalkthrough(const int id) {
154155
status = query.prepare(
155156
"SELECT Level.walkthrough "
156157
"FROM Level "
157-
"WHERE Level.LevelID = :id");
158+
"JOIN Info ON Level.infoID = Info.InfoID "
159+
"WHERE Info.trleID = :id");
158160
query.bindValue(":id", id);
159161

160162
if (status) {
@@ -178,9 +180,8 @@ int Data::getType(const int id) {
178180

179181
status = query.prepare(
180182
"SELECT Info.type "
181-
"FROM Level "
182-
"JOIN Info ON Level.infoID = Info.InfoID "
183-
"WHERE Level.LevelID = :id");
183+
"FROM Info "
184+
"WHERE Info.trleID = :id");
184185
query.bindValue(":id", id);
185186

186187
if (status) {
@@ -205,10 +206,10 @@ ZipData Data::getDownload(const int id) {
205206
status = query.prepare(
206207
"SELECT Zip.*, Info.type "
207208
"FROM Level "
209+
"JOIN Info ON Level.infoID = Info.InfoID "
208210
"JOIN ZipList ON Level.LevelID = ZipList.levelID "
209211
"JOIN Zip ON ZipList.zipID = Zip.ZipID "
210-
"JOIN Info ON Level.infoID = Info.InfoID "
211-
"WHERE Level.LevelID = :id");
212+
"WHERE Info.trleID = :id");
212213
query.bindValue(":id", id);
213214

214215
if (status) {

src/Data.hpp

Lines changed: 121 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@
2525
#include <QSqlError>
2626
#include <QSqlQuery>
2727

28+
29+
/**
30+
* @struct FileList
31+
* @brief Files object to keep track of files.
32+
*
33+
*/
2834
struct FileList {
2935
QString path;
3036
QString md5sum;
3137
};
3238

3339
/**
3440
* @struct FolderNames
35-
* @brief Folder names game used on Windows
41+
* @brief Folder names game used on Windows.
42+
*
3643
* These names are used by steam and installed in the common folder on Linux.
3744
* Except for `TombEngine (TEN)` I made that one up.
3845
*/
@@ -48,6 +55,13 @@ struct FolderNames {
4855
};
4956
};
5057

58+
/**
59+
* @struct ExecutableNames
60+
* @brief Executable game file names used on Windows used to start the games.
61+
*
62+
* These are searched for together with rootless tree patterns. Also used as a default
63+
* starter by using a symbolic link to the executable that links to ddraw, directx11 or opengl.
64+
*/
5165
struct ExecutableNames {
5266
QMap<int, QString> data = {
5367
{0, "null"},
@@ -60,14 +74,33 @@ struct ExecutableNames {
6074
};
6175
};
6276

77+
/**
78+
* @struct ZipData
79+
* @brief Holds download information for a Tomb Raider Level.
80+
*
81+
* This struct is designed to store a TRLE download file record for trle.net or trcustoms.org.
82+
* Each file record contains data for downloading and file name etc for the application.
83+
*/
6384
struct ZipData {
6485
/**
65-
* @struct ZipData
66-
* @brief
67-
* @param
68-
* @details
86+
* @brief Default constructor for `ZipData`.
87+
*
88+
* Initializes an empty instance of `ZipData`.
6989
*/
7090
ZipData() {}
91+
/**
92+
* @brief Parameterized constructor for `ZipData`.
93+
*
94+
* This constructor initializes a `ZipData` object with metadata.
95+
*
96+
* @param zipName TRLE level zip file name.
97+
* @param zipSize Size of the file form TRLE in MiB.
98+
* @param md5sum checksum of the archive.
99+
* @param url String of download address.
100+
* @param version File version from trcustoms.org
101+
* @param type Level type.
102+
* @param release date of file release.
103+
*/
71104
ZipData(
72105
const QString& zipName,
73106
float zipSize,
@@ -77,21 +110,21 @@ struct ZipData {
77110
int type,
78111
const QString& release) :
79112
name(zipName),
80-
megabyteSize(zipSize),
113+
mebibyteSize(zipSize),
81114
md5sum(md5sum),
82115
url(url),
83116
version(version),
84117
type(type),
85118
release(release) {}
86-
QString name;
87-
float megabyteSize;
88-
QString md5sum;
89-
QString url;
90-
int version;
91-
int type;
92-
QString release;
93-
};
94119

120+
QString name; ///< The archive file name.
121+
float mebibyteSize; ///< The archive file size in MiB.
122+
QString md5sum; ///< The archive md5sum.
123+
QString url; ///< The URL of the TRLE level download.
124+
int version; ///< The Version of trcustoms archive file.
125+
int type; ///< The TRLE type used to identify a executable.
126+
QString release; ///< The The date of file release from trcustoms.
127+
};
95128

96129
/**
97130
* @struct ListItemData
@@ -180,11 +213,11 @@ struct ListItemData {
180213

181214
/**
182215
* @struct InfoData
183-
* @brief Store HTML data and a list of icons generated from image WEBP data.
216+
* @brief Store HTML data and a list of level pictures generated from image WEBP data.
184217
*
185218
* This struct is designed to store a body of HTML and convert a list of image data
186-
* (provided as `QByteArray`) into `QIcon` objects. The `QIcon` objects can then
187-
* be used in Qt-based applications with QtWebEngine and QIcons in a split view manner.
219+
* (provided as `QByteArray`) into `QPixmap` objects. The `QPixmap` objects can then
220+
* be used in Qt-based applications with QtWebEngine and QPixmap in a split view manner.
188221
*/
189222
struct InfoData {
190223
/**
@@ -197,18 +230,18 @@ struct InfoData {
197230
/**
198231
* @brief Constructs an `InfoData` object with the given body and image list.
199232
*
200-
* Converts each image in the provided `QVector<QByteArray>` to a `QIcon` object
233+
* Converts each image in the provided `QVector<QByteArray>` to a `QPixmap` object
201234
* using the "WEBP" format and stores them in the icon list.
202235
*
203-
* @param body A string representing the main textual content.
236+
* @param body A string representing the main textual content in HTML.
204237
* @param imageList A vector of image data in `QByteArray` format.
205238
*/
206239
InfoData(const QString& body, const QVector<QByteArray>& imageList)
207240
: m_body(body) {
208241
for (const QByteArray& image : imageList) {
209242
QPixmap pixmap;
210243

211-
// Load image data into a QPixmap and convert it to a QIcon
244+
// Load image data into a QPixmap
212245
if (!pixmap.loadFromData(image, "WEBP")) {
213246
qDebug() << "Could not load webp data to QPixmap.";
214247
}
@@ -221,16 +254,36 @@ struct InfoData {
221254
QVector<QPixmap> m_imageList; ///< A list of level large screen image data.
222255
};
223256

257+
/**
258+
* @class Data
259+
* @brief Data component connected to the Model in the MVC pattern.
260+
*
261+
* It handles database connection(s) and reads and write scraped data.
262+
* Its a singlton in global space that packs data into struct's and passes them
263+
* to and from the Model.
264+
*
265+
*/
224266
class Data : public QObject {
225267
Q_OBJECT
226268

227269
public:
270+
/**
271+
* Mayers thread safe singleton pattern.
272+
*/
228273
static Data& getInstance() {
229274
// cppcheck-suppress threadsafety-threadsafety
230275
static Data instance;
231276
return instance;
232277
}
233278

279+
/**
280+
* @brief Connect to the main database.
281+
*
282+
* Once we setup camp in home, we can use the path to camp.
283+
* That is usually in ~/.local/share/AppName
284+
*
285+
* @param path Full path to the datbase without the file name.
286+
*/
234287
bool initializeDatabase(const QString& path) {
235288
bool status = false;
236289
const QString filePath = QString("%1/%2").arg(path, "tombll.db");
@@ -244,7 +297,6 @@ class Data : public QObject {
244297
} else {
245298
db = QSqlDatabase::addDatabase("QSQLITE");
246299
db.setDatabaseName(QString("%1/tombll.db").arg(path));
247-
// db.setConnectOptions("QSQLITE_OPEN_READONLY");
248300
if (db.open() == true) { // flawfinder: ignore
249301
status = true;
250302
} else {
@@ -255,19 +307,67 @@ class Data : public QObject {
255307
return status;
256308
}
257309

310+
/**
311+
* @brief Close the connection to the main database.
312+
*
313+
* Dont need to be called before the application exit.
314+
*/
258315
void releaseDatabase() {
259316
db.close();
260317
}
261318

319+
/**
320+
* @brief Count all the Level records in the database
321+
* @return The number of Level records
322+
*/
262323
qint64 getListRowCount();
324+
/**
325+
* @brief Get the main list of levels, without the picture
326+
* @return The QVector ListItemData is all the level metadata
327+
*/
263328
QVector<ListItemData> getListItems();
329+
/**
330+
* @brief Add Cover Pictures to ListItemData pointers
331+
* @param Cache like used QVector for holding ListItemData pointers
332+
*/
264333
void getCoverPictures(QVector<ListItemData*>* items);
334+
/**
335+
* @brief Get the info page, this is HTML and picture data you see on trel.net
336+
* @param
337+
* @return The InfoData is a struct of QString and QVector<QPixmap>
338+
*/
265339
InfoData getInfo(int id);
340+
/**
341+
* @brief Get the walkthrough HTML page
342+
* @param
343+
* @return
344+
*/
266345
QString getWalkthrough(int id);
346+
/**
347+
* @brief
348+
* @param
349+
* @return
350+
*/
267351
int getType(int id);
268352

353+
/**
354+
* @brief
355+
* @param
356+
* @return
357+
*/
269358
QVector<FileList> getFileList(const int id);
359+
/**
360+
* @brief
361+
* @param
362+
* @return
363+
*/
270364
ZipData getDownload(const int id);
365+
/**
366+
* @brief
367+
* @param
368+
* @param
369+
* @return
370+
*/
271371
void setDownloadMd5(const int id, const QString& newMd5sum);
272372

273373
private:

src/TombRaiderLinuxLauncher.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ QT_BEGIN_NAMESPACE
3333
namespace Ui { class TombRaiderLinuxLauncher; }
3434
QT_END_NAMESPACE
3535

36+
/** @mainpage TombRaiderLinuxLauncher
37+
*
38+
* @section intro
39+
*
40+
* @section getting started
41+
* @subsection step one
42+
* @subsection step two
43+
*/
44+
3645
/**
3746
* @class TombRaiderLinuxLauncher
3847
* @brief View component in the MVC pattern; Main Window UI class.

0 commit comments

Comments
 (0)