reinterpret_cast<LPVOID*>(&pvi),
&pviLen)) {
TCHAR buf[30];
-
-#ifdef _UNICODE
- swprintf_s(
-#else
- sprintf_s(
-#endif
+ StringCchPrintf(
buf,
ARRAY_SIZE(buf),
_T("%d.%d.%d.%d"),
TrayIcon::TrayIcon(HWND hWnd, UINT trayID, HICON hIcon,
const tstring& tooltip, bool show) :
+ initialized_(false),
iconVisible_(false)
{
Init(hWnd, trayID, hIcon, tooltip, show);
if (show) {
Show();
}
+ initialized_ = true;
+ if (popupQueue_.size() > 0) {
+ for (const auto& p : popupQueue_) {
+ ShowPopup(p.title, p.text);
+ }
+ popupQueue_.clear();
+ }
}
TrayIcon::~TrayIcon()
void TrayIcon::ShowPopup(const tstring& title, const tstring& text) const
{
+ if (!initialized_) {
+ TrayIconPopup popup;
+ popup.title = title;
+ popup.text = text;
+ popupQueue_.push_back(popup);
+ return;
+ }
NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = hWnd_;
#define WM_TRAYICON (WM_APP + 700)
+struct TrayIconPopup {
+ tstring title;
+ tstring text;
+};
+
class TrayIcon {
public:
TrayIcon();
bool RemoveNotifyIcon();
bool ChangeText();
+ mutable std::vector<TrayIconPopup> popupQueue_;
+
+ bool initialized_;
bool iconVisible_;
UINT trayID_;
HICON hIcon_;
for (size_t i = 0; i < networks.size(); ++i) {
TCHAR valueName[10];
-#ifdef _UNICODE
- swprintf(valueName, ARRAY_SIZE(valueName), _T("WiFi %03zu"), i + 1);
-#else
- sprintf_s(valueName, "WiFi %03zu", i + 1);
-#endif
+ StringCchPrintfW(valueName, ARRAY_SIZE(valueName), _T("WiFi %03zu"), i + 1);
const tstring& v = networks[i];
DWORD regError = RegSetValueEx(
hWifiKey_,
void Unload();
void SetNetworkList(const std::vector<tstring> networks, bool isMuteList);
+ void CheckNetwork();
void WlanNotificationCallback(PWLAN_NOTIFICATION_DATA notifyData);
private:
HWND hNotifyWnd_;
HANDLE wlanHandle_;
+ // If "true" then networks_ contains all networks where the workstation should
+ // be muted. If false, then networks_ contains all networks where the ws should
+ // not be muted.
bool isMuteList_;
bool initialized_;
std::vector<tstring> networks_;
isMuteList_ = isMuteList;
}
+void WifiDetector::CheckNetwork()
+{
+ PWLAN_INTERFACE_INFO_LIST ifList;
+ DWORD wlanErr = WlanEnumInterfaces(wlanHandle_, NULL, &ifList);
+ if (wlanErr != ERROR_SUCCESS) {
+ PrintWindowsError(_T("WlanEnumInterfaces"), wlanErr);
+ } else {
+ for (; ifList->dwIndex < ifList->dwNumberOfItems; ++ifList->dwIndex) {
+ PWLAN_AVAILABLE_NETWORK_LIST availList;
+ wlanErr = WlanGetAvailableNetworkList(
+ wlanHandle_,
+ &ifList->InterfaceInfo[ifList->dwIndex].InterfaceGuid,
+ 0,
+ NULL,
+ &availList);
+ if (wlanErr != ERROR_SUCCESS) {
+ PrintWindowsError(_T("WlanGetAvailableNetworkList"), wlanErr);
+ } else {
+ for (; availList->dwIndex < availList->dwNumberOfItems; ++availList->dwIndex) {
+ PWLAN_AVAILABLE_NETWORK net = &availList->Network[availList->dwIndex];
+ if (net->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) {
+ const auto it = std::find(std::begin(networks_),
+ std::end(networks_),
+ net->strProfileName);
+ if (isMuteList_ && it != std::end(networks_)
+ || !isMuteList_ && it == std::end(networks_)) {
+ size_t profileNameLen = lstrlen(net->strProfileName);
+ TCHAR* wiFiName = new TCHAR[profileNameLen + 1];
+ StringCchCopy(wiFiName, profileNameLen + 1, net->strProfileName);
+ SendMessage(hNotifyWnd_, WM_WIFISTATUSCHANGED, 1,
+ reinterpret_cast<LPARAM>(wiFiName));
+ break;
+ }
+ }
+ }
+ WlanFreeMemory(availList);
+ }
+ }
+ WlanFreeMemory(ifList);
+ }
+}
+
void WifiDetector::WlanNotificationCallback(PWLAN_NOTIFICATION_DATA notifyData)
{
if (notifyData->NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM) {
if (notifyData->NotificationCode == wlan_notification_acm_connection_complete
|| notifyData->NotificationCode == wlan_notification_acm_disconnected) {
bool connected = notifyData->NotificationCode == wlan_notification_acm_connection_complete;
- WLAN_CONNECTION_NOTIFICATION_DATA *wcnd =
+ WLAN_CONNECTION_NOTIFICATION_DATA * wcnd =
reinterpret_cast<WLAN_CONNECTION_NOTIFICATION_DATA*>(notifyData->pData);
const auto it = std::find(std::begin(networks_), std::end(networks_),
wcnd->strProfileName);
- if (isMuteList_ && it != std::end(networks_)) {
+
+ if (isMuteList_ && it != std::end(networks_)
+ || !isMuteList_ && it == std::end(networks_)) {
+ size_t profileNameLen = lstrlen(wcnd->strProfileName);
+ TCHAR* wiFiName = new TCHAR[profileNameLen + 1];
+ StringCchCopy(wiFiName, profileNameLen + 1, wcnd->strProfileName);
SendMessage(hNotifyWnd_, WM_WIFISTATUSCHANGED, connected,
- reinterpret_cast<LPARAM>((*it).c_str()));
- } else if (!isMuteList_ && it == std::end(networks_)) {
- SendMessage(hNotifyWnd_, WM_WIFISTATUSCHANGED, connected, NULL);
+ reinterpret_cast<LPARAM>(wiFiName));
}
}
}
muteConfig_.muteOnWlan = settings_.QueryValue(SettingsKey::MUTE_ON_WLAN);
if (muteConfig_.muteOnWlan) {
- wifiDetector_.Init(hWnd_);
- bool isMuteList = !settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST);
- wifiDetector_.SetNetworkList(settings_.GetWifiNetworks(), isMuteList);
+ if (!wifiDetector_.Init(hWnd_)) {
+ TaskDialog(nullptr, nullptr, PROGRAM_NAME,
+ _T("WLAN Detection"),
+ _T("Failed to initialize WLAN detection. ")
+ _T("This feature will be unavailable for this session"),
+ TDCBF_OK_BUTTON, TD_ERROR_ICON, nullptr);
+ } else {
+ bool isMuteList = !settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST);
+ wifiDetector_.SetNetworkList(settings_.GetWifiNetworks(), isMuteList);
+ wifiDetector_.CheckNetwork();
+ }
} else {
wifiDetector_.Unload();
}
if (wParam == 1) { // Connected
if (settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)) {
TCHAR msgBuf[260] = { 0 };
- const TCHAR* wifiName = reinterpret_cast<TCHAR*>(lParam);
-
+ TCHAR* wifiName = reinterpret_cast<TCHAR*>(lParam);
if (settings_.QueryValue(SettingsKey::MUTE_ON_WLAN_ALLOWLIST)) {
- StringCchCopy(
- msgBuf,
- ARRAY_SIZE(msgBuf),
- _T("Current WLAN network is not on allowed list for AutoMute"));
+ StringCchPrintfW(
+ msgBuf, ARRAY_SIZE(msgBuf),
+ _T("WLAN \"%s\"network is not on allowed list.\n"),
+ wifiName);
} else {
-#ifdef _UNICODE
- swprintf(
+ StringCchPrintfW(
msgBuf, ARRAY_SIZE(msgBuf),
_T("WLAN network \"%s\" is configured for AutoMute."),
wifiName);
-#else
- sprintf_s(
- msgBuf,
- "WLAN network \"%s\" is configured for AutoMute.",
- wifiName);
-#endif
}
trayIcon_.ShowPopup(_T("Workstation muted"), msgBuf);
-
+ delete [] wifiName;
}
muteCtrl_.SetMute(true);
}
//
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,9,9,2
- PRODUCTVERSION 1,9,9,2
+ FILEVERSION 1,9,9,3
+ PRODUCTVERSION 1,9,9,3
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
BEGIN
VALUE "CompanyName", "LX-Systems"
VALUE "FileDescription", "WinMute"
- VALUE "FileVersion", "1.9.9.2"
+ VALUE "FileVersion", "1.9.9.3"
VALUE "InternalName", "WinMute.exe"
VALUE "LegalCopyright", "Copyright (C) 2022, Alexander Steinhöfer"
VALUE "OriginalFilename", "WinMute.exe"
VALUE "ProductName", "WinMute"
- VALUE "ProductVersion", "1.9.9.2"
+ VALUE "ProductVersion", "1.9.9.3"
END
BLOCK "040704b0"
BEGIN
VALUE "CompanyName", "LX-Systems"
VALUE "FileDescription", "WinMute"
- VALUE "FileVersion", "1.9.9.2"
+ VALUE "FileVersion", "1.9.9.3"
VALUE "InternalName", "WinMute.exe"
VALUE "LegalCopyright", "Copyright (C) 2022, Alexander Steinhöfer"
VALUE "OriginalFilename", "WinMute.exe"
VALUE "ProductName", "WinMute"
- VALUE "ProductVersion", "1.9.9.2"
+ VALUE "ProductVersion", "1.9.9.3"
END
END
BLOCK "VarFileInfo"