Skip to content

Commit

Permalink
[FancyZones][Tool]Monitor id tool (#18589)
Browse files Browse the repository at this point in the history
* tool

* log ccd and wmi/cimv2

* rename

* spell

* clean up

* spellcheck
  • Loading branch information
SeraphimaZykova committed Jun 13, 2022
1 parent 55f3801 commit b5531a1
Show file tree
Hide file tree
Showing 14 changed files with 779 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/actions/spell-check/expect.txt
Expand Up @@ -117,6 +117,7 @@ aumid
Aut
Authenticode
AUTHN
AUTHZ
autogenerate
autogenerated
AUTOHIDE
Expand Down Expand Up @@ -230,6 +231,7 @@ Chukotka
Chuuk
cielab
ciexyz
cim
CImage
cinttypes
cla
Expand Down Expand Up @@ -292,6 +294,9 @@ companding
Compat
COMPOSITIONFULL
comsupp
comsuppw
comsuppwd
comutil
Concat
concrt
configs
Expand Down Expand Up @@ -447,6 +452,7 @@ DISABLEASACTIONKEY
dispid
DISPIDAMBIENTDLCONTROL
DISPLAYCHANGE
DISPLAYCONFIG
displayname
divyan
DLACTIVEXCTLS
Expand Down Expand Up @@ -510,6 +516,7 @@ dxgiformat
dxguid
ecount
EData
Edid
EDITKEYBOARD
editkeyboardwindow
editorconfig
Expand Down Expand Up @@ -730,6 +737,7 @@ HKPD
HKU
HLOCAL
HLSL
HMD
hmenu
hmodule
hmonitor
Expand Down Expand Up @@ -981,6 +989,7 @@ IValue
IVector
IView
IVirtual
IWbem
IWeb
IWIC
iwindow
Expand Down Expand Up @@ -1124,6 +1133,7 @@ LPMINMAXINFO
LPOSVERSIONINFOEXW
lprc
LPRECT
LPSAFEARRAY
LPSTR
lpsz
lpt
Expand Down Expand Up @@ -1613,6 +1623,7 @@ pwsh
PWSTR
pwsz
pwtd
QDC
qianlifeng
qit
QITAB
Expand Down Expand Up @@ -2225,6 +2236,8 @@ VSTHRD
VSTT
vtable
Vtbl
wbem
wbemuuid
WBounds
wca
wcautil
Expand Down Expand Up @@ -2315,6 +2328,8 @@ WKSG
Wlkr
wmain
Wman
wmi
WMICIM
WMKEYDOWN
WMKEYUP
wmp
Expand All @@ -2338,6 +2353,7 @@ wpf
wpr
wprintf
wprp
WQL
wregex
WResize
writefile
Expand Down
26 changes: 26 additions & 0 deletions tools/MonitorReportTool/ErrorMessage.h
@@ -0,0 +1,26 @@
#pragma once

#include <optional>
#include <string>
#include <system_error>
#include <Windows.h>

inline std::optional<std::wstring> get_last_error_message(const DWORD dw)
{
std::optional<std::wstring> message;
try
{
const auto msg = std::system_category().message(dw);
message.emplace(begin(msg), end(msg));
}
catch (...)
{
}
return message;
}

inline std::wstring get_last_error_or_default(const DWORD dw)
{
auto message = get_last_error_message(dw);
return message.has_value() ? message.value() : L"";
}
45 changes: 45 additions & 0 deletions tools/MonitorReportTool/Logger.h
@@ -0,0 +1,45 @@
#pragma once

#include <fstream>
#include <filesystem>

#include <shlobj.h>

std::filesystem::path get_desktop_path()
{
wchar_t* p;
if (S_OK != SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &p)) return "";

std::filesystem::path result = p;
CoTaskMemFree(p);

return result;
}

class Logger
{
private:
inline static std::wofstream logger;

public:
~Logger()
{
logger.close();
}

static void init(std::string loggerName)
{
std::filesystem::path rootFolder(get_desktop_path());

auto logsPath = rootFolder;
logsPath.append(L"monitor_ids.txt");

logger.open(logsPath.string(), std::ios_base::out | std::ios_base::app);
}

template<typename FormatString, typename... Args>
static void log(FormatString fmt, Args&&... args)
{
logger << std::vformat(fmt, std::make_wformat_args(args...)) << std::endl;
}
};

0 comments on commit b5531a1

Please sign in to comment.