From f0baddbe63ba1a0de27e00fc3556eaa1fdc20030 Mon Sep 17 00:00:00 2001 From: chrodger <45440867+chrodger@users.noreply.github.com> Date: Fri, 29 May 2020 14:10:37 -0700 Subject: filemanager.cpp: use non-deprecated SHGetKnownFolderPath() function to get the user writable directory on Windows (#2246) Fixes #2245 --- src/filemanager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/filemanager.cpp b/src/filemanager.cpp index a5bb779c..33ce4492 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -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) { -- cgit v1.2.3