Skip to content

Commit

Permalink
Merge pull request #2831 from gorlak-forks/uwp-filemanager
Browse files Browse the repository at this point in the history
Make filemanager aware of UWP Win32 API
  • Loading branch information
rouault authored Sep 1, 2021
2 parents fc4663a + 5d8abfd commit 1ed57b9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@

#include "proj_config.h"

#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
#define UWP 1
#else
#define UWP 0
#endif

#ifdef _WIN32
#include <shlobj.h>
#include <windows.h>
Expand Down Expand Up @@ -692,10 +698,21 @@ std::unique_ptr<File> FileWin32::open(PJ_CONTEXT *ctx, const char *filename,
? FILE_ATTRIBUTE_READONLY
: FILE_ATTRIBUTE_NORMAL;
try {
#if UWP
CREATEFILE2_EXTENDED_PARAMETERS extendedParameters;
ZeroMemory(&extendedParameters, sizeof(extendedParameters));
extendedParameters.dwSize = sizeof(extendedParameters);
extendedParameters.dwFileAttributes = dwFlagsAndAttributes;
HANDLE hFile = CreateFile2(
UTF8ToWString(std::string(filename)).c_str(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
dwCreationDisposition, &extendedParameters);
#else // UWP
HANDLE hFile = CreateFileW(
UTF8ToWString(std::string(filename)).c_str(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
dwCreationDisposition, dwFlagsAndAttributes, nullptr);
#endif // UWP
return std::unique_ptr<File>(hFile != INVALID_HANDLE_VALUE
? new FileWin32(filename, ctx, hFile)
: nullptr);
Expand Down Expand Up @@ -1136,13 +1153,17 @@ const char *proj_context_get_user_writable_directory(PJ_CONTEXT *ctx,
wPath.resize(wcslen(wPath.data()));
path = NS_PROJ::WStringToUTF8(wPath);
#else
#if UWP
if (false) {
#else // UWP
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 // UWP
#endif
} else {
const char *local_app_data = getenv("LOCALAPPDATA");
Expand Down Expand Up @@ -1236,11 +1257,13 @@ static std::string pj_get_relative_share_proj_internal_no_check() {
#if defined(_WIN32) || defined(HAVE_LIBDL)
#ifdef _WIN32
HMODULE hm = NULL;
#if !UWP
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR)&pj_get_relative_share_proj, &hm) == 0) {
return std::string();
}
#endif // UWP

DWORD path_size = 1024;

Expand Down

0 comments on commit 1ed57b9

Please sign in to comment.