Windows: look for config files in $LOCALAPPDATA

This commit is contained in:
李通洲
2023-01-02 11:49:41 +08:00
parent 8533dc234b
commit 822496808d
6 changed files with 39 additions and 2 deletions
+6 -1
View File
@@ -11,7 +11,12 @@ struct passwd* ffGetPasswd()
DWORD len = sizeof(res.pw_name);
GetUserNameA(res.pw_name, &len);
SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, res.pw_dir);
PWSTR pPath;
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DEFAULT, NULL, &pPath)))
WideCharToMultiByte(CP_UTF8, 0, pPath, -1, res.pw_dir, sizeof(res.pw_dir), NULL, NULL); //res has been NULL inited
CoTaskMemFree(pPath);
for (char *current_pos = strchr(res.pw_dir, '\\'); current_pos; current_pos = strchr(current_pos + 1, '\\'))
*current_pos = '/';
return &res;
}