optimise ProfileLoader
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3c673beed1
commit
2f135cd373
1 changed files with 42 additions and 24 deletions
|
@ -16,18 +16,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "ProfileLoader.h"
|
|
||||||
#include "SnapmaticPicture.h"
|
#include "SnapmaticPicture.h"
|
||||||
|
#include "ProfileLoader.h"
|
||||||
#include "SavegameData.h"
|
#include "SavegameData.h"
|
||||||
#include "CrewDatabase.h"
|
#include "CrewDatabase.h"
|
||||||
#include "wrapper.h"
|
#include "wrapper.h"
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QStringList>
|
#include <QVector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QThread>
|
|
||||||
#include <QList>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QList>
|
||||||
|
#else
|
||||||
|
#include "sys/types.h"
|
||||||
|
#include "dirent.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
|
ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
|
||||||
{
|
{
|
||||||
|
@ -36,30 +40,44 @@ ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObjec
|
||||||
void ProfileLoader::run()
|
void ProfileLoader::run()
|
||||||
{
|
{
|
||||||
int curFile = 1;
|
int curFile = 1;
|
||||||
QDir profileDir;
|
int maximumV = 0;
|
||||||
QList<int> crewList;
|
QVector<int> crewList;
|
||||||
profileDir.setPath(profileFolder);
|
QVector<QString> savegameFiles;
|
||||||
|
QVector<QString> snapmaticPics;
|
||||||
|
|
||||||
// Seek pictures and savegames
|
#ifdef Q_OS_WIN
|
||||||
profileDir.setNameFilters(QStringList("SGTA5*"));
|
QDir dir(profileFolder);
|
||||||
QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
|
const QStringList files = dir.entryList();
|
||||||
QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive);
|
for (const QString &fileName : files) {
|
||||||
profileDir.setNameFilters(QStringList("PGTA5*"));
|
if (fileName.startsWith("SGTA5") && !fileName.endsWith(".bak")) {
|
||||||
QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
|
savegameFiles << fileName;
|
||||||
BackupFiles += SnapmaticPics.filter(".bak", Qt::CaseInsensitive);
|
maximumV++;
|
||||||
|
|
||||||
SavegameFiles.removeDuplicates();
|
|
||||||
SnapmaticPics.removeDuplicates();
|
|
||||||
for (const QString &BackupFile : qAsConst(BackupFiles)) {
|
|
||||||
SavegameFiles.removeAll(BackupFile);
|
|
||||||
SnapmaticPics.removeAll(BackupFile);
|
|
||||||
}
|
}
|
||||||
|
if (fileName.startsWith("PGTA5") && !fileName.endsWith(".bak")) {
|
||||||
int maximumV = SavegameFiles.length() + SnapmaticPics.length();
|
snapmaticPics << fileName;
|
||||||
|
maximumV++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
DIR *dirp = opendir(profileFolder.toUtf8().constData());
|
||||||
|
struct dirent *dp;
|
||||||
|
while ((dp = readdir(dirp)) != 0) {
|
||||||
|
const QString fileName = QString::fromUtf8(dp->d_name);
|
||||||
|
if (fileName.startsWith("SGTA5") && !fileName.endsWith(".bak")) {
|
||||||
|
savegameFiles << fileName;
|
||||||
|
maximumV++;
|
||||||
|
}
|
||||||
|
if (fileName.startsWith("PGTA5") && !fileName.endsWith(".bak")) {
|
||||||
|
snapmaticPics << fileName;
|
||||||
|
maximumV++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dirp);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Loading pictures and savegames
|
// Loading pictures and savegames
|
||||||
emit loadingProgress(curFile, maximumV);
|
emit loadingProgress(curFile, maximumV);
|
||||||
for (const QString &SavegameFile : qAsConst(SavegameFiles)) {
|
for (const QString &SavegameFile : qAsConst(savegameFiles)) {
|
||||||
emit loadingProgress(curFile, maximumV);
|
emit loadingProgress(curFile, maximumV);
|
||||||
const QString sgdPath = profileFolder % "/" % SavegameFile;
|
const QString sgdPath = profileFolder % "/" % SavegameFile;
|
||||||
SavegameData *savegame = new SavegameData(sgdPath);
|
SavegameData *savegame = new SavegameData(sgdPath);
|
||||||
|
@ -68,7 +86,7 @@ void ProfileLoader::run()
|
||||||
}
|
}
|
||||||
curFile++;
|
curFile++;
|
||||||
}
|
}
|
||||||
for (const QString &SnapmaticPic : qAsConst(SnapmaticPics)) {
|
for (const QString &SnapmaticPic : qAsConst(snapmaticPics)) {
|
||||||
emit loadingProgress(curFile, maximumV);
|
emit loadingProgress(curFile, maximumV);
|
||||||
const QString picturePath = profileFolder % "/" % SnapmaticPic;
|
const QString picturePath = profileFolder % "/" % SnapmaticPic;
|
||||||
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
|
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
|
||||||
|
|
Loading…
Reference in a new issue