Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/

ProfileLoader.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*****************************************************************************
  2. * gta5view Grand Theft Auto V Profile Viewer
  3. * Copyright (C) 2016-2017 Syping
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *****************************************************************************/
  18. #include "ProfileLoader.h"
  19. #include "SnapmaticPicture.h"
  20. #include "SavegameData.h"
  21. #include "CrewDatabase.h"
  22. #include <QStringBuilder>
  23. #include <QStringList>
  24. #include <QString>
  25. #include <QThread>
  26. #include <QList>
  27. #include <QFile>
  28. #include <QDir>
  29. ProfileLoader::ProfileLoader(QString profileFolder, CrewDatabase *crewDB, QObject *parent) : QThread(parent), profileFolder(profileFolder), crewDB(crewDB)
  30. {
  31. }
  32. void ProfileLoader::run()
  33. {
  34. int curFile = 1;
  35. QDir profileDir;
  36. QList<int> crewList;
  37. profileDir.setPath(profileFolder);
  38. // Seek pictures and savegames
  39. profileDir.setNameFilters(QStringList("SGTA*"));
  40. QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
  41. QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive);
  42. profileDir.setNameFilters(QStringList("PGTA*"));
  43. QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort);
  44. BackupFiles += SnapmaticPics.filter(".bak", Qt::CaseInsensitive);
  45. SavegameFiles.removeDuplicates();
  46. SnapmaticPics.removeDuplicates();
  47. for (QString BackupFile : BackupFiles)
  48. {
  49. SavegameFiles.removeAll(BackupFile);
  50. SnapmaticPics.removeAll(BackupFile);
  51. }
  52. int maximumV = SavegameFiles.length() + SnapmaticPics.length();
  53. // Loading pictures and savegames
  54. emit loadingProgress(curFile, maximumV);
  55. for (QString SavegameFile : SavegameFiles)
  56. {
  57. emit loadingProgress(curFile, maximumV);
  58. QString sgdPath = profileFolder % "/" % SavegameFile;
  59. SavegameData *savegame = new SavegameData(sgdPath);
  60. if (savegame->readingSavegame())
  61. {
  62. emit savegameLoaded(savegame, sgdPath);
  63. }
  64. curFile++;
  65. }
  66. for (QString SnapmaticPic : SnapmaticPics)
  67. {
  68. emit loadingProgress(curFile, maximumV);
  69. QString picturePath = profileFolder % "/" % SnapmaticPic;
  70. SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
  71. if (picture->readingPicture(true, true, true))
  72. {
  73. if (picture->isFormatSwitched())
  74. {
  75. picture->setSnapmaticFormat(SnapmaticFormat::PGTA_Format);
  76. if (picture->exportPicture(picturePath, SnapmaticFormat::PGTA_Format))
  77. {
  78. emit pictureFixed(picture);
  79. }
  80. }
  81. emit pictureLoaded(picture);
  82. int crewNumber = picture->getSnapmaticProperties().crewID;
  83. if (!crewList.contains(crewNumber))
  84. {
  85. crewList += crewNumber;
  86. }
  87. }
  88. curFile++;
  89. }
  90. // adding found crews
  91. crewDB->setAddingCrews(true);
  92. for (int crewID : crewList)
  93. {
  94. crewDB->addCrew(crewID);
  95. }
  96. crewDB->setAddingCrews(false);
  97. }
  98. void ProfileLoader::preloaded()
  99. {
  100. }
  101. void ProfileLoader::loaded()
  102. {
  103. }