_T("\\"),
reinterpret_cast<LPVOID*>(&pvi),
&pviLen)) {
- versNumber = std::format(_T("{}.{}.{}.{}"),
+ TCHAR buf[30];
+
+#ifdef _UNICODE
+ swprintf_s(
+#else
+ sprintf_s(
+#endif
+ buf,
+ ARRAY_SIZE(buf),
+ _T("%d.%d.%d.%d"),
pvi->dwProductVersionMS >> 16,
pvi->dwFileVersionMS & 0xFFFF,
pvi->dwFileVersionLS >> 16,
pvi->dwFileVersionLS & 0xFFFF);
+ versNumber = buf;
success = true;
}
}
tstring progName = _T("WinMute");
tstring progVers = _T("WinMute");
if (GetWinMuteVersion(progVers)) {
- progName = std::format(_T("WinMute {}"), progVers);
+ progName = tstring(_T("WinMute")) + progVers;
Static_SetText(hTitle, progName.c_str());
}
void MuteControl::SetMute(bool mute)
{
- WMLog::GetInstance().Write(_T("Manual muting: {}"), mute ? _T("on") : _T("off"));
+ WMLog::GetInstance().Write(_T("Manual muting: %s"), mute ? _T("on") : _T("off"));
winAudio_->SetMute(mute);
}
void MuteControl::NotifyWorkstationLock(bool active)
{
- WMLog::GetInstance().Write(_T("Mute Event: Workstation Lock {}"),
+ WMLog::GetInstance().Write(_T("Mute Event: Workstation Lock %s"),
active ? _T("start") : _T("stop"));
NotifyRestoreCondition(MuteTypeWorkstationLock, active);
}
void MuteControl::NotifyScreensaver(bool active)
{
- WMLog::GetInstance().Write(_T("Mute Event: Screensaver {}"),
+ WMLog::GetInstance().Write(_T("Mute Event: Screensaver %s"),
active ? _T("start") : _T("stop"));
NotifyRestoreCondition(MuteTypeScreensaverActive, active);
}
void MuteControl::NotifyRemoteSession(bool active)
{
- WMLog::GetInstance().Write(_T("Mute Event: Remote Session {}"),
+ WMLog::GetInstance().Write(_T("Mute Event: Remote Session %s"),
active ? _T("start") : _T("stop"));
NotifyRestoreCondition(MuteTypeRemoteSession, active);
}
void MuteControl::NotifyDisplayStandby(bool active)
{
if (displayWasOffOnce_ || active) {
- WMLog::GetInstance().Write(_T("Mute Event: Display Standby {}"),
+ WMLog::GetInstance().Write(_T("Mute Event: Display Standby %s"),
active ? _T("start") : _T("stop"));
NotifyRestoreCondition(MuteTypeDisplayStandby, active);
displayWasOffOnce_ = true;
ResizeTab(dlgData->hTabCtrl, hCurTab);
}
- HICON hIcon = LoadIcon(
+ /*HICON hIcon = LoadIcon(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_SETTINGS));
- SendMessageW(hDlg, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hIcon));
+ SendMessageW(hDlg, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hIcon));*/
SwitchTab(dlgData, dlgData->hTabs[SETTINGS_TAB_GENERAL]);
return TRUE;
hr = audioEndpoints->Item(i, &device);
if (FAILED(hr)) {
- log.Write(_T("Failed to get audio endpoint #{}"), i);
+ log.Write(_T("Failed to get audio endpoint #%d"), i);
continue;
}
hr = device->OpenPropertyStore(STGM_READ, &propStore);
if (FAILED(hr)) {
- log.Write(_T("Failed to open property store for audio endpoint #{}"), i);
+ log.Write(_T("Failed to open property store for audio endpoint #%d"), i);
continue;
}
PropVariantInit(&value);
hr = propStore->GetValue(PKEY_Device_FriendlyName, &value);
if (FAILED(hr)) {
- log.Write(_T("Failed to get device name for audio endpoint #{}"), i);
+ log.Write(_T("Failed to get device name for audio endpoint #%d"), i);
continue;
}
- log.Write(_T("Found audio endpoint \"{}\""), value.pwszVal);
+ log.Write(_T("Found audio endpoint \"%s\""), value.pwszVal);
StringCchCopy(ep->deviceName,
sizeof(ep->deviceName)/sizeof(ep->deviceName[0]),
value.pwszVal);
if (FAILED(device->Activate(
__uuidof(IAudioSessionManager2), CLSCTX_INPROC_SERVER, nullptr,
reinterpret_cast<LPVOID*>(&sessionManager2)))) {
- log.Write(_T("Failed to retrieve audio session manager for {}"),
+ log.Write(_T("Failed to retrieve audio session manager for \"%s\""),
ep->deviceName);
continue;
}
hr = sessionManager2->GetAudioSessionControl(nullptr, 0, &ep->sessionCtrl);
if (FAILED(hr)) {
- log.Write(_T("Failed to retrieve audio session manager for {}"),
+ log.Write(_T("Failed to retrieve audio session manager for \"%s\""),
ep->deviceName);
continue;
}
__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER,
nullptr, reinterpret_cast<LPVOID*>(&ep->endpointVolume));
if (FAILED(hr)) {
- log.Write(_T("Failed to active endpoint volume for device {}"),
+ log.Write(_T("Failed to active endpoint volume for device \"%s\""),
ep->deviceName);
continue;
}
for (auto& e : endpoints_) {
BOOL isMuted = FALSE;
if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
- log.Write(_T("Failed to get mute status for \"{}\""),
+ log.Write(_T("Failed to get mute status for \"%s\""),
e->deviceName);
allMuted = false;
break;
for (auto& e : endpoints_) {
BOOL isMuted = FALSE;
if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
- log.Write(_T("Failed to get mute status for \"{}\""),
+ log.Write(_T("Failed to get mute status for \"%s\""),
e->deviceName);
success = false;
} else {
WMLog& log = WMLog::GetInstance();
for (auto& e : endpoints_) {
- log.Write(_T("Restoring: Mute {} for \"{}\""),
- e->wasMuted, e->deviceName);
+ log.Write(_T("Restoring: Mute %s for \"%s\""),
+ (e->wasMuted) ? _T("true") : _T("false"),
+ e->deviceName);
if (e->wasMuted != true) {
if (FAILED(e->endpointVolume->SetMute(false, nullptr))) {
- log.Write(_T("Failed to restore mute status to {} for \"{}\""),
- e->wasMuted,
+ log.Write(_T("Failed to restore mute status to %s for \"%s\""),
+ (e->wasMuted) ? _T("true") : _T("false"),
e->deviceName);
success = false;
}
for (auto& e : endpoints_) {
BOOL isMuted = !mute;
if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
- log.Write(_T("Failed to get mute status for \"{}\""),
+ log.Write(_T("Failed to get mute status for \"%s\""),
e->deviceName);
}
if (!!isMuted != mute) {
if (FAILED(e->endpointVolume->SetMute(mute, nullptr))) {
- log.Write(_T("Failed to set mute status to {} for \"{}\""),
- e->wasMuted,
+ log.Write(_T("Failed to set mute status to %s for \"%s\""),
+ (e->wasMuted) ? _T("true") : _T("false"),
e->deviceName);
}
}
enabled_ = enable;
}
-void WMLog::WriteMessage(const tstring& msg)
+void WMLog::WriteMessage(const TCHAR* msg)
{
struct tm tm;
auto now = std::chrono::system_clock::now();
logFile_.flush();
}
-void WMLog::Write(const tstring& msg)
+void WMLog::Write(const TCHAR *fmt, ...)
{
if (!initialized_ || !enabled_) {
return;
}
- WriteMessage(msg);
+
+ TCHAR buf[200];
+ va_list ap;
+ va_start(ap, fmt);
+
+#ifdef _UNICODE
+ vswprintf_s(buf, fmt, ap);
+#else
+ snprintf(buf, ARRAY_SIZE(buf), fmt, ap);
+#endif
+ WriteMessage(buf);
+
+ va_end(ap);
}
public:
static WMLog& GetInstance();
- void Write(const tstring& wmsg);
-
- template<typename... Args>
- void Write(
- [[maybe_unused]] const tstring_view& fmt,
- [[maybe_unused]] Args&&... args)
- {
- if (!initialized_ || !enabled_) {
- return;
- }
-#ifdef UNICODE
- const std::wstring str = std::vformat(
- fmt, std::make_wformat_args(args...));
-#else
- const std::wstring str = std::vformat(
- fmt, std::make_format_args(args...));
-#endif
- WriteMessage(str);
- }
+ void Write(const TCHAR* fmt, ...);
void SetEnabled(bool enable);
std::string GetLogFilePath();
WMLog(const WMLog&) = delete;
WMLog& operator=(const WMLog&) = delete;
- void WriteMessage(const tstring& msg);
+ void WriteMessage(const TCHAR* msg);
bool initialized_;
bool enabled_;
hAppIcon_ = LoadIcon(hglobInstance, MAKEINTRESOURCE(IDI_APP));
- if (!InitAudio()) {
- return false;
- }
-
- if (!settings_.Init() || !LoadDefaults()) {
+ if (!settings_.Init()) {
return false;
}
#endif
log.Write(_T("Starting new session..."));
+ if (!InitAudio()) {
+ return false;
+ }
+
+ if (!LoadDefaults()) {
+ return false;
+ }
+
if (!RegisterWindowClass() ||
!InitWindow() ||
!InitTrayMenu()) {
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
- <LanguageStandard>stdcpplatest</LanguageStandard>
+ <LanguageStandard>stdcpp20</LanguageStandard>
<TreatWarningAsError>true</TreatWarningAsError>
<DiagnosticsFormat>Caret</DiagnosticsFormat>
<PrecompiledHeader>Use</PrecompiledHeader>
#include <cassert>
#include <chrono>
#include <filesystem>
-#include <format>
#include <fstream>
#include <memory>
#include <string_view>
#include <string>
#include <unordered_map>
#include <vector>
+#include <cstdarg>
#include <windows.h>
#include <windowsx.h>