8
8
#include " mpt/base/detect.hpp"
9
9
#include " mpt/base/namespace.hpp"
10
10
#include " mpt/path/native_path.hpp"
11
+ #include " mpt/path/os_path_long.hpp"
11
12
12
13
#if MPT_OS_WINDOWS
13
14
#include < vector>
@@ -42,37 +43,38 @@ class fs<mpt::native_path> {
42
43
43
44
// Verify if this path represents a valid directory on the file system.
44
45
bool is_directory (const mpt::native_path & path) {
45
- // Using PathIsDirectoryW here instead would increase libopenmpt dependencies by shlwapi.dll.
46
+ // Using PathIsDirectoryW here instead would increase libopenmpt dependencies by shlwapi.dll (and it would only work with paths up to MAX_PATH) .
46
47
// GetFileAttributesW also does the job just fine.
47
- #if MPT_OS_WINDOWS_WINRT
48
- WIN32_FILE_ATTRIBUTE_DATA data = {};
49
- if (::GetFileAttributesExW (path.AsNative ().c_str (), GetFileExInfoStandard, &data) == 0 ) {
50
- return false ;
51
- }
52
- DWORD dwAttrib = data.dwFileAttributes ;
53
- #else // !MPT_OS_WINDOWS_WINRT
54
- DWORD dwAttrib = ::GetFileAttributes (path.AsNative ().c_str ());
55
- #endif // MPT_OS_WINDOWS_WINRT
48
+ DWORD dwAttrib = get_file_attributes (path);
56
49
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
57
50
}
58
51
59
52
// Verify if this path exists and is a file on the file system.
60
53
bool is_file (const mpt::native_path & path) {
54
+ DWORD dwAttrib = get_file_attributes (path);
55
+ return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
56
+ }
57
+
58
+ // Verify that a path exists (no matter what type)
59
+ bool exists (const mpt::native_path & path) {
60
+ DWORD dwAttrib = get_file_attributes (path);
61
+ return (dwAttrib != INVALID_FILE_ATTRIBUTES);
62
+ }
63
+
64
+
65
+
66
+ private:
67
+
68
+ DWORD get_file_attributes (const mpt::native_path & path) {
61
69
#if MPT_OS_WINDOWS_WINRT
62
70
WIN32_FILE_ATTRIBUTE_DATA data = {};
63
71
if (::GetFileAttributesExW (path.AsNative ().c_str (), GetFileExInfoStandard, &data) == 0 ) {
64
- return false ;
72
+ return INVALID_FILE_ATTRIBUTES ;
65
73
}
66
- DWORD dwAttrib = data.dwFileAttributes ;
74
+ return data.dwFileAttributes ;
67
75
#else // !MPT_OS_WINDOWS_WINRT
68
- DWORD dwAttrib = ::GetFileAttributes (path.AsNative ().c_str ());
76
+ return ::GetFileAttributes (path.AsNative ().c_str ());
69
77
#endif // MPT_OS_WINDOWS_WINRT
70
- return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
71
- }
72
-
73
- // Verify that a path exists (no matter what type)
74
- bool exists (const mpt::native_path & path) {
75
- return ::PathFileExists (path.AsNative ().c_str ()) != FALSE ;
76
78
}
77
79
78
80
@@ -81,12 +83,13 @@ class fs<mpt::native_path> {
81
83
82
84
#if !(MPT_WINRT_BEFORE(MPT_WIN_10))
83
85
mpt::native_path absolute (const mpt::native_path & path) {
84
- DWORD size = ::GetFullPathName (path.AsNative ().c_str (), 0 , nullptr , nullptr );
86
+ const auto long_path = mpt::support_long_path (path.AsNative ());
87
+ DWORD size = ::GetFullPathName (long_path.c_str (), 0 , nullptr , nullptr );
85
88
if (size == 0 ) {
86
89
return path;
87
90
}
88
91
std::vector<TCHAR> fullPathName (size, TEXT (' \0 ' ));
89
- if (::GetFullPathName (path. AsNative () .c_str (), size, fullPathName.data (), nullptr ) == 0 ) {
92
+ if (::GetFullPathName (long_path .c_str (), size, fullPathName.data (), nullptr ) == 0 ) {
90
93
return path;
91
94
}
92
95
return mpt::native_path::FromNative (fullPathName.data ());
@@ -116,7 +119,7 @@ class fs<mpt::native_path> {
116
119
path = path.WithTrailingSlash ();
117
120
HANDLE hFind = NULL ;
118
121
WIN32_FIND_DATA wfd = {};
119
- hFind = ::FindFirstFile (( path + MPT_NATIVE_PATH (" *.*" )).AsNative ().c_str (), &wfd);
122
+ hFind = ::FindFirstFile (mpt::support_long_path (( path + MPT_NATIVE_PATH (" *.*" )).AsNative () ).c_str (), &wfd);
120
123
if (hFind != NULL && hFind != INVALID_HANDLE_VALUE) {
121
124
do {
122
125
mpt::native_path filename = mpt::native_path::FromNative (wfd.cFileName );
0 commit comments