summaryrefslogtreecommitdiff
path: root/src/core/telemetry_session.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/telemetry_session.cpp')
-rw-r--r--src/core/telemetry_session.cpp47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 6dcff5400..ad1a9ffb4 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -9,7 +9,9 @@
9 9
10#include "common/assert.h" 10#include "common/assert.h"
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/file_util.h" 12#include "common/fs/file.h"
13#include "common/fs/fs.h"
14#include "common/fs/path_util.h"
13#include "common/logging/log.h" 15#include "common/logging/log.h"
14 16
15#include "common/settings.h" 17#include "common/settings.h"
@@ -72,31 +74,41 @@ static const char* TranslateGPUAccuracyLevel(Settings::GPUAccuracy backend) {
72 74
73u64 GetTelemetryId() { 75u64 GetTelemetryId() {
74 u64 telemetry_id{}; 76 u64 telemetry_id{};
75 const std::string filename{Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) + 77 const auto filename = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "telemetry_id";
76 "telemetry_id"};
77 78
78 bool generate_new_id = !Common::FS::Exists(filename); 79 bool generate_new_id = !Common::FS::Exists(filename);
80
79 if (!generate_new_id) { 81 if (!generate_new_id) {
80 Common::FS::IOFile file(filename, "rb"); 82 Common::FS::IOFile file{filename, Common::FS::FileAccessMode::Read,
83 Common::FS::FileType::BinaryFile};
84
81 if (!file.IsOpen()) { 85 if (!file.IsOpen()) {
82 LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); 86 LOG_ERROR(Core, "failed to open telemetry_id: {}",
87 Common::FS::PathToUTF8String(filename));
83 return {}; 88 return {};
84 } 89 }
85 file.ReadBytes(&telemetry_id, sizeof(u64)); 90
86 if (telemetry_id == 0) { 91 if (!file.ReadObject(telemetry_id) || telemetry_id == 0) {
87 LOG_ERROR(Frontend, "telemetry_id is 0. Generating a new one.", telemetry_id); 92 LOG_ERROR(Frontend, "telemetry_id is 0. Generating a new one.", telemetry_id);
88 generate_new_id = true; 93 generate_new_id = true;
89 } 94 }
90 } 95 }
91 96
92 if (generate_new_id) { 97 if (generate_new_id) {
93 Common::FS::IOFile file(filename, "wb"); 98 Common::FS::IOFile file{filename, Common::FS::FileAccessMode::Write,
99 Common::FS::FileType::BinaryFile};
100
94 if (!file.IsOpen()) { 101 if (!file.IsOpen()) {
95 LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); 102 LOG_ERROR(Core, "failed to open telemetry_id: {}",
103 Common::FS::PathToUTF8String(filename));
96 return {}; 104 return {};
97 } 105 }
106
98 telemetry_id = GenerateTelemetryId(); 107 telemetry_id = GenerateTelemetryId();
99 file.WriteBytes(&telemetry_id, sizeof(u64)); 108
109 if (!file.WriteObject(telemetry_id)) {
110 LOG_ERROR(Core, "Failed to write telemetry_id to file.");
111 }
100 } 112 }
101 113
102 return telemetry_id; 114 return telemetry_id;
@@ -104,15 +116,20 @@ u64 GetTelemetryId() {
104 116
105u64 RegenerateTelemetryId() { 117u64 RegenerateTelemetryId() {
106 const u64 new_telemetry_id{GenerateTelemetryId()}; 118 const u64 new_telemetry_id{GenerateTelemetryId()};
107 const std::string filename{Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) + 119 const auto filename = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "telemetry_id";
108 "telemetry_id"}; 120
121 Common::FS::IOFile file{filename, Common::FS::FileAccessMode::Write,
122 Common::FS::FileType::BinaryFile};
109 123
110 Common::FS::IOFile file(filename, "wb");
111 if (!file.IsOpen()) { 124 if (!file.IsOpen()) {
112 LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); 125 LOG_ERROR(Core, "failed to open telemetry_id: {}", Common::FS::PathToUTF8String(filename));
113 return {}; 126 return {};
114 } 127 }
115 file.WriteBytes(&new_telemetry_id, sizeof(u64)); 128
129 if (!file.WriteObject(new_telemetry_id)) {
130 LOG_ERROR(Core, "Failed to write telemetry_id to file.");
131 }
132
116 return new_telemetry_id; 133 return new_telemetry_id;
117} 134}
118 135