summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2017-08-23 02:58:19 +0200
committerbunnei <bunneidev@gmail.com>2017-08-26 05:10:00 +0200
commitd6a819c7cb1ac00671b7e76b23d7d065d1fd76a3 (patch)
tree509f019ccc3d49f6646b4cd26d36ca3cf2b93b7c /src
parentcitra_qt: Show one-time callout messages to user. (diff)
downloadyuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar
yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.gz
yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.bz2
yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.lz
yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.xz
yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.tar.zst
yuzu-d6a819c7cb1ac00671b7e76b23d7d065d1fd76a3.zip
Diffstat (limited to '')
-rw-r--r--src/core/telemetry_session.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 94483f385..61ba78457 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -3,8 +3,10 @@
// Refer to the license.txt file included.
#include <cstring>
+#include <cryptopp/osrng.h>
#include "common/assert.h"
+#include "common/file_util.h"
#include "common/scm_rev.h"
#include "common/x64/cpu_detect.h"
#include "core/core.h"
@@ -29,12 +31,46 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) {
UNREACHABLE();
}
+static u64 GenerateTelemetryId() {
+ u64 telemetry_id{};
+ CryptoPP::AutoSeededRandomPool rng;
+ rng.GenerateBlock(reinterpret_cast<CryptoPP::byte*>(&telemetry_id), sizeof(u64));
+ return telemetry_id;
+}
+
+static u64 GetTelemetryId() {
+ u64 telemetry_id{};
+ static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
+
+ if (FileUtil::Exists(filename)) {
+ FileUtil::IOFile file(filename, "rb");
+ if (!file.IsOpen()) {
+ LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str());
+ return {};
+ }
+ file.ReadBytes(&telemetry_id, sizeof(u64));
+ } else {
+ FileUtil::IOFile file(filename, "wb");
+ if (!file.IsOpen()) {
+ LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str());
+ return {};
+ }
+ telemetry_id = GenerateTelemetryId();
+ file.WriteBytes(&telemetry_id, sizeof(u64));
+ }
+
+ return telemetry_id;
+}
+
TelemetrySession::TelemetrySession() {
#ifdef ENABLE_WEB_SERVICE
backend = std::make_unique<WebService::TelemetryJson>();
#else
backend = std::make_unique<Telemetry::NullVisitor>();
#endif
+ // Log one-time top-level information
+ AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
+
// Log one-time session start information
const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())