lfreist / hwinfo

cross platform C++ library for hardware information (CPU, RAM, GPU, ...)
MIT License
433 stars 74 forks source link

Windows: Ensure returned value type is checked #84

Closed julianxhokaxhiu closed 4 months ago

julianxhokaxhiu commented 4 months ago

I'm opening this PR because I got a report from a user that was not able to get the RAM SerialNumber, and others having various sporadic issue also around RAM across other fields. This made me wonder how the code is shielding and making sure that only when the value is a valid one is being used.

Checking just the result of the hr unfortunately is not enough as the call my succeed but the value of the string but be NULL, so an additional check is required as per documentation.

So by following that I added those checks in all windows entries where we query information via the WMI layer.

While doing so, and running the example project I noticed that the Capacity for the Battery was always returning -nan for Windows, which to my own surprise I found out the values are hardcoded. Not focusing on fixing this part, atm I just made sure the calculation returns 0, instead of -nan.

Finally also while running the test and checking information I found out that the Disk size was reported incorrectly as the Size field is a string, not an integer, for some reason so I'm parsing and converting that to a valid integer. Now the disk size in bytes is reported correctly.