qt: Add an option to view/regenerate telemetry ID.

This commit is contained in:
bunnei 2017-08-23 00:08:07 -04:00
parent 5d7b364a21
commit 9f0da33c33
4 changed files with 40 additions and 7 deletions

View file

@ -4,11 +4,15 @@
#include "citra_qt/configuration/configure_web.h" #include "citra_qt/configuration/configure_web.h"
#include "core/settings.h" #include "core/settings.h"
#include "core/telemetry_session.h"
#include "ui_configure_web.h" #include "ui_configure_web.h"
ConfigureWeb::ConfigureWeb(QWidget* parent) ConfigureWeb::ConfigureWeb(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) { : QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
ui->setupUi(this); ui->setupUi(this);
connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this,
&ConfigureWeb::refreshTelemetryID);
this->setConfiguration(); this->setConfiguration();
} }
@ -30,8 +34,8 @@ void ConfigureWeb::setConfiguration() {
ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry); ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry);
ui->edit_username->setText(QString::fromStdString(Settings::values.citra_username)); ui->edit_username->setText(QString::fromStdString(Settings::values.citra_username));
ui->edit_token->setText(QString::fromStdString(Settings::values.citra_token)); ui->edit_token->setText(QString::fromStdString(Settings::values.citra_token));
ui->label_telemetry_id->setText("Telemetry ID: 0x" +
updateWeb(); QString::number(Core::GetTelemetryId(), 16).toUpper());
} }
void ConfigureWeb::applyConfiguration() { void ConfigureWeb::applyConfiguration() {
@ -41,4 +45,8 @@ void ConfigureWeb::applyConfiguration() {
Settings::Apply(); Settings::Apply();
} }
void ConfigureWeb::updateWeb() {} void ConfigureWeb::refreshTelemetryID() {
const u64 new_telemetry_id{Core::RegenerateTelemetryId()};
ui->label_telemetry_id->setText("Telemetry ID: 0x" +
QString::number(new_telemetry_id, 16).toUpper());
}

View file

@ -21,7 +21,7 @@ public:
void applyConfiguration(); void applyConfiguration();
public slots: public slots:
void updateWeb(); void refreshTelemetryID();
private: private:
void setConfiguration(); void setConfiguration();

View file

@ -38,21 +38,21 @@ static u64 GenerateTelemetryId() {
return telemetry_id; return telemetry_id;
} }
static u64 GetTelemetryId() { u64 GetTelemetryId() {
u64 telemetry_id{}; u64 telemetry_id{};
static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
if (FileUtil::Exists(filename)) { if (FileUtil::Exists(filename)) {
FileUtil::IOFile file(filename, "rb"); FileUtil::IOFile file(filename, "rb");
if (!file.IsOpen()) { if (!file.IsOpen()) {
LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str()); LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str());
return {}; return {};
} }
file.ReadBytes(&telemetry_id, sizeof(u64)); file.ReadBytes(&telemetry_id, sizeof(u64));
} else { } else {
FileUtil::IOFile file(filename, "wb"); FileUtil::IOFile file(filename, "wb");
if (!file.IsOpen()) { if (!file.IsOpen()) {
LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str()); LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str());
return {}; return {};
} }
telemetry_id = GenerateTelemetryId(); telemetry_id = GenerateTelemetryId();
@ -62,6 +62,19 @@ static u64 GetTelemetryId() {
return telemetry_id; return telemetry_id;
} }
u64 RegenerateTelemetryId() {
const u64 new_telemetry_id{GenerateTelemetryId()};
static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
FileUtil::IOFile file(filename, "wb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str());
return {};
}
file.WriteBytes(&new_telemetry_id, sizeof(u64));
return new_telemetry_id;
}
TelemetrySession::TelemetrySession() { TelemetrySession::TelemetrySession() {
#ifdef ENABLE_WEB_SERVICE #ifdef ENABLE_WEB_SERVICE
backend = std::make_unique<WebService::TelemetryJson>(); backend = std::make_unique<WebService::TelemetryJson>();

View file

@ -35,4 +35,16 @@ private:
std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
}; };
/**
* Gets TelemetryId, a unique identifier used for the user's telemetry sessions.
* @returns The current TelemetryId for the session.
*/
u64 GetTelemetryId();
/**
* Regenerates TelemetryId, a unique identifier used for the user's telemetry sessions.
* @returns The new TelemetryId that was generated.
*/
u64 RegenerateTelemetryId();
} // namespace Core } // namespace Core