Skip to content

home: Consider replacing the deprecated SHGetFolderPathW with SHGetKnownFolderPath #13138

Closed
@ChrisDenton

Description

@ChrisDenton

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-homeArea: the `home` crateO-windowsOS: WindowsS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions