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

ProfileDatabase.cpp 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "ProfileDatabase.h"
  19. #include "StandardPaths.h"
  20. #include "config.h"
  21. #include <QStringBuilder>
  22. #include <QMutexLocker>
  23. #include <QDebug>
  24. #include <QFile>
  25. #include <QDir>
  26. ProfileDatabase::ProfileDatabase(QObject *parent) : QObject(parent)
  27. {
  28. QDir dir;
  29. dir.mkpath(StandardPaths::dataLocation());
  30. dir.setPath(StandardPaths::dataLocation());
  31. QString dirPath = dir.absolutePath();
  32. QString defaultConfPath = dirPath % "/players.ini";
  33. QSettings confPathSettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
  34. confPathSettings.beginGroup("Database");
  35. QString confPathFile = confPathSettings.value("Players", defaultConfPath).toString();
  36. confPathSettings.endGroup();
  37. profileDB = new QSettings(confPathFile, QSettings::IniFormat);
  38. profileDB->beginGroup("Players");
  39. }
  40. ProfileDatabase::~ProfileDatabase()
  41. {
  42. profileDB->endGroup();
  43. delete profileDB;
  44. }
  45. QStringList ProfileDatabase::getPlayers()
  46. {
  47. QMutexLocker locker(&mutex);
  48. #ifdef GTA5SYNC_DEBUG
  49. qDebug() << "getPlayers";
  50. #endif
  51. return profileDB->childKeys();
  52. }
  53. QString ProfileDatabase::getPlayerName(QString playerID)
  54. {
  55. QMutexLocker locker(&mutex);
  56. #ifdef GTA5SYNC_DEBUG
  57. qDebug() << "getPlayerName" << playerID;
  58. #endif
  59. return profileDB->value(playerID, playerID).toString();
  60. }
  61. QString ProfileDatabase::getPlayerName(int playerID)
  62. {
  63. QMutexLocker locker(&mutex);
  64. #ifdef GTA5SYNC_DEBUG
  65. qDebug() << "getPlayerName" << playerID;
  66. #endif
  67. return profileDB->value(QString::number(playerID), playerID).toString();
  68. }
  69. void ProfileDatabase::setPlayerName(int playerID, QString playerName)
  70. {
  71. QMutexLocker locker(&mutex);
  72. #ifdef GTA5SYNC_DEBUG
  73. qDebug() << "setPlayerName" << playerID << playerName;
  74. #endif
  75. profileDB->setValue(QString::number(playerID), playerName);
  76. }