Files
wehub-resource-sync 79031da543
Spell checking / Check Spelling (push) Has been cancelled
Spell checking / Update PR (push) Has been cancelled
Publish Dev Docs Website / build (push) Failing after 1s
Publish Dev Docs Website / deploy (push) Has been skipped
Spell checking / Report (Push) (push) Has been cancelled
Spell checking / Report (PR) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:16:02 +08:00

63 lines
1.6 KiB
C++

#pragma once
#include "ProjectTelemetry.h"
#define TraceLoggingWriteWrapper(provider, eventName, ...) \
if (IsDataDiagnosticsEnabled()) \
{ \
TraceLoggingWrite(provider, eventName, __VA_ARGS__); \
}
namespace telemetry
{
constexpr inline const wchar_t* DataDiagnosticsRegKey = L"Software\\Classes\\PowerToys";
constexpr inline const wchar_t* DataDiagnosticsRegValueName = L"AllowDataDiagnostics";
class TraceBase
{
public:
static void RegisterProvider()
{
TraceLoggingRegister(g_hProvider);
}
static void UnregisterProvider()
{
TraceLoggingUnregister(g_hProvider);
}
static bool IsDataDiagnosticsEnabled()
{
HKEY key{};
if (RegOpenKeyExW(HKEY_CURRENT_USER,
DataDiagnosticsRegKey,
0,
KEY_READ,
&key) != ERROR_SUCCESS)
{
return false;
}
DWORD isDataDiagnosticsEnabled = 0;
DWORD size = sizeof(isDataDiagnosticsEnabled);
if (RegGetValueW(
HKEY_CURRENT_USER,
DataDiagnosticsRegKey,
DataDiagnosticsRegValueName,
RRF_RT_REG_DWORD,
nullptr,
&isDataDiagnosticsEnabled,
&size) != ERROR_SUCCESS)
{
RegCloseKey(key);
return false;
}
RegCloseKey(key);
return isDataDiagnosticsEnabled;
}
};
} // namespace telemetry