mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-29 02:59:00 +08:00
Add SQM User Id to metrics
This commit is contained in:
parent
1726d62911
commit
1310e9e052
@ -13,6 +13,7 @@ namespace vcpkg
|
||||
void TrackProperty(const std::string& name, const std::string& value);
|
||||
void TrackProperty(const std::string& name, const std::wstring& value);
|
||||
bool GetCompiledMetricsEnabled();
|
||||
std::wstring GetSQMUser();
|
||||
|
||||
void Upload(const std::string& payload);
|
||||
void Flush();
|
||||
|
@ -197,6 +197,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
|
||||
const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW()));
|
||||
TrackProperty("cmdline", trimmed_command_line);
|
||||
loadConfig();
|
||||
TrackProperty("sqmuser", GetSQMUser());
|
||||
|
||||
const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv);
|
||||
|
||||
|
@ -235,6 +235,40 @@ true
|
||||
return DISABLE_METRICS == 0;
|
||||
}
|
||||
|
||||
std::wstring GetSQMUser()
|
||||
{
|
||||
LONG err = NULL;
|
||||
|
||||
struct RAII_HKEY {
|
||||
HKEY hkey = NULL;
|
||||
~RAII_HKEY()
|
||||
{
|
||||
if (hkey != NULL)
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
} HKCU_SQMClient;
|
||||
|
||||
err = RegOpenKeyExW(HKEY_CURRENT_USER, LR"(Software\Microsoft\SQMClient)", NULL, KEY_READ, &HKCU_SQMClient.hkey);
|
||||
if (err != ERROR_SUCCESS)
|
||||
{
|
||||
return L"{}";
|
||||
}
|
||||
|
||||
std::array<wchar_t,128> buffer;
|
||||
DWORD lType = 0;
|
||||
DWORD dwBufferSize = static_cast<DWORD>(buffer.size() * sizeof(wchar_t));
|
||||
err = RegQueryValueExW(HKCU_SQMClient.hkey, L"UserId", NULL, &lType, reinterpret_cast<LPBYTE>(buffer.data()), &dwBufferSize);
|
||||
if (err == ERROR_SUCCESS && lType == REG_SZ && dwBufferSize >= sizeof(wchar_t))
|
||||
{
|
||||
size_t sz = dwBufferSize / sizeof(wchar_t);
|
||||
if (buffer[sz - 1] == '\0')
|
||||
--sz;
|
||||
return std::wstring(buffer.begin(), buffer.begin() + sz);
|
||||
}
|
||||
|
||||
return L"{}";
|
||||
}
|
||||
|
||||
void SetUserInformation(const std::string& user_id, const std::string& first_use_time)
|
||||
{
|
||||
g_metricmessage.user_id = user_id;
|
||||
|
Loading…
Reference in New Issue
Block a user