apple / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.23k stars 1.12k forks source link

Use SHGetKnownFolderPath to get path to localappdata for current user #4998

Open stevenbrix opened 6 days ago

stevenbrix commented 6 days ago

On Windows, it's not guaranteed that USERPROFILE is equivalent to %SYSTEMDRIVE%\Users\%USERNAME%. So it's possible that UserDefaults tries to write to a non-existent location, in which case it will never work. When this happens, all writes silently no-op.

This PR uses the Shell API SHGetKnownFolderPath to get the location of %LOCALAPPDATA% instead of manually building the path.

See documentation for this API: image

Fixes #4997