Skip to content

Commit

Permalink
Bug report tool for registry (#9213)
Browse files Browse the repository at this point in the history
* 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 <davide.giacometti@outlook.it>
  • Loading branch information
ivan100sic and davidegiacometti committed Jan 21, 2021
1 parent b74afd3 commit 0b12798
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ nielslaute
NIF
NLD
NLog
NLSTEXT
NMLVEMPTYMARKUP
NOACTIVATE
noactive
Expand Down
2 changes: 2 additions & 0 deletions tools/BugReportTool/BugReportTool/BugReportTool.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</ClCompile>
<ClCompile Include="ReportMonitorInfo.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="ReportRegistry.cpp" />
<ClCompile Include="ZipTools\zipfolder.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -53,6 +54,7 @@
<ClInclude Include="..\..\..\deps\cziplib\src\zip.h" />
<ClInclude Include="ReportMonitorInfo.h" />
<ClInclude Include="..\..\..\common\utils\json.h" />
<ClInclude Include="ReportRegistry.h" />
<ClInclude Include="ZipTools\zipfolder.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ClCompile>
<ClCompile Include="..\..\..\deps\cziplib\src\zip.c" />
<ClCompile Include="ReportMonitorInfo.cpp" />
<ClCompile Include="ReportRegistry.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="ZipTools">
Expand All @@ -24,5 +25,6 @@
<ClInclude Include="..\..\..\deps\cziplib\src\miniz.h" />
<ClInclude Include="..\..\..\deps\cziplib\src\zip.h" />
<ClInclude Include="ReportMonitorInfo.h" />
<ClInclude Include="ReportRegistry.h" />
</ItemGroup>
</Project>
27 changes: 5 additions & 22 deletions tools/BugReportTool/BugReportTool/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <common/utils/exec.h>

#include "ReportMonitorInfo.h"
#include "ReportRegistry.h"
using namespace std;
using namespace std::filesystem;
using namespace winrt::Windows::Data::Json;
Expand Down Expand Up @@ -148,27 +149,6 @@ void hideUserPrivateInfo(const filesystem::path& dir)
}
}

void reportMonitorInfo(const filesystem::path& tmpDir)
{
auto monitorReportPath = tmpDir;
monitorReportPath.append("monitor-report-info.txt");

try
{
wofstream monitorReport(monitorReportPath);
monitorReport << "GetSystemMetrics = " << GetSystemMetrics(SM_CMONITORS) << '\n';
report(monitorReport);
}
catch (std::exception& ex)
{
printf("Failed to report monitor info. %s\n", ex.what());
}
catch (...)
{
printf("Failed to report monitor info\n");
}
}

void reportWindowsVersion(const filesystem::path& tmpDir)
{
auto versionReportPath = tmpDir;
Expand Down Expand Up @@ -285,6 +265,9 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
// Write dotnet installation info to the temporary folder
reportDotNetInstallationInfo(tmpDir);

// Write registry to the temporary folder
reportRegistry(tmpDir);

// Zip folder
auto zipPath = path::path(saveZipPath);
std::string reportFilename{"PowerToysReport_"};
Expand All @@ -304,4 +287,4 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)

deleteFolder(tmpDir);
return 0;
}
}
96 changes: 61 additions & 35 deletions tools/BugReportTool/BugReportTool/ReportMonitorInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,82 @@
#pragma once
#include "ReportMonitorInfo.h"
#include <Windows.h>
#include <filesystem>
#include "../../../src/common/utils/winapi_error.h"
using namespace std;

int report(std::wostream& os)
namespace
{
struct capture
int buildMonitorInfoReport(std::wostream& os)
{
std::wostream* os = nullptr;
};
struct capture
{
std::wostream* os = nullptr;
};

auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
std::wostream& os = *((capture*)prm)->os;
MONITORINFOEX mi;
mi.cbSize = sizeof(mi);
auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
std::wostream& os = *((capture*)prm)->os;
MONITORINFOEX mi;
mi.cbSize = sizeof(mi);

if (GetMonitorInfoW(monitor, &mi))
{
os << "GetMonitorInfo OK\n";
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };
if (GetMonitorInfoW(monitor, &mi))
{
os << "GetMonitorInfo OK\n";
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };

DWORD i = 0;
while (EnumDisplayDevicesW(mi.szDevice, i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
DWORD i = 0;
while (EnumDisplayDevicesW(mi.szDevice, i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
{
const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
os << "EnumDisplayDevices OK:\n"
<< "\tMirroring = " << mirroring << '\n'
<< "\tActive = " << active << '\n'
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
}
}
else
{
const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
os << "EnumDisplayDevices OK:\n"
<< "\tMirroring = " << mirroring << '\n'
<< "\tActive = " << active << '\n'
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
auto message = get_last_error_message(GetLastError());
os << "GetMonitorInfo FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
}
return TRUE;
};
capture c;
c.os = &os;
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&c))
{
os << "EnumDisplayMonitors OK\n";
}
else
{
auto message = get_last_error_message(GetLastError());
os << "GetMonitorInfo FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
os << "EnumDisplayMonitors FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
}
return TRUE;
};
capture c;
c.os = &os;
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&c))
return 0;
}
}

void reportMonitorInfo(const filesystem::path& tmpDir)
{
auto monitorReportPath = tmpDir;
monitorReportPath.append("monitor-report-info.txt");

try
{
wofstream monitorReport(monitorReportPath);
monitorReport << "GetSystemMetrics = " << GetSystemMetrics(SM_CMONITORS) << '\n';
buildMonitorInfoReport(monitorReport);
}
catch (std::exception& ex)
{
os << "EnumDisplayMonitors OK\n";
printf("Failed to report monitor info. %s\n", ex.what());
}
else
catch (...)
{
auto message = get_last_error_message(GetLastError());
os << "EnumDisplayMonitors FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
printf("Failed to report monitor info\n");
}
return 0;
}
}
2 changes: 1 addition & 1 deletion tools/BugReportTool/BugReportTool/ReportMonitorInfo.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#include <fstream>

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

0 comments on commit 0b12798

Please sign in to comment.