Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a17e18a

Browse files
committed
Fix fml::GetFullHandlePath for WINUWP target
1 parent 05347d4 commit a17e18a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

fml/platform/win/file_win.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <Fileapi.h>
88
#include <Shlwapi.h>
99
#include <fcntl.h>
10+
#include <limits.h>
11+
#include <sys/stat.h>
12+
#include <map>
13+
#include <string>
1014

1115
#include <algorithm>
1216
#include <climits>
@@ -20,7 +24,24 @@
2024

2125
namespace fml {
2226

27+
#ifdef WINUWP
28+
static std::map<HANDLE, std::wstring> file_map;
29+
#endif
30+
2331
static std::string GetFullHandlePath(const fml::UniqueFD& handle) {
32+
// Although the documentation claims that GetFinalPathNameByHandle is
33+
// supported for UWP apps, turns out it does not work correctly hence the need
34+
// to workaround it by maintaining a map of file handles to absolute paths
35+
// populated by fml::OpenDirectory.
36+
#ifdef WINUWP
37+
if (file_map.count(handle.get()) > 0) {
38+
auto found = file_map[handle.get()];
39+
return WideStringToString(found);
40+
} else {
41+
return std::string();
42+
}
43+
44+
#else
2445
wchar_t buffer[MAX_PATH] = {0};
2546
const DWORD buffer_size = ::GetFinalPathNameByHandle(
2647
handle.get(), buffer, MAX_PATH, FILE_NAME_NORMALIZED);
@@ -30,6 +51,7 @@ static std::string GetFullHandlePath(const fml::UniqueFD& handle) {
3051
return {};
3152
}
3253
return WideStringToString({buffer, buffer_size});
54+
#endif
3355
}
3456

3557
static std::string GetAbsolutePath(const fml::UniqueFD& base_directory,
@@ -223,6 +245,8 @@ fml::UniqueFD OpenDirectory(const char* path,
223245
return {};
224246
}
225247

248+
file_map[handle] = file_name;
249+
226250
return fml::UniqueFD{handle};
227251
}
228252

0 commit comments

Comments
 (0)