|
18 | 18 |
|
19 | 19 | #if TARGET_OS_WIN32 |
20 | 20 | #include <userenv.h> |
| 21 | +#include <shlobj_core.h> |
21 | 22 | #endif |
22 | 23 |
|
23 | 24 | CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user, CFStringRef _Nullable username) { |
@@ -48,7 +49,7 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs |
48 | 49 |
|
49 | 50 | break; |
50 | 51 | } |
51 | | - |
| 52 | + |
52 | 53 | } |
53 | 54 | #elif !DEPLOYMENT_RUNTIME_OBJC && !TARGET_OS_WIN32 && !TARGET_OS_ANDROID |
54 | 55 |
|
@@ -96,30 +97,16 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs |
96 | 97 | } |
97 | 98 | case _kCFKnownLocationUserCurrent: |
98 | 99 | username = CFGetUserName(); |
99 | | - // fallthrough |
| 100 | + break; |
100 | 101 | case _kCFKnownLocationUserByName: { |
101 | | - DWORD size = 0; |
102 | | - GetProfilesDirectoryW(NULL, &size); |
103 | | - |
104 | | - wchar_t* path = (wchar_t*)malloc(size * sizeof(wchar_t)); |
105 | | - GetProfilesDirectoryW(path, &size); |
106 | | - |
107 | | - CFStringRef pathRef = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, path, size - 1); |
108 | | - free(path); |
109 | | - |
110 | | - CFURLRef profilesDir = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, pathRef, kCFURLWindowsPathStyle, true); |
111 | | - CFRelease(pathRef); |
112 | | - |
113 | | - CFURLRef usernameDir = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, profilesDir, username, true); |
114 | | - CFURLRef appdataDir = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, usernameDir, CFSTR("AppData"), true); |
115 | | - location = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, appdataDir, CFSTR("Local"), true); |
116 | | - CFRelease(usernameDir); |
117 | | - CFRelease(appdataDir); |
| 102 | + wchar_t* path = NULL; |
| 103 | + SHGetKnownFolderPath(&FOLDERID_LocalAppData, 0, NULL, &path); |
| 104 | + |
| 105 | + CFStringRef userPath = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, path, wcslen(path)); |
| 106 | + CoTaskMemFree(path); |
118 | 107 |
|
119 | | - CFRelease(profilesDir); |
120 | | - if (user == _kCFKnownLocationUserCurrent) { |
121 | | - CFRelease(username); |
122 | | - } |
| 108 | + location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, userPath, kCFURLWindowsPathStyle, true); |
| 109 | + CFRelease(userPath); |
123 | 110 | break; |
124 | 111 | } |
125 | 112 | } |
|
0 commit comments