gta5view/ProfileLoader.cpp

131 lines
4.2 KiB
C++
Raw Normal View History

2017-10-09 08:35:48 +02:00
/*****************************************************************************
* gta5view Grand Theft Auto V Profile Viewer
* Copyright (C) 2016-2021 Syping
2017-10-09 08:35:48 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "SnapmaticPicture.h"
2021-04-02 02:54:28 +02:00
#include "ProfileLoader.h"
2017-10-09 08:35:48 +02:00
#include "SavegameData.h"
#include "CrewDatabase.h"
2021-03-26 10:59:34 +01:00
#include "wrapper.h"
2017-10-09 08:35:48 +02:00
#include <QStringBuilder>
2021-04-02 02:54:28 +02:00
#include <QVector>
2017-10-09 08:35:48 +02:00
#include <QString>
#include <QFile>
2021-04-02 02:54:28 +02:00
#ifdef Q_OS_WIN
2017-10-09 08:35:48 +02:00
#include <QDir>
2021-04-02 02:54:28 +02:00
#include <QList>
#else
#include "sys/types.h"
2021-04-02 03:05:54 +02:00
#include "sys/stat.h"
2021-04-02 02:54:28 +02:00
#include "dirent.h"
#endif
2017-10-09 08:35:48 +02:00
ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
{
}
void ProfileLoader::run()
{
int curFile = 1;
2021-04-02 02:54:28 +02:00
int maximumV = 0;
QVector<int> crewList;
QVector<QString> savegameFiles;
QVector<QString> snapmaticPics;
2017-10-09 08:35:48 +02:00
2021-04-02 02:54:28 +02:00
#ifdef Q_OS_WIN
QDir dir(profileFolder);
2021-04-02 03:05:54 +02:00
const QStringList files = dir.entryList(QDir::Files);
2021-04-02 02:54:28 +02:00
for (const QString &fileName : files) {
if (fileName.startsWith("SGTA5") && !fileName.endsWith(".bak")) {
savegameFiles << fileName;
maximumV++;
}
if (fileName.startsWith("PGTA5") && !fileName.endsWith(".bak")) {
snapmaticPics << fileName;
maximumV++;
}
2017-10-09 08:35:48 +02:00
}
2021-04-02 02:54:28 +02:00
#else
DIR *dirp = opendir(profileFolder.toUtf8().constData());
struct dirent *dp;
while ((dp = readdir(dirp)) != 0) {
const QString fileName = QString::fromUtf8(dp->d_name);
2021-04-02 03:05:54 +02:00
const QString filePath = profileFolder % "/" % fileName;
struct stat fileStat;
stat(filePath.toUtf8().constData(), &fileStat);
if (S_ISREG(fileStat.st_mode) != 0) {
if (fileName.startsWith("SGTA5") && !fileName.endsWith(".bak")) {
savegameFiles << fileName;
maximumV++;
}
if (fileName.startsWith("PGTA5") && !fileName.endsWith(".bak")) {
snapmaticPics << fileName;
maximumV++;
}
2021-04-02 02:54:28 +02:00
}
}
closedir(dirp);
#endif
2017-10-09 08:35:48 +02:00
// Loading pictures and savegames
emit loadingProgress(curFile, maximumV);
2021-04-02 02:54:28 +02:00
for (const QString &SavegameFile : qAsConst(savegameFiles)) {
2017-10-09 08:35:48 +02:00
emit loadingProgress(curFile, maximumV);
const QString sgdPath = profileFolder % "/" % SavegameFile;
2017-10-09 08:35:48 +02:00
SavegameData *savegame = new SavegameData(sgdPath);
if (savegame->readingSavegame()) {
2017-10-09 08:35:48 +02:00
emit savegameLoaded(savegame, sgdPath);
}
curFile++;
}
2021-04-02 02:54:28 +02:00
for (const QString &SnapmaticPic : qAsConst(snapmaticPics)) {
2017-10-09 08:35:48 +02:00
emit loadingProgress(curFile, maximumV);
const QString picturePath = profileFolder % "/" % SnapmaticPic;
2017-10-09 08:35:48 +02:00
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
if (picture->readingPicture(true)) {
if (picture->isFormatSwitched()) {
picture->setSnapmaticFormat(SnapmaticFormat::PGTA_Format);
if (picture->exportPicture(picturePath, SnapmaticFormat::PGTA_Format)) {
emit pictureFixed(picture);
}
}
2017-10-09 08:35:48 +02:00
emit pictureLoaded(picture);
int crewNumber = picture->getSnapmaticProperties().crewID;
if (!crewList.contains(crewNumber)) {
2017-10-09 08:35:48 +02:00
crewList += crewNumber;
}
}
curFile++;
}
// adding found crews
crewDB->setAddingCrews(true);
for (int crewID : qAsConst(crewList)) {
2017-10-09 08:35:48 +02:00
crewDB->addCrew(crewID);
}
crewDB->setAddingCrews(false);
}
void ProfileLoader::preloaded()
{
}
void ProfileLoader::loaded()
{
}