Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Ensure returned value type is checked #84

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

julianxhokaxhiu
Copy link
Contributor

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.

This prevents some PC configurations that do not have the expected return to crash while querying entries.
Additionally, tweak the battery energy params to return 0 for the capacity instead of -nan.
Finally fix the disk size detection in bytes as it was completely wrong.
@lfreist lfreist merged commit 3d234f4 into lfreist:main Apr 17, 2024
4 of 5 checks passed
@julianxhokaxhiu julianxhokaxhiu deleted the fix/windows-query branch April 17, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants