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

Rewrote disk_info to use Windows API calls instead of WMIC. Renamed o… #94

Merged
merged 6 commits into from
Jul 19, 2021
Merged

Rewrote disk_info to use Windows API calls instead of WMIC. Renamed o… #94

merged 6 commits into from
Jul 19, 2021

Conversation

AwesomeCronk
Copy link
Contributor

…ld disk_info to disk_info_CIM.

Fixes #93

@rashil2000
Copy link
Member

I'm only getting C: drive's information when ShowDisks is set to *.

It showed all three (C:, D:, E:) before.

@AwesomeCronk
Copy link
Contributor Author

Interesting… Not sure what caused that because I was able to get an array of all the disks in my system, even my USB hub’s attachment points. I must have forgotten to actually show all disks and figures only C: chowed up because it was the only one with media in it.

@rashil2000
Copy link
Member

Hmm. All 3 of my drives have significant usage so this is probably something that we'll have to fix before this is merged.

@AwesomeCronk
Copy link
Contributor Author

Yes, it most definitely is. I am in the middle of some sleuthing around and I have found that my method of checking if the array $showDisks contains each $diskLetter was not working. I redid that and got that part to work, but now I have come across the issue that from some reason, the values that [WinAPI.DiskMethods]::GetDiskFreeSpaceEx writes to are overridden to 0 on each consecutive pass. C: is my only drive that isn't virtual or an empty hub/cd drive, so I am going to do some testing with media in them.

@AwesomeCronk
Copy link
Contributor Author

AwesomeCronk commented Jul 15, 2021

Decided to check the success flag returned by the API call. Gotta love this...
image
In this case E: actually had media in it, so I have no clue why it won't work.

@AwesomeCronk
Copy link
Contributor Author

Running the same loop that checks the disk usage in winfetch at the terminal works, though it fails inside winfetch. No idea why.

@AwesomeCronk
Copy link
Contributor Author

Much better!
image
I found it to be related to the PowerShell/C# interop layer. For whatever reason, the System.String[] that splitting the C# string[] returned for GetLogicalDriveStringsW was designed to be close enough to System.Object[] that I could do all that without errors, but refused to pass correctly to GetDiskFreeSpaceEx. That should all be fixed now.

@rashil2000
Copy link
Member

Great! It's working slick now.

If you have a Win 7 machine or VM lying around, please test it there. If there are no problems, we can get rid of the info_disk_CIM function.

@AwesomeCronk
Copy link
Contributor Author

I lack a win7 machine. I’ll ask around and see if I know someone who does and if I can find someone I’ll see if they are ok with testing it.

@rashil2000
Copy link
Member

Just tested it in a VM, works fine.

Please remove the old function.

@AwesomeCronk
Copy link
Contributor Author

Will do 👍

winfetch.ps1 Outdated Show resolved Hide resolved
@rashil2000
Copy link
Member

Great, thanks for the awesome contribution!

@rashil2000 rashil2000 requested a review from jcwillox July 17, 2021 05:56
Copy link
Member

@jcwillox jcwillox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, seems to work perfectly and is even faster than before 👍

@jcwillox jcwillox merged commit 1d2977a into lptstr:master Jul 19, 2021
@AwesomeCronk
Copy link
Contributor Author

Thank you! Happy to have been able to help!

@rashil2000 rashil2000 mentioned this pull request Nov 2, 2022
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.

Winfetch 2.1.0 taking ages to get disk info
3 participants