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

home: Consider replacing the deprecated SHGetFolderPathW with SHGetKnownFolderPath #13138

Closed
ChrisDenton opened this issue Dec 8, 2023 · 0 comments · Fixed by #13173
Closed
Labels
A-home Area: the `home` crate O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@ChrisDenton
Copy link
Member

Currently home uses SHGetFolderPathW to get the home directory on Windows:

let mut path: Vec<u16> = Vec::with_capacity(MAX_PATH as usize);
match SHGetFolderPathW(0, CSIDL_PROFILE as i32, 0, 0, path.as_mut_ptr()) {
S_OK => {
let len = wcslen(path.as_ptr());
path.set_len(len);
let s = OsString::from_wide(&path);
Some(PathBuf::from(s))
}

SHGetFolderPathW is marked as deprecated and is simply a wrapper around SHGetKnownFolderPath. It might be better to use the not-deprecated function.

This would allow home to support user directories longer than MAX_PATH if, in the future, the OS does. I do however think that's very unlikely so this change isn't that important.

@weihanglo weihanglo added O-windows OS: Windows A-home Area: the `home` crate S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review labels Dec 8, 2023
@bors bors closed this as completed in e9a1b4b Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-home Area: the `home` crate O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants