]> repos.lx-s.de Git - winmute.git/commitdiff
Replaced printf-format styles with std::format
authorlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 13:09:14 +0000 (15:09 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 13:09:14 +0000 (15:09 +0200)
15 files changed:
WinMute/BluetoothDetector.cpp
WinMute/MMNotificationClient.cpp
WinMute/MediaController.cpp
WinMute/MuteControl.cpp
WinMute/QuietHoursTimer.cpp
WinMute/Settings_GeneralDlg.cpp
WinMute/Settings_ManageEndpointsDlg.cpp
WinMute/UpdateChecker.cpp
WinMute/Utility.cpp
WinMute/VistaAudio.cpp
WinMute/WMLog.cpp
WinMute/WMLog.h
WinMute/WMSettings.cpp
WinMute/WMi18n.cpp
WinMute/WinMute.cpp

index 460a53af40e0331e5316d981766640dce614e178..2dd4586213267f3a8f9764aed2de5dc60bbf5509 100644 (file)
@@ -162,15 +162,15 @@ BluetoothDetector::BluetoothStatus BluetoothDetector::GetBluetoothStatus(
    if (useDeviceList_) {
       auto pos = std::find(begin(deviceNames_), end(deviceNames_), deviceName);
       if (pos == end(deviceNames_)) {
-         log.LogInfo(L"Bluetooth device \"%s\" not in list.", deviceName.c_str());
+         log.LogInfo(L"Bluetooth device \"{}\" not in list.", deviceName);
          return BluetoothStatus::Unknown;
       }
    }
    if ((inRangeInfo->deviceInfo.flags & BDIF_CONNECTED) && !(inRangeInfo->previousDeviceFlags & BDIF_CONNECTED)) {
-      log.LogInfo(L"Bluetooth Audio device \"%s\" connected.", deviceName.c_str());
+      log.LogInfo(L"Bluetooth Audio device \"{}\" connected.", deviceName);
       return BluetoothStatus::Connected;
    } else if (!(inRangeInfo->deviceInfo.flags & BDIF_CONNECTED) && (inRangeInfo->previousDeviceFlags & BDIF_CONNECTED)) {
-      log.LogInfo(L"Bluetooth Audio device \"%s\" disconnected.", deviceName.c_str());
+      log.LogInfo(L"Bluetooth Audio device \"{}\" disconnected.", deviceName);
       return BluetoothStatus::Disconnected;
    }
    return BluetoothStatus::Unknown;
index f144ce0711698c6ac5ee690205db563cb3e47abd..bc00b255666a192a29256592e34c58f8cb2d62ae 100644 (file)
@@ -89,7 +89,7 @@ STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId
 {
    if (notifyParent_ && pwstrDeviceId != nullptr) {
       const auto deviceName = GetDeviceNameFromId(pwstrDeviceId);
-      WMLog::GetInstance().LogInfo(L"Device \"%s\" added", deviceName.c_str());
+      WMLog::GetInstance().LogInfo(L"Device \"{}\" added", deviceName);
       notifyParent_->ShouldReInit();
    }
    return S_OK;
@@ -99,7 +99,7 @@ STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDevice
 {
    if (notifyParent_ && pwstrDeviceId != nullptr) {
       const auto deviceName = GetDeviceNameFromId(pwstrDeviceId);
-      WMLog::GetInstance().LogInfo(L"Device \"%s\" removed", deviceName.c_str());
+      WMLog::GetInstance().LogInfo(L"Device \"{}\" removed", deviceName);
       notifyParent_->ShouldReInit();
    }
    return S_OK;
@@ -127,9 +127,9 @@ STDMETHODIMP_(HRESULT) MMNotificationClient::OnDeviceStateChanged(
       // TODO: Check if output device
       const auto deviceName = GetDeviceNameFromId(pwstrDeviceId);
       WMLog::GetInstance().LogInfo(
-         L"Device \"%s\" status changed to %s",
-         deviceName.c_str(),
-         what.c_str());
+         L"Device \"{}\" status changed to {}",
+         deviceName,
+         what);
       notifyParent_->ShouldReInit();
    } 
    return S_OK;
index 92bcdf18f6dc269983701373219a868ca251a64d..98a145a0a9a0a441dacc4397333d3ea67faca90f 100644 (file)
@@ -84,8 +84,8 @@ bool MediaPlaybackController::TryPauseCurrentSession(bool &pausedMedia)
          }
       }
    } catch (const hresult_error &e) {
-      log.LogError(L"MediaPlaybackController: Failed to pause current media session. Error: %s",
-                   e.message().c_str());
+      log.LogError(L"MediaPlaybackController: Failed to pause current media session. Error: {}",
+                   e.message());
       return false;
    }
    return true;
@@ -108,8 +108,8 @@ bool MediaPlaybackController::TryPlayCurrentSession()
          }
       }
    } catch (const hresult_error &e) {
-      log.LogError(L"MediaPlaybackController: Failed to resume current media session. Error: %s",
-                   e.message().c_str());
+      log.LogError(L"MediaPlaybackController: Failed to resume current media session. Error: {}",
+                   e.message());
       return false;
    }
    return true;
index 3141e6982eff1a593cc643774baf0ae8a0eff599..48f468c906343a17493e2cfa1ebed21d26d51736 100644 (file)
@@ -161,7 +161,7 @@ LRESULT CALLBACK MuteControl::WindowProc(
 
 void MuteControl::SetMute(bool mute)
 {
-   WMLog::GetInstance().LogInfo(L"Manual muting: %s", mute ? L"on" : L"off");
+   WMLog::GetInstance().LogInfo(L"Manual muting: {}", mute ? L"on" : L"off");
    winAudio_->SetMute(mute);
 }
 
@@ -438,14 +438,14 @@ void MuteControl::NotifyRestoreCondition(MuteType type, bool active, bool withDe
 
 void MuteControl::NotifyWorkstationLock(bool active)
 {
-   WMLog::GetInstance().LogInfo(L"Mute Event: Workstation Lock %s",
+   WMLog::GetInstance().LogInfo(L"Mute Event: Workstation Lock {}",
                                 active ? L"start" : L"stop");
    NotifyRestoreCondition(MuteTypeWorkstationLock, active);
 }
 
 void MuteControl::NotifyRemoteSession(bool active)
 {
-   WMLog::GetInstance().LogInfo(L"Mute Event: Remote Session %s",
+   WMLog::GetInstance().LogInfo(L"Mute Event: Remote Session {}",
                                 active ? L"start" : L"stop");
    NotifyRestoreCondition(MuteTypeRemoteSession, active);
 }
@@ -454,7 +454,7 @@ void MuteControl::NotifyDisplayStandby(bool active)
 {
    if (displayWasOffOnce_ || active)
    {
-      WMLog::GetInstance().LogInfo(L"Mute Event: Display Standby %s",
+      WMLog::GetInstance().LogInfo(L"Mute Event: Display Standby {}",
                                    active ? L"start" : L"stop");
       NotifyRestoreCondition(MuteTypeDisplayStandby, active);
       displayWasOffOnce_ = true;
@@ -464,7 +464,7 @@ void MuteControl::NotifyDisplayStandby(bool active)
 void MuteControl::NotifyBluetoothConnected(bool connected)
 {
    WMLog::GetInstance().LogInfo(
-       L"Mute Event: Bluetooth audio device %s",
+       L"Mute Event: Bluetooth audio device {}",
        connected ? L"connected" : L"disconnected");
    NotifyRestoreCondition(MuteTypeBluetoothDisconnect, !connected, true);
 }
index 56b997c86071bc4e5b18291e503206610c50aeb0..adc1f32110093e6fb54558b72e651c4fc53218e2 100644 (file)
@@ -153,7 +153,7 @@ bool QuietHoursTimer::SetStart()
    }
 
    WMLog::GetInstance().LogInfo(
-      L"QuietHours: Next start scheduled in %u s (window %d, %02u:%02u-%02u:%02u)",
+      L"QuietHours: Next start scheduled in {} s (window {}, {:02}:{:02}-{:02}:{:02})",
       diffSec, idx,
       windows_[idx].first / 3600,  (windows_[idx].first % 3600) / 60,
       windows_[idx].second / 3600, (windows_[idx].second % 3600) / 60);
@@ -189,7 +189,7 @@ bool QuietHoursTimer::SetEnd()
    }
 
    WMLog::GetInstance().LogInfo(
-      L"QuietHours: End scheduled in %u s (window %d)", diffSec, activeWindowIdx_);
+      L"QuietHours: End scheduled in {} s (window {})", diffSec, activeWindowIdx_);
 
    return true;
 }
@@ -226,7 +226,7 @@ bool QuietHoursTimer::LoadFromSettings(WMSettings& settings)
    const int activeIdx = FindActiveWindowIdx();
    if (activeIdx != -1) {
       activeWindowIdx_ = activeIdx;
-      WMLog::GetInstance().LogInfo(L"QuietHours: Currently inside window %d — muting now", activeIdx);
+      WMLog::GetInstance().LogInfo(L"QuietHours: Currently inside window {} — muting now", activeIdx);
       // Sending START will cause WinMute to mute and call SetEnd()
       SendMessageW(hParent_, WM_WINMUTE_QUIETHOURS_START, 0, 0);
    } else {
index 1e22dded26ffffa69b651465484a75f7c89a6d3a..4d48f6705e43cb4e381ee703b2b46398d0334d65 100644 (file)
@@ -52,7 +52,7 @@ static void FillLanguageList(HWND hLanguageList, const SettingsGeneralData& dlgD
    for (const auto &lang : dlgData.langModules) {
       const auto itemId = SendMessage(hLanguageList, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(lang.langName.c_str()));
       if (itemId == CB_ERR || itemId == CB_ERRSPACE) {
-         WMLog::GetInstance().LogError(L"Failed to add language %ls to language selector", lang.langName.c_str());
+         WMLog::GetInstance().LogError(L"Failed to add language {} to language selector", lang.langName);
       } else {
          ComboBox_SetItemData(hLanguageList, itemId, lang.fileName.c_str());
       }
index baef2af4e5b1bd97e291667f8480e715509efcb4..4b654bbaac742b82d22a71ac526e36ef8c68e86b 100644 (file)
@@ -69,7 +69,7 @@ static bool GetAudioEndpoints(std::vector<std::wstring>& endpoints)
    for (UINT i = 0; i < epCount; ++i) {
       CComPtr<IMMDevice> device = nullptr;
       if (FAILED(audioEndpoints->Item(i, &device))) {
-         log.LogError(L"Failed to get audio endpoint #%d", i);
+         log.LogError(L"Failed to get audio endpoint #{}", i);
          continue;
       }
 
index ecf9e28825816b07c63f14360ba8f5c0c69f8b9d..03dc1488643d0ec45f976fdaa72fe64ba333710c 100644 (file)
@@ -129,13 +129,13 @@ bool UpdateChecker::ParseVersionFile(const std::string& fileContents,
         }
 
     } catch (const nlohmann::json::parse_error& pe) {
-        log.LogError(L"Failed to parse update: %S", pe.what());
+        log.LogError(L"Failed to parse update: {}", ConvertStringToWideString(pe.what()));
         return false;
     } catch (const nlohmann::json::type_error& te) {
-        log.LogError(L"Failed to parse update: %S", te.what());
+        log.LogError(L"Failed to parse update: {}", ConvertStringToWideString(te.what()));
         return false;
     } catch (const std::exception& e) {
-        log.LogError(L"Failed to parse update: %S", e.what());
+        log.LogError(L"Failed to parse update: {}", ConvertStringToWideString(e.what()));
         return false;
     }
     return true;
@@ -168,16 +168,16 @@ std::optional<bool> UpdateChecker::IsVersionGreater(
     std::vector<int> curVersParsed;
     WMLog& log = WMLog::GetInstance();
     if (!ParseVersion(newVers, newVersParsed)) {
-        log.LogError(L"Failed to parse new version string \"%s\"",
-                     newVers.c_str());
+        log.LogError(L"Failed to parse new version string \"{}\"",
+                     newVers);
         return std::nullopt;
     } else if (!ParseVersion(curVers, curVersParsed)) {
-        log.LogError(L"Failed to parse current version string \"%s\"",
-                     curVers.c_str());
+        log.LogError(L"Failed to parse current version string \"{}\"",
+                     curVers);
         return std::nullopt;
     } else if (newVersParsed.size() != curVersParsed.size()) {
-        log.LogError(L"Version format mismatch \"%s\" / \"%s\"",
-                     curVers.c_str(), newVers.c_str());
+        log.LogError(L"Version format mismatch \"{}\" / \"{}\"",
+                     curVers, newVers);
         return std::nullopt;
     }
     for (size_t i = 0; i < newVersParsed.size(); ++i) {
@@ -294,7 +294,7 @@ bool UpdateChecker::GetVersionFile(std::string& fileContents) const
                         GetLastError());
         return false;
     } else if (statusCode != HTTP_STATUS_OK) {
-        log.LogError(L"Update-Server returned HTTP %d", statusCode);
+        log.LogError(L"Update-Server returned HTTP {}", statusCode);
         return false;
     }
 
index eac3f6149fb3396db9eba1d674ceeb064a6bfceb..d798c38529db9a632f00f5ad7a651ee93d87011e 100644 (file)
@@ -197,7 +197,7 @@ bool LaunchBrowser(HWND hParent, const std::wstring &url)
    };
    if (!hasPrefix(L"https://") && !hasPrefix(L"http://")) {
       WMLog::GetInstance().LogError(
-         L"Refused to open \"%s\": not a http(s) URL", url.c_str());
+         L"Refused to open \"{}\": not a http(s) URL", url);
       return false;
    }
 
index 7cef244a6284b8da1b282724afb70949ca3fdd33..ef4093bce99a8b2906afcf2da56283491d681c80 100644 (file)
@@ -86,16 +86,16 @@ bool VistaAudio::LoadAllEndpoints()
 
       hr = audioEndpoints->Item(i, &device);
       if (FAILED(hr)) {
-         log.LogError(L"Failed to get audio endpoint #%d", i);
+         log.LogError(L"Failed to get audio endpoint #{}", i);
          continue;
       }
 
       const auto deviceName = GetAudioDeviceName(device);
       if (!deviceName) {
-         log.LogError(L"Failed to get device name for audio endpoint #%d", i);
+         log.LogError(L"Failed to get device name for audio endpoint #{}", i);
          continue;
       } else {
-         log.LogInfo(L"Found audio endpoint \"%s\"", deviceName->c_str());
+         log.LogInfo(L"Found audio endpoint \"{}\"", *deviceName);
          ep->deviceName = *deviceName;
       }
       
@@ -103,15 +103,15 @@ bool VistaAudio::LoadAllEndpoints()
       if (FAILED(device->Activate(
             __uuidof(IAudioSessionManager2), CLSCTX_INPROC_SERVER, nullptr,
             reinterpret_cast<LPVOID*>(&sessionManager2)))) {
-         log.LogError(L"Failed to retrieve audio session manager for \"%s\"",
-                   ep->deviceName.c_str());
+         log.LogError(L"Failed to retrieve audio session manager for \"{}\"",
+                   ep->deviceName);
          continue;
       }
 
       hr = sessionManager2->GetAudioSessionControl(nullptr, 0, &ep->sessionCtrl);
       if (FAILED(hr)) {
-         log.LogError(L"Failed to retrieve audio session manager for \"%s\"",
-            ep->deviceName.c_str());
+         log.LogError(L"Failed to retrieve audio session manager for \"{}\"",
+            ep->deviceName);
          continue;
       }
 
@@ -124,8 +124,8 @@ bool VistaAudio::LoadAllEndpoints()
          __uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER,
          nullptr, reinterpret_cast<LPVOID*>(&ep->endpointVolume));
       if (FAILED(hr)) {
-         log.LogError(L"Failed to active endpoint volume for device \"%s\"",
-            ep->deviceName.c_str());
+         log.LogError(L"Failed to active endpoint volume for device \"{}\"",
+            ep->deviceName);
          continue;
       }
       endpoints_.push_back(std::move(ep));
@@ -199,8 +199,8 @@ bool VistaAudio::AllEndpointsMuted()
       BOOL isMuted = FALSE;
       if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
          log.LogError(
-            L"Failed to get mute status for \"%s\"",
-            e->deviceName.c_str());
+            L"Failed to get mute status for \"{}\"",
+            e->deviceName);
          return false;
       } else if (isMuted == FALSE) {
          return false;
@@ -219,8 +219,8 @@ bool VistaAudio::SaveMuteStatus()
          BOOL isMuted = FALSE;
          if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
             log.LogError(
-               L"Failed to get mute status for \"%s\"",
-               e->deviceName.c_str());
+               L"Failed to get mute status for \"{}\"",
+               e->deviceName);
             success = false;
          } else {
             e->wasMuted = isMuted;
@@ -240,17 +240,17 @@ bool VistaAudio::RestoreMuteStatus()
    }
    for (auto& e : endpoints_) {
       if (!IsEndpointManaged(e->deviceName)) {
-         log.LogInfo(L"Skipping Endpoint %s", e->deviceName.c_str());
+         log.LogInfo(L"Skipping Endpoint {}", e->deviceName);
          continue;
       }
-      log.LogInfo(L"Restoring: Mute %s for \"%s\"",
+      log.LogInfo(L"Restoring: Mute {} for \"{}\"",
                 (e->wasMuted) ? L"true" : L"false",
-                e->deviceName.c_str());
+                e->deviceName);
       if (e->wasMuted != true) {
          if (FAILED(e->endpointVolume->SetMute(false, nullptr))) {
-            log.LogError(L"Failed to restore mute status to %s for \"%s\"",
+            log.LogError(L"Failed to restore mute status to {} for \"{}\"",
                       (e->wasMuted) ? L"true" : L"false",
-                      e->deviceName.c_str());
+                      e->deviceName);
             success = false;
          }
       }
@@ -266,20 +266,20 @@ void VistaAudio::SetMute(bool mute)
       for (auto& e : endpoints_) {
          BOOL isMuted = !mute;
          if (!IsEndpointManaged(e->deviceName)) {
-            log.LogInfo(L"Skipping Endpoint %s", e->deviceName.c_str());
+            log.LogInfo(L"Skipping Endpoint {}", e->deviceName);
             continue;
          }
          if (FAILED(e->endpointVolume->GetMute(&isMuted))) {
             log.LogError(
-               L"Failed to get mute status for \"%s\"",
-               e->deviceName.c_str());
+               L"Failed to get mute status for \"{}\"",
+               e->deviceName);
          }
          if (!!isMuted != mute) {
             if (FAILED(e->endpointVolume->SetMute(mute, nullptr))) {
                log.LogError(
-                  L"Failed to set mute status to %s for \"%s\"",
+                  L"Failed to set mute status to {} for \"{}\"",
                   (e->wasMuted) ? L"true" : L"false",
-                  e->deviceName.c_str());
+                  e->deviceName);
             }
          }
       }
index 7f65dff1381c71135e68d89648027ed5c7a1e47c..1c76be47d7ab480e41cd7b77dd68f8002c0c7169 100644 (file)
@@ -205,56 +205,6 @@ void WMLog::UnregisterForLogUpdates(HWND hWnd)
    }
 }
 
-void WMLog::LogDebug(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...)
-{
-   wchar_t buf[1024];
-   va_list ap;
-   va_start(ap, fmt);
-
-   // _TRUNCATE: oversized messages (e.g. containing long external strings)
-   // must be cut short, not trip the invalid-parameter handler.
-   _vsnwprintf_s(buf, ARRAY_SIZE(buf), _TRUNCATE, fmt, ap);
-   StoreMessage(LogLevel::Debug, buf);
-
-   va_end(ap);
-}
-
-void WMLog::LogInfo(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...)
-{
-   wchar_t buf[1024];
-   va_list ap;
-   va_start(ap, fmt);
-
-   _vsnwprintf_s(buf, ARRAY_SIZE(buf), _TRUNCATE, fmt, ap);
-   StoreMessage(LogLevel::Info, buf);
-
-   va_end(ap);
-}
-
-void WMLog::LogWarning(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...)
-{
-   wchar_t buf[1024];
-   va_list ap;
-   va_start(ap, fmt);
-
-   _vsnwprintf_s(buf, ARRAY_SIZE(buf), _TRUNCATE, fmt, ap);
-   StoreMessage(LogLevel::Warning, buf);
-
-   va_end(ap);
-}
-
-void WMLog::LogError(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...)
-{
-   wchar_t buf[1024];
-   va_list ap;
-   va_start(ap, fmt);
-
-   _vsnwprintf_s(buf, ARRAY_SIZE(buf), _TRUNCATE, fmt, ap);
-   StoreMessage(LogLevel::Error, buf);
-
-   va_end(ap);
-}
-
 void WMLog::LogWinError(const wchar_t *functionName, DWORD lastError)
 {
    // Retrieve the system error message for the last-error code
index 0964863fc38e057a87b6b213263bba0eea296f95..795515988db7f6ccad88fea19f60e90352d12f96 100644 (file)
@@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "common.h"
 
+#include <format>
+
 enum class LogLevel {
    Debug,
    Info,
@@ -52,10 +54,31 @@ class WMLog {
 public:
    static WMLog& GetInstance();
 
-   void LogDebug(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...);
-   void LogInfo(_In_z_ _Printf_format_string_ const wchar_t* fmt, ...);
-   void LogWarning(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...);
-   void LogError(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...);
+   // The format string is validated against the arguments at compile time.
+   template<typename... Args>
+   void LogDebug(std::wformat_string<Args...> fmt, Args&&... args)
+   {
+      StoreMessage(LogLevel::Debug,
+                   std::format(fmt, std::forward<Args>(args)...).c_str());
+   }
+   template<typename... Args>
+   void LogInfo(std::wformat_string<Args...> fmt, Args&&... args)
+   {
+      StoreMessage(LogLevel::Info,
+                   std::format(fmt, std::forward<Args>(args)...).c_str());
+   }
+   template<typename... Args>
+   void LogWarning(std::wformat_string<Args...> fmt, Args&&... args)
+   {
+      StoreMessage(LogLevel::Warning,
+                   std::format(fmt, std::forward<Args>(args)...).c_str());
+   }
+   template<typename... Args>
+   void LogError(std::wformat_string<Args...> fmt, Args&&... args)
+   {
+      StoreMessage(LogLevel::Error,
+                   std::format(fmt, std::forward<Args>(args)...).c_str());
+   }
    void LogWinError(const wchar_t *functionName, DWORD errorCode = -1);
 
    void EnableLogFile(bool enable);
index 27e2223ee7423420ec3dfc683ad9dc69c629c0a0..6a7da028d3e99482ccf8414947af4b475947dbdd 100644 (file)
@@ -218,7 +218,7 @@ static bool ReadStringFromRegistry(HKEY hKey, const wchar_t* valueName,
     if (regError != ERROR_SUCCESS) {
         if (regError != ERROR_FILE_NOT_FOUND) {
             ShowWindowsError(L"RegGetValueW", regError);
-            log.LogError(L"[Registry] Failed to read key \"%s\".", valueName);
+            log.LogError(L"[Registry] Failed to read key \"{}\".", valueName);
         }
     } else {
         std::wstring buf(bufSize / sizeof(wchar_t), L'\0');
@@ -226,7 +226,7 @@ static bool ReadStringFromRegistry(HKEY hKey, const wchar_t* valueName,
                                 nullptr, buf.data(), &bufSize);
         if (regError != ERROR_SUCCESS) {
             ShowWindowsError(L"RegGetValueW", regError);
-            log.LogError(L"[Registry] Failed to query value for key \"%s\".",
+            log.LogError(L"[Registry] Failed to query value for key \"{}\".",
                          valueName);
         } else {
             buf.resize(wcslen(buf.c_str()));  // Drop trailing '\0's
@@ -257,7 +257,7 @@ bool WMSettings::MigrateSettings()
     DWORD version = QueryValue(SettingsKey::SETTINGS_VERSION);
     if (version > CURRENT_SETTINGS_VERSION) {
         WMLog::GetInstance().LogError(
-            L"Settings version %d is newer than application supports (%d). "
+            L"Settings version {} is newer than application supports ({}). "
             L"Some settings may not work correctly.",
             version, CURRENT_SETTINGS_VERSION);
     } else if (version == 0) {
@@ -421,8 +421,8 @@ bool WMSettings::IsAutostartEnabled()
                     log.LogWarning(
                         L"Registry entry for auto start has wrong executable "
                         L"path."
-                        L"Current path \"%s\". Path in registry \"%s\"",
-                        wmPath, autostartPathFromReg.c_str());
+                        L"Current path \"{}\". Path in registry \"{}\"",
+                        wmPath, autostartPathFromReg);
                 } else {
                     isEnabled = true;
                 }
@@ -480,7 +480,7 @@ DWORD WMSettings::QueryValue(SettingsKey key) const
         if (regError != ERROR_FILE_NOT_FOUND) {
             ShowWindowsError(L"RegQueryValueExW", regError);
             WMLog& log = WMLog::GetInstance();
-            log.LogError(L"[Registry] Failed to query value for key \"%s\"",
+            log.LogError(L"[Registry] Failed to query value for key \"{}\"",
                          keyStr);
         }
         return GetDefaultSetting(key);
@@ -735,7 +735,7 @@ std::vector<std::pair<DWORD, DWORD>> WMSettings::GetQuietHoursTimes()
     if (numEntries % 2 != 0) {
         WMLog::GetInstance().LogError(
             L"Corrupted Quiet Hours times in registry: odd number of entries "
-            L"(%d). Resetting QuietHours",
+            L"({}). Resetting QuietHours",
             numEntries);
         TaskDialog(
             nullptr, nullptr, PROGRAM_NAME,
@@ -759,9 +759,9 @@ std::vector<std::pair<DWORD, DWORD>> WMSettings::GetQuietHoursTimes()
                              reinterpret_cast<LPBYTE>(&timeEntry.first), &size);
         if (regError != ERROR_SUCCESS) {
             WMLog::GetInstance().LogError(
-                L"Failed to read entry \"%s\" while initializing quiet hours "
-                L"(%d)",
-                keyStart.c_str(), regError);
+                L"Failed to read entry \"{}\" while initializing quiet hours "
+                L"({})",
+                keyStart, regError);
             continue;
         }
 
@@ -771,9 +771,9 @@ std::vector<std::pair<DWORD, DWORD>> WMSettings::GetQuietHoursTimes()
             reinterpret_cast<LPBYTE>(&timeEntry.second), &size);
         if (regError != ERROR_SUCCESS) {
             WMLog::GetInstance().LogError(
-                L"Failed to read entry \"%s\" while initializing quiet hours "
-                L"(%d)",
-                keyStart.c_str(), regError);
+                L"Failed to read entry \"{}\" while initializing quiet hours "
+                L"({})",
+                keyEnd, regError);
             continue;
         }
         times.push_back(std::move(timeEntry));
index f4aa480c08456cd297ee29d3fae240d36a49eafe..7f79b2ecf472207af66067b0039db3b8262b4e44 100644 (file)
@@ -92,7 +92,8 @@ std::vector<LanguageModule> WMi18n::GetAvailableLanguages() const
                   langDlls.push_back(langMod);
                }
             } catch (const nlohmann::json::parse_error &pe) {
-               WMLog::GetInstance().LogError(L"Failed to parse language file \"%ls\": %S", wfd.cFileName, pe.what());
+               WMLog::GetInstance().LogError(L"Failed to parse language file \"{}\": {}",
+                                             wfd.cFileName, ConvertStringToWideString(pe.what()));
             }
          } while (FindNextFileW(hFindFile, &wfd));
       }
@@ -136,7 +137,7 @@ bool WMi18n::LoadLanguage(const std::wstring &fileName, TranslationMap &strings)
    const fs::path loadFilePath{ fileName};
    *langFilePath /= loadFilePath.filename(); // Sanitize
    if (!fs::exists(*langFilePath)) {
-      log.LogError(L"Language module \"%ls\" does not exist", langFilePath->c_str());
+      log.LogError(L"Language module \"{}\" does not exist", langFilePath->wstring());
       return false;
    }
    try {
@@ -145,19 +146,22 @@ bool WMi18n::LoadLanguage(const std::wstring &fileName, TranslationMap &strings)
       TranslationMap translations_temp;
       for (auto it = json_data.begin(); it != json_data.end(); ++it) {
          if (it->is_structured()) {
-            log.LogError(L"Language module \"%ls\" has nested elements", langFilePath->c_str());
+            log.LogError(L"Language module \"{}\" has nested elements", langFilePath->wstring());
             return false;
          }
          if (it.value() == L"") {
-            log.LogInfo(L"No translation for \"%S\" found in language file", it.key().c_str());
+            log.LogInfo(L"No translation for \"{}\" found in language file",
+                        ConvertStringToWideString(it.key()));
          } else {
             const auto value = ConvertStringToWideString(it.value());
             if (value == L"") {
-               log.LogError(L"Unable to convert language element \"%S\"", it.key().c_str());
+               log.LogError(L"Unable to convert language element \"{}\"",
+                            ConvertStringToWideString(it.key()));
                return false;
             }
             if (translations_temp.contains(it.key())) {
-               log.LogError(L"Double entry for language key \"%S\" found.", it.key().c_str());
+               log.LogError(L"Double entry for language key \"{}\" found.",
+                            ConvertStringToWideString(it.key()));
                return false;
             }
             translations_temp[it.key()] = value;
@@ -166,9 +170,9 @@ bool WMi18n::LoadLanguage(const std::wstring &fileName, TranslationMap &strings)
       strings = std::move(translations_temp);
    } catch (const nlohmann::json::parse_error &pe) {
       log.LogError(
-         L"Failed to parse language file \"%ls\": %S",
-         langFilePath->filename().c_str(),
-         pe.what());
+         L"Failed to parse language file \"{}\": {}",
+         langFilePath->filename().wstring(),
+         ConvertStringToWideString(pe.what()));
       return false;
    }
    return true;
@@ -185,8 +189,8 @@ bool WMi18n::LoadLanguage(const std::wstring &fileName)
    TranslationMap new_lang;
    if (!LoadLanguage(fileName, new_lang)) {
       WMLog::GetInstance().LogError(
-         L"Failed to load language \"%ls\"",
-         fileName.c_str());
+         L"Failed to load language \"{}\"",
+         fileName);
       return false;
    } else {
       UnloadLanguage();
index 154bd04f6875a04c846041754985aad4e39c920a..0c5f414b2ab62b6b9e8fa50617ff5fdb32b9b224 100644 (file)
@@ -284,25 +284,25 @@ bool WinMute::LoadSettings()
    if (log.IsLogFileEnabled()) {
       std::wstring versionNumber;
       GetWinMuteVersion(versionNumber);
-      log.LogInfo(L"Starting WinMute %s", versionNumber.c_str());
+      log.LogInfo(L"Starting WinMute {}", versionNumber);
       log.LogInfo(L"Loading settings:");
-      log.LogInfo(L"Check for updates: %s", settings_.QueryValue(SettingsKey::CHECK_FOR_UPDATE) ? L"Yes" : L"No");
-      log.LogInfo(L"\tCheck for beta updates: %s", settings_.QueryValue(SettingsKey::CHECK_FOR_BETA_UPDATE) ? L"Yes" : L"No");
-      log.LogInfo(L"\tRestore volume: %s", settings_.QueryValue(SettingsKey::RESTORE_AUDIO) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute delay: %d", settings_.QueryValue(SettingsKey::MUTE_DELAY));
-      log.LogInfo(L"\tMute on lock: %s", settings_.QueryValue(SettingsKey::MUTE_ON_LOCK) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute on display standby: %s", settings_.QueryValue(SettingsKey::MUTE_ON_DISPLAYSTANDBY) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute on logout: %s", settings_.QueryValue(SettingsKey::MUTE_ON_LOGOUT) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute on suspend: %s", settings_.QueryValue(SettingsKey::MUTE_ON_SUSPEND) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute on shutdown: %s", settings_.QueryValue(SettingsKey::MUTE_ON_SHUTDOWN) ? L"Yes" : L"No");
-      log.LogInfo(L"\tShow notifications: %s", settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute on bluetooth: %s", settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH) ? L"Yes" : L"No");
-      log.LogInfo(L"\tTry pausing media when muting: %s", settings_.QueryValue(SettingsKey::MUTE_TRY_PAUSE_MEDIA) ? L"Yes" : L"No");
-      log.LogInfo(L"\tTry resuming media when unmuting: %s", settings_.QueryValue(SettingsKey::MUTE_TRY_RESUME_MEDIA) ? L"Yes" : L"No");
-      log.LogInfo(L"\t\tUse devicelist: %s", settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute on WLAN: %s", settings_.QueryValue(SettingsKey::MUTE_ON_WLAN) ? L"Yes" : L"No");
-      log.LogInfo(L"\t\tUse allowlist: %s", settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST) ? L"Yes" : L"No");
-      log.LogInfo(L"\tMute specific endpoints only: %s", settings_.QueryValue(SettingsKey::MUTE_INDIVIDUAL_ENDPOINTS) ? L"Yes" : L"No");
+      log.LogInfo(L"Check for updates: {}", settings_.QueryValue(SettingsKey::CHECK_FOR_UPDATE) ? L"Yes" : L"No");
+      log.LogInfo(L"\tCheck for beta updates: {}", settings_.QueryValue(SettingsKey::CHECK_FOR_BETA_UPDATE) ? L"Yes" : L"No");
+      log.LogInfo(L"\tRestore volume: {}", settings_.QueryValue(SettingsKey::RESTORE_AUDIO) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute delay: {}", settings_.QueryValue(SettingsKey::MUTE_DELAY));
+      log.LogInfo(L"\tMute on lock: {}", settings_.QueryValue(SettingsKey::MUTE_ON_LOCK) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute on display standby: {}", settings_.QueryValue(SettingsKey::MUTE_ON_DISPLAYSTANDBY) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute on logout: {}", settings_.QueryValue(SettingsKey::MUTE_ON_LOGOUT) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute on suspend: {}", settings_.QueryValue(SettingsKey::MUTE_ON_SUSPEND) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute on shutdown: {}", settings_.QueryValue(SettingsKey::MUTE_ON_SHUTDOWN) ? L"Yes" : L"No");
+      log.LogInfo(L"\tShow notifications: {}", settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute on bluetooth: {}", settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH) ? L"Yes" : L"No");
+      log.LogInfo(L"\tTry pausing media when muting: {}", settings_.QueryValue(SettingsKey::MUTE_TRY_PAUSE_MEDIA) ? L"Yes" : L"No");
+      log.LogInfo(L"\tTry resuming media when unmuting: {}", settings_.QueryValue(SettingsKey::MUTE_TRY_RESUME_MEDIA) ? L"Yes" : L"No");
+      log.LogInfo(L"\t\tUse devicelist: {}", settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute on WLAN: {}", settings_.QueryValue(SettingsKey::MUTE_ON_WLAN) ? L"Yes" : L"No");
+      log.LogInfo(L"\t\tUse allowlist: {}", settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST) ? L"Yes" : L"No");
+      log.LogInfo(L"\tMute specific endpoints only: {}", settings_.QueryValue(SettingsKey::MUTE_INDIVIDUAL_ENDPOINTS) ? L"Yes" : L"No");
    }
 
    if (!settings_.QueryValue(SettingsKey::MUTE_INDIVIDUAL_ENDPOINTS)) {