Browse Source

added telemetry

1.5.x
Syping 5 years ago
parent
commit
d0caea372c
  1. 2
      .travis/debian32_travis.sh
  2. 9
      AboutDialog.cpp
  3. 7
      AppEnv.cpp
  4. 5
      AppEnv.h
  5. 29
      ImageEditorDialog.cpp
  6. 13
      ImportDialog.cpp
  7. 20
      JsonEditorDialog.cpp
  8. 13
      OptionsDialog.cpp
  9. 8
      PictureDialog.cpp
  10. 28
      PlayerListDialog.cpp
  11. 13
      ProfileInterface.cpp
  12. 18
      SnapmaticEditor.cpp
  13. 384
      TelemetryClass.cpp
  14. 75
      TelemetryClass.h
  15. 27
      UserInterface.cpp
  16. 2
      config.h
  17. 18
      gta5view.pro
  18. 58
      main.cpp
  19. 14
      res/app.rc
  20. 99
      tmext/TelemetryClassAuthenticator.cpp
  21. 41
      tmext/TelemetryClassAuthenticator.h

2
.travis/debian32_travis.sh

@ -1,7 +1,7 @@
#!/bin/bash
DOCKER_IMAGE=i386/debian:jessie
PROJECT_DIR_DOCKER=/gta5view/
PROJECT_DIR_DOCKER=/gta5view
cd $PROJECT_DIR && \
docker pull $DOCKER_IMAGE && \

9
AboutDialog.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@ AboutDialog::AboutDialog(QWidget *parent) :
QString appVersion = qApp->applicationVersion();
QString buildType = tr(GTA5SYNC_BUILDTYPE);
buildType.replace("_", " ");
QString projectBuild = GTA5SYNC_BUILDDATETIME;
QString projectBuild = AppEnv::getBuildDateTime();
QString buildStr = GTA5SYNC_BUILDSTRING;
// Translator Comments
@ -102,10 +102,15 @@ AboutDialog::AboutDialog(QWidget *parent) :
ui->labAbout->setText(aboutStr.arg(GTA5SYNC_APPSTR, projectDes, appVersion % " (" % buildType % ")", projectBuild, buildStr, qVersion(), copyrightDesA));
this->setWindowTitle(titleStr.arg(GTA5SYNC_APPSTR));
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();

7
AppEnv.cpp

@ -37,6 +37,13 @@ AppEnv::AppEnv()
}
// Build Stuff
QString AppEnv::getBuildDateTime()
{
return GTA5SYNC_BUILDDATETIME;
}
// Folder Stuff
QString AppEnv::getGameFolder(bool *ok)

5
AppEnv.h

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,6 +27,9 @@ class AppEnv
public:
AppEnv();
// Build Stuff
static QString getBuildDateTime();
// Folder Stuff
static QString getGameFolder(bool *ok = 0);
static bool setGameFolder(QString gameFolder);

29
ImageEditorDialog.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2017-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,8 +37,35 @@ ImageEditorDialog::ImageEditorDialog(SnapmaticPicture *picture, QString profileN
setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
ui->setupUi(this);
ui->cmdClose->setDefault(true);
ui->cmdClose->setFocus();
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Import Button
if (QIcon::hasThemeIcon("document-import"))
{
ui->cmdReplace->setIcon(QIcon::fromTheme("document-import"));
}
// Set Icon for Overwrite Button
if (QIcon::hasThemeIcon("document-save"))
{
ui->cmdSave->setIcon(QIcon::fromTheme("document-save"));
}
else if (QIcon::hasThemeIcon("gtk-save"))
{
ui->cmdSave->setIcon(QIcon::fromTheme("gtk-save"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();

13
ImportDialog.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping
* Copyright (C) 2017-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -55,14 +55,25 @@ ImportDialog::ImportDialog(QWidget *parent) :
avatarAreaImage = QImage(":/img/avatarareaimport.png");
selectedColour = QColor::fromRgb(0, 0, 0, 255);
// Set Icon for OK Button
if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
else if (QIcon::hasThemeIcon("gtk-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("gtk-ok"));
}
// Set Icon for Cancel Button
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
else if (QIcon::hasThemeIcon("gtk-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("gtk-cancel"));
}
ui->cbIgnore->setChecked(false);
ui->labColour->setText(tr("Background Colour: <span style=\"color: %1\">%1</span>").arg(selectedColour.name()));

20
JsonEditorDialog.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2017 Syping
* Copyright (C) 2017-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -38,10 +38,28 @@ JsonEditorDialog::JsonEditorDialog(SnapmaticPicture *picture, QWidget *parent) :
ui->setupUi(this);
ui->cmdClose->setDefault(true);
ui->cmdClose->setFocus();
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Save Button
if (QIcon::hasThemeIcon("document-save"))
{
ui->cmdSave->setIcon(QIcon::fromTheme("document-save"));
}
else if (QIcon::hasThemeIcon("gtk-save"))
{
ui->cmdSave->setIcon(QIcon::fromTheme("gtk-save"));
}
jsonCode = picture->getJsonStr();
#if QT_VERSION >= 0x050200

13
OptionsDialog.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -64,14 +64,25 @@ OptionsDialog::OptionsDialog(ProfileDatabase *profileDB, QWidget *parent) :
ui->rbPicDesktopRes->setText(ui->rbPicDesktopRes->text().arg(QString::number(desktopSizeWidth), QString::number(desktopSizeHeight)));
ui->rbPicDefaultRes->setText(ui->rbPicDefaultRes->text().arg(QString::number(defExportSize.width()), QString::number(defExportSize.height())));
// Set Icon for OK Button
if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("dialog-ok"));
}
else if (QIcon::hasThemeIcon("gtk-ok"))
{
ui->cmdOK->setIcon(QIcon::fromTheme("gtk-ok"));
}
// Set Icon for Cancel Button
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
else if (QIcon::hasThemeIcon("gtk-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("gtk-cancel"));
}
setupTreeWidget();
setupLanguageBox();

8
PictureDialog.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -166,11 +166,15 @@ void PictureDialog::setupPictureDialog()
// Event connects
connect(ui->labJSON, SIGNAL(resized(QSize)), this, SLOT(adaptNewDialogSize(QSize)));
// Dialog buttons
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
}
installEventFilter(this);
installEventFilter(ui->labPicture);

28
PlayerListDialog.cpp

@ -37,7 +37,9 @@ PlayerListDialog::PlayerListDialog(QStringList players, ProfileDatabase *profile
ui->setupUi(this);
ui->cmdCancel->setDefault(true);
ui->cmdCancel->setFocus();
// Set Icon for Apply Button
if (QIcon::hasThemeIcon("dialog-ok-apply"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-ok-apply"));
@ -46,16 +48,40 @@ PlayerListDialog::PlayerListDialog(QStringList players, ProfileDatabase *profile
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-apply"));
}
else if (QIcon::hasThemeIcon("gtk-apply"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("gtk-apply"));
}
else if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-ok"));
}
else if (QIcon::hasThemeIcon("gtk-ok"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-ok"));
}
// Set Icon for Cancel Button
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
else if (QIcon::hasThemeIcon("gtk-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("gtk-cancel"));
}
drawSwitchButtons();
// Set Icon for Manage Buttons
if (QIcon::hasThemeIcon("go-previous") && QIcon::hasThemeIcon("go-next") && QIcon::hasThemeIcon("list-add"))
{
ui->cmdMakeAv->setIcon(QIcon::fromTheme("go-previous"));
ui->cmdMakeSe->setIcon(QIcon::fromTheme("go-next"));
ui->cmdMakeAd->setIcon(QIcon::fromTheme("list-add"));
}
else
{
drawSwitchButtons();
}
buildInterface();
// DPI calculation

13
ProfileInterface.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -79,10 +79,21 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
ui->saProfileContent->setFilesMode(true);
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdCloseProfile->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdCloseProfile->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Import Button
if (QIcon::hasThemeIcon("document-import"))
{
ui->cmdImport->setIcon(QIcon::fromTheme("document-import"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();

18
SnapmaticEditor.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,7 +39,9 @@ SnapmaticEditor::SnapmaticEditor(CrewDatabase *crewDB, ProfileDatabase *profileD
ui->setupUi(this);
ui->cmdCancel->setDefault(true);
ui->cmdCancel->setFocus();
// Set Icon for Apply Button
if (QIcon::hasThemeIcon("dialog-ok-apply"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-ok-apply"));
@ -48,14 +50,28 @@ SnapmaticEditor::SnapmaticEditor(CrewDatabase *crewDB, ProfileDatabase *profileD
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-apply"));
}
else if (QIcon::hasThemeIcon("gtk-apply"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("gtk-apply"));
}
else if (QIcon::hasThemeIcon("dialog-ok"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-ok"));
}
else if (QIcon::hasThemeIcon("gtk-ok"))
{
ui->cmdApply->setIcon(QIcon::fromTheme("dialog-ok"));
}
// Set Icon for Cancel Button
if (QIcon::hasThemeIcon("dialog-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("dialog-cancel"));
}
else if (QIcon::hasThemeIcon("gtk-cancel"))
{
ui->cmdCancel->setIcon(QIcon::fromTheme("gtk-cancel"));
}
snapmaticTitle = QString();
smpic = 0;

384
TelemetryClass.cpp

@ -0,0 +1,384 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "TelemetryClassAuthenticator.h"
#include "TelemetryClass.h"
#include "AppEnv.h"
#include "config.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QHttpMultiPart>
#include <QStringBuilder>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QSettings>
#include <QSysInfo>
#include <QLocale>
#include <QBuffer>
#include <QDebug>
#include <QFile>
#include <QDir>
#ifdef GTA5SYNC_WIN
#include "windows.h"
#include "intrin.h"
#endif
TelemetryClass TelemetryClass::telemetryClassInstance;
void TelemetryClass::init()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Telemetry");
#ifndef GTA5SYNC_BUILDTYPE_DEV
telemetryEnabled = settings.value("IsEnabled", false).toBool();
#else
telemetryEnabled = true; // Always enable Telemetry for Developer Versions
#endif
telemetryClientID = settings.value("ClientID", QString()).toString();
settings.endGroup();
}
void TelemetryClass::refresh()
{
init();
}
bool TelemetryClass::canPush()
{
if (!isEnabled() || !isRegistered() || !TelemetryClassAuthenticator::havePushURL()) return false;
return true;
}
bool TelemetryClass::canRegister()
{
if (!isEnabled() || isRegistered() || !TelemetryClassAuthenticator::haveRegURL()) return false;
return true;
}
bool TelemetryClass::isEnabled()
{
return telemetryEnabled;
}
bool TelemetryClass::isStateForced()
{
return telemetryStateForced;
}
bool TelemetryClass::isRegistered()
{
return !telemetryClientID.isEmpty();
}
void TelemetryClass::setEnabled(bool enabled)
{
telemetryEnabled = enabled;
telemetryStateForced = true;
}
void TelemetryClass::setDisabled(bool disabled)
{
telemetryEnabled = !disabled;
telemetryStateForced = true;
}
void TelemetryClass::push(TelemetryCategory category)
{
if (!canPush()) return;
switch (category)
{
case TelemetryCategory::OperatingSystemSpec:
push(category, getOperatingSystem());
break;
case TelemetryCategory::HardwareSpec:
push(category, getSystemHardware());
break;
case TelemetryCategory::UserLocaleData:
push(category, getSystemLocaleList());
break;
case TelemetryCategory::ApplicationConfiguration:
break;
case TelemetryCategory::ApplicationSpec:
push(category, getApplicationSpec());
break;
}
}
void TelemetryClass::push(TelemetryCategory category, QJsonDocument json)
{
if (!canPush()) return;
QJsonDocument jsonDocument(json);
QJsonObject jsonObject = jsonDocument.object();
jsonObject["ClientID"] = telemetryClientID;
jsonDocument.setObject(jsonObject);
QHttpMultiPart *httpMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart categoryPart;
categoryPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"json-category\""));
categoryPart.setBody(categoryToString(category).toUtf8());
QHttpPart jsonPart;
jsonPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
jsonPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"json-deflated\""));
jsonPart.setBody(qCompress(jsonDocument.toJson(QJsonDocument::Compact)));
httpMultiPart->append(categoryPart);
httpMultiPart->append(jsonPart);
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(TelemetryClassAuthenticator::getTrackingPushURL());
QNetworkReply *netReply = netManager->post(netRequest, httpMultiPart);
httpMultiPart->setParent(netReply);
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(pushFinished(QNetworkReply*)));
}
QJsonDocument TelemetryClass::getOperatingSystem()
{
QJsonDocument jsonDocument;
QJsonObject jsonObject;
#if QT_VERSION >= 0x050400
jsonObject["OSName"] = QSysInfo::prettyProductName();
jsonObject["OSArch"] = QSysInfo::currentCpuArchitecture();
#endif
jsonDocument.setObject(jsonObject);
return jsonDocument;
}
QJsonDocument TelemetryClass::getSystemHardware()
{
QJsonDocument jsonDocument;
QJsonObject jsonObject;
#ifdef GTA5SYNC_WIN
{
int CPUInfo[4] = {-1};
unsigned nExIds, i = 0;
char CPUBrandString[0x40];
__cpuid(CPUInfo, 0x80000000);
nExIds = CPUInfo[0];
for (i = 0x80000000; i <= nExIds; ++i)
{
__cpuid(CPUInfo, i);
if (i == 0x80000002) { memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo)); }
else if (i == 0x80000003) { memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo)); }
else if (i == 0x80000004) { memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo)); }
}
jsonObject["CPUName"] = QString(CPUBrandString).trimmed();
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
jsonObject["CPUThreads"] = QString::number(sysInfo.dwNumberOfProcessors);
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
jsonObject["SystemRAM"] = QString(QString::number((statex.ullTotalPhys / 1024) / 1024) % "MB");
}
#else
QDir procDir("/proc");
if (procDir.exists())
{
QFile cpuInfo("/proc/cpuinfo");
if (cpuInfo.open(QFile::ReadOnly))
{
QByteArray cpuInfoArray = cpuInfo.readAll();
QBuffer cpuInfoBuffer(&cpuInfoArray);
if (cpuInfoBuffer.open(QBuffer::ReadOnly))
{
QByteArray toFind = "model name";
while (cpuInfoBuffer.canReadLine())
{
QByteArray cpuData = cpuInfoBuffer.readLine();
if (cpuData.left(toFind.length()) == toFind)
{
jsonObject["CPUName"] = QString::fromUtf8(cpuData).split(':').at(1).trimmed();
break;
}
}
int cpuThreads = 0;
toFind = "processor";
cpuInfoBuffer.seek(0);
while (cpuInfoBuffer.canReadLine())
{
QByteArray cpuData = cpuInfoBuffer.readLine();
if (cpuData.left(toFind.length()) == toFind)
{
cpuThreads++;
}
}
jsonObject["CPUThreads"] = QString::number(cpuThreads);
}
}
QFile memInfo("/proc/meminfo");
if (memInfo.open(QFile::ReadOnly))
{
QByteArray memInfoArray = memInfo.readAll();
QBuffer memInfoBuffer(&memInfoArray);
if (memInfoBuffer.open(QBuffer::ReadOnly))
{
QByteArray toFind = "MemTotal:";
while (memInfoBuffer.canReadLine())
{
QByteArray memData = memInfoBuffer.readLine();
if (memData.left(toFind.length()) == toFind)
{
QByteArray memDataVal = memData.mid(toFind.length()).trimmed();
int totalMemoryInKB = memDataVal.left(memDataVal.length() - 3).toInt();
jsonObject["SystemRAM"] = QString(QString::number(totalMemoryInKB / 1024) % "MB");
break;
}
}
}
}
}
#endif
jsonDocument.setObject(jsonObject);
return jsonDocument;
}
QJsonDocument TelemetryClass::getApplicationSpec()
{
QJsonDocument jsonDocument;
QJsonObject jsonObject;
#if QT_VERSION >= 0x050400
jsonObject["Arch"] = QSysInfo::buildCpuArchitecture();
#endif
jsonObject["Name"] = GTA5SYNC_APPSTR;
jsonObject["Version"] = GTA5SYNC_APPVER;
jsonObject["BuildDateTime"] = AppEnv::getBuildDateTime();
jsonObject["BuildType"] = GTA5SYNC_BUILDTYPE;
jsonObject["QtVersion"] = qVersion();
jsonDocument.setObject(jsonObject);
return jsonDocument;
}
QJsonDocument TelemetryClass::getSystemLocaleList()
{
QJsonDocument jsonDocument;
QJsonObject jsonObject;
QStringList languagesList = QLocale::system().uiLanguages();
if (languagesList.length() >= 1)
{
jsonObject["PrimaryLanguage"] = languagesList.at(0);
}
if (languagesList.length() >= 2)
{
languagesList.removeAt(0);
jsonObject["SecondaryLanguages"] = QJsonValue::fromVariant(languagesList);
}
jsonDocument.setObject(jsonObject);
return jsonDocument;
}
QString TelemetryClass::categoryToString(TelemetryCategory category)
{
switch (category)
{
case TelemetryCategory::OperatingSystemSpec:
return QString("OperatingSystemSpec");
break;
case TelemetryCategory::HardwareSpec:
return QString("HardwareSpec");
break;
case TelemetryCategory::UserLocaleData:
return QString("UserLocaleData");
break;
case TelemetryCategory::ApplicationConfiguration:
return QString("ApplicationConfiguration");
break;
case TelemetryCategory::UserFeedback:
return QString("UserFeedback");
break;
case TelemetryCategory::ApplicationSpec:
return QString("ApplicationSpec");
break;
case TelemetryCategory::CustomEmitted:
return QString("CustomEmitted");
break;
default:
return QString("UnknownCategory");
break;
}
}
void TelemetryClass::registerClient()
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(TelemetryClassAuthenticator::getTrackingRegURL());
netManager->get(netRequest);
connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(registerFinished(QNetworkReply*)));
}
void TelemetryClass::pushStartupSet()
{
push(TelemetryCategory::ApplicationSpec);
push(TelemetryCategory::UserLocaleData);
push(TelemetryCategory::OperatingSystemSpec);
push(TelemetryCategory::HardwareSpec);
}
void TelemetryClass::pushFinished(QNetworkReply *reply)
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "Telemetry" << reply->readAll().trimmed();
#endif
reply->deleteLater();
sender()->deleteLater();
emit pushed();
}
void TelemetryClass::registerFinished(QNetworkReply *reply)
{
if (reply->canReadLine())
{
QByteArray readData = reply->readLine();
if (QString::fromUtf8(readData).trimmed() == QString("Registration success!") && reply->canReadLine())
{
readData = reply->readLine();
telemetryClientID = QString::fromUtf8(readData).trimmed();
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Telemetry");
settings.setValue("ClientID", telemetryClientID);
settings.endGroup();
#ifdef GTA5SYNC_DEBUG
qDebug() << "Telemetry" << QString("Registration success!");
#endif
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "Telemetry" << QString("Registration failed!");
#endif
}
}
else
{
#ifdef GTA5SYNC_DEBUG
qDebug() << "Telemetry" << QString("Registration failed!");
#endif
}
reply->deleteLater();
sender()->deleteLater();
emit registered();
}

75
TelemetryClass.h

@ -0,0 +1,75 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef TELEMETRYCLASS_H
#define TELEMETRYCLASS_H
#include <QNetworkReply>
#include <QApplication>
#include <QObject>
#include <QString>
enum class TelemetryCategory : int { OperatingSystemSpec = 0, HardwareSpec = 1, UserLocaleData = 2, ApplicationConfiguration = 3, UserFeedback = 4, ApplicationSpec = 5, CustomEmitted = 99};
class TelemetryClass : public QObject
{
Q_OBJECT
public:
static TelemetryClass* getInstance() { return &telemetryClassInstance; }
static QString categoryToString(TelemetryCategory category);
bool canPush();
bool canRegister();
bool isEnabled();
bool isStateForced();
bool isRegistered();
void init();
void refresh();
void setEnabled(bool enabled);
void setDisabled(bool disabled);
void push(TelemetryCategory category);
void push(TelemetryCategory category, const QJsonDocument json);
void registerClient();
private:
static TelemetryClass telemetryClassInstance;
QString telemetryClientID;
bool telemetryEnabled;
bool telemetryStateForced;
QJsonDocument getOperatingSystem();
QJsonDocument getSystemHardware();
QJsonDocument getApplicationSpec();
QJsonDocument getSystemLocaleList();
public slots:
void pushStartupSet();
private slots:
void pushFinished(QNetworkReply *reply);
void registerFinished(QNetworkReply *reply);
signals:
void pushed();
void registered();
};
extern TelemetryClass telemetryClass;
#define Telemetry TelemetryClass::getInstance()
#endif // TELEMETRYCLASS_H

27
UserInterface.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -63,16 +63,41 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER));
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Reload Button
if (QIcon::hasThemeIcon("view-refresh"))
{
ui->cmdReload->setIcon(QIcon::fromTheme("view-refresh"));
}
else if (QIcon::hasThemeIcon("reload"))
{
ui->cmdReload->setIcon(QIcon::fromTheme("reload"));
}
// Set Icon for Preferences Menu Item
if (QIcon::hasThemeIcon("preferences-system"))
{
#ifndef Q_OS_MACOS // Setting icon for preferences/settings/options lead to a crash in Mac OS X
ui->actionOptions->setIcon(QIcon::fromTheme("preferences-system"));
#endif
}
else if (QIcon::hasThemeIcon("configure"))
{
#ifndef Q_OS_MACOS // Setting icon for preferences/settings/options lead to a crash in Mac OS X
ui->actionOptions->setIcon(QIcon::fromTheme("configure"));
#endif
}
// Set Icon for Exit Menu Item
if (QIcon::hasThemeIcon("application-exit"))
{
#ifndef Q_OS_MACOS // Setting icon for exit/quit lead to a crash in Mac OS X

2
config.h

@ -50,7 +50,7 @@
#ifndef GTA5SYNC_APPVER
#ifndef GTA5SYNC_DAILYB
#define GTA5SYNC_APPVER "1.5.0-dev7"
#define GTA5SYNC_APPVER "1.5.0-dev8"
#else
#define GTA5SYNC_APPVER GTA5SYNC_DAILYB
#endif

18
gta5view.pro

@ -1,6 +1,6 @@
#/*****************************************************************************
#* gta5view Grand Theft Auto V Profile Viewer
#* Copyright (C) 2015-2017 Syping
#* Copyright (C) 2015-2018 Syping
#*
#* This program is free software: you can redistribute it and/or modify
#* it under the terms of the GNU General Public License as published by
@ -60,9 +60,11 @@ SOURCES += main.cpp \
SnapmaticWidget.cpp \
StandardPaths.cpp \
StringParser.cpp \
TelemetryClass.cpp \
TranslationClass.cpp \
UserInterface.cpp \
anpro/JSHighlighter.cpp \
tmext/TelemetryClassAuthenticator.cpp \
uimod/UiModLabel.cpp \
uimod/UiModWidget.cpp
@ -98,9 +100,11 @@ HEADERS += \
SnapmaticWidget.h \
StandardPaths.h \
StringParser.h \
TelemetryClass.h \
TranslationClass.h \
UserInterface.h \
anpro/JSHighlighter.h \
tmext/TelemetryClassAuthenticator.h \
uimod/UiModLabel.h \
uimod/UiModWidget.h
@ -142,7 +146,7 @@ DISTFILES += res/app.rc \
lang/gta5sync_no.ts \
lang/README.txt
INCLUDEPATH += ./anpro ./uimod
INCLUDEPATH += ./anpro ./tmext ./uimod
# GTA5SYNC/GTA5VIEW ONLY
@ -156,6 +160,7 @@ win32: DEFINES += GTA5SYNC_WIN
win32: RC_FILE += res/app.rc
win32: LIBS += -luser32
win32: CONFIG -= embed_manifest_exe
contains(DEFINES, GTA5SYNC_APV): greaterThan(QT_MAJOR_VERSION, 4): greaterThan(QT_MINOR_VERSION, 1): win32: LIBS += -ldwmapi
# MAC OS X ONLY
macx: ICON = res/5sync.icns
@ -208,3 +213,12 @@ contains(DEFINES, GTA5SYNC_QCONF){
INSTALLS += langfiles
}
}
# TELEMETRY BASED STUFF
!contains(DEFINES, GTA5SYNC_TELEMETRY){
SOURCES -= TelemetryClass.cpp \
tmext/TelemetryClassAuthenticator.cpp
HEADERS -= TelemetryClass.h \
tmext/TelemetryClassAuthenticator.h
}

58
main.cpp

@ -1,6 +1,6 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2016-2017 Syping
* Copyright (C) 2016-2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -49,6 +49,10 @@
#include <iostream>
#endif
#ifdef GTA5SYNC_TELEMETRY
#include "TelemetryClass.h"
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
@ -100,29 +104,55 @@ int main(int argc, char *argv[])
a.addLibraryPath(pluginsDir);
}
QStringList applicationArgs = a.arguments();
QString selectedAction;
QString arg1;
applicationArgs.removeAt(0);
TCInstance->initUserLanguage();
TCInstance->loadTranslation(&a);
if (isFirstStart)
if (!applicationArgs.contains("--skip-firststart"))
{
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);
if (button == QMessageBox::Yes)
if (isFirstStart)
{
ProfileDatabase profileDB;
OptionsDialog optionsDialog(&profileDB);
optionsDialog.setWindowIcon(IconLoader::loadingAppIcon());
optionsDialog.show();
optionsDialog.exec();
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);
if (button == QMessageBox::Yes)
{
ProfileDatabase profileDB;
OptionsDialog optionsDialog(&profileDB);
optionsDialog.setWindowIcon(IconLoader::loadingAppIcon());
optionsDialog.show();
optionsDialog.exec();
}
settings.setValue("IsFirstStart", false);
}
settings.setValue("IsFirstStart", false);
}
settings.endGroup();
QStringList applicationArgs = a.arguments();
QString selectedAction;
QString arg1;
applicationArgs.removeAt(0);
#ifdef GTA5SYNC_TELEMETRY
if (!applicationArgs.contains("--disable-telemetry"))
{
QObject::connect(Telemetry, SIGNAL(registered()), Telemetry, SLOT(pushStartupSet()));
if (!applicationArgs.contains("--skip-telemetryinit"))
{
Telemetry->init();
if (Telemetry->canPush())
{
Telemetry->pushStartupSet();
}
else if (Telemetry->canRegister())
{
Telemetry->registerClient();
}
}
}
else
{
Telemetry->setDisabled(true);
}
#endif
for (QString currentArg : applicationArgs)
{

14
res/app.rc

@ -24,13 +24,13 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Syping"
VALUE "FileDescription", "gta5view\0"
VALUE "FileVersion", "1.5.0-dev7\0"
VALUE "InternalName", "gta5view\0"
VALUE "LegalCopyright", "Copyright © 2016-2017 Syping\0"
VALUE "OriginalFilename", "gta5view.exe\0"
VALUE "ProductName", "gta5view\0"
VALUE "ProductVersion", "1.5.0-dev7\0"
VALUE "FileDescription", "gta5view"
VALUE "FileVersion", "1.5.0-dev8"
VALUE "InternalName", "gta5view"
VALUE "LegalCopyright", "Copyright © 2016-2017 Syping"
VALUE "OriginalFilename", "gta5view.exe"
VALUE "ProductName", "gta5view"
VALUE "ProductVersion", "1.5.0-dev8"
END
END
END

99
tmext/TelemetryClassAuthenticator.cpp

@ -0,0 +1,99 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "TelemetryClassAuthenticator.h"
#include <QUrlQuery>
#include <QUrl>
#ifndef GTA5SYNC_TELEMETRY_PUSHURL
#define GTA5SYNC_TELEMETRY_PUSHURL ""
#endif
#ifndef GTA5SYNC_TELEMETRY_REGURL
#define GTA5SYNC_TELEMETRY_REGURL ""
#endif
#ifndef GTA5SYNC_TELEMETRY_AUTHID
#define GTA5SYNC_TELEMETRY_AUTHID ""
#endif
#ifndef GTA5SYNC_TELEMETRY_AUTHPW
#define GTA5SYNC_TELEMETRY_AUTHPW ""
#endif
const QUrl TelemetryClassAuthenticator::getTrackingPushURL()
{
if (haveAccessData())
{
QUrl pushUrl(GTA5SYNC_TELEMETRY_PUSHURL);
QUrlQuery pushQuery(pushUrl);
if (!getTrackingAuthID().isEmpty()) { pushQuery.addQueryItem("tid", getTrackingAuthID()); }
if (!getTrackingAuthPW().isEmpty()) { pushQuery.addQueryItem("tpw", getTrackingAuthPW()); }
pushUrl.setQuery(pushQuery.query(QUrl::FullyEncoded));
return pushUrl;
}
else
{
QUrl pushUrl(GTA5SYNC_TELEMETRY_PUSHURL);
return pushUrl;
}
}
const QUrl TelemetryClassAuthenticator::getTrackingRegURL()
{
if (haveAccessData())
{
QUrl regUrl(GTA5SYNC_TELEMETRY_REGURL);
QUrlQuery regQuery(regUrl);
if (!getTrackingAuthID().isEmpty()) { regQuery.addQueryItem("tid", getTrackingAuthID()); }
if (!getTrackingAuthPW().isEmpty()) { regQuery.addQueryItem("tpw", getTrackingAuthPW()); }
regUrl.setQuery(regQuery.query(QUrl::FullyEncoded));
return regUrl;
}
else
{
QUrl regUrl(GTA5SYNC_TELEMETRY_REGURL);
return regUrl;
}
}
const QString TelemetryClassAuthenticator::getTrackingAuthID()
{
return QString(GTA5SYNC_TELEMETRY_AUTHID);
}
const QString TelemetryClassAuthenticator::getTrackingAuthPW()
{
return QString(GTA5SYNC_TELEMETRY_AUTHPW);
}
bool TelemetryClassAuthenticator::havePushURL()
{
return !getTrackingPushURL().isEmpty();
}
bool TelemetryClassAuthenticator::haveRegURL()
{
return !getTrackingRegURL().isEmpty();
}
bool TelemetryClassAuthenticator::haveAccessData()
{
if (getTrackingAuthID().isEmpty() && getTrackingAuthPW().isEmpty()) { return false; }
return true;
}

41
tmext/TelemetryClassAuthenticator.h

@ -0,0 +1,41 @@
/*****************************************************************************
* gta5sync GRAND THEFT AUTO V SYNC
* Copyright (C) 2018 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef TELEMETRYCLASSAUTHENTICATOR_H
#define TELEMETRYCLASSAUTHENTICATOR_H
#include <QApplication>
#include <QObject>
#include <QString>
#include <QUrl>
class TelemetryClassAuthenticator : public QObject
{
Q_OBJECT
public:
static const QUrl getTrackingPushURL();
static const QUrl getTrackingRegURL();
static const QString getTrackingAuthID();
static const QString getTrackingAuthPW();
static bool havePushURL();
static bool haveRegURL();
static bool haveAccessData();
};
#endif // TELEMETRYCLASSAUTHENTICATOR_H
Loading…
Cancel
Save