Skip to content

Commit

Permalink
filemanager.cpp: use non-deprecated SHGetKnownFolderPath() function t…
Browse files Browse the repository at this point in the history
…o get the user writable directory on Windows (#2246)

Fixes #2245
  • Loading branch information
chrodger committed May 29, 2020
1 parent e9a5add commit f0baddb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/filemanager.cpp
Expand Up @@ -1203,12 +1203,21 @@ const char *proj_context_get_user_writable_directory(PJ_CONTEXT *ctx,
if (ctx->user_writable_directory.empty()) {
std::string path;
#ifdef _WIN32
#ifdef __MINGW32__
std::wstring wPath;
wPath.resize(MAX_PATH);
if (SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0,
&wPath[0]) == S_OK) {
wPath.resize(wcslen(wPath.data()));
path = NS_PROJ::WStringToUTF8(wPath);
#else
wchar_t* wPath;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &wPath) == S_OK){
std::wstring ws(wPath);
std::string str = NS_PROJ::WStringToUTF8(ws);
path = str;
CoTaskMemFree(wPath);
#endif
} else {
const char *local_app_data = getenv("LOCALAPPDATA");
if (!local_app_data) {
Expand Down

0 comments on commit f0baddb

Please sign in to comment.