-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use SHGetKnownFolderPath to get path to localappdata for current user #4998
base: main
Are you sure you want to change the base?
Conversation
@stevenbrix You might want to remove the format changes introduced on your computer. P.S.: This PR is really important and I don't know why it gets abandoned here for months. |
@stevenbrix This PR is fallen behind the main branch too far. swift-corelibs-foundation/Sources/CoreFoundation/CFKnownLocations.c Lines 97 to 123 in 0129358
|
} | ||
wchar_t* path = NULL; | ||
SHGetKnownFolderPath(&FOLDERID_LocalAppData, 0, NULL, &path); | ||
location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, path, kCFURLWindowsPathStyle, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems incorrect. The path
parameter is a wide C String not a CFStrimg. This should do the creation of the CFString and pass that.
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:
Fixes #4997