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

SavegameData.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "SnapmaticPicture.h"
  19. #include "StringParser.h"
  20. #include "SavegameData.h"
  21. #include <QStringBuilder>
  22. #include <QTextCodec>
  23. #include <QByteArray>
  24. #include <QDebug>
  25. #include <QFile>
  26. #define savegameHeaderLength 260
  27. #define verificationValue QByteArray::fromHex("00000001")
  28. SavegameData::SavegameData(const QString &fileName, QObject *parent) : QObject(parent), savegameFileName(fileName)
  29. {
  30. // INIT SAVEGAME
  31. savegameStr = "";
  32. savegameOk = 0;
  33. }
  34. bool SavegameData::readingSavegame()
  35. {
  36. // Start opening file
  37. // lastStep is like currentStep
  38. QFile *saveFile = new QFile(savegameFileName);
  39. if (!saveFile->open(QFile::ReadOnly))
  40. {
  41. lastStep = "1;/1,OpenFile," % SnapmaticPicture::convertDrawStringForLog(savegameFileName);
  42. saveFile->deleteLater();
  43. delete saveFile;
  44. return false;
  45. }
  46. // Reading Savegame Header
  47. if (!saveFile->isReadable())
  48. {
  49. lastStep = "2;/3,ReadingFile," % SnapmaticPicture::convertDrawStringForLog(savegameFileName) % ",1,NOHEADER";
  50. saveFile->close();
  51. saveFile->deleteLater();
  52. delete saveFile;
  53. return false;
  54. }
  55. QByteArray savegameHeaderLine = saveFile->read(savegameHeaderLength);
  56. if (savegameHeaderLine.left(4) == verificationValue)
  57. {
  58. savegameStr = getSavegameDataString(savegameHeaderLine);
  59. if (savegameStr.length() >= 1)
  60. {
  61. savegameOk = true;
  62. }
  63. }
  64. saveFile->close();
  65. saveFile->deleteLater();
  66. delete saveFile;
  67. return savegameOk;
  68. }
  69. QString SavegameData::getSavegameDataString(const QByteArray &savegameHeader)
  70. {
  71. QByteArray savegameBytes = savegameHeader.left(savegameHeaderLength);
  72. QList<QByteArray> savegameBytesList = savegameBytes.split(char(0x01));
  73. savegameBytes = savegameBytesList.at(1);
  74. savegameBytesList.clear();
  75. return SnapmaticPicture::parseTitleString(savegameBytes, savegameBytes.length());
  76. }
  77. bool SavegameData::readingSavegameFromFile(const QString &fileName)
  78. {
  79. if (fileName != "")
  80. {
  81. savegameFileName = fileName;
  82. return readingSavegame();
  83. }
  84. else
  85. {
  86. return false;
  87. }
  88. }
  89. bool SavegameData::isSavegameOk()
  90. {
  91. return savegameOk;
  92. }
  93. QString SavegameData::getSavegameFileName()
  94. {
  95. return savegameFileName;
  96. }
  97. QString SavegameData::getSavegameStr()
  98. {
  99. return savegameStr;
  100. }
  101. QString SavegameData::getLastStep()
  102. {
  103. return lastStep;
  104. }
  105. void SavegameData::setSavegameFileName(QString savegameFileName_)
  106. {
  107. savegameFileName = savegameFileName_;
  108. }