24#include <wx/filename.h>
39#if !defined( __MINGW32__ )
63#define FileFullDirectoryInformation ( (FILE_INFORMATION_CLASS) 2 )
70#if defined( _MSC_VER ) || !defined( USE_MSYS2_FALLBACK )
73 HANDLE hFile = INVALID_HANDLE_VALUE;
74 hFile = CreateFileW( aPath.wc_str(),
79 FILE_FLAG_SEQUENTIAL_SCAN,
82 if (hFile == INVALID_HANDLE_VALUE)
87 int fd = _open_osfhandle(
reinterpret_cast<intptr_t
>( hFile ), 0 );
96 FILE* fp = _fdopen( fd, aMode.c_str() );
107 return wxFopen( aPath, aMode );
117 if( GetFileSecurity( aSrc.wc_str(),
118 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
126 BYTE* pSD =
new BYTE[dwSize];
128 PSECURITY_DESCRIPTOR pSD =
static_cast<PSECURITY_DESCRIPTOR
>(
new BYTE[dwSize] );
134 if( !GetFileSecurity( aSrc.wc_str(),
135 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION
136 | DACL_SECURITY_INFORMATION, pSD, dwSize, &dwSize ) )
143 if( !SetFileSecurity( aDest.wc_str(),
144 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION
145 | DACL_SECURITY_INFORMATION, pSD ) )
158 DWORD attrs = GetFileAttributesW( aFilePath.wc_str() );
160 if( attrs == INVALID_FILE_ATTRIBUTES )
166 DWORD attrsToRemove = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
168 if( attrs & attrsToRemove )
170 attrs &= ~attrsToRemove;
171 return SetFileAttributesW( aFilePath.wc_str(), attrs ) != 0;
181 if( ( GetFileAttributesW( aFileName.fn_str() ) & FILE_ATTRIBUTE_HIDDEN ) )
194 if( aFilename.GetVolume().Length() == 1 )
196 aFilename.SetVolume(
"\\\\?\\" + aFilename.GetVolume() +
":" );
197 else if( aFilename.GetVolume().Length() > 1
198 && aFilename.GetVolume().StartsWith( wxT(
"\\\\" ) )
199 && !aFilename.GetVolume().StartsWith( wxT(
"\\\\?" ) ) )
204 aFilename.SetVolume(
"\\\\?\\UNC" + aFilename.GetVolume().Mid( 1 ) );
205 else if( aFilename.GetVolume().StartsWith( wxT(
"\\\\?" ) )
206 && aFilename.GetDirs().size() >= 2
207 && aFilename.GetDirs()[0] ==
"UNC" )
213 aFilename.SetVolume(
"\\\\?\\UNC\\" + aFilename.GetDirs()[1] );
214 aFilename.RemoveDir( 0 );
215 aFilename.RemoveDir( 0 );
222 long long timestamp = 0;
227 static PFN_NtQueryDirectoryFile pNtQueryDirectoryFile =
nullptr;
229 if( !pNtQueryDirectoryFile )
231 HMODULE ntdll = GetModuleHandleW(
L"ntdll.dll" );
235 pNtQueryDirectoryFile =
236 (PFN_NtQueryDirectoryFile) GetProcAddress( ntdll,
"NtQueryDirectoryFile" );
240 if( !pNtQueryDirectoryFile )
243 std::wstring dirPath( aDirPath.t_str() );
245 if( !dirPath.empty() && dirPath.back() !=
L'\\' )
251 if( dirPath.size() >= 2 && dirPath[0] ==
L'\\' && dirPath[1] ==
L'\\' )
253 if( dirPath.size() >= 4 && dirPath[2] ==
L'?' && dirPath[3] ==
L'\\' )
261 ntPath =
L"\\\\?\\UNC\\" + dirPath.substr( 2 );
267 ntPath =
L"\\\\?\\" + dirPath;
270 HANDLE hDir = CreateFileW( ntPath.c_str(), FILE_LIST_DIRECTORY,
271 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr,
272 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
nullptr );
274 if( hDir == INVALID_HANDLE_VALUE )
277 std::wstring pattern( aFilespec.t_str() );
280 alignas(
sizeof( LONGLONG ) )
char buffer[64 * 1024];
282 IO_STATUS_BLOCK iosb;
284 bool firstQuery =
true;
288 status = pNtQueryDirectoryFile( hDir,
nullptr,
nullptr,
nullptr, &iosb, buffer,
290 nullptr, firstQuery ? TRUE : FALSE );
305 && PathMatchSpecW( fileName.c_str(), pattern.c_str() ) )
wxString result
Test unit parsing edge cases and error handling.
typedef FILE_INFORMATION_CLASS
struct _FILE_FULL_DIR_INFORMATION FILE_FULL_DIR_INFORMATION
typedef NTSTATUS(NTAPI *PFN_NtQueryDirectoryFile)(HANDLE
struct _FILE_FULL_DIR_INFORMATION * PFILE_FULL_DIR_INFORMATION
#define FileFullDirectoryInformation