14 internal static class Kernel32
44 internal struct SECURITY_ATTRIBUTES
102 [DllImport(
"kernel32.dll", BestFitMapping =
false,
CharSet =
CharSet.Unicode, EntryPoint =
"CreateFileW", ExactSpelling =
true,
SetLastError =
true)]
108 return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
114 [DllImport(
"kernel32.dll",
CharSet =
CharSet.Unicode, EntryPoint =
"FindFirstFileExW", ExactSpelling =
true,
SetLastError =
true)]
123 [DllImport(
"kernel32.dll", BestFitMapping =
true,
CharSet =
CharSet.Unicode, EntryPoint =
"FormatMessageW", ExactSpelling =
true,
SetLastError =
true)]
124 private unsafe
static extern int FormatMessage(
int dwFlags,
IntPtr lpSource, uint dwMessageId,
int dwLanguageId,
void* lpBuffer,
int nSize,
IntPtr arguments);
139 fixed (
char* lpBuffer = span)
163 return $
"Unknown error (0x{errorCode:x})";
169 while (num > 0 &&
buffer[num - 1] <=
' ')
173 return buffer.Slice(0, num).ToString();
176 [DllImport(
"kernel32.dll",
CharSet =
CharSet.Unicode, EntryPoint =
"GetFileAttributesExW", ExactSpelling =
true,
SetLastError =
true)]
185 [DllImport(
"kernel32.dll", ExactSpelling =
true,
SetLastError =
true)]
186 [SuppressGCTransition]
189 [DllImport(
"kernel32.dll", BestFitMapping =
false,
CharSet =
CharSet.Unicode, EntryPoint =
"CreateDirectoryW",
SetLastError =
true)]
static bool FindClose(IntPtr hFindFile)
static Microsoft.Win32.SafeHandles.SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags)
static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
static void SetLastError(int errorCode)
static unsafe SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
static bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode)
static string GetMessage(int errorCode)
static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
static bool CreateDirectory(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
static bool CreateDirectoryPrivate(string path, ref SECURITY_ATTRIBUTES lpSecurityAttributes)
static unsafe SafeFileHandle CreateFilePrivate(string lpFileName, int dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES *lpSecurityAttributes, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile)
static bool GetFileAttributesExPrivate(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static Microsoft.Win32.SafeHandles.SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
@ FindExSearchLimitToDevices
@ FindExSearchLimitToDirectories
@ FindExSearchMaxSearchOp
static string GetAndTrimString(Span< char > buffer)
static string EnsureExtendedPrefix(string path)
static string EnsureExtendedPrefixIfNeeded(string path)
static void FreeHGlobal(IntPtr hglobal)
static int GetLastWin32Error()
IntPtr lpSecurityDescriptor
FILE_TIME ftLastAccessTime
void PopulateFrom(ref WIN32_FIND_DATA findData)
FILE_TIME ftLastWriteTime
unsafe fixed char _cAlternateFileName[14]
FILE_TIME ftLastWriteTime
FILE_TIME ftLastAccessTime
unsafe fixed char _cFileName[260]
static readonly IntPtr Zero
Span< T > Slice(int start)