Skip to content

Commit 9b2ecec

Browse files
committed
fix some MISRA
1 parent a959461 commit 9b2ecec

File tree

4 files changed

+54
-51
lines changed

4 files changed

+54
-51
lines changed

src/Data.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct FolderNames {
3636
const QString TR5 = "/Tomb Raider (V) Chronicles";
3737
};
3838

39-
4039
struct ZipData {
4140
/**
4241
* @struct ZipData
@@ -51,7 +50,7 @@ struct ZipData {
5150
QString md5sum,
5251
QString url,
5352
int version,
54-
QString release) :
53+
const QString& release) :
5554
name(zipName),
5655
megabyteSize(zipSize),
5756
md5sum(md5sum),
@@ -145,7 +144,7 @@ struct InfoData {
145144
QIcon finalIcon;
146145

147146
// Load image data into a QPixmap and convert it to a QIcon
148-
if (pixmap.loadFromData(image, "WEBP")) {
147+
if (pixmap.loadFromData(image, "WEBP") == true) {
149148
finalIcon.addPixmap(pixmap);
150149
}
151150

@@ -168,7 +167,7 @@ class Data : public QObject {
168167

169168
bool initializeDatabase(const QString& path) {
170169
bool status = false;
171-
const QString filePath = path + "/tombll.db";
170+
const QString filePath = QString("%1/%2").arg(path, "tombll.db");
172171
QFileInfo fileInfo(filePath);
173172

174173
// Open the file
@@ -180,7 +179,7 @@ class Data : public QObject {
180179
db = QSqlDatabase::addDatabase("QSQLITE");
181180
db.setDatabaseName(path + "/tombll.db");
182181
db.setConnectOptions("QSQLITE_OPEN_READONLY");
183-
if (db.open()) { // flawfinder: ignore
182+
if (db.open() == true) { // flawfinder: ignore
184183
status = true;
185184
} else {
186185
qDebug() << "Error opening database:" << db.lastError().text();

src/FileManager.cpp

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool FileManager::setUpCamp(const QString& levelDir, const QString& gameDir) {
3030
return false;
3131
}
3232
}
33-
levelDir_m.setPath(levelDir);
33+
m_levelDir.setPath(levelDir);
3434

3535
QDir gameDirPath(gameDir);
3636
if (!gameDirPath.exists()) {
@@ -39,15 +39,15 @@ bool FileManager::setUpCamp(const QString& levelDir, const QString& gameDir) {
3939
return false;
4040
}
4141
}
42-
gameDir_m.setPath(gameDir);
42+
m_gameDir.setPath(gameDir);
4343

4444
return true;
4545
}
4646

4747
const QString FileManager::calculateMD5(const QString& file, bool lookGameDir) {
4848
const QString& path = lookGameDir ?
49-
gameDir_m.absolutePath() + QDir::separator()+file :
50-
levelDir_m.absolutePath() + QDir::separator()+file;
49+
m_gameDir.absolutePath() + QDir::separator()+file :
50+
m_levelDir.absolutePath() + QDir::separator()+file;
5151

5252
QFileInfo fileInfo(path);
5353

@@ -79,10 +79,10 @@ bool FileManager::extractZip(
7979
const QString& zipFilename,
8080
const QString& outputFolder) {
8181
const QString& zipPath =
82-
levelDir_m.absolutePath() + QDir::separator() + zipFilename;
82+
m_levelDir.absolutePath() + QDir::separator() + zipFilename;
8383

8484
const QString& outputPath =
85-
levelDir_m.absolutePath() + QDir::separator() + outputFolder;
85+
m_levelDir.absolutePath() + QDir::separator() + outputFolder;
8686

8787
qDebug() << "Unzipping file" << zipFilename << "to" << outputPath;
8888

@@ -173,9 +173,9 @@ bool FileManager::extractZip(
173173
bool FileManager::checkDir(const QString& file, bool lookGameDir ) {
174174
QString path;
175175
if (!lookGameDir) {
176-
path = levelDir_m.absolutePath() + QDir::separator() + file;
176+
path = m_levelDir.absolutePath() + QDir::separator() + file;
177177
} else {
178-
path = gameDir_m.absolutePath() + QDir::separator() + file;
178+
path = m_gameDir.absolutePath() + QDir::separator() + file;
179179
}
180180
QDir directory(path);
181181
return directory.exists();
@@ -184,18 +184,18 @@ bool FileManager::checkDir(const QString& file, bool lookGameDir ) {
184184
bool FileManager::checkFile(const QString& file, bool lookGameDir ) {
185185
QString path;
186186
if (!lookGameDir) {
187-
path = levelDir_m.absolutePath() + QDir::separator() + file;
187+
path = m_levelDir.absolutePath() + QDir::separator() + file;
188188
} else {
189-
path = gameDir_m.absolutePath() + QDir::separator() + file;
189+
path = m_gameDir.absolutePath() + QDir::separator() + file;
190190
}
191191
QFile fFile(path);
192192
return fFile.exists();
193193
}
194194

195195
int FileManager::checkFileInfo(const QString& file, bool lookGameDir) {
196196
const QString& path = lookGameDir ?
197-
gameDir_m.absolutePath() + QDir::separator()+file :
198-
levelDir_m.absolutePath() + QDir::separator()+file;
197+
m_gameDir.absolutePath() + QDir::separator()+file :
198+
m_levelDir.absolutePath() + QDir::separator()+file;
199199

200200
QFileInfo fileInfo(path);
201201
if (fileInfo.isDir()) {
@@ -215,8 +215,8 @@ int FileManager::checkFileInfo(const QString& file, bool lookGameDir) {
215215
}
216216

217217
bool FileManager::linkGameDir(const QString& levelDir, const QString& gameDir) {
218-
const QString& l = levelDir_m.absolutePath() + levelDir;
219-
const QString& g = gameDir_m.absolutePath() + gameDir;
218+
const QString& l = m_levelDir.absolutePath() + levelDir;
219+
const QString& g = m_gameDir.absolutePath() + gameDir;
220220

221221
test(l);
222222

@@ -245,7 +245,7 @@ bool FileManager::makeRelativeLink(
245245
const QString& levelDir,
246246
const QString& from,
247247
const QString& to) {
248-
const QString& l = levelDir_m.absolutePath() + levelDir;
248+
const QString& l = m_levelDir.absolutePath() + levelDir;
249249
const QString& f = l + from;
250250
const QString& t = l + to;
251251

@@ -270,67 +270,74 @@ bool FileManager::makeRelativeLink(
270270
}
271271
}
272272

273-
int FileManager::removeFileOrDirectory(const QString &file, bool lookGameDir) {
274-
const QString& path = lookGameDir ?
275-
gameDir_m.absolutePath() + QDir::separator()+file :
276-
levelDir_m.absolutePath() + QDir::separator()+file;
273+
qint64 FileManager::removeFileOrDirectory(
274+
const QString &file,
275+
bool lookGameDir) {
276+
qint64 status = 0;
277+
const QString& sep = QDir::separator();
278+
const QString& gamePath = m_gameDir.absolutePath() + sep + file;
279+
const QString& levelPath = m_levelDir.absolutePath() + sep + file;
280+
const QString& path = lookGameDir ? gamePath : levelPath;
277281

278282
QDir dir(path);
279283
if (dir.exists()) {
280284
// Remove directory and its contents
281285
if (dir.removeRecursively()) {
282286
qDebug() << "Directory removed successfully:" << path;
283-
return 0;
287+
status = 0;
284288
} else {
285289
qWarning() << "Failed to remove directory:" << path;
286-
return 1;
290+
status = 1;
287291
}
288292
} else {
289-
QFile file(path);
293+
QFile f(path);
290294
// Check if the file exists before attempting to remove it
291-
if (file.exists()) {
292-
if (file.remove()) {
295+
if (f.exists()) {
296+
if (f.remove()) {
293297
qDebug() << "File removed successfully:" << path;
294-
return 0;
298+
status = 0;
295299
} else {
296300
qWarning() << "Failed to remove file:" << path;
297-
return 1;
301+
status = 1;
298302
}
299303
} else {
300304
qDebug() << "File or directory does not exist:" << path;
301-
return 2;
305+
status = 2;
302306
}
303307
}
308+
return status;
304309
}
305310

306311
int FileManager::createDirectory(const QString &file, bool gameDir) {
312+
qint64 status = 0;
307313
const QString& sep = QDir::separator();
308-
const QString& g = gameDir_m.absolutePath() + sep + file;
309-
const QString& l = levelDir_m.absolutePath() + sep + file;
310-
const QString& path = gameDir ? g : l;
314+
const QString& gamePath = m_gameDir.absolutePath() + sep + file;
315+
const QString& levelPath = m_levelDir.absolutePath() + sep + file;
316+
const QString& path = gameDir ? gamePath : levelPath;
311317

312318
// Create the directory if it doesn't exist
313319
if (!QDir(path).exists()) {
314320
if (QDir().mkpath(path)) {
315321
qDebug() << "Directory created successfully.";
316-
return 0;
322+
status = 0;
317323
} else {
318324
qDebug() << "Error creating directory.";
319-
return 1;
325+
status = 1;
320326
}
321327
} else {
322328
qDebug() << "Directory already exists.";
323-
return 0;
329+
status = 0;
324330
}
331+
return status;
325332
}
326333

327334
int FileManager::copyFile(
328335
const QString &gameFile,
329336
const QString &levelFile,
330337
bool fromGameDir) {
331338

332-
const QString& gamePath = gameDir_m.absolutePath() + gameFile;
333-
const QString& levelPath = levelDir_m.absolutePath() + levelFile;
339+
const QString& gamePath = m_gameDir.absolutePath() + gameFile;
340+
const QString& levelPath = m_levelDir.absolutePath() + levelFile;
334341

335342
const QString& g = fromGameDir ? gamePath : levelPath;
336343
const QString& l = fromGameDir ? levelPath : gamePath;
@@ -364,7 +371,7 @@ int FileManager::copyFile(
364371
int FileManager::cleanWorkingDir(const QString &levelDir) {
365372
const QString sep = QDir::separator();
366373
const QString& directoryPath =
367-
levelDir_m.absolutePath() + sep + levelDir;
374+
m_levelDir.absolutePath() + sep + levelDir;
368375

369376
QDir directory(directoryPath);
370377
if (directory.exists()) {
@@ -381,7 +388,7 @@ int FileManager::cleanWorkingDir(const QString &levelDir) {
381388
}
382389

383390
bool FileManager::backupGameDir(const QString &gameDir) {
384-
const QString& source = gameDir_m.absolutePath() + gameDir.chopped(1);
391+
const QString& source = m_gameDir.absolutePath() + gameDir.chopped(1);
385392
const QString& des = source + ".old";
386393
QDir directory;
387394
if (directory.rename(source, des)) {
@@ -400,10 +407,10 @@ bool FileManager::moveFilesToDirectory(
400407
const QString& sep = QDir::separator();
401408

402409
const QString& directoryFromPath =
403-
levelDir_m.absolutePath() + sep + fromLevelDirectory;
410+
m_levelDir.absolutePath() + sep + fromLevelDirectory;
404411

405412
const QString& directoryToPath =
406-
levelDir_m.absolutePath() + sep + toLevelDirectory;
413+
m_levelDir.absolutePath() + sep + toLevelDirectory;
407414

408415
QDir dir(directoryFromPath);
409416

@@ -430,7 +437,7 @@ bool FileManager::moveFilesToParentDirectory(
430437
int levelsUp) {
431438

432439
const QString& sep = QDir::separator();
433-
QDir levelDirectoryFullPath(levelDir_m.absolutePath() + sep +
440+
QDir levelDirectoryFullPath(m_levelDir.absolutePath() + sep +
434441
levelDirectory);
435442

436443
if (!levelDirectoryFullPath.exists()) {

src/FileManager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FileManager : public QObject {
3636
bool checkDir(const QString& file, bool lookGameDir);
3737
bool checkFile(const QString& file, bool lookGameDir);
3838
int checkFileInfo(const QString& file, bool lookGameDir = true);
39-
int removeFileOrDirectory(const QString &file, bool lookGameDir);
39+
qint64 removeFileOrDirectory(const QString &file, bool lookGameDir);
4040
bool moveFilesToDirectory(
4141
const QString& fromLevelDirectory,
4242
const QString& toLevelDirectory);
@@ -65,8 +65,8 @@ class FileManager : public QObject {
6565
private:
6666
explicit FileManager(QObject *parent = nullptr) : QObject(parent) {}
6767

68-
QDir levelDir_m;
69-
QDir gameDir_m;
68+
QDir m_levelDir;
69+
QDir m_gameDir;
7070
Q_DISABLE_COPY(FileManager)
7171
};
7272
#endif // SRC_FILEMANAGER_HPP_

src/TombRaiderLinuxLauncher.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,10 @@ class TombRaiderLinuxLauncher : public QMainWindow {
114114
QListWidgetItem*,
115115
QListWidgetItem*)> compare);
116116

117-
// cppcheck-suppress unusedStructMember
118117
QSet<QListWidgetItem*> originalGamesSet_m;
119-
// cppcheck-suppress unusedStructMember
120118
QList<QListWidgetItem*> originalGamesList_m;
121119
Controller& controller = Controller::getInstance();
122120
QSettings settings;
123-
// cppcheck-suppress unusedStructMember
124121
Ui::TombRaiderLinuxLauncher *ui;
125122
};
126123
#endif // SRC_TOMBRAIDERLINUXLAUNCHER_HPP_

0 commit comments

Comments
 (0)