}
void BluetoothDetector::SetDeviceList(
- const std::vector<std::string>& devices,
+ const std::vector<std::wstring>& devices,
bool useDeviceList)
{
deviceNames_ = devices;
}
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;
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());
}
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) {
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;