Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

308 lines
12 KiB

  1. /*****************************************************************************
  2. * gta5view Grand Theft Auto V Profile Viewer
  3. * Copyright (C) 2016-2018 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 "TranslationClass.h"
  19. #include "SnapmaticPicture.h"
  20. #include "ProfileDatabase.h"
  21. #include "DatabaseThread.h"
  22. #include "SavegameDialog.h"
  23. #include "OptionsDialog.h"
  24. #include "PictureDialog.h"
  25. #include "UserInterface.h"
  26. #include "CrewDatabase.h"
  27. #include "SavegameData.h"
  28. #include "UiModWidget.h"
  29. #include "UiModLabel.h"
  30. #include "IconLoader.h"
  31. #include "AppEnv.h"
  32. #include "config.h"
  33. #include <QDesktopWidget>
  34. #include <QStringBuilder>
  35. #include <QSignalMapper>
  36. #include <QStyleFactory>
  37. #include <QApplication>
  38. #include <QPushButton>
  39. #include <QSpacerItem>
  40. #include <QVBoxLayout>
  41. #include <QHBoxLayout>
  42. #include <QMessageBox>
  43. #include <QStringList>
  44. #include <QTranslator>
  45. #include <QResource>
  46. #include <QCheckBox>
  47. #include <QFileInfo>
  48. #include <QSysInfo>
  49. #include <QLayout>
  50. #include <QObject>
  51. #include <QString>
  52. #include <QDebug>
  53. #include <QFont>
  54. #include <QFile>
  55. #ifdef GTA5SYNC_WIN
  56. #include "windows.h"
  57. #include <iostream>
  58. #endif
  59. #ifdef GTA5SYNC_TELEMETRY
  60. #include "TelemetryClass.h"
  61. #endif
  62. int main(int argc, char *argv[])
  63. {
  64. QApplication a(argc, argv);
  65. a.setApplicationName(GTA5SYNC_APPSTR);
  66. a.setApplicationVersion(GTA5SYNC_APPVER);
  67. a.setQuitOnLastWindowClosed(false);
  68. QResource::registerResource(":/global/global.rcc");
  69. QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
  70. settings.beginGroup("Startup");
  71. bool isFirstStart = settings.value("IsFirstStart", true).toBool();
  72. bool customStyle = settings.value("CustomStyle", false).toBool();
  73. QString appStyle = settings.value("AppStyle", "Default").toString();
  74. if (customStyle)
  75. {
  76. if (QStyleFactory::keys().contains(appStyle, Qt::CaseInsensitive))
  77. {
  78. a.setStyle(QStyleFactory::create(appStyle));
  79. }
  80. }
  81. #ifdef GTA5SYNC_WIN
  82. #if QT_VERSION >= 0x050400
  83. bool alwaysUseMessageFont = settings.value("AlwaysUseMessageFont", false).toBool();
  84. if (QSysInfo::windowsVersion() >= 0x0080 || alwaysUseMessageFont)
  85. {
  86. // Get Windows Font
  87. NONCLIENTMETRICS ncm;
  88. ncm.cbSize = sizeof(ncm);
  89. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
  90. LOGFONTW uiFont = ncm.lfMessageFont;
  91. QString uiFontStr(QString::fromStdWString(std::wstring(uiFont.lfFaceName)));
  92. #ifdef GTA5SYNC_DEBUG
  93. qDebug() << QApplication::tr("Font") << QApplication::tr("Selected Font: %1").arg(uiFontStr);
  94. #endif
  95. // Set Application Font
  96. QFont appFont(uiFontStr, 9);
  97. a.setFont(appFont);
  98. }
  99. #endif
  100. #endif
  101. QStringList applicationArgs = a.arguments();
  102. QString selectedAction;
  103. QString arg1;
  104. applicationArgs.removeAt(0);
  105. Translator->initUserLanguage();
  106. Translator->loadTranslation(&a);
  107. #ifdef GTA5SYNC_TELEMETRY
  108. Telemetry->init();
  109. Telemetry->work();
  110. #endif
  111. if (!applicationArgs.contains("--skip-firststart"))
  112. {
  113. if (isFirstStart)
  114. {
  115. QMessageBox::StandardButton button = QMessageBox::information(a.desktop(), QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER), QApplication::tr("<h4>Welcome to %1!</h4>You want to configure %1 before you start using it?").arg(GTA5SYNC_APPSTR), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  116. if (button == QMessageBox::Yes)
  117. {
  118. ProfileDatabase profileDB;
  119. OptionsDialog optionsDialog(&profileDB);
  120. optionsDialog.setWindowIcon(IconLoader::loadingAppIcon());
  121. optionsDialog.show();
  122. optionsDialog.exec();
  123. }
  124. settings.setValue("IsFirstStart", false);
  125. }
  126. }
  127. #ifdef GTA5SYNC_TELEMETRY
  128. bool telemetryWindowLaunched = settings.value("PersonalUsageDataWindowLaunched", false).toBool();
  129. bool pushUsageData = settings.value("PushUsageData", false).toBool();
  130. if (!telemetryWindowLaunched && !pushUsageData)
  131. {
  132. QDialog *telemetryDialog = new QDialog();
  133. telemetryDialog->setObjectName(QStringLiteral("TelemetryDialog"));
  134. telemetryDialog->setWindowTitle(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
  135. telemetryDialog->setWindowFlags(telemetryDialog->windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint);
  136. telemetryDialog->setWindowIcon(IconLoader::loadingAppIcon());
  137. QVBoxLayout *telemetryLayout = new QVBoxLayout(telemetryDialog);
  138. telemetryLayout->setObjectName(QStringLiteral("TelemetryLayout"));
  139. telemetryDialog->setLayout(telemetryLayout);
  140. UiModLabel *telemetryLabel = new UiModLabel(telemetryDialog);
  141. telemetryLabel->setObjectName(QStringLiteral("TelemetryLabel"));
  142. telemetryLabel->setText(QString("<h4>%2</h4>%1").arg(
  143. QApplication::translate("TelemetryDialog", "You want help %1 to improve in the future by including personal usage data in your submission?").arg(GTA5SYNC_APPSTR),
  144. QApplication::translate("TelemetryDialog", "%1 User Statistics").arg(GTA5SYNC_APPSTR)));
  145. telemetryLayout->addWidget(telemetryLabel);
  146. QCheckBox *telemetryCheckBox = new QCheckBox(telemetryDialog);
  147. telemetryCheckBox->setObjectName(QStringLiteral("TelemetryCheckBox"));
  148. telemetryCheckBox->setText(QApplication::translate("TelemetryDialog", "Yes, I want include personal usage data."));
  149. telemetryLayout->addWidget(telemetryCheckBox);
  150. QHBoxLayout *telemetryButtonLayout = new QHBoxLayout();
  151. telemetryButtonLayout->setObjectName(QStringLiteral("TelemetryButtonLayout"));
  152. telemetryLayout->addLayout(telemetryButtonLayout);
  153. QSpacerItem *telemetryButtonSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
  154. telemetryButtonLayout->addSpacerItem(telemetryButtonSpacer);
  155. QPushButton *telemetryButton = new QPushButton(telemetryDialog);
  156. telemetryButton->setObjectName(QStringLiteral("TelemetryButton"));
  157. telemetryButton->setText(QApplication::translate("TelemetryDialog", "&OK"));
  158. telemetryButtonLayout->addWidget(telemetryButton);
  159. QObject::connect(telemetryButton, SIGNAL(clicked(bool)), telemetryDialog, SLOT(close()));
  160. telemetryDialog->setFixedSize(telemetryDialog->sizeHint());
  161. telemetryDialog->exec();
  162. QObject::disconnect(telemetryButton, SIGNAL(clicked(bool)), telemetryDialog, SLOT(close()));
  163. if (telemetryCheckBox->isChecked())
  164. {
  165. QSettings telemetrySettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
  166. telemetrySettings.beginGroup("Telemetry");
  167. telemetrySettings.setValue("PushUsageData", true);
  168. telemetrySettings.endGroup();
  169. Telemetry->init();
  170. Telemetry->work();
  171. }
  172. settings.setValue("PersonalUsageDataWindowLaunched", true);
  173. delete telemetryDialog;
  174. }
  175. #endif
  176. settings.endGroup();
  177. for (QString currentArg : applicationArgs)
  178. {
  179. QString reworkedArg;
  180. if (currentArg.left(9) == "-showpic=" && selectedAction == "")
  181. {
  182. reworkedArg = currentArg.remove(0,9);
  183. arg1 = reworkedArg;
  184. selectedAction = "showpic";
  185. }
  186. else if (currentArg.left(9) == "-showsgd=" && selectedAction == "")
  187. {
  188. reworkedArg = currentArg.remove(0,9);
  189. arg1 = reworkedArg;
  190. selectedAction = "showsgd";
  191. }
  192. else if (selectedAction == "")
  193. {
  194. QFile argumentFile(currentArg);
  195. QFileInfo argumentFileInfo(argumentFile);
  196. if (argumentFile.exists())
  197. {
  198. QString argumentFileName = argumentFileInfo.fileName();
  199. QString argumentFileType = argumentFileName.left(4);
  200. QString argumentFileExt = argumentFileName.right(4);
  201. if (argumentFileType == "PGTA" || argumentFileExt == ".g5e")
  202. {
  203. arg1 = currentArg;
  204. selectedAction = "showpic";
  205. }
  206. else if (argumentFileType == "SGTA")
  207. {
  208. arg1 = currentArg;
  209. selectedAction = "showsgd";
  210. }
  211. else if (argumentFileType == "MISR")
  212. {
  213. arg1 = currentArg;
  214. selectedAction = "showsgd";
  215. }
  216. }
  217. }
  218. }
  219. if (selectedAction == "showpic")
  220. {
  221. CrewDatabase crewDB;
  222. ProfileDatabase profileDB;
  223. DatabaseThread threadDB(&crewDB);
  224. PictureDialog picDialog(true, &profileDB, &crewDB);
  225. SnapmaticPicture picture;
  226. bool readOk = picture.readingPictureFromFile(arg1);
  227. picDialog.setWindowIcon(IconLoader::loadingAppIcon());
  228. picDialog.setSnapmaticPicture(&picture, readOk);
  229. #ifndef Q_OS_LINUX
  230. picDialog.setWindowFlags(picDialog.windowFlags()^Qt::Dialog^Qt::Window);
  231. #endif
  232. int crewID = picture.getSnapmaticProperties().crewID;
  233. if (crewID != 0) { crewDB.addCrew(crewID); }
  234. if (!readOk) { return 1; }
  235. QObject::connect(&threadDB, SIGNAL(crewNameFound(int, QString)), &crewDB, SLOT(setCrewName(int, QString)));
  236. QObject::connect(&threadDB, SIGNAL(crewNameUpdated()), &picDialog, SLOT(crewNameUpdated()));
  237. QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
  238. QObject::connect(&threadDB, SIGNAL(playerNameUpdated()), &picDialog, SLOT(playerNameUpdated()));
  239. QObject::connect(&threadDB, SIGNAL(finished()), &a, SLOT(quit()));
  240. QObject::connect(&picDialog, SIGNAL(endDatabaseThread()), &threadDB, SLOT(terminateThread()));
  241. threadDB.start();
  242. picDialog.show();
  243. return a.exec();
  244. }
  245. else if (selectedAction == "showsgd")
  246. {
  247. SavegameDialog savegameDialog;
  248. SavegameData savegame;
  249. bool readOk = savegame.readingSavegameFromFile(arg1);
  250. savegameDialog.setWindowIcon(IconLoader::loadingAppIcon());
  251. savegameDialog.setSavegameData(&savegame, arg1, readOk);
  252. savegameDialog.setWindowFlags(savegameDialog.windowFlags()^Qt::Dialog^Qt::Window);
  253. if (!readOk) { return 1; }
  254. a.setQuitOnLastWindowClosed(true);
  255. savegameDialog.show();
  256. return a.exec();
  257. }
  258. CrewDatabase crewDB;
  259. ProfileDatabase profileDB;
  260. DatabaseThread threadDB(&crewDB);
  261. QObject::connect(&threadDB, SIGNAL(crewNameFound(int,QString)), &crewDB, SLOT(setCrewName(int, QString)));
  262. QObject::connect(&threadDB, SIGNAL(playerNameFound(int, QString)), &profileDB, SLOT(setPlayerName(int, QString)));
  263. QObject::connect(&threadDB, SIGNAL(finished()), &a, SLOT(quit()));
  264. threadDB.start();
  265. UserInterface uiWindow(&profileDB, &crewDB, &threadDB);
  266. uiWindow.setWindowIcon(IconLoader::loadingAppIcon());
  267. uiWindow.setupDirEnv();
  268. #ifdef Q_OS_ANDROID
  269. uiWindow.showMaximized();
  270. #else
  271. uiWindow.show();
  272. #endif
  273. return a.exec();
  274. }