]> repos.lx-s.de Git - winmute.git/commitdiff
Removed std::format to reduce file size by about 130kb.
authorlx-s <lx-s@users.noreply.github.com>
Fri, 8 Apr 2022 05:29:51 +0000 (07:29 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Fri, 8 Apr 2022 05:29:51 +0000 (07:29 +0200)
WinMute/AboutDlg.cpp
WinMute/MuteControl.cpp
WinMute/SettingsDlg.cpp
WinMute/VistaAudio.cpp
WinMute/WMLog.cpp
WinMute/WMLog.h
WinMute/WinMute.cpp
WinMute/WinMute.vcxproj
WinMute/common.h

index e5bef645830edbe8ec65402f96d4fc8a48b2c7cb..d2da303df5decec8064c3f8b02e8e06f705ead0c 100644 (file)
@@ -195,11 +195,21 @@ static bool GetWinMuteVersion(tstring& versNumber)
                _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;
          }
       }
@@ -246,7 +256,7 @@ INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
       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());
       }
 
index 6c46fdaf39108e6fa08e3a7677a9b604675234f6..3bc0bd8ac28b8f718558e9be14085109bdf254b4 100644 (file)
@@ -74,7 +74,7 @@ bool MuteControl::Init(HWND hParent, const TrayIcon *trayIcon)
 
 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);
 }
 
@@ -230,21 +230,21 @@ void MuteControl::NotifyRestoreCondition(int type, bool active)
 
 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);
 }
@@ -252,7 +252,7 @@ void MuteControl::NotifyRemoteSession(bool 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;
index 6ccd061ec048c02ee5cc2ba21234515109f8a544..a41a7b472e1dfe353081227773af91bda26d7f7d 100644 (file)
@@ -123,10 +123,10 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar
          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;
index 85185259e54ec45d3d5bbf71b76610ab6ce93edd..0b5aa2aaa3559db102ffdeafb106c3efb1d39c83 100644 (file)
@@ -99,13 +99,13 @@ bool VistaAudio::LoadAllEndpoints()
 
       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;
       }
 
@@ -113,10 +113,10 @@ bool VistaAudio::LoadAllEndpoints()
       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);
@@ -127,14 +127,14 @@ bool VistaAudio::LoadAllEndpoints()
       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;
       }
@@ -149,7 +149,7 @@ bool VistaAudio::LoadAllEndpoints()
          __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;
       }
@@ -221,7 +221,7 @@ bool VistaAudio::AllEndpointsMuted()
       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;
@@ -243,7 +243,7 @@ bool VistaAudio::SaveMuteStatus()
       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 {
@@ -260,12 +260,13 @@ bool VistaAudio::RestoreMuteStatus()
    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;
          }
@@ -282,13 +283,13 @@ void VistaAudio::SetMute(bool mute)
       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);
             }
          }
index 1a31ddcbec3a109f2574e7e71339d74d8c3b413b..22c27488cbb4bbb16458f6523235f1b8e5ce6737 100644 (file)
@@ -76,7 +76,7 @@ void WMLog::SetEnabled(bool enable)
    enabled_ = enable;
 }
 
-void WMLog::WriteMessage(const tstring& msg)
+void WMLog::WriteMessage(const TCHAR* msg)
 {
    struct tm tm;
    auto now = std::chrono::system_clock::now();
@@ -95,10 +95,22 @@ void WMLog::WriteMessage(const tstring& msg)
    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);
 }
index 20016b9895633d32ba63419b34013551362c61d2..ab173dcc499b00f9e124990ed90a8640980a4860 100644 (file)
@@ -39,25 +39,7 @@ class WMLog {
 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();
@@ -68,7 +50,7 @@ private:
    WMLog(const WMLog&) = delete;
    WMLog& operator=(const WMLog&) = delete;
 
-   void WriteMessage(const tstring& msg);
+   void WriteMessage(const TCHAR* msg);
 
    bool initialized_;
    bool enabled_;
index 81a4882529c37b03abc014e8c1816e0191b0947d..d5371e71c004be13e0218676a71aac0fff0a550a 100644 (file)
@@ -191,11 +191,7 @@ bool WinMute::Init()
 
    hAppIcon_ = LoadIcon(hglobInstance, MAKEINTRESOURCE(IDI_APP));
 
-   if (!InitAudio()) {
-      return false;
-   }
-
-   if (!settings_.Init() || !LoadDefaults()) {
+   if (!settings_.Init()) {
       return false;
    }
 
@@ -206,6 +202,14 @@ bool WinMute::Init()
 #endif
    log.Write(_T("Starting new session..."));
 
+   if (!InitAudio()) {
+      return false;
+   }
+
+   if (!LoadDefaults()) {
+      return false;
+   }
+
    if (!RegisterWindowClass() ||
        !InitWindow() ||
        !InitTrayMenu()) {
index 2bc5a7bf77949933acd84432ffe3bae6f1d837b0..b23e2cf57f63f6feb232c5fa2218d1fc4bab48a1 100644 (file)
       <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>
index 0ab3349e2347efcf62453ff8acad4d2502651af1..3150072c102d049d2491056efc11955439f4e810 100644 (file)
@@ -54,13 +54,13 @@ POSSIBILITY OF SUCH DAMAGE.
 #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>