From: lx-s Date: Thu, 27 Jul 2023 06:15:21 +0000 (+0200) Subject: Improved Logging. Removed error when SystemUsesLightTheme is not present. X-Git-Tag: 2.3.1.0~2 X-Git-Url: https://repos.lx-s.de/gitweb/?a=commitdiff_plain;h=b02c43e1c0ecc09bcd76926e9c3463f1da3a35f0;p=winmute.git Improved Logging. Removed error when SystemUsesLightTheme is not present. --- diff --git a/WinMute/AboutDlg.cpp b/WinMute/AboutDlg.cpp index b7f2c55..bcf953e 100644 --- a/WinMute/AboutDlg.cpp +++ b/WinMute/AboutDlg.cpp @@ -202,46 +202,6 @@ static INT_PTR CALLBACK About_LicenseDlgProc(HWND hDlg, UINT msg, WPARAM, LPARAM return FALSE; } -static bool GetWinMuteVersion(std::wstring& versNumber) -{ - bool success = false; - DWORD dummy; - wchar_t szFileName[MAX_PATH]; - GetModuleFileName(nullptr, szFileName, sizeof(szFileName)/sizeof(szFileName[0])); - const DWORD versSize = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL, szFileName, &dummy); - LPVOID versData = malloc(versSize); - if (versData != nullptr) { - if (GetFileVersionInfoExW( - FILE_VER_GET_NEUTRAL, - szFileName, - 0, - versSize, - versData)) { - VS_FIXEDFILEINFO *pvi; - UINT pviLen = sizeof(*pvi); - if (VerQueryValueW( - versData, - L"\\", - reinterpret_cast(&pvi), - &pviLen)) { - wchar_t buf[50]; - StringCchPrintfW( - buf, - ARRAY_SIZE(buf), - L"%d.%d.%d.%d", - pvi->dwProductVersionMS >> 16, - pvi->dwFileVersionMS & 0xFFFF, - pvi->dwFileVersionLS >> 16, - pvi->dwFileVersionLS & 0xFFFF); - versNumber = buf; - success = true; - } - } - free(versData); - } - return success; -} - INT_PTR CALLBACK AboutDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { AboutDlgData* dlgData = diff --git a/WinMute/Utility.cpp b/WinMute/Utility.cpp index 8e66a6f..6678eec 100644 --- a/WinMute/Utility.cpp +++ b/WinMute/Utility.cpp @@ -76,3 +76,43 @@ void PrintWindowsError(const wchar_t *functionName, DWORD lastError) LocalFree(lpMsgBuf); } } + +bool GetWinMuteVersion(std::wstring &versNumber) +{ + bool success = false; + DWORD dummy; + wchar_t szFileName[MAX_PATH]; + GetModuleFileName(nullptr, szFileName, sizeof(szFileName) / sizeof(szFileName[0])); + const DWORD versSize = GetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL, szFileName, &dummy); + LPVOID versData = malloc(versSize); + if (versData != nullptr) { + if (GetFileVersionInfoExW( + FILE_VER_GET_NEUTRAL, + szFileName, + 0, + versSize, + versData)) { + VS_FIXEDFILEINFO *pvi; + UINT pviLen = sizeof(*pvi); + if (VerQueryValueW( + versData, + L"\\", + reinterpret_cast(&pvi), + &pviLen)) { + wchar_t buf[50]; + StringCchPrintfW( + buf, + ARRAY_SIZE(buf), + L"%d.%d.%d.%d", + pvi->dwProductVersionMS >> 16, + pvi->dwFileVersionMS & 0xFFFF, + pvi->dwFileVersionLS >> 16, + pvi->dwFileVersionLS & 0xFFFF); + versNumber = buf; + success = true; + } + } + free(versData); + } + return success; +} diff --git a/WinMute/WMSettings.cpp b/WinMute/WMSettings.cpp index aecf1fd..0c8f8e0 100644 --- a/WinMute/WMSettings.cpp +++ b/WinMute/WMSettings.cpp @@ -179,10 +179,12 @@ static bool ReadStringFromRegistry(HKEY hKey, const wchar_t *subKey, std::wstrin bool success = false; DWORD regError = 0; DWORD bufSize = 0; + WMLog &log = WMLog::GetInstance(); regError = RegQueryValueExW(hKey, subKey, nullptr, nullptr, nullptr, &bufSize); if (regError != ERROR_SUCCESS) { if (regError != ERROR_FILE_NOT_FOUND) { - PrintWindowsError(L"RegQueryValueEx", regError); + PrintWindowsError(L"RegQueryValueExW", regError); + log.Write(L"[Registry] Failed to read key \"%s\".", subKey); } } else { bufSize += 1; // Trailing '\0' @@ -190,7 +192,8 @@ static bool ReadStringFromRegistry(HKEY hKey, const wchar_t *subKey, std::wstrin regError = RegQueryValueExW(hKey, subKey, nullptr, nullptr, reinterpret_cast(buf), &bufSize); if (regError != ERROR_SUCCESS) { - PrintWindowsError(L"RegQueryValueEx", regError); + PrintWindowsError(L"RegQueryValueExW", regError); + log.Write(L"[Registry] Failed to query value for key \"%s\".", subKey); } else { success = true; val = buf; @@ -403,7 +406,9 @@ DWORD WMSettings::QueryValue(SettingsKey key) const &size); if (regError != ERROR_SUCCESS) { if (regError != ERROR_FILE_NOT_FOUND) { - PrintWindowsError(L"RegCreateKeyEx", regError); + PrintWindowsError(L"RegQueryValueExW", regError); + WMLog &log = WMLog::GetInstance(); + log.Write(L"[Registry] Failed to query value for key \"%s\"", keyStr); } return GetDefaultSetting(key); } @@ -424,7 +429,7 @@ bool WMSettings::SetValue(SettingsKey key, DWORD value) reinterpret_cast(&value), sizeof(DWORD)); if (regError != ERROR_SUCCESS) { - PrintWindowsError(L"RegCreateKeyEx", regError); + PrintWindowsError(L"RegSetValueExW", regError); return false; } diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 0c37005..e28a706 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "WinMute.h" #include "WinAudio.h" + extern HINSTANCE hglobInstance; extern INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); extern INT_PTR CALLBACK SettingsDlgProc(HWND, UINT, WPARAM, LPARAM); @@ -69,16 +70,19 @@ static LRESULT CALLBACK WinMuteWndProc( static int IsDarkMode(bool& isDarkMode) { + WMLog &log = WMLog::GetInstance(); HKEY hKey; int rc = 1; //RegOpenCurrentUser + const std::wstring regKey = + L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; LSTATUS error = RegOpenKeyW( HKEY_CURRENT_USER, - L"Software\\Microsoft\\Windows\\CurrentVersion\\" - L"Themes\\Personalize", + regKey.c_str(), &hKey); if (error != ERROR_SUCCESS) { PrintWindowsError(L"RegOpenKey", error); + log.Write(L"[Registry] Failed to open registry key \"%s\"", regKey.c_str()); } else { DWORD isLightTheme = 0; DWORD bufSize = sizeof(isLightTheme); @@ -91,7 +95,7 @@ static int IsDarkMode(bool& isDarkMode) reinterpret_cast(&isLightTheme), &bufSize); if (error != ERROR_SUCCESS) { - PrintWindowsError(L"RegQueryValueEx", error); + log.Write(L"[Registry] Failed to query value for key \"SystemUsesLightTheme\""); } else { isDarkMode = !isLightTheme; rc = 0; @@ -299,6 +303,9 @@ bool WinMute::LoadSettings() WMLog& log = WMLog::GetInstance(); if (log.IsEnabled()) { + std::wstring versionNumber; + GetWinMuteVersion(versionNumber); + log.Write(L"Starting WinMute %s", versionNumber.c_str()); log.Write(L"Loading settings:"); log.Write(L"\tRestore volume: %s", settings_.QueryValue(SettingsKey::RESTORE_AUDIO) ? L"Yes" : L"No"); log.Write(L"\tMute on lock: %s", settings_.QueryValue(SettingsKey::MUTE_ON_LOCK) ? L"Yes" : L"No"); diff --git a/WinMute/common.h b/WinMute/common.h index f4a52e1..484b002 100644 --- a/WinMute/common.h +++ b/WinMute/common.h @@ -87,6 +87,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #pragma warning(disable : 4201) # include #pragma warning(default : 4201) @@ -106,6 +107,7 @@ POSSIBILITY OF SUCH DAMAGE. // Utility void PrintWindowsError(const wchar_t *functionName, DWORD lastError = -1); +bool GetWinMuteVersion(std::wstring &versNumber); static const wchar_t *PROGRAM_NAME = L"WinMute"; constexpr int WM_SAVESETTINGS = WM_USER + 300;