Chore: run clang-format

```bash
find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i
```
This commit is contained in:
李通洲
2026-03-29 09:28:49 +08:00
parent cdd4cee968
commit e0eba8ce21
690 changed files with 28093 additions and 30062 deletions
+1 -2
View File
@@ -3,8 +3,7 @@
#include "fastfetch.h"
#include "modules/bluetooth/option.h"
typedef struct FFBluetoothResult
{
typedef struct FFBluetoothResult {
FFstrbuf name;
FFstrbuf address;
FFstrbuf type;
+7 -8
View File
@@ -3,15 +3,14 @@
#define L2CAP_SOCKET_CHECKED
#include <bluetooth.h>
static int enumDev(FF_MAYBE_UNUSED int sockfd, struct bt_devinfo const* dev, FFlist* devices)
{
static int enumDev(FF_MAYBE_UNUSED int sockfd, struct bt_devinfo const* dev, FFlist* devices) {
FFBluetoothResult* device = ffListAdd(devices);
ffStrbufInitS(&device->name,
#if __FreeBSD__
#if __FreeBSD__
bt_devremote_name_gen(dev->devname, &dev->bdaddr)
#else
#else
dev->devname
#endif
#endif
);
ffStrbufInitS(&device->address, bt_ntoa(&dev->bdaddr, NULL));
ffStrbufUpperCase(&device->address);
@@ -21,11 +20,11 @@ static int enumDev(FF_MAYBE_UNUSED int sockfd, struct bt_devinfo const* dev, FFl
return 0;
}
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
{
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */) {
// struct hostent* ent = bt_gethostent();
if (bt_devenum((void*) enumDev, devices) < 0)
if (bt_devenum((void*) enumDev, devices) < 0) {
return "bt_devenum() failed";
}
return NULL;
}
+4 -3
View File
@@ -5,13 +5,14 @@ extern "C" {
#include <bluetooth/LocalDevice.h>
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FFlist* devices /* FFBluetoothResult */)
{
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FFlist* devices /* FFBluetoothResult */) {
using namespace Bluetooth;
FF_SUPPRESS_IO();
LocalDevice* dev = LocalDevice::GetLocalDevice();
if (!dev) return NULL;
if (!dev) {
return NULL;
}
BString devClass;
dev->GetDeviceClass().DumpDeviceClass(devClass);
+71 -70
View File
@@ -2,8 +2,8 @@
#include "common/stringUtils.h"
#ifdef FF_HAVE_DBUS
#include "common/dbus.h"
#include "common/io.h"
# include "common/dbus.h"
# include "common/io.h"
/* Example dbus reply, striped to only the relevant parts:
array [ //root
@@ -45,103 +45,108 @@ array [ //root
]
*/
static bool detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothResult* device)
{
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
static bool detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothResult* device) {
if (dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) {
return true;
}
DBusMessageIter dictIter;
dbus->lib->ffdbus_message_iter_recurse(iter, &dictIter);
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING)
if (dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING) {
return true;
}
const char* deviceProperty;
dbus->lib->ffdbus_message_iter_get_basic(&dictIter, &deviceProperty);
dbus->lib->ffdbus_message_iter_next(&dictIter);
if(ffStrEquals(deviceProperty, "Address"))
if (ffStrEquals(deviceProperty, "Address")) {
ffDBusGetString(dbus, &dictIter, &device->address);
else if(ffStrEquals(deviceProperty, "Name"))
} else if (ffStrEquals(deviceProperty, "Name")) {
ffDBusGetString(dbus, &dictIter, &device->name);
else if(ffStrEquals(deviceProperty, "Icon"))
} else if (ffStrEquals(deviceProperty, "Icon")) {
ffDBusGetString(dbus, &dictIter, &device->type);
else if(ffStrEquals(deviceProperty, "Percentage"))
{
} else if (ffStrEquals(deviceProperty, "Percentage")) {
uint32_t percentage;
if (ffDBusGetUint(dbus, &dictIter, &percentage))
if (ffDBusGetUint(dbus, &dictIter, &percentage)) {
device->battery = (uint8_t) percentage;
}
else if(ffStrEquals(deviceProperty, "Connected"))
}
} else if (ffStrEquals(deviceProperty, "Connected")) {
ffDBusGetBool(dbus, &dictIter, &device->connected);
else if(ffStrEquals(deviceProperty, "Paired"))
{
} else if (ffStrEquals(deviceProperty, "Paired")) {
bool paired = true;
ffDBusGetBool(dbus, &dictIter, &paired);
if (!paired) return false;
if (!paired) {
return false;
}
}
return true;
}
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothResult* device)
{
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothResult* device) {
if (dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) {
return;
}
DBusMessageIter dictIter;
dbus->lib->ffdbus_message_iter_recurse(iter, &dictIter);
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING)
if (dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING) {
return;
}
const char* propertyType;
dbus->lib->ffdbus_message_iter_get_basic(&dictIter, &propertyType);
if(!ffStrContains(propertyType, ".Device") && !ffStrContains(propertyType, ".Battery"))
if (!ffStrContains(propertyType, ".Device") && !ffStrContains(propertyType, ".Battery")) {
return; // We don't care about other properties
}
dbus->lib->ffdbus_message_iter_next(&dictIter);
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_ARRAY)
if (dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_ARRAY) {
return;
}
DBusMessageIter arrayIter;
dbus->lib->ffdbus_message_iter_recurse(&dictIter, &arrayIter);
do
{
do {
bool shouldContinue = detectBluetoothValue(dbus, &arrayIter, device);
if (!shouldContinue)
{
if (!shouldContinue) {
ffStrbufClear(&device->name);
break;
}
} while (dbus->lib->ffdbus_message_iter_next(&arrayIter));
}
static FFBluetoothResult* detectBluetoothObject(FFlist* devices, FFDBusData* dbus, DBusMessageIter* iter)
{
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
static FFBluetoothResult* detectBluetoothObject(FFlist* devices, FFDBusData* dbus, DBusMessageIter* iter) {
if (dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) {
return NULL;
}
DBusMessageIter dictIter;
dbus->lib->ffdbus_message_iter_recurse(iter, &dictIter);
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_OBJECT_PATH)
if (dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_OBJECT_PATH) {
return NULL;
}
const char* objectPath;
dbus->lib->ffdbus_message_iter_get_basic(&dictIter, &objectPath);
// We don't want adapter objects
if(!ffStrContains(objectPath, "/dev_"))
if (!ffStrContains(objectPath, "/dev_")) {
return NULL;
}
dbus->lib->ffdbus_message_iter_next(&dictIter);
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_ARRAY)
if (dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_ARRAY) {
return NULL;
}
DBusMessageIter arrayIter;
dbus->lib->ffdbus_message_iter_recurse(&dictIter, &arrayIter);
@@ -153,56 +158,53 @@ static FFBluetoothResult* detectBluetoothObject(FFlist* devices, FFDBusData* dbu
device->battery = 0;
device->connected = false;
do
{
do {
detectBluetoothProperty(dbus, &arrayIter, device);
} while (dbus->lib->ffdbus_message_iter_next(&arrayIter));
return device;
}
static void detectBluetoothRoot(FFlist* devices, FFDBusData* dbus, DBusMessageIter* iter, int32_t connectedCount)
{
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
static void detectBluetoothRoot(FFlist* devices, FFDBusData* dbus, DBusMessageIter* iter, int32_t connectedCount) {
if (dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) {
return;
}
DBusMessageIter arrayIter;
dbus->lib->ffdbus_message_iter_recurse(iter, &arrayIter);
do
{
do {
FFBluetoothResult* device = detectBluetoothObject(devices, dbus, &arrayIter);
if (device)
{
if(device->name.length == 0 || (connectedCount > 0 && !device->connected))
{
if (device) {
if (device->name.length == 0 || (connectedCount > 0 && !device->connected)) {
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->address);
ffStrbufDestroy(&device->type);
--devices->length;
}
if (device->connected && --connectedCount == 0)
if (device->connected && --connectedCount == 0) {
break;
}
}
} while (dbus->lib->ffdbus_message_iter_next(&arrayIter));
}
static const char* detectBluetooth(FFlist* devices, int32_t connectedCount)
{
static const char* detectBluetooth(FFlist* devices, int32_t connectedCount) {
FF_DBUS_AUTO_DESTROY_DATA FFDBusData dbus = {};
const char* error = ffDBusLoadData(DBUS_BUS_SYSTEM, &dbus);
if(error)
if (error) {
return error;
}
DBusMessage* managedObjects = ffDBusGetMethodReply(&dbus, "org.bluez", "/", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", NULL, NULL);
if(!managedObjects)
if (!managedObjects) {
return "Failed to call GetManagedObjects";
}
DBusMessageIter rootIter;
if(!dbus.lib->ffdbus_message_iter_init(managedObjects, &rootIter))
{
if (!dbus.lib->ffdbus_message_iter_init(managedObjects, &rootIter)) {
dbus.lib->ffdbus_message_unref(managedObjects);
return "Failed to get root iterator of GetManagedObjects";
}
@@ -213,18 +215,18 @@ static const char* detectBluetooth(FFlist* devices, int32_t connectedCount)
return NULL;
}
static uint32_t connectedDevices(void)
{
static uint32_t connectedDevices(void) {
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/bluetooth");
if(dirp == NULL)
if (dirp == NULL) {
return 0;
}
uint32_t result = 0;
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL)
{
if (strchr(entry->d_name, ':') != NULL)
while ((entry = readdir(dirp)) != NULL) {
if (strchr(entry->d_name, ':') != NULL) {
++result;
}
}
return result;
@@ -232,19 +234,18 @@ static uint32_t connectedDevices(void)
#endif
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
{
#ifdef FF_HAVE_DBUS
int32_t connectedCount = -1;
if (!options->showDisconnected)
{
connectedCount = (int32_t) connectedDevices();
if (connectedCount == 0)
return NULL;
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */) {
#ifdef FF_HAVE_DBUS
int32_t connectedCount = -1;
if (!options->showDisconnected) {
connectedCount = (int32_t) connectedDevices();
if (connectedCount == 0) {
return NULL;
}
}
return detectBluetooth(devices, connectedCount);
#else
return "Fastfetch was compiled without DBus support";
#endif
return detectBluetooth(devices, connectedCount);
#else
return "Fastfetch was compiled without DBus support";
#endif
}
@@ -1,6 +1,5 @@
#include "bluetooth.h"
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
{
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */) {
return "Not supported on this platform";
}
+38 -39
View File
@@ -7,73 +7,74 @@
#pragma GCC diagnostic ignored "-Wpointer-sign"
const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FFBluetoothResult */)
{
const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FFBluetoothResult */) {
FF_LIBRARY_LOAD_MESSAGE(bluetoothapis, "bluetoothapis.dll", 1)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindFirstDevice)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindNextDevice)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(bluetoothapis, BluetoothFindDeviceClose)
BLUETOOTH_DEVICE_INFO btdi = {
.dwSize = sizeof(btdi)
};
.dwSize = sizeof(btdi)};
HBLUETOOTH_DEVICE_FIND hFind = ffBluetoothFindFirstDevice(&(BLUETOOTH_DEVICE_SEARCH_PARAMS) {
.fReturnConnected = TRUE,
.fReturnRemembered = options->showDisconnected,
.fReturnAuthenticated = options->showDisconnected,
.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS)
}, &btdi);
if(!hFind)
{
if (GetLastError() == ERROR_NO_MORE_ITEMS)
.fReturnConnected = TRUE,
.fReturnRemembered = options->showDisconnected,
.fReturnAuthenticated = options->showDisconnected,
.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS)},
&btdi);
if (!hFind) {
if (GetLastError() == ERROR_NO_MORE_ITEMS) {
return NULL;
}
return "BluetoothFindFirstDevice() failed";
}
do {
FFBluetoothResult* device = ffListAdd(devices);
ffStrbufInitWS(&device->name, btdi.szName);
ffStrbufInitF(&device->address, "%02X:%02X:%02X:%02X:%02X:%02X",
btdi.Address.rgBytes[5],
btdi.Address.rgBytes[4],
btdi.Address.rgBytes[3],
btdi.Address.rgBytes[2],
btdi.Address.rgBytes[1],
btdi.Address.rgBytes[0]);
ffStrbufInitF(&device->address, "%02X:%02X:%02X:%02X:%02X:%02X", btdi.Address.rgBytes[5], btdi.Address.rgBytes[4], btdi.Address.rgBytes[3], btdi.Address.rgBytes[2], btdi.Address.rgBytes[1], btdi.Address.rgBytes[0]);
ffStrbufInit(&device->type);
device->battery = 0;
device->connected = !!btdi.fConnected;
//https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned%20Numbers.pdf
// https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned%20Numbers.pdf
if(BitTest(&btdi.ulClassofDevice, 13))
if (BitTest(&btdi.ulClassofDevice, 13)) {
ffStrbufAppendS(&device->type, "Limited Discoverable Mode, ");
if(BitTest(&btdi.ulClassofDevice, 14))
}
if (BitTest(&btdi.ulClassofDevice, 14)) {
ffStrbufAppendS(&device->type, "LE audio, ");
if(BitTest(&btdi.ulClassofDevice, 15))
}
if (BitTest(&btdi.ulClassofDevice, 15)) {
ffStrbufAppendS(&device->type, "Reserved for future use, ");
if(BitTest(&btdi.ulClassofDevice, 16))
}
if (BitTest(&btdi.ulClassofDevice, 16)) {
ffStrbufAppendS(&device->type, "Positioning, ");
if(BitTest(&btdi.ulClassofDevice, 17))
}
if (BitTest(&btdi.ulClassofDevice, 17)) {
ffStrbufAppendS(&device->type, "Networking, ");
if(BitTest(&btdi.ulClassofDevice, 18))
}
if (BitTest(&btdi.ulClassofDevice, 18)) {
ffStrbufAppendS(&device->type, "Rendering, ");
if(BitTest(&btdi.ulClassofDevice, 19))
}
if (BitTest(&btdi.ulClassofDevice, 19)) {
ffStrbufAppendS(&device->type, "Capturing, ");
if(BitTest(&btdi.ulClassofDevice, 20))
}
if (BitTest(&btdi.ulClassofDevice, 20)) {
ffStrbufAppendS(&device->type, "Object Transfer, ");
if(BitTest(&btdi.ulClassofDevice, 21))
}
if (BitTest(&btdi.ulClassofDevice, 21)) {
ffStrbufAppendS(&device->type, "Audio, ");
if(BitTest(&btdi.ulClassofDevice, 22))
}
if (BitTest(&btdi.ulClassofDevice, 22)) {
ffStrbufAppendS(&device->type, "Telephony, ");
if(BitTest(&btdi.ulClassofDevice, 23))
}
if (BitTest(&btdi.ulClassofDevice, 23)) {
ffStrbufAppendS(&device->type, "Information, ");
}
if(device->type.length == 0)
{
if (device->type.length == 0) {
uint32_t majorDeviceClasses = (btdi.ulClassofDevice >> 8) & ~(UINT32_MAX << 5);
switch(majorDeviceClasses)
{
switch (majorDeviceClasses) {
case 0b00000:
ffStrbufAppendS(&device->type, "Miscellaneous");
break;
@@ -111,9 +112,7 @@ const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FF
ffStrbufAppendS(&device->type, "Unknown");
break;
}
}
else
{
} else {
ffStrbufTrimRight(&device->type, ' ');
ffStrbufTrimRight(&device->type, ',');
}
@@ -121,7 +120,7 @@ const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FF
ffBluetoothFindDeviceClose(hFind);
const char* ffBluetoothDetectBattery(FFlist* result);
const char* ffBluetoothDetectBattery(FFlist * result);
ffBluetoothDetectBattery(devices);
return NULL;
+33 -30
View File
@@ -1,84 +1,88 @@
extern "C"
{
extern "C" {
#include "bluetooth.h"
}
#include "common/windows/wmi.hpp"
#include "common/windows/unicode.hpp"
#include "common/windows/util.hpp"
extern "C"
const char* ffBluetoothDetectBattery(FFlist* devices)
{
extern "C" const char* ffBluetoothDetectBattery(FFlist* devices) {
FFWmiQuery query(L"SELECT __PATH FROM Win32_PnPEntity WHERE Service = 'BthHFEnum'", nullptr, FFWmiNamespace::CIMV2);
if(!query)
if (!query) {
return "Query WMI service failed";
}
IWbemClassObject* pInParams = nullptr;
on_scope_exit releaseInParams([&] { pInParams && pInParams->Release(); });
{
IWbemClassObject* pnpEntityClass = nullptr;
if (FAILED(query.pService->GetObjectW(bstr_t(L"Win32_PnPEntity"), 0, nullptr, &pnpEntityClass, nullptr)))
if (FAILED(query.pService->GetObjectW(bstr_t(L"Win32_PnPEntity"), 0, nullptr, &pnpEntityClass, nullptr))) {
return "Failed to get PnP entity class";
}
on_scope_exit releasePnpEntityClass([&] { pnpEntityClass && pnpEntityClass->Release(); });
if (FAILED(pnpEntityClass->GetMethod(bstr_t(L"GetDeviceProperties"), 0, &pInParams, NULL)))
if (FAILED(pnpEntityClass->GetMethod(bstr_t(L"GetDeviceProperties"), 0, &pInParams, NULL))) {
return "Failed to get GetDeviceProperties method";
}
FFWmiVariant devicePropertyKeys({ L"{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2", L"DEVPKEY_Bluetooth_DeviceAddress" });
if (FAILED(pInParams->Put(L"devicePropertyKeys", 0, &devicePropertyKeys, CIM_FLAG_ARRAY | CIM_STRING)))
FFWmiVariant devicePropertyKeys({L"{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2", L"DEVPKEY_Bluetooth_DeviceAddress"});
if (FAILED(pInParams->Put(L"devicePropertyKeys", 0, &devicePropertyKeys, CIM_FLAG_ARRAY | CIM_STRING))) {
return "Failed to put devicePropertyKeys";
}
}
while (FFWmiRecord record = query.next())
{
while (FFWmiRecord record = query.next()) {
IWbemCallResult* pCallResult = nullptr;
if (FAILED(query.pService->ExecMethod(record.get(L"__PATH").bstrVal, bstr_t(L"GetDeviceProperties"), 0, nullptr, pInParams, nullptr, &pCallResult)))
if (FAILED(query.pService->ExecMethod(record.get(L"__PATH").bstrVal, bstr_t(L"GetDeviceProperties"), 0, nullptr, pInParams, nullptr, &pCallResult))) {
continue;
}
on_scope_exit releaseCallResult([&] { pCallResult && pCallResult->Release(); });
IWbemClassObject* pResultObject = nullptr;
if (FAILED(pCallResult->GetResultObject((LONG) WBEM_INFINITE, &pResultObject)))
if (FAILED(pCallResult->GetResultObject((LONG) WBEM_INFINITE, &pResultObject))) {
continue;
}
on_scope_exit releaseResultObject([&] { pResultObject && pResultObject->Release(); });
VARIANT propArray;
if (FAILED(pResultObject->Get(L"deviceProperties", 0, &propArray, nullptr, nullptr)))
if (FAILED(pResultObject->Get(L"deviceProperties", 0, &propArray, nullptr, nullptr))) {
continue;
}
on_scope_exit releasePropArray([&] { VariantClear(&propArray); });
if (propArray.vt != (VT_ARRAY | VT_UNKNOWN) ||
(propArray.parray->fFeatures & FADF_UNKNOWN) == 0 ||
propArray.parray->cDims != 1 ||
propArray.parray->rgsabound[0].cElements != 2
)
propArray.parray->rgsabound[0].cElements != 2) {
continue;
}
uint8_t batt = 0;
for (LONG i = 0; i < 2; i++)
{
for (LONG i = 0; i < 2; i++) {
IWbemClassObject* object = nullptr;
if (FAILED(SafeArrayGetElement(propArray.parray, &i, &object)))
if (FAILED(SafeArrayGetElement(propArray.parray, &i, &object))) {
continue;
}
FFWmiRecord rec(object);
auto data = rec.get(L"Data");
if (data.vt == VT_EMPTY)
if (data.vt == VT_EMPTY) {
break;
}
if (i == 0)
if (i == 0) {
batt = data.get<uint8_t>();
else
{
} else {
FF_STRBUF_AUTO_DESTROY addr = ffStrbufCreateWSV(data.get<std::wstring_view>()); // MAC address without colon
if (__builtin_expect(addr.length != 12, 0))
if (__builtin_expect(addr.length != 12, 0)) {
continue;
}
FF_LIST_FOR_EACH(FFBluetoothResult, bt, *devices)
{
if (bt->address.length != 12 + 5)
FF_LIST_FOR_EACH (FFBluetoothResult, bt, *devices) {
if (bt->address.length != 12 + 5) {
continue;
}
if (addr.chars[0] == bt->address.chars[0] &&
addr.chars[1] == bt->address.chars[1] &&
@@ -91,8 +95,7 @@ const char* ffBluetoothDetectBattery(FFlist* devices)
addr.chars[8] == bt->address.chars[12] &&
addr.chars[9] == bt->address.chars[13] &&
addr.chars[10] == bt->address.chars[15] &&
addr.chars[11] == bt->address.chars[16])
{
addr.chars[11] == bt->address.chars[16]) {
bt->battery = batt;
break;
}