Skip to content

Commit 0b12798

Browse files
Bug report tool for registry (microsoft#9213)
* wip * Improved registry bug reporting * Don't use macros * Ignore spelling of NLSTEXT in macro * Various improvements * Move functions to separate files * Rename result file to registry-report-info.txt * Rename a poorly named function in ReportMonitorInfo.cpp * Restrict scope of symbols in these .cpp files Co-authored-by: Davide <[email protected]>
1 parent b74afd3 commit 0b12798

File tree

8 files changed

+289
-58
lines changed

8 files changed

+289
-58
lines changed

.github/actions/spell-check/expect.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ nielslaute
14461446
NIF
14471447
NLD
14481448
NLog
1449+
NLSTEXT
14491450
NMLVEMPTYMARKUP
14501451
NOACTIVATE
14511452
noactive

tools/BugReportTool/BugReportTool/BugReportTool.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</ClCompile>
3939
<ClCompile Include="ReportMonitorInfo.cpp" />
4040
<ClCompile Include="Main.cpp" />
41+
<ClCompile Include="ReportRegistry.cpp" />
4142
<ClCompile Include="ZipTools\zipfolder.cpp" />
4243
</ItemGroup>
4344
<ItemGroup>
@@ -53,6 +54,7 @@
5354
<ClInclude Include="..\..\..\deps\cziplib\src\zip.h" />
5455
<ClInclude Include="ReportMonitorInfo.h" />
5556
<ClInclude Include="..\..\..\common\utils\json.h" />
57+
<ClInclude Include="ReportRegistry.h" />
5658
<ClInclude Include="ZipTools\zipfolder.h" />
5759
</ItemGroup>
5860
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

tools/BugReportTool/BugReportTool/BugReportTool.vcxproj.filters

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</ClCompile>
1111
<ClCompile Include="..\..\..\deps\cziplib\src\zip.c" />
1212
<ClCompile Include="ReportMonitorInfo.cpp" />
13+
<ClCompile Include="ReportRegistry.cpp" />
1314
</ItemGroup>
1415
<ItemGroup>
1516
<Filter Include="ZipTools">
@@ -24,5 +25,6 @@
2425
<ClInclude Include="..\..\..\deps\cziplib\src\miniz.h" />
2526
<ClInclude Include="..\..\..\deps\cziplib\src\zip.h" />
2627
<ClInclude Include="ReportMonitorInfo.h" />
28+
<ClInclude Include="ReportRegistry.h" />
2729
</ItemGroup>
2830
</Project>

tools/BugReportTool/BugReportTool/Main.cpp

+5-22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <common/utils/exec.h>
1414

1515
#include "ReportMonitorInfo.h"
16+
#include "ReportRegistry.h"
1617
using namespace std;
1718
using namespace std::filesystem;
1819
using namespace winrt::Windows::Data::Json;
@@ -148,27 +149,6 @@ void hideUserPrivateInfo(const filesystem::path& dir)
148149
}
149150
}
150151

151-
void reportMonitorInfo(const filesystem::path& tmpDir)
152-
{
153-
auto monitorReportPath = tmpDir;
154-
monitorReportPath.append("monitor-report-info.txt");
155-
156-
try
157-
{
158-
wofstream monitorReport(monitorReportPath);
159-
monitorReport << "GetSystemMetrics = " << GetSystemMetrics(SM_CMONITORS) << '\n';
160-
report(monitorReport);
161-
}
162-
catch (std::exception& ex)
163-
{
164-
printf("Failed to report monitor info. %s\n", ex.what());
165-
}
166-
catch (...)
167-
{
168-
printf("Failed to report monitor info\n");
169-
}
170-
}
171-
172152
void reportWindowsVersion(const filesystem::path& tmpDir)
173153
{
174154
auto versionReportPath = tmpDir;
@@ -285,6 +265,9 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
285265
// Write dotnet installation info to the temporary folder
286266
reportDotNetInstallationInfo(tmpDir);
287267

268+
// Write registry to the temporary folder
269+
reportRegistry(tmpDir);
270+
288271
// Zip folder
289272
auto zipPath = path::path(saveZipPath);
290273
std::string reportFilename{"PowerToysReport_"};
@@ -304,4 +287,4 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
304287

305288
deleteFolder(tmpDir);
306289
return 0;
307-
}
290+
}
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,82 @@
11
#pragma once
22
#include "ReportMonitorInfo.h"
33
#include <Windows.h>
4+
#include <filesystem>
45
#include "../../../src/common/utils/winapi_error.h"
6+
using namespace std;
57

6-
int report(std::wostream& os)
8+
namespace
79
{
8-
struct capture
10+
int buildMonitorInfoReport(std::wostream& os)
911
{
10-
std::wostream* os = nullptr;
11-
};
12+
struct capture
13+
{
14+
std::wostream* os = nullptr;
15+
};
1216

13-
auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
14-
std::wostream& os = *((capture*)prm)->os;
15-
MONITORINFOEX mi;
16-
mi.cbSize = sizeof(mi);
17+
auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
18+
std::wostream& os = *((capture*)prm)->os;
19+
MONITORINFOEX mi;
20+
mi.cbSize = sizeof(mi);
1721

18-
if (GetMonitorInfoW(monitor, &mi))
19-
{
20-
os << "GetMonitorInfo OK\n";
21-
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };
22+
if (GetMonitorInfoW(monitor, &mi))
23+
{
24+
os << "GetMonitorInfo OK\n";
25+
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };
2226

23-
DWORD i = 0;
24-
while (EnumDisplayDevicesW(mi.szDevice, i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
27+
DWORD i = 0;
28+
while (EnumDisplayDevicesW(mi.szDevice, i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
29+
{
30+
const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
31+
const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
32+
os << "EnumDisplayDevices OK:\n"
33+
<< "\tMirroring = " << mirroring << '\n'
34+
<< "\tActive = " << active << '\n'
35+
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
36+
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
37+
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
38+
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
39+
}
40+
}
41+
else
2542
{
26-
const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
27-
const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
28-
os << "EnumDisplayDevices OK:\n"
29-
<< "\tMirroring = " << mirroring << '\n'
30-
<< "\tActive = " << active << '\n'
31-
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
32-
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
33-
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
34-
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
43+
auto message = get_last_error_message(GetLastError());
44+
os << "GetMonitorInfo FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
3545
}
46+
return TRUE;
47+
};
48+
capture c;
49+
c.os = &os;
50+
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&c))
51+
{
52+
os << "EnumDisplayMonitors OK\n";
3653
}
3754
else
3855
{
3956
auto message = get_last_error_message(GetLastError());
40-
os << "GetMonitorInfo FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
57+
os << "EnumDisplayMonitors FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
4158
}
42-
return TRUE;
43-
};
44-
capture c;
45-
c.os = &os;
46-
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&c))
59+
return 0;
60+
}
61+
}
62+
63+
void reportMonitorInfo(const filesystem::path& tmpDir)
64+
{
65+
auto monitorReportPath = tmpDir;
66+
monitorReportPath.append("monitor-report-info.txt");
67+
68+
try
69+
{
70+
wofstream monitorReport(monitorReportPath);
71+
monitorReport << "GetSystemMetrics = " << GetSystemMetrics(SM_CMONITORS) << '\n';
72+
buildMonitorInfoReport(monitorReport);
73+
}
74+
catch (std::exception& ex)
4775
{
48-
os << "EnumDisplayMonitors OK\n";
76+
printf("Failed to report monitor info. %s\n", ex.what());
4977
}
50-
else
78+
catch (...)
5179
{
52-
auto message = get_last_error_message(GetLastError());
53-
os << "EnumDisplayMonitors FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
80+
printf("Failed to report monitor info\n");
5481
}
55-
return 0;
56-
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#pragma once
22
#include <fstream>
33

4-
int report(std::wostream& os);
4+
void reportMonitorInfo(const std::filesystem::path& tmpDir);

0 commit comments

Comments
 (0)