-
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.
@compnerd I emailed stevenbrix on Feb 18 trying to bring his attention towards your previous response here, but he has no response. I am less familiar with the moral culture context in FOSS projects like this one. Is it appropriate for me (or anyone else) to replicate this PR and patch this? (with credits of stevenbrix in the commit message wherever necessary.) |
Yes, maintaining the authorship/credit is key. It would be very much acceptable for someone to pick up the patch and help push it along if the original author is unable to do so. |
Solid copy. Thanks for your response. While I may see whether I can have some time to handle this issue within the next week, anyone can go ahead doing this without having to wait for me. This issue directly affects the usability of Swift (especially UserDefaults) on Windows. |
Hi @ShikiSuen sorry for not responding. I'm not sure these changes are needed anymore now that the code has moved. I'll need to do more investigation here. |
Thanks for your response. Good to see you get back online. |
8566cb1
to
0a1a7c8
Compare
0a1a7c8
to
733f2b0
Compare
@swift-ci test |
@compnerd Sorry for bothering you. |
@@ -96,30 +97,16 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs | |||
} | |||
case _kCFKnownLocationUserCurrent: | |||
username = CFGetUserName(); | |||
// fallthrough | |||
break; |
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 wrong. It is backwards no? LocalAppData
would be for the current user, not a specified user. This seems like it would not return a location for the current user, and return the location for the current user when you specify a user name.
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