From 44af8b85adeca5c8bd682272f1091098eafb2e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 5 Apr 2026 18:44:42 +0800 Subject: [PATCH] Battery (Windows): tidy --- src/detection/battery/battery_windows.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index 18194fa34..32ac33b77 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -15,8 +15,11 @@ static const char* detectWithCmApi(FFBatteryOptions* options, FFlist* results) { // https://learn.microsoft.com/en-us/windows-hardware/drivers/install/using-device-interfaces ULONG cchDeviceInterfaces = 0; - CONFIGRET cr = CM_Get_Device_Interface_List_SizeW(&cchDeviceInterfaces, (LPGUID) &GUID_DEVCLASS_BATTERY, NULL, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); - if (cr != CR_SUCCESS) { + if (CM_Get_Device_Interface_List_SizeW( + &cchDeviceInterfaces, + (LPGUID) &GUID_DEVCLASS_BATTERY, + NULL, + CM_GET_DEVICE_INTERFACE_LIST_PRESENT) != CR_SUCCESS) { return "CM_Get_Device_Interface_List_SizeW() failed"; } @@ -25,14 +28,18 @@ static const char* detectWithCmApi(FFBatteryOptions* options, FFlist* results) { } wchar_t* FF_AUTO_FREE mszDeviceInterfaces = (wchar_t*) malloc(cchDeviceInterfaces * sizeof(wchar_t)); - cr = CM_Get_Device_Interface_ListW((LPGUID) &GUID_DEVCLASS_BATTERY, NULL, mszDeviceInterfaces, cchDeviceInterfaces, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); - if (cr != CR_SUCCESS) { + if (CM_Get_Device_Interface_ListW( + (LPGUID) &GUID_DEVCLASS_BATTERY, + NULL, + mszDeviceInterfaces, + cchDeviceInterfaces, + CM_GET_DEVICE_INTERFACE_LIST_PRESENT) != CR_SUCCESS) { return "CM_Get_Device_Interface_ListW() failed"; } - for (const wchar_t* pDeviceInterface = mszDeviceInterfaces; *pDeviceInterface; pDeviceInterface += wcslen(pDeviceInterface) + 1) { + for (const wchar_t* p = mszDeviceInterfaces; *p; p += wcslen(p) + 1) { HANDLE FF_AUTO_CLOSE_FD hBattery = - CreateFileW(pDeviceInterface, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + CreateFileW(p, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hBattery == INVALID_HANDLE_VALUE) { continue;