This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 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>
2024
2125namespace fml {
2226
27+ #ifdef WINUWP
28+ static std::map<HANDLE, std::wstring> file_map;
29+ #endif
30+
2331static 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
3557static 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
You can’t perform that action at this time.
0 commit comments