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

Replace winapi dependency with windows #28

Closed
wants to merge 2 commits into from

Conversation

skipkayhil
Copy link

Since normpath was added, opener has depended on both winapi (directly) and windows-sys (transitively).

This commit replaces usage of winapi with the windows crate so that it only depends on a single windows API crate. Additionally, the windows crate includes some functions that were manually linked in opener, so those manual links were able to be cleaned up.


I'm not very experienced with unsafe Rust 😅. Any feedback is appreciated!

Comment on lines 25 to 26
let item_id_list = unsafe { ILCreateFromPathW(PCWSTR::from_raw(path.as_ptr())) };
unsafe { SHOpenFolderAndSelectItems(item_id_list, None, 0) }?;
Copy link
Author

Choose a reason for hiding this comment

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

This is one of those things I'm not sure of: do we still need to call ILFree on item_id_list after SHOpen...?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, and it needs to be called even if SHOpenFolderAndSelectItems() fails. The same goes for CoUninitialize().

Since normpath was [added][1], opener has depended on both winapi (directly)
and windows-sys (transitively).

This commit replaces usage of winapi with the windows crate so that it
only depends on a single windows API crate. Additionally, the windows
crate includes some functions that were manually linked in opener, so
those manual links were able to be cleaned up.

[1]: 3b48ee0
@skipkayhil
Copy link
Author

Friendly bump 🙂 Anything needed from me?

@Seeker14491
Copy link
Owner

I just pushed a commit fixing some style nits. However, I've just realized we're using the windows crate here, while normpath depends on the windows-sys crate, which is actually a totally separate crate (windows does not depend on windows-sys). So we would still be depending on two separate Windows API crates. Two possible solutions:

  • Switch from normpath to dunce, which has no dependencies
  • Don't use windows, and instead use windows-sys like normpath

The first option is simpler, but I believe there's some edge cases where normpath is more compatible with certain paths, so maybe we'd need to go with the second option.

@Seeker14491
Copy link
Owner

I've switched over to windows-sys in #29, so now we only have one Windows API crate in our dependency tree.

@skipkayhil skipkayhil deleted the hm-use-windows branch March 22, 2024 21:47
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.

2 participants