mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-22 00:03:48 +00:00
b5531a1f6b
* tool * log ccd and wmi/cimv2 * rename * spell * clean up * spellcheck
46 lines
915 B
C++
46 lines
915 B
C++
#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;
|
|
}
|
|
};
|