diff options
Diffstat (limited to 'src/core/telemetry_session.cpp')
| -rw-r--r-- | src/core/telemetry_session.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 61ba78457..d0f257f58 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -38,21 +38,21 @@ static u64 GenerateTelemetryId() { | |||
| 38 | return telemetry_id; | 38 | return telemetry_id; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | static u64 GetTelemetryId() { | 41 | u64 GetTelemetryId() { |
| 42 | u64 telemetry_id{}; | 42 | u64 telemetry_id{}; |
| 43 | static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; | 43 | static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; |
| 44 | 44 | ||
| 45 | if (FileUtil::Exists(filename)) { | 45 | if (FileUtil::Exists(filename)) { |
| 46 | FileUtil::IOFile file(filename, "rb"); | 46 | FileUtil::IOFile file(filename, "rb"); |
| 47 | if (!file.IsOpen()) { | 47 | if (!file.IsOpen()) { |
| 48 | LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str()); | 48 | LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str()); |
| 49 | return {}; | 49 | return {}; |
| 50 | } | 50 | } |
| 51 | file.ReadBytes(&telemetry_id, sizeof(u64)); | 51 | file.ReadBytes(&telemetry_id, sizeof(u64)); |
| 52 | } else { | 52 | } else { |
| 53 | FileUtil::IOFile file(filename, "wb"); | 53 | FileUtil::IOFile file(filename, "wb"); |
| 54 | if (!file.IsOpen()) { | 54 | if (!file.IsOpen()) { |
| 55 | LOG_ERROR(WebService, "failed to open telemetry_id: %s", filename.c_str()); | 55 | LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str()); |
| 56 | return {}; | 56 | return {}; |
| 57 | } | 57 | } |
| 58 | telemetry_id = GenerateTelemetryId(); | 58 | telemetry_id = GenerateTelemetryId(); |
| @@ -62,6 +62,19 @@ static u64 GetTelemetryId() { | |||
| 62 | return telemetry_id; | 62 | return telemetry_id; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | u64 RegenerateTelemetryId() { | ||
| 66 | const u64 new_telemetry_id{GenerateTelemetryId()}; | ||
| 67 | static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; | ||
| 68 | |||
| 69 | FileUtil::IOFile file(filename, "wb"); | ||
| 70 | if (!file.IsOpen()) { | ||
| 71 | LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str()); | ||
| 72 | return {}; | ||
| 73 | } | ||
| 74 | file.WriteBytes(&new_telemetry_id, sizeof(u64)); | ||
| 75 | return new_telemetry_id; | ||
| 76 | } | ||
| 77 | |||
| 65 | TelemetrySession::TelemetrySession() { | 78 | TelemetrySession::TelemetrySession() { |
| 66 | #ifdef ENABLE_WEB_SERVICE | 79 | #ifdef ENABLE_WEB_SERVICE |
| 67 | backend = std::make_unique<WebService::TelemetryJson>(); | 80 | backend = std::make_unique<WebService::TelemetryJson>(); |