important telemetry changes

This commit is contained in:
Syping 2018-01-26 07:48:59 +01:00
parent fc44406caf
commit 4ce39ab7fd
1 changed files with 54 additions and 2 deletions

View File

@ -18,6 +18,7 @@
#include "TelemetryClassAuthenticator.h" #include "TelemetryClassAuthenticator.h"
#include "TelemetryClass.h" #include "TelemetryClass.h"
#include "StandardPaths.h"
#include "AppEnv.h" #include "AppEnv.h"
#include "config.h" #include "config.h"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
@ -57,7 +58,40 @@ void TelemetryClass::init()
telemetryEnabled = true; // Always enable Telemetry for Developer Versions telemetryEnabled = true; // Always enable Telemetry for Developer Versions
telemetryStateForced = true; telemetryStateForced = true;
#endif #endif
telemetryClientID = settings.value("ClientID", QString()).toString(); QString telemetryLegacyClientID = settings.value("ClientID", QString()).toString();
if (telemetryLegacyClientID.isEmpty())
{
telemetryClientID = QString::fromUtf8(QByteArray::fromBase64(settings.value("Identification", QByteArray()).toByteArray()));
}
else
{
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString portLoc = dirPath % "/.ported";
bool telemetryPortedKey = settings.value("IsPorted", false).toBool();
bool telemetryPortedFile = QFile::exists(portLoc);
if (!telemetryPortedKey && !telemetryPortedFile)
{
QFile portFile(portLoc);
if (portFile.open(QFile::WriteOnly))
{
portFile.write("\n");
portFile.flush();
}
portFile.close();
telemetryClientID = telemetryLegacyClientID;
settings.setValue("Identification", telemetryLegacyClientID.toUtf8().toBase64());
settings.setValue("IsPorted", true);
settings.setValue("ClientID", QString());
settings.remove("ClientID");
}
else
{
telemetryClientID = QString();
}
}
telemetryPushAppConf = settings.value("PushAppConf", false).toBool(); telemetryPushAppConf = settings.value("PushAppConf", false).toBool();
settings.endGroup(); settings.endGroup();
} }
@ -75,6 +109,12 @@ bool TelemetryClass::canPush()
bool TelemetryClass::canRegister() bool TelemetryClass::canRegister()
{ {
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString regLoc = dirPath % "/.reg";
if (QFile::exists(regLoc)) return false;
if (!isEnabled() || isRegistered() || !TelemetryClassAuthenticator::haveRegURL()) return false; if (!isEnabled() || isRegistered() || !TelemetryClassAuthenticator::haveRegURL()) return false;
return true; return true;
} }
@ -483,12 +523,24 @@ void TelemetryClass::registerFinished(QNetworkReply *reply)
QByteArray readedData = reply->readLine(); QByteArray readedData = reply->readLine();
if (QString::fromUtf8(readedData).trimmed() == QString("Registration success!") && reply->canReadLine()) if (QString::fromUtf8(readedData).trimmed() == QString("Registration success!") && reply->canReadLine())
{ {
QDir dir;
dir.mkpath(StandardPaths::dataLocation());
dir.setPath(StandardPaths::dataLocation());
QString dirPath = dir.absolutePath();
QString regLoc = dirPath % "/.reg";
readedData = reply->readLine(); readedData = reply->readLine();
telemetryClientID = QString::fromUtf8(readedData).trimmed(); telemetryClientID = QString::fromUtf8(readedData).trimmed();
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Telemetry"); settings.beginGroup("Telemetry");
settings.setValue("ClientID", telemetryClientID); settings.setValue("Identification", telemetryClientID.toUtf8().toBase64());
settings.endGroup(); settings.endGroup();
QFile regFile(regLoc);
if (regFile.open(QFile::WriteOnly))
{
regFile.write("\n");
regFile.flush();
}
regFile.close();
#ifdef GTA5SYNC_DEBUG #ifdef GTA5SYNC_DEBUG
qDebug() << "Telemetry" << QString("Registration success!"); qDebug() << "Telemetry" << QString("Registration success!");
#endif #endif