From ae05c2d82f996eabdfb5dfa6f57eecc169b36acd Mon Sep 17 00:00:00 2001 From: lx-s Date: Thu, 13 Apr 2023 15:36:16 +0200 Subject: [PATCH] CPP Warnings and Recommendations --- WinMute/MuteControl.cpp | 37 ++++++++++++++++++++----------------- WinMute/MuteControl.h | 5 +++-- WinMute/QuietHoursTimer.cpp | 9 +++++++-- WinMute/SettingsDlg.cpp | 2 +- WinMute/WinAudio.h | 4 ++-- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/WinMute/MuteControl.cpp b/WinMute/MuteControl.cpp index a2b2f68..b3d18a7 100644 --- a/WinMute/MuteControl.cpp +++ b/WinMute/MuteControl.cpp @@ -85,15 +85,17 @@ void MuteControl::SetMute(bool mute) void MuteControl::SaveMuteStatus() { - bool alreadySaved = false; - for (const auto& conf : muteConfig_) { - if (conf.shouldMute && conf.active) { - WMLog::GetInstance().Write(L"Muting event already active. Skipping status save"); - alreadySaved = true; - break; + const bool alreadySaved = std::any_of( + muteConfig_.begin(), + muteConfig_.end(), + [](const MuteConfig &conf) { + return conf.shouldMute && conf.active; } - } - if (!alreadySaved) { + ); + + if (alreadySaved) { + WMLog::GetInstance().Write(L"Muting event already active. Skipping status save"); + } else { WMLog::GetInstance().Write(L"Saving mute status"); winAudio_->SaveMuteStatus(); } @@ -118,15 +120,16 @@ void MuteControl::RestoreVolume(bool withDelay) log.Write(L"Volume Restore has been disabled"); return; } - bool restore = true; - for (const auto& conf : muteConfig_) { - if (conf.shouldMute && conf.active) { - log.Write(L"Skipping restore since other mute event is currently active"); - restore = false; - break; + const bool restore = !std::any_of( + muteConfig_.begin(), + muteConfig_.end(), + [](const MuteConfig &conf) { + return conf.shouldMute && conf.active; } - } - if (restore) { + ); + if (!restore) { + log.Write(L"Skipping restore since other mute event is currently active"); + } else { log.Write(L"Restoring previous mute state"); ShowNotification( L"Volume restored", @@ -310,7 +313,7 @@ void MuteControl::NotifyQuietHours(bool active) } void MuteControl::SetManagedEndpoints( - const std::vector endpoints, + const std::vector& endpoints, bool isAllowList) { winAudio_->MuteSpecificEndpoints(true); diff --git a/WinMute/MuteControl.h b/WinMute/MuteControl.h index db22ba4..1a53aff 100644 --- a/WinMute/MuteControl.h +++ b/WinMute/MuteControl.h @@ -81,8 +81,9 @@ public: void NotifyQuietHours(bool active); - void SetManagedEndpoints(const std::vector endpoints, - bool isAllowList); + void SetManagedEndpoints( + const std::vector& endpoints, + bool isAllowList); void ClearManagedEndpoints(); private: struct MuteConfig { diff --git a/WinMute/QuietHoursTimer.cpp b/WinMute/QuietHoursTimer.cpp index 38632a7..b2ce833 100644 --- a/WinMute/QuietHoursTimer.cpp +++ b/WinMute/QuietHoursTimer.cpp @@ -104,8 +104,13 @@ static VOID CALLBACK QuietHoursTimerProc(HWND hWnd, UINT msg, UINT_PTR id, DWORD } QuietHoursTimer::QuietHoursTimer() : - initialized_{ false }, enabled_{ false }, hParent_{ nullptr }, qhStart_{0}, qhEnd_{ 0 } -{} + initialized_{ false }, + enabled_{ false }, + hParent_{ nullptr }, + qhStart_{0}, + qhEnd_{ 0 } +{ +} QuietHoursTimer::~QuietHoursTimer() { diff --git a/WinMute/SettingsDlg.cpp b/WinMute/SettingsDlg.cpp index 6f82de0..ea0e434 100644 --- a/WinMute/SettingsDlg.cpp +++ b/WinMute/SettingsDlg.cpp @@ -49,7 +49,7 @@ struct SettingsDlgData { HWND hActiveTab; WMSettings* settings; - SettingsDlgData(WMSettings* settings) + explicit SettingsDlgData(WMSettings* settings) : settings(settings), hTabCtrl(nullptr), hActiveTab(nullptr) { ZeroMemory(hTabs, sizeof(hTabs)); diff --git a/WinMute/WinAudio.h b/WinMute/WinAudio.h index d6b7dba..2cd3372 100644 --- a/WinMute/WinAudio.h +++ b/WinMute/WinAudio.h @@ -83,10 +83,10 @@ public: bool RestoreMuteStatus() override; void SetMute(bool mute) override; - void MuteSpecificEndpoints(bool muteSpecific); + void MuteSpecificEndpoints(bool muteSpecific) override; void SetManagedEndpoints( const std::vector &endpoints, - bool isAllowList); + bool isAllowList) override; private: void Uninit(); -- 2.43.0