Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make filemanager aware of UWP Win32 API #2831

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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