]> repos.lx-s.de Git - winmute.git/commitdiff
Keep bluetooth device names as wide char end-to-end
authorlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 12:43:57 +0000 (14:43 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 12:43:57 +0000 (14:43 +0200)
WinMute/BluetoothDetector.cpp
WinMute/Settings_BluetoothDlg.cpp
WinMute/WMSettings.cpp
WinMute/WMSettings.h

index 8b045bcb1ad11e51522929648f36d64e4969474f..460a53af40e0331e5316d981766640dce614e178 100644 (file)
@@ -119,7 +119,7 @@ void BluetoothDetector::Unload()
 }
 
 void BluetoothDetector::SetDeviceList(
-   const std::vector<std::string>& devices,
+   const std::vector<std::wstring>& devices,
    bool useDeviceList)
 {
    deviceNames_ = devices;
@@ -155,18 +155,22 @@ BluetoothDetector::BluetoothStatus BluetoothDetector::GetBluetoothStatus(
    }
 
    auto& log = WMLog::GetInstance();
+   // BTH_DEVICE_INFO.name is UTF-8; convert it once so the comparison and
+   // the log output are correct for non-ASCII device names.
+   const std::wstring deviceName =
+      ConvertStringToWideString(inRangeInfo->deviceInfo.name);
    if (useDeviceList_) {
-      auto pos = std::find(begin(deviceNames_), end(deviceNames_), inRangeInfo->deviceInfo.name);
+      auto pos = std::find(begin(deviceNames_), end(deviceNames_), deviceName);
       if (pos == end(deviceNames_)) {
-         log.LogInfo(L"Bluetooth device \"%S\" not in list.", inRangeInfo->deviceInfo.name);
+         log.LogInfo(L"Bluetooth device \"%s\" not in list.", deviceName.c_str());
          return BluetoothStatus::Unknown;
       }
    }
    if ((inRangeInfo->deviceInfo.flags & BDIF_CONNECTED) && !(inRangeInfo->previousDeviceFlags & BDIF_CONNECTED)) {
-      log.LogInfo(L"Bluetooth Audio device \"%S\" connected.", inRangeInfo->deviceInfo.name);
+      log.LogInfo(L"Bluetooth Audio device \"%s\" connected.", deviceName.c_str());
       return BluetoothStatus::Connected;
    } else if (!(inRangeInfo->deviceInfo.flags & BDIF_CONNECTED) && (inRangeInfo->previousDeviceFlags & BDIF_CONNECTED)) {
-      log.LogInfo(L"Bluetooth Audio device \"%S\" disconnected.", inRangeInfo->deviceInfo.name);
+      log.LogInfo(L"Bluetooth Audio device \"%s\" disconnected.", deviceName.c_str());
       return BluetoothStatus::Disconnected;
    }
    return BluetoothStatus::Unknown;
index e28a505886e1b6bf11b2ba1e79f6600d7f11c796..5c6559a4d0f170a783c0267b67eecd16e61082ed 100644 (file)
@@ -232,7 +232,7 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
       Button_Enable(GetDlgItem(hDlg, IDC_BLUETOOTH_REMOVE), FALSE);
 
       HWND hList = GetDlgItem(hDlg, IDC_BLUETOOTH_LIST);
-      const auto devices = settings->GetBluetoothDevicesW();
+      const auto devices = settings->GetBluetoothDevices();
       for (const auto& dev : devices) {
          ListBox_AddString(hList, dev.c_str());
       }
index 30daaaa91a2bf0eca8d22981e0f8a15fecf7d945..27e2223ee7423420ec3dfc683ad9dc69c629c0a0 100644 (file)
@@ -646,33 +646,7 @@ bool WMSettings::StoreBluetoothDevices(std::vector<std::wstring>& devices)
     return true;
 }
 
-std::vector<std::string> WMSettings::GetBluetoothDevicesA() const
-{
-    std::vector<std::string> devices;
-    for (int valIdx = 0;; ++valIdx) {
-        char valueName[260] = {0};
-        char dataBuf[260] = {0};
-        DWORD valueSize = ARRAY_SIZE(valueName);
-        DWORD valType = 0;
-        DWORD dataLen = sizeof(dataBuf) - sizeof(char);
-
-        DWORD regError = RegEnumValueA(
-            hBluetoothKey_, valIdx, valueName, &valueSize, nullptr, &valType,
-            reinterpret_cast<BYTE*>(dataBuf), &dataLen);
-        if (regError == ERROR_NO_MORE_ITEMS) {
-            break;
-        } else if (regError != ERROR_SUCCESS) {
-            ShowWindowsError(L"RegEnumValue", regError);
-            return {};
-        } else {
-            devices.push_back(dataBuf);
-        }
-    }
-    NormalizeStringList(devices);
-    return devices;
-}
-
-std::vector<std::wstring> WMSettings::GetBluetoothDevicesW() const
+std::vector<std::wstring> WMSettings::GetBluetoothDevices() const
 {
     std::vector<std::wstring> devices;
     for (int valIdx = 0;; ++valIdx) {
index be680de98dc76f73bebd3bc238c2d3eb2912f7a5..82ccd85aa4aa08dc16a860e71d7871159930397d 100644 (file)
@@ -89,8 +89,7 @@ public:
    std::vector<std::wstring> GetWifiNetworks() const;
 
    bool StoreBluetoothDevices(std::vector<std::wstring>& networks);
-   std::vector<std::wstring> GetBluetoothDevicesW() const;
-   std::vector<std::string> GetBluetoothDevicesA() const;
+   std::vector<std::wstring> GetBluetoothDevices() const;
 
    bool StoreManagedAudioEndpoints(std::vector<std::wstring> &endpoints);
    std::vector<std::wstring> GetManagedAudioEndpoints() const;