зеркало из https://github.com/dotnet/pinvoke.git
Add FindFirstFileEx
And moved a bunch of related functionality to be available to Store apps, consistent with MSDN documentation on these methods.
This commit is contained in:
Родитель
cb02623332
Коммит
786b8180b5
11
CONTRIB.md
11
CONTRIB.md
|
@ -6,6 +6,15 @@ Please send pull requests to add what you've come up with.
|
|||
|
||||
## Guidelines
|
||||
|
||||
### Learn how to write P/Invoke signatures
|
||||
|
||||
The [sigimp tool][SigImp] will automatically generate P/Invoke signatures for most Win32 functions
|
||||
and interop types. Use it to save time and improve accuracy as we collect these signatures into these
|
||||
reusable libraries. But try to cut down the verbose output that may be produced by a tool.
|
||||
|
||||
Remember whether you write the signatures yourself or use a tool, to follow the rest of the guidelines
|
||||
in this document.
|
||||
|
||||
### Project structure
|
||||
|
||||
* One class library and NuGet package per P/Invoke'd DLL.
|
||||
|
@ -64,3 +73,5 @@ Take care to set the package version such that it exactly matches the AppVeyor b
|
|||
for your pull request. You can get the version number by reviewing the result of the
|
||||
validation build for your pull request, clicking ARTIFACTS, and noting the version
|
||||
of the produced packages.
|
||||
|
||||
[SigImp]: http://blogs.msdn.com/b/vbteam/archive/2008/03/14/making-pinvoke-easy.aspx
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Kernel32+SafeFindFilesHandle.cs" />
|
||||
<Compile Include="Kernel32.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -45,83 +45,5 @@ namespace PInvoke
|
|||
/// </returns>
|
||||
[DllImport(nameof(Kernel32), SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern bool FindNextFile(SafeFindFilesHandle hFindFile, out WIN32_FIND_DATA lpFindFileData);
|
||||
|
||||
/// <summary>
|
||||
/// Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW, FindFirstFileNameTransactedW, FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.
|
||||
/// </summary>
|
||||
/// <param name="hFindFile">The file search handle.</param>
|
||||
/// <returns>
|
||||
/// If the function succeeds, the return value is nonzero.
|
||||
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
/// </returns>
|
||||
[DllImport(nameof(Kernel32), SetLastError = true)]
|
||||
public static extern bool FindClose(IntPtr hFindFile);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct WIN32_FIND_DATA
|
||||
{
|
||||
/// <summary>
|
||||
/// The file attributes of a file.
|
||||
/// </summary>
|
||||
public FileAttributes dwFileAttributes;
|
||||
|
||||
/// <summary>
|
||||
/// A FILETIME structure that specifies when a file or directory was created.
|
||||
/// If the underlying file system does not support creation time, this member is zero.
|
||||
/// </summary>
|
||||
public FILETIME ftCreationTime;
|
||||
|
||||
/// <summary>
|
||||
/// A FILETIME structure.
|
||||
/// For a file, the structure specifies when the file was last read from, written to, or for executable files, run.
|
||||
/// For a directory, the structure specifies when the directory is created.If the underlying file system does not support last access time, this member is zero.
|
||||
/// On the FAT file system, the specified date for both files and directories is correct, but the time of day is always set to midnight.
|
||||
/// </summary>
|
||||
public FILETIME ftLastAccessTime;
|
||||
|
||||
/// <summary>
|
||||
/// A FILETIME structure.
|
||||
/// For a file, the structure specifies when the file was last written to, truncated, or overwritten, for example, when WriteFile or SetEndOfFile are used.The date and time are not updated when file attributes or security descriptors are changed.
|
||||
/// For a directory, the structure specifies when the directory is created.If the underlying file system does not support last write time, this member is zero.
|
||||
/// </summary>
|
||||
public FILETIME ftLastWriteTime;
|
||||
|
||||
/// <summary>
|
||||
/// The high-order DWORD value of the file size, in bytes.
|
||||
/// This value is zero unless the file size is greater than MAXDWORD.
|
||||
/// The size of the file is equal to(nFileSizeHigh* (MAXDWORD+1)) + nFileSizeLow.
|
||||
/// </summary>
|
||||
public uint nFileSizeHigh;
|
||||
|
||||
/// <summary>
|
||||
/// The low-order DWORD value of the file size, in bytes.
|
||||
/// </summary>
|
||||
public uint nFileSizeLow;
|
||||
|
||||
/// <summary>
|
||||
/// If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies the reparse point tag.
|
||||
/// Otherwise, this value is undefined and should not be used.
|
||||
/// For more information see Reparse Point Tags.
|
||||
/// </summary>
|
||||
public uint dwReserved0;
|
||||
|
||||
/// <summary>
|
||||
/// Reserved for future use.
|
||||
/// </summary>
|
||||
public uint dwReserved1;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the file.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
||||
public string cFileName;
|
||||
|
||||
/// <summary>
|
||||
/// An alternative name for the file.
|
||||
/// This name is in the classic 8.3 file name format.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
|
||||
public string cAlternateFileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<Import_RootNamespace>PInvoke.Kernel32.Shared</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Kernel32+SafeFindFilesHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Kernel32+SafeObjectHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Kernel32.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Kernel32.Helpers.cs" />
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
namespace PInvoke
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
|
||||
|
||||
/// <summary>
|
||||
/// Exported functions from the Kernel32.dll Windows library.
|
||||
|
@ -17,6 +18,83 @@ namespace PInvoke
|
|||
/// </summary>
|
||||
public static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
|
||||
|
||||
public enum FINDEX_INFO_LEVELS
|
||||
{
|
||||
FindExInfoStandard,
|
||||
FindExInfoMaxInfoLevel,
|
||||
}
|
||||
|
||||
public enum FINDEX_SEARCH_OPS
|
||||
{
|
||||
FindExSearchNameMatch,
|
||||
FindExSearchLimitToDirectories,
|
||||
FindExSearchLimitToDevices,
|
||||
FindExSearchMaxSearchOp,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional flags to pass to the <see cref="FindFirstFileEx"/> method.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum FindFirstFileExFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// Searches are case-sensitive.
|
||||
/// </summary>
|
||||
CaseSensitive,
|
||||
|
||||
/// <summary>
|
||||
/// Uses a larger buffer for directory queries, which can increase performance of the find operation.
|
||||
/// </summary>
|
||||
LargeFetch,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches a directory for a file or subdirectory with a name and attributes that match those specified.
|
||||
/// For the most basic version of this function, see <see cref="FindFirstFile"/>.
|
||||
/// To perform this operation as a transacted operation, use the FindFirstFileTransacted function.
|
||||
/// </summary>
|
||||
/// <param name="lpFileName">
|
||||
/// The directory or path, and the file name, which can include wildcard characters, for example, an asterisk (*) or a question mark (?).
|
||||
/// This parameter should not be NULL, an invalid string (for example, an empty string or a string that is missing the terminating null character), or end in a trailing backslash (\).
|
||||
/// If the string ends with a wildcard, period, or directory name, the user must have access to the root and all subdirectories on the path.
|
||||
/// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to approximately 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.
|
||||
/// </param>
|
||||
/// <param name="fInfoLevelId">
|
||||
/// The information level of the returned data.
|
||||
/// This parameter is one of the <see cref="FINDEX_INFO_LEVELS"/> enumeration values.
|
||||
/// </param>
|
||||
/// <param name="lpFindFileData">
|
||||
/// A pointer to the buffer that receives the file data.
|
||||
/// The pointer type is determined by the level of information that is specified in the <paramref name="fInfoLevelId"/> parameter.
|
||||
/// </param>
|
||||
/// <param name="fSearchOp">
|
||||
/// The type of filtering to perform that is different from wildcard matching.
|
||||
/// This parameter is one of the <see cref="FINDEX_SEARCH_OPS"/> enumeration values.
|
||||
/// </param>
|
||||
/// <param name="lpSearchFilter">
|
||||
/// A pointer to the search criteria if the specified <paramref name="fSearchOp"/> needs structured search information.
|
||||
/// At this time, none of the supported fSearchOp values require extended search information. Therefore, this pointer must be NULL.
|
||||
/// </param>
|
||||
/// <param name="dwAdditionalFlags">Specifies additional flags that control the search.</param>
|
||||
/// <returns>
|
||||
/// If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose, and the lpFindFileData parameter contains information about the first file or directory found.
|
||||
/// If the function fails or fails to locate files from the search string in the lpFileName parameter, the return value is INVALID_HANDLE_VALUE and the contents of lpFindFileData are indeterminate.To get extended error information, call the GetLastError function.
|
||||
/// </returns>
|
||||
[DllImport(nameof(Kernel32))]
|
||||
public static extern SafeFindFilesHandle FindFirstFileEx(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, out WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, FindFirstFileExFlags dwAdditionalFlags);
|
||||
|
||||
/// <summary>
|
||||
/// Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW, FindFirstFileNameTransactedW, FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.
|
||||
/// </summary>
|
||||
/// <param name="hFindFile">The file search handle.</param>
|
||||
/// <returns>
|
||||
/// If the function succeeds, the return value is nonzero.
|
||||
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
/// </returns>
|
||||
[DllImport(nameof(Kernel32), SetLastError = true)]
|
||||
public static extern bool FindClose(IntPtr hFindFile);
|
||||
|
||||
/// <summary>
|
||||
/// Closes an open object handle.
|
||||
/// </summary>
|
||||
|
@ -27,5 +105,72 @@ namespace PInvoke
|
|||
/// </returns>
|
||||
[DllImport(nameof(Kernel32), SetLastError = true)]
|
||||
public static extern bool CloseHandle(IntPtr hObject);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct WIN32_FIND_DATA
|
||||
{
|
||||
/// <summary>
|
||||
/// The file attributes of a file.
|
||||
/// </summary>
|
||||
public FileAttributes dwFileAttributes;
|
||||
|
||||
/// <summary>
|
||||
/// A FILETIME structure that specifies when a file or directory was created.
|
||||
/// If the underlying file system does not support creation time, this member is zero.
|
||||
/// </summary>
|
||||
public FILETIME ftCreationTime;
|
||||
|
||||
/// <summary>
|
||||
/// A FILETIME structure.
|
||||
/// For a file, the structure specifies when the file was last read from, written to, or for executable files, run.
|
||||
/// For a directory, the structure specifies when the directory is created.If the underlying file system does not support last access time, this member is zero.
|
||||
/// On the FAT file system, the specified date for both files and directories is correct, but the time of day is always set to midnight.
|
||||
/// </summary>
|
||||
public FILETIME ftLastAccessTime;
|
||||
|
||||
/// <summary>
|
||||
/// A FILETIME structure.
|
||||
/// For a file, the structure specifies when the file was last written to, truncated, or overwritten, for example, when WriteFile or SetEndOfFile are used.The date and time are not updated when file attributes or security descriptors are changed.
|
||||
/// For a directory, the structure specifies when the directory is created.If the underlying file system does not support last write time, this member is zero.
|
||||
/// </summary>
|
||||
public FILETIME ftLastWriteTime;
|
||||
|
||||
/// <summary>
|
||||
/// The high-order DWORD value of the file size, in bytes.
|
||||
/// This value is zero unless the file size is greater than MAXDWORD.
|
||||
/// The size of the file is equal to(nFileSizeHigh* (MAXDWORD+1)) + nFileSizeLow.
|
||||
/// </summary>
|
||||
public uint nFileSizeHigh;
|
||||
|
||||
/// <summary>
|
||||
/// The low-order DWORD value of the file size, in bytes.
|
||||
/// </summary>
|
||||
public uint nFileSizeLow;
|
||||
|
||||
/// <summary>
|
||||
/// If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies the reparse point tag.
|
||||
/// Otherwise, this value is undefined and should not be used.
|
||||
/// For more information see Reparse Point Tags.
|
||||
/// </summary>
|
||||
public uint dwReserved0;
|
||||
|
||||
/// <summary>
|
||||
/// Reserved for future use.
|
||||
/// </summary>
|
||||
public uint dwReserved1;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the file.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
||||
public string cFileName;
|
||||
|
||||
/// <summary>
|
||||
/// An alternative name for the file.
|
||||
/// This name is in the classic 8.3 file name format.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
|
||||
public string cAlternateFileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
// Copyright (c) to owners found in https://github.com/AArnott/pinvoke/blob/master/COPYRIGHT.md. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
|
||||
|
||||
namespace PInvoke
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <content>
|
||||
/// Contains the nested <see cref="FileAttributes"/> type.
|
||||
/// </content>
|
||||
public static partial class Kernel32
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the Win32 FileAttributes enum.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is similar to the System.IO.FileAttributes enum, but that enum
|
||||
/// is not available in the portable profile, although it is allowed to call
|
||||
/// certain file methods via P/Invoke in Windows Store apps, per MSDN docs.
|
||||
/// </remarks>
|
||||
[Flags]
|
||||
public enum FileAttributes
|
||||
{
|
||||
/// <summary>
|
||||
/// A file or directory that is an archive file or directory. Applications typically use this attribute to mark files for backup or removal.
|
||||
/// </summary>
|
||||
Archive = 0x20,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that is compressed. For a file, all of the data in the file is compressed. For a directory, compression is the default for newly created files and subdirectories.
|
||||
/// </summary>
|
||||
Compressed = 0x800,
|
||||
|
||||
/// <summary>
|
||||
/// This value is reserved for system use.
|
||||
/// </summary>
|
||||
Device = 0x40,
|
||||
|
||||
/// <summary>
|
||||
/// The handle that identifies a directory.
|
||||
/// </summary>
|
||||
Directory = 0x10,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that is encrypted. For a file, all data streams in the file are encrypted. For a directory, encryption is the default for newly created files and subdirectories.
|
||||
/// </summary>
|
||||
Encrypted = 0x4000,
|
||||
|
||||
/// <summary>
|
||||
/// The file or directory is hidden. It is not included in an ordinary directory listing.
|
||||
/// </summary>
|
||||
Hidden = 0x2,
|
||||
|
||||
/// <summary>
|
||||
/// The directory or user data stream is configured with integrity (only supported on ReFS volumes). It is not included in an ordinary directory listing. The integrity setting persists with the file if it's renamed. If a file is copied the destination file will have integrity set if either the source file or destination directory have integrity set.
|
||||
/// </summary>
|
||||
IntegrityStream = 0x8000,
|
||||
|
||||
/// <summary>
|
||||
/// A file that does not have other attributes set. This attribute is valid only when used alone.
|
||||
/// </summary>
|
||||
Normal = 0x80,
|
||||
|
||||
/// <summary>
|
||||
/// The file or directory is not to be indexed by the content indexing service.
|
||||
/// </summary>
|
||||
NotContentIndexed = 0x2000,
|
||||
|
||||
/// <summary>
|
||||
/// The user data stream not to be read by the background data integrity scanner (AKA scrubber). When set on a directory it only provides inheritance. This flag is only supported on Storage Spaces and ReFS volumes. It is not included in an ordinary directory listing.
|
||||
/// </summary>
|
||||
NoScrubData = 0x20000,
|
||||
|
||||
/// <summary>
|
||||
/// The data of a file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is the hierarchical storage management software. Applications should not arbitrarily change this attribute.
|
||||
/// </summary>
|
||||
Offline = 0x1000,
|
||||
|
||||
/// <summary>
|
||||
/// A file that is read-only. Applications can read the file, but cannot write to it or delete it. This attribute is not honored on directories.
|
||||
/// </summary>
|
||||
ReadOnly = 0x1,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that has an associated reparse point, or a file that is a symbolic link.
|
||||
/// </summary>
|
||||
ReparsePoint = 0x400,
|
||||
|
||||
/// <summary>
|
||||
/// A file or directory that the operating system uses a part of, or uses exclusively.
|
||||
/// </summary>
|
||||
System = 0x4,
|
||||
|
||||
/// <summary>
|
||||
/// A file that is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is available, because typically, an application deletes a temporary file after the handle is closed. In that scenario, the system can entirely avoid writing the data. Otherwise, the data is written after the handle is closed.
|
||||
/// </summary>
|
||||
Temporary = 0x100,
|
||||
|
||||
/// <summary>
|
||||
/// This value is reserved for system use.
|
||||
/// </summary>
|
||||
Virtual = 0x10000,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Kernel32+FileAttributes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче