Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FancyZones][Tool]Monitor id tool (#18589)
* tool * log ccd and wmi/cimv2 * rename * spell * clean up * spellcheck
- Loading branch information
1 parent
55f3801
commit b5531a1
Showing
14 changed files
with
779 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}; |
Oops, something went wrong.