Browse Source

new upload

tags/4.2.4
Raimund Andée 7 years ago
parent
commit
dd883f889b
100 changed files with 16577 additions and 0 deletions
  1. +393
    -0
      AlphaFS/AlphaFS.csproj
  2. +7
    -0
      AlphaFS/AlphaFS.ruleset
  3. +35
    -0
      AlphaFS/AssemblyVersionInfo.cs
  4. +138
    -0
      AlphaFS/Filesystem/AlternateDataStreamInfo.cs
  5. +650
    -0
      AlphaFS/Filesystem/BackupFileStream.cs
  6. +84
    -0
      AlphaFS/Filesystem/BackupStreamInfo.cs
  7. +177
    -0
      AlphaFS/Filesystem/ByHandleFileInfo.cs
  8. +56
    -0
      AlphaFS/Filesystem/ChangeErrorMode.cs
  9. +28
    -0
      AlphaFS/Filesystem/CopyMoveProgressRoutine.cs
  10. +82
    -0
      AlphaFS/Filesystem/CopyMoveResult.cs
  11. +459
    -0
      AlphaFS/Filesystem/Device.cs
  12. +141
    -0
      AlphaFS/Filesystem/DeviceInfo.cs
  13. +484
    -0
      AlphaFS/Filesystem/Directory Class/Directory.Compression.cs
  14. +969
    -0
      AlphaFS/Filesystem/Directory Class/Directory.CopyMove.cs
  15. +195
    -0
      AlphaFS/Filesystem/Directory Class/Directory.CountFileSystemObjects.cs
  16. +800
    -0
      AlphaFS/Filesystem/Directory Class/Directory.CreateDirectory.cs
  17. +126
    -0
      AlphaFS/Filesystem/Directory Class/Directory.CurrentDirectory.cs
  18. +417
    -0
      AlphaFS/Filesystem/Directory Class/Directory.Delete.cs
  19. +211
    -0
      AlphaFS/Filesystem/Directory Class/Directory.DeleteEmptySubdirectories.cs
  20. +154
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EncryptedDirectoryRaw.cs
  21. +272
    -0
      AlphaFS/Filesystem/Directory Class/Directory.Encryption.cs
  22. +69
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EnumerateAlternateDataStreams.cs
  23. +500
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EnumerateDirectories.cs
  24. +230
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EnumerateFileIdBothDirectoryInfo.cs
  25. +472
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EnumerateFileSystemEntries.cs
  26. +670
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EnumerateFileSystemEntryInfos.cs
  27. +502
    -0
      AlphaFS/Filesystem/Directory Class/Directory.EnumerateFiles.cs
  28. +110
    -0
      AlphaFS/Filesystem/Directory Class/Directory.Exists.cs
  29. +113
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetAccessControl.cs
  30. +138
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetChangeTime.cs
  31. +124
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetCreationTime.cs
  32. +210
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetDirectories.cs
  33. +115
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetDirectoryRoot.cs
  34. +210
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetFileSystemEntries.cs
  35. +216
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetFiles.cs
  36. +121
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetLastAccessTime.cs
  37. +123
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetLastWriteTime.cs
  38. +150
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetLogicalDrives.cs
  39. +92
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetParent.cs
  40. +286
    -0
      AlphaFS/Filesystem/Directory Class/Directory.GetProperties.cs
  41. +58
    -0
      AlphaFS/Filesystem/Directory Class/Directory.HasInheritedPermissions.cs
  42. +104
    -0
      AlphaFS/Filesystem/Directory Class/Directory.SetAccessControl.cs
  43. +169
    -0
      AlphaFS/Filesystem/Directory Class/Directory.SetCreationTime.cs
  44. +169
    -0
      AlphaFS/Filesystem/Directory Class/Directory.SetLastAccessTime.cs
  45. +167
    -0
      AlphaFS/Filesystem/Directory Class/Directory.SetLastWriteTime.cs
  46. +187
    -0
      AlphaFS/Filesystem/Directory Class/Directory.SetTimestamps.cs
  47. +76
    -0
      AlphaFS/Filesystem/Directory Class/Directory.TransferTimestamps.cs
  48. +31
    -0
      AlphaFS/Filesystem/Directory Class/Directory.cs
  49. +128
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Compression.cs
  50. +459
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.CopyToMoveTo.cs
  51. +70
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.CountFileSystemObjects.cs
  52. +81
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Create.cs
  53. +165
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.CreateSubdirectory.cs
  54. +28
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Decrypt.cs
  55. +88
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Delete.cs
  56. +57
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.DeleteEmptySubdirectories.cs
  57. +122
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Encryption.cs
  58. +37
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateAlternateDataStreams.cs
  59. +138
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateDirectories.cs
  60. +136
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateFileSystemInfos.cs
  61. +138
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateFiles.cs
  62. +52
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetAccessControl.cs
  63. +110
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetDirectories.cs
  64. +124
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetFileSystemInfos.cs
  65. +114
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetFiles.cs
  66. +39
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Refresh.cs
  67. +39
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.RefreshEntryInfo.cs
  68. +49
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.SetAccessControl.cs
  69. +33
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.ToString.cs
  70. +203
    -0
      AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.cs
  71. +265
    -0
      AlphaFS/Filesystem/DiskSpaceInfo.cs
  72. +422
    -0
      AlphaFS/Filesystem/DriveInfo.cs
  73. +84
    -0
      AlphaFS/Filesystem/Enumerations/BackupStreamType.cs
  74. +37
    -0
      AlphaFS/Filesystem/Enumerations/CopyMoveProgressCallbackReason.cs
  75. +47
    -0
      AlphaFS/Filesystem/Enumerations/CopyMoveProgressResult.cs
  76. +69
    -0
      AlphaFS/Filesystem/Enumerations/CopyOptions.cs
  77. +200
    -0
      AlphaFS/Filesystem/Enumerations/DeviceGuid.cs
  78. +61
    -0
      AlphaFS/Filesystem/Enumerations/DiGetClassFlags.cs
  79. +62
    -0
      AlphaFS/Filesystem/Enumerations/DirectoryEnumerationOptions.cs
  80. +60
    -0
      AlphaFS/Filesystem/Enumerations/DosDeviceAttributes.cs
  81. +45
    -0
      AlphaFS/Filesystem/Enumerations/EncryptedFileRawMode.cs
  82. +48
    -0
      AlphaFS/Filesystem/Enumerations/ErrorMode.cs
  83. +143
    -0
      AlphaFS/Filesystem/Enumerations/ExtendedFileAttributes.cs
  84. +44
    -0
      AlphaFS/Filesystem/Enumerations/FINDEX_INFO_LEVELS.cs
  85. +58
    -0
      AlphaFS/Filesystem/Enumerations/FileEncryptionStatus.cs
  86. +270
    -0
      AlphaFS/Filesystem/Enumerations/FileInfoByHandleClass.cs
  87. +45
    -0
      AlphaFS/Filesystem/Enumerations/FinalPathFormats.cs
  88. +43
    -0
      AlphaFS/Filesystem/Enumerations/FindExAdditionalFlags.cs
  89. +57
    -0
      AlphaFS/Filesystem/Enumerations/FindExSearchOps.cs
  90. +33
    -0
      AlphaFS/Filesystem/Enumerations/GetFileExInfoLevels.cs
  91. +60
    -0
      AlphaFS/Filesystem/Enumerations/GetFullPathOptions.cs
  92. +83
    -0
      AlphaFS/Filesystem/Enumerations/MoveOptions.cs
  93. +59
    -0
      AlphaFS/Filesystem/Enumerations/PathFormat.cs
  94. +106
    -0
      AlphaFS/Filesystem/Enumerations/ReparsePointTag.cs
  95. +40
    -0
      AlphaFS/Filesystem/Enumerations/STREAM_INFO_LEVELS.cs
  96. +169
    -0
      AlphaFS/Filesystem/Enumerations/SetupDiGetDeviceRegistryPropertyEnum.cs
  97. +56
    -0
      AlphaFS/Filesystem/Enumerations/StreamAttributes.cs
  98. +34
    -0
      AlphaFS/Filesystem/Enumerations/SymbolicLinkTarget.cs
  99. +33
    -0
      AlphaFS/Filesystem/Enumerations/SymbolicLinkType.cs
  100. +144
    -0
      AlphaFS/Filesystem/Enumerations/VolumeInfoAttributes.cs

+ 393
- 0
AlphaFS/AlphaFS.csproj View File

@@ -0,0 +1,393 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="11.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F0F9AF1E-D5B5-4D72-804A-5380622FBDEA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Alphaleonis.Win32</RootNamespace>
<AssemblyName>AlphaFS</AssemblyName>
<FileAlignment>512</FileAlignment>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>..\AlphaFS.snk</AssemblyOriginatorKeyFile>
<CodeAnalysisRuleSet>AlphaFS.ruleset</CodeAnalysisRuleSet>
<DelaySign>false</DelaySign>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Bin\Debug\Net35</OutputPath>
<DefineConstants>DEBUG;TRACE;NET35</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>true</RunCodeAnalysis>
<DocumentationFile>..\Bin\Debug\Net35\AlphaFS.XML</DocumentationFile>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<RegisterForComInterop>false</RegisterForComInterop>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<PlatformTarget>AnyCPU</PlatformTarget>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>AlphaFS.ruleset</CodeAnalysisRuleSet>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Bin\Release\Net35</OutputPath>
<DefineConstants>TRACE;NET35</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\Bin\Release\Net35\AlphaFS.XML</DocumentationFile>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRuleSet>AlphaFS.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyVersionInfo.cs">
<DoTransformOnBuild>True</DoTransformOnBuild>
</Compile>
<Compile Include="Filesystem\AlternateDataStreamInfo.cs" />
<Compile Include="Filesystem\BackupStreamInfo.cs" />
<Compile Include="Filesystem\CopyMoveProgressRoutine.cs" />
<Compile Include="Filesystem\Directory Class\Directory.CopyMove.cs" />
<Compile Include="Filesystem\Directory Class\Directory.CountFileSystemObjects.cs" />
<Compile Include="Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs" />
<Compile Include="Filesystem\Directory Class\Directory.Delete.cs" />
<Compile Include="Filesystem\Directory Class\Directory.CreateDirectory.cs" />
<Compile Include="Filesystem\Directory Class\Directory.EnumerateDirectories.cs" />
<Compile Include="Filesystem\Directory Class\Directory.EnumerateFiles.cs" />
<Compile Include="Filesystem\Directory Class\Directory.EnumerateFileSystemEntryInfos.cs" />
<Compile Include="Filesystem\Directory Class\Directory.EnumerateFileSystemEntries.cs" />
<Compile Include="Filesystem\Directory Class\Directory.Exists.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetDirectories.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetFiles.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetCreationTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetLastAccessTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetLastWriteTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.HasInheritedPermissions.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetAccessControl.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetChangeTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.CurrentDirectory.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetFileSystemEntries.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetDirectoryRoot.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetLogicalDrives.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetParent.cs" />
<Compile Include="Filesystem\Directory Class\Directory.SetAccessControl.cs" />
<Compile Include="Filesystem\Directory Class\Directory.SetCreationTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.SetLastAccessTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.SetTimestamps.cs" />
<Compile Include="Filesystem\Directory Class\Directory.TransferTimestamps.cs" />
<Compile Include="Filesystem\Directory Class\Directory.SetLastWriteTime.cs" />
<Compile Include="Filesystem\Directory Class\Directory.Compression.cs" />
<Compile Include="Filesystem\Directory Class\Directory.Encryption.cs" />
<Compile Include="Filesystem\Directory Class\Directory.EnumerateFileIdBothDirectoryInfo.cs" />
<Compile Include="Filesystem\Directory Class\Directory.GetProperties.cs" />
<Compile Include="Filesystem\Directory Class\Directory.EnumerateAlternateDataStreams.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.RefreshEntryInfo.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Encryption.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.DeleteEmptySubdirectories.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Decrypt.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Compression.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.CountFileSystemObjects.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.CopyToMoveTo.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.ToString.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.SetAccessControl.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Refresh.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.GetFileSystemInfos.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.GetFiles.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.GetDirectories.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.GetAccessControl.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnumerateFileSystemInfos.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnumerateFiles.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnumerateDirectories.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Delete.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.CreateSubdirectory.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Create.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnumerateAlternateDataStreams.cs" />
<Compile Include="Filesystem\Enumerations\EncryptedFileRawMode.cs" />
<Compile Include="Filesystem\Enumerations\STREAM_INFO_LEVELS.cs" />
<Compile Include="Filesystem\Enumerations\PathFormat.cs" />
<Compile Include="Filesystem\Exceptions\AlreadyExistsException.cs" />
<Compile Include="Filesystem\Exceptions\DeviceNotReadyException.cs" />
<Compile Include="Filesystem\Exceptions\DirectoryReadOnlyException.cs" />
<Compile Include="Filesystem\Exceptions\DirectoryNotEmptyException.cs" />
<Compile Include="Filesystem\Exceptions\FileReadOnlyException.cs" />
<Compile Include="Filesystem\File Class\File.GetHash.cs" />
<Compile Include="Filesystem\File Class\File.EncryptedFileRaw.cs" />
<Compile Include="Filesystem\File Class\File.EnumerateAlternateDataStreams.cs" />
<Compile Include="Filesystem\File Class\File.EnumerateHardlinks.cs" />
<Compile Include="Filesystem\File Class\File.CreateSymbolicLink.cs" />
<Compile Include="Filesystem\File Class\File.CreateHardlink.cs" />
<Compile Include="Filesystem\File Class\File.Compress.cs" />
<Compile Include="Filesystem\File Class\File.Delete.cs" />
<Compile Include="Filesystem\File Class\File.EncryptDecrypt.cs" />
<Compile Include="Filesystem\File Class\File.CreateText.cs" />
<Compile Include="Filesystem\File Class\File.CopyMove.cs" />
<Compile Include="Filesystem\File Class\File.IsLocked.cs" />
<Compile Include="Filesystem\File Class\File.WriteText.cs" />
<Compile Include="Filesystem\File Class\File.AppendText.cs" />
<Compile Include="Filesystem\File Class\File.Create.cs" />
<Compile Include="Filesystem\DeviceInfo.cs" />
<Compile Include="Filesystem\DiskSpaceInfo.cs" />
<Compile Include="Filesystem\DriveInfo.cs" />
<Compile Include="Filesystem\Enumerations\CopyMoveProgressResult.cs" />
<Compile Include="Filesystem\Enumerations\DirectoryEnumerationOptions.cs" />
<Compile Include="Filesystem\Enumerations\DeviceGuid.cs" />
<Compile Include="Filesystem\Enumerations\DiGetClassFlags.cs" />
<Compile Include="Filesystem\Enumerations\DosDeviceAttributes.cs" />
<Compile Include="Filesystem\Enumerations\FileInfoByHandleClass.cs" />
<Compile Include="Filesystem\Enumerations\FinalPathFormats.cs" />
<Compile Include="Filesystem\Enumerations\FindExAdditionalFlags.cs" />
<Compile Include="Filesystem\Enumerations\FINDEX_INFO_LEVELS.cs" />
<Compile Include="Filesystem\Enumerations\FindExSearchOps.cs" />
<Compile Include="Filesystem\Enumerations\ErrorMode.cs" />
<Compile Include="Filesystem\Enumerations\ReparsePointTag.cs" />
<Compile Include="Filesystem\Enumerations\SetupDiGetDeviceRegistryPropertyEnum.cs" />
<Compile Include="Filesystem\Enumerations\StreamAttributes.cs" />
<Compile Include="Filesystem\Enumerations\BackupStreamType.cs" />
<Compile Include="Filesystem\Enumerations\VolumeInfoAttributes.cs" />
<Compile Include="Filesystem\Enumerations\CopyOptions.cs" />
<Compile Include="Filesystem\Enumerations\CopyMoveProgressCallbackReason.cs" />
<Compile Include="Filesystem\Device.cs" />
<Compile Include="Filesystem\Directory Class\Directory.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.cs" />
<Compile Include="Filesystem\File Class\File.cs" />
<Compile Include="Filesystem\BackupFileStream.cs" />
<Compile Include="Filesystem\Enumerations\FileEncryptionStatus.cs" />
<Compile Include="Filesystem\ByHandleFileInfo.cs" />
<Compile Include="Filesystem\File Class\File.Exists.cs" />
<Compile Include="Filesystem\File Class\File.GetAccessControl.cs" />
<Compile Include="Filesystem\File Class\File.GetAttributes.cs" />
<Compile Include="Filesystem\File Class\File.GetCreationTime.cs" />
<Compile Include="Filesystem\File Class\File.GetLastAccessTime.cs" />
<Compile Include="Filesystem\File Class\File.GetLastWriteTime.cs" />
<Compile Include="Filesystem\File Class\File.Open.cs" />
<Compile Include="Filesystem\File Class\File.ReadAllBytes.cs" />
<Compile Include="Filesystem\File Class\File.ReadAllLines.cs" />
<Compile Include="Filesystem\File Class\File.ReadAllText.cs" />
<Compile Include="Filesystem\File Class\File.ReadLines.cs" />
<Compile Include="Filesystem\File Class\File.Replace.cs" />
<Compile Include="Filesystem\File Class\File.SetAccessControl.cs" />
<Compile Include="Filesystem\File Class\File.SetAttributes.cs" />
<Compile Include="Filesystem\File Class\File.SetFileTime.cs" />
<Compile Include="Filesystem\File Class\File.WriteAllBytes.cs" />
<Compile Include="Filesystem\File Class\File.GetChangeTime.cs" />
<Compile Include="Filesystem\File Class\File.GetCompressedSize.cs" />
<Compile Include="Filesystem\File Class\File.GetEncryptionStatus.cs" />
<Compile Include="Filesystem\File Class\File.GetFileInfoByHandleC.cs" />
<Compile Include="Filesystem\File Class\File.GetFileSystemEntryInfo.cs" />
<Compile Include="Filesystem\File Class\File.GetLinkTargetInfo.cs" />
<Compile Include="Filesystem\File Class\File.GetSize.cs" />
<Compile Include="Filesystem\File Class\File.TransferTimestamps.cs" />
<Compile Include="Filesystem\File Class\File.OpenRead.cs" />
<Compile Include="Filesystem\File Class\File.OpenText.cs" />
<Compile Include="Filesystem\File Class\File.OpenWrite.cs" />
<Compile Include="Filesystem\File Class\File.OpenBackupRead.cs" />
<Compile Include="Filesystem\FileIdBothDirectoryInfo.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.GetHash.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.RefreshEntryInfo.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.EnumerateAlternateDataStreams.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Decompress.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Compress.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.ToString.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.SetAccessControl.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Replace.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Refresh.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.OpenWrite.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.OpenText.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.OpenRead.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Open.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.GetAccessControl.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Encrypt.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Delete.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Decrypt.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.CreateText.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.Create.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.CopyToMoveTo.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.AppendText.cs" />
<Compile Include="Filesystem\FileInfo Class\FileInfo.cs" />
<Compile Include="Filesystem\Enumerations\ExtendedFileAttributes.cs" />
<Compile Include="Filesystem\FindFileSystemEntryInfo.cs" />
<Compile Include="Filesystem\FileSystemEntryInfo.cs" />
<Compile Include="Filesystem\FileSystemInfo.cs" />
<Compile Include="Filesystem\Enumerations\GetFileExInfoLevels.cs" />
<Compile Include="Filesystem\Enumerations\GetFullPathOptions.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.EncryptedFileRaw.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.Shell32.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.KernelTransactions.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.Handles.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.FileManagement.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.DiskManagement.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.DirectoryManagement.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.DeviceManagement.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.Constants.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.BackupStreams.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.Utilities.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.PathManagement.cs" />
<Compile Include="Filesystem\Native Structures\WIN32_FIND_STREAM_DATA.cs" />
<Compile Include="Filesystem\Path Class\Path.cs" />
<Compile Include="Filesystem\Path Class\Path.ValidationAndChecks.cs" />
<Compile Include="Filesystem\Path Class\Path.GetComponents.cs" />
<Compile Include="Filesystem\Path Class\Path.GetFinalPathNameByHandle.cs" />
<Compile Include="Filesystem\Path Class\Path.Combine.cs" />
<Compile Include="Filesystem\Path Class\Path.Constants.cs" />
<Compile Include="Filesystem\Path Class\Path.GetFullPath.cs" />
<Compile Include="Filesystem\Path Class\Path.SeparatorManipulation.cs" />
<Compile Include="Filesystem\Path Class\Path.UncPaths.cs" />
<Compile Include="Filesystem\Path Class\Path.ShortLongConversions.cs" />
<Compile Include="Filesystem\Path Class\Path.Temporary.cs" />
<Compile Include="Filesystem\Safe Handles\SafeCmConnectMachineHandle.cs" />
<Compile Include="Filesystem\Safe Handles\SafeEncryptedFileRawHandle.cs" />
<Compile Include="Filesystem\Safe Handles\SafeSetupDiClassDevsExHandle.cs" />
<Compile Include="Filesystem\Shell32Info.cs" />
<Compile Include="Filesystem\CopyMoveResult.cs" />
<Compile Include="Filesystem\Native Structures\FILE_BASIC_INFO.cs" />
<Compile Include="Filesystem\Native Structures\BY_HANDLE_FILE_INFORMATION.cs" />
<Compile Include="Filesystem\ChangeErrorMode.cs" />
<Compile Include="Filesystem\Native Structures\FILE_ID_BOTH_DIR_INFO.cs" />
<Compile Include="Filesystem\Native Structures\FILETIME.cs" />
<Compile Include="Filesystem\LinkTargetInfo.cs" />
<Compile Include="Filesystem\Enumerations\MoveOptions.cs" />
<Compile Include="Filesystem\Exceptions\NotAReparsePointException.cs" />
<Compile Include="Filesystem\Shell32.cs" />
<Compile Include="Filesystem\Native Structures\MountPointReparseBuffer.cs" />
<Compile Include="Filesystem\Native Structures\ReparseDataBufferHeader.cs" />
<Compile Include="Filesystem\Native Structures\SP_DEVINFO_DATA.cs" />
<Compile Include="Filesystem\Native Structures\SP_DEVICE_INTERFACE_DATA.cs" />
<Compile Include="Filesystem\Native Structures\SP_DEVICE_INTERFACE_DETAIL_DATA.cs" />
<Compile Include="Filesystem\Native Structures\SymbolicLinkReparseBuffer.cs" />
<Compile Include="Filesystem\Native Structures\WIN32_FILE_ATTRIBUTE_DATA.cs" />
<Compile Include="Filesystem\Native Structures\WIN32_FIND_DATA.cs" />
<Compile Include="Filesystem\Native Structures\WIN32_STREAM_ID.cs" />
<Compile Include="Network\DfsInfo.cs" />
<Compile Include="Network\DfsStorageInfo.cs" />
<Compile Include="Network\Enumerations\DfsPropertyFlags.cs" />
<Compile Include="Network\Enumerations\DfsTargetPriorityClass.cs" />
<Compile Include="Network\Enumerations\ShareInfoLevel.cs" />
<Compile Include="Network\Enumerations\ResourceUsage.cs" />
<Compile Include="Network\Enumerations\ResourceType.cs" />
<Compile Include="Network\Enumerations\ResourceScope.cs" />
<Compile Include="Network\Enumerations\ResourceDisplayType.cs" />
<Compile Include="Network\Enumerations\Connect.cs" />
<Compile Include="Network\Enumerations\DfsNamespaceFlavors.cs" />
<Compile Include="Network\Enumerations\DfsStorageStates.cs" />
<Compile Include="Network\Enumerations\DfsVolumeStates.cs" />
<Compile Include="Network\Enumerations\AccessPermissions.cs" />
<Compile Include="Network\Enumerations\ShareResourceTypes.cs" />
<Compile Include="Network\Enumerations\ShareType.cs" />
<Compile Include="Network\Host Class\EnumerateOpenResources.cs" />
<Compile Include="Network\Host Class\EnumerateDrives.cs" />
<Compile Include="Network\Host Class\ServerMessageBlock.cs" />
<Compile Include="Network\Host Class\DriveConnection.cs" />
<Compile Include="Network\Host Class\DistributedFileSystem.cs" />
<Compile Include="Network\Host Class\Connect.cs" />
<Compile Include="Network\Host Class\Host.cs" />
<Compile Include="Network\Native Methods\NativeMethods.WindowsNetworking.cs" />
<Compile Include="Network\Native Methods\NativeMethods.NetworkShareManagement.cs" />
<Compile Include="Network\Native Methods\NativeMethods.NetworkManagement.cs" />
<Compile Include="Network\Native Methods\NativeMethods.DistributedFileSystem.cs" />
<Compile Include="Network\Native Methods\NativeMethods.cs" />
<Compile Include="Network\Native Structures\DFS_INFO_9.cs" />
<Compile Include="Network\Native Structures\DFS_TARGET_PRIORITY.cs" />
<Compile Include="Network\Native Structures\DFS_STORAGE_INFO_1.cs" />
<Compile Include="Network\OpenConnectionInfo.cs" />
<Compile Include="Network\OpenResourceInfo.cs" />
<Compile Include="Network\ShareInfo.cs" />
<Compile Include="Network\Native Structures\NETRESOURCE.cs" />
<Compile Include="Network\Native Structures\FILE_INFO_3.cs" />
<Compile Include="Network\Native Structures\DFS_INFO_200.cs" />
<Compile Include="Network\Native Structures\DFS_INFO_300.cs" />
<Compile Include="Network\Native Structures\REMOTE_NAME_INFO.cs" />
<Compile Include="Network\Native Structures\CONNECTION_INFO_1.cs" />
<Compile Include="Network\Native Structures\SHARE_INFO_1005.cs" />
<Compile Include="Network\Native Structures\SHARE_INFO_1.cs" />
<Compile Include="Network\Native Structures\SHARE_INFO_2.cs" />
<Compile Include="Network\Native Structures\SHARE_INFO_503.cs" />
<Compile Include="OperatingSystem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="SafeGlobalMemoryBufferHandle.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="SafeNativeMemoryBufferHandle.cs" />
<Compile Include="Security\Crc64.cs" />
<Compile Include="Security\Enumerations\HashType.cs" />
<Compile Include="Security\Enumerations\ObjectType.cs" />
<Compile Include="Security\Enumerations\SecurityDescriptorControl.cs" />
<Compile Include="Security\Enumerations\SecurityInformation.cs" />
<Compile Include="Filesystem\Safe Handles\SafeLocalMemoryBufferHandle.cs" />
<Compile Include="Filesystem\Enumerations\SymbolicLinkTarget.cs" />
<Compile Include="Filesystem\SymbolicLinkTargetInfo.cs" />
<Compile Include="Filesystem\Enumerations\SymbolicLinkType.cs" />
<Compile Include="Filesystem\Exceptions\TransactionalConflictException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Filesystem\Exceptions\UnrecognizedReparsePointException.cs" />
<Compile Include="Filesystem\Exceptions\UnsupportedRemoteTransactionException.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Security\NativeMethods.cs" />
<Compile Include="Security\Crc32.cs" />
<Compile Include="Security\Privilege.cs" />
<Compile Include="Security\PrivilegeEnabler.cs" />
<Compile Include="Security\InternalPrivilegeEnabler.cs" />
<Compile Include="Filesystem\Exceptions\InvalidTransactionException.cs" />
<Compile Include="Filesystem\KernelTransaction.cs" />
<Compile Include="NativeError.cs" />
<Compile Include="Filesystem\Safe Handles\SafeFindFileHandle.cs" />
<Compile Include="Filesystem\Safe Handles\SafeFindVolumeMountPointHandle.cs" />
<Compile Include="Filesystem\Safe Handles\SafeFindVolumeHandle.cs" />
<Compile Include="Filesystem\Safe Handles\SafeKernelTransactionHandle.cs" />
<Compile Include="Filesystem\Exceptions\TransactionAlreadyAbortedException.cs" />
<Compile Include="Filesystem\Exceptions\TransactionAlreadyCommittedException.cs" />
<Compile Include="Filesystem\Exceptions\TransactionException.cs" />
<Compile Include="Filesystem\Volume.cs" />
<Compile Include="Filesystem\VolumeInfo.cs" />
<Compile Include="Security\Structures\Luid.cs" />
<Compile Include="Security\SecurityAttributes.cs" />
<Compile Include="Security\Structures\TokenPrivileges.cs" />
<Compile Include="Utils.cs" />
<Compile Include="Win32Errors.cs" />
<Compile Include="Filesystem\Native Methods\NativeMethods.VolumeManagement.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<Compile Include="Filesystem\Directory Class\Directory.EncryptedDirectoryRaw.cs" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ProjectExtensions>
<VisualStudio>
<UserProperties StartDate="20080813" AssemblyFileVersion="0" AssemblyVersion="0" Reset="1" />
</VisualStudio>
</ProjectExtensions>
</Project>

+ 7
- 0
AlphaFS/AlphaFS.ruleset View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="AlphaFS Ruleset" Description="This rule set contains all rules. Running this rule set may result in a large number of warnings being reported. Use this rule set to get a comprehensive picture of all issues in your code. This can help you decide which of the more focused rule sets are most appropriate to run for your projects." ToolsVersion="4.0">
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1300" Action="None" />
</Rules>
</RuleSet>

+ 35
- 0
AlphaFS/AssemblyVersionInfo.cs View File

@@ -0,0 +1,35 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;

[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AlphaFS")]
[assembly: AssemblyCopyright("© 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov")]
[assembly: AssemblyTrademark("")]

[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.0")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]


+ 138
- 0
AlphaFS/Filesystem/AlternateDataStreamInfo.cs View File

@@ -0,0 +1,138 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Text;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Information about an alternate data stream.</summary>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.EnumerateAlternateDataStreams"/>
public struct AlternateDataStreamInfo
{
#region Constructor

internal AlternateDataStreamInfo(string fullPath, NativeMethods.WIN32_FIND_STREAM_DATA findData) : this()
{
StreamName = ParseStreamName(findData.cStreamName);
Size = findData.StreamSize;
_fullPath = fullPath;
}

#endregion // Constructor

#region Public Properties

/// <summary>Gets the name of the alternate data stream.</summary>
/// <remarks>This value is an empty string for the default stream (:$DATA), and for any other data stream it contains the name of the stream.</remarks>
/// <value>The name of the stream.</value>
public string StreamName { get; private set; }

/// <summary>Gets the size of the stream.</summary>
public long Size { get; private set; }


private readonly string _fullPath;

/// <summary>Gets the full path to the stream.</summary>
/// <remarks>
/// This is a path in long path format that can be passed to <see cref="O:Alphaleonis.Win32.Filesystem.File.Open"/> to open the stream if
/// <see cref="PathFormat.FullPath"/> or
/// <see cref="PathFormat.LongFullPath"/> is specified.
/// </remarks>
/// <value>The full path to the stream in long path format.</value>
public string FullPath
{
get { return _fullPath + Path.StreamSeparator + StreamName + Path.StreamDataLabel; }
}

#endregion // Public Properties

#region Public Methods

/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode()
{
return StreamName.GetHashCode();
}

/// <summary>Indicates whether this instance and a specified object are equal.</summary>
/// <param name="obj">The object to compare with the current instance.</param>
/// <returns>
/// true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.
/// </returns>
public override bool Equals(object obj)
{
if (obj is AlternateDataStreamInfo)
{
AlternateDataStreamInfo other = (AlternateDataStreamInfo) obj;
return StreamName.Equals(other.StreamName, StringComparison.OrdinalIgnoreCase) && Size.Equals(other.Size);
}

return false;
}

/// <summary>Equality operator.</summary>
/// <param name="first">The first operand.</param>
/// <param name="second">The second operand.</param>
/// <returns>The result of the operation.</returns>
public static bool operator ==(AlternateDataStreamInfo first, AlternateDataStreamInfo second)
{
return first.Equals(second);
}

/// <summary>Inequality operator.</summary>
/// <param name="first">The first operand.</param>
/// <param name="second">The second operand.</param>
/// <returns>The result of the operation.</returns>
public static bool operator !=(AlternateDataStreamInfo first, AlternateDataStreamInfo second)
{
return !first.Equals(second);
}

#endregion // Public Methods

#region Private Methods

private static string ParseStreamName(string input)
{
if (input == null || input.Length < 2)
return string.Empty;

if (input[0] != Path.StreamSeparatorChar)
throw new ArgumentException(Resources.Invalid_Stream_Name);

var sb = new StringBuilder();
for (int i = 1; i < input.Length; i++)
{
if (input[i] == Path.StreamSeparatorChar)
break;

sb.Append(input[i]);
}

return sb.ToString();
}

#endregion // Private Methods
}
}

+ 650
- 0
AlphaFS/Filesystem/BackupFileStream.cs View File

@@ -0,0 +1,650 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using Alphaleonis.Win32.Security;
using Microsoft.Win32.SafeHandles;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;
using SecurityNativeMethods = Alphaleonis.Win32.Security.NativeMethods;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>The <see cref="BackupFileStream"/> provides access to data associated with a specific file or directory, including security information and alternative data streams, for backup and restore operations.</summary>
/// <remarks>This class uses the <see href="http://msdn.microsoft.com/en-us/library/aa362509(VS.85).aspx">BackupRead</see>,
/// <see href="http://msdn.microsoft.com/en-us/library/aa362510(VS.85).aspx">BackupSeek</see> and
/// <see href="http://msdn.microsoft.com/en-us/library/aa362511(VS.85).aspx">BackupWrite</see> functions from the Win32 API to provide access to the file or directory.
/// </remarks>
public sealed class BackupFileStream : Stream
{
#region Private Fields

private readonly bool _canRead;
private readonly bool _canWrite;
private readonly bool _processSecurity;

[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")]
private IntPtr _context = IntPtr.Zero;

#endregion // Private Fields

#region Construction and Destruction

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path and creation mode.</summary>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <remarks>The file will be opened for exclusive access for both reading and writing.</remarks>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(string path, FileMode mode)
: this(File.CreateFileCore(null, path, ExtendedFileAttributes.Normal, null, mode, FileSystemRights.Read | FileSystemRights.Write, FileShare.None, true, PathFormat.RelativePath), FileSystemRights.Read | FileSystemRights.Write)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode and access rights.</summary>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <remarks>The file will be opened for exclusive access.</remarks>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(string path, FileMode mode, FileSystemRights access)
: this(File.CreateFileCore(null, path, ExtendedFileAttributes.Normal, null, mode, access, FileShare.None, true, PathFormat.RelativePath), access)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode, access rights and sharing permission.</summary>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <param name="share">A <see cref="FileShare"/> constant that determines how the file will be shared by processes.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(string path, FileMode mode, FileSystemRights access, FileShare share)
: this(File.CreateFileCore(null, path, ExtendedFileAttributes.Normal, null, mode, access, share, true, PathFormat.RelativePath), access)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode, access rights and sharing permission, and additional file attributes.</summary>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <param name="share">A <see cref="FileShare"/> constant that determines how the file will be shared by processes.</param>
/// <param name="attributes">A <see cref="ExtendedFileAttributes"/> constant that specifies additional file attributes.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(string path, FileMode mode, FileSystemRights access, FileShare share, ExtendedFileAttributes attributes)
: this(File.CreateFileCore(null, path, attributes, null, mode, access, share, true, PathFormat.RelativePath), access)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode, access rights and sharing permission, additional file attributes, access control and audit security.</summary>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <param name="share">A <see cref="FileShare"/> constant that determines how the file will be shared by processes.</param>
/// <param name="attributes">A <see cref="ExtendedFileAttributes"/> constant that specifies additional file attributes.</param>
/// <param name="security">A <see cref="FileSecurity"/> constant that determines the access control and audit security for the file. This parameter This parameter may be <see langword="null"/>.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(string path, FileMode mode, FileSystemRights access, FileShare share, ExtendedFileAttributes attributes, FileSecurity security)
: this(File.CreateFileCore(null, path, attributes, security, mode, access, share, true, PathFormat.RelativePath), access)
{
}

#region Transactional

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path and creation mode.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <remarks>The file will be opened for exclusive access for both reading and writing.</remarks>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(KernelTransaction transaction, string path, FileMode mode)
: this(File.CreateFileCore(transaction, path, ExtendedFileAttributes.Normal, null, mode, FileSystemRights.Read | FileSystemRights.Write, FileShare.None, true, PathFormat.RelativePath), FileSystemRights.Read | FileSystemRights.Write)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode and access rights.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <remarks>The file will be opened for exclusive access.</remarks>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(KernelTransaction transaction, string path, FileMode mode, FileSystemRights access)
: this(File.CreateFileCore(transaction, path, ExtendedFileAttributes.Normal, null, mode, access, FileShare.None, true, PathFormat.RelativePath), access)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode, access rights and sharing permission.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <param name="share">A <see cref="FileShare"/> constant that determines how the file will be shared by processes.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(KernelTransaction transaction, string path, FileMode mode, FileSystemRights access, FileShare share)
: this(File.CreateFileCore(transaction, path, ExtendedFileAttributes.Normal, null, mode, access, share, true, PathFormat.RelativePath), access)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode, access rights and sharing permission, and additional file attributes.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <param name="share">A <see cref="FileShare"/> constant that determines how the file will be shared by processes.</param>
/// <param name="attributes">A <see cref="ExtendedFileAttributes"/> constant that specifies additional file attributes.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(KernelTransaction transaction, string path, FileMode mode, FileSystemRights access, FileShare share, ExtendedFileAttributes attributes)
: this(File.CreateFileCore(transaction, path, attributes, null, mode, access, share, true, PathFormat.RelativePath), access)
{
}

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class with the specified path, creation mode, access rights and sharing permission, additional file attributes, access control and audit security.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A relative or absolute path for the file that the current <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="mode">A <see cref="FileMode"/> constant that determines how to open or create the file.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that determines the access rights to use when creating access and audit rules for the file.</param>
/// <param name="share">A <see cref="FileShare"/> constant that determines how the file will be shared by processes.</param>
/// <param name="attributes">A <see cref="ExtendedFileAttributes"/> constant that specifies additional file attributes.</param>
/// <param name="security">A <see cref="FileSecurity"/> constant that determines the access control and audit security for the file. This parameter This parameter may be <see langword="null"/>.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SecurityCritical]
public BackupFileStream(KernelTransaction transaction, string path, FileMode mode, FileSystemRights access, FileShare share, ExtendedFileAttributes attributes, FileSecurity security)
: this(File.CreateFileCore(transaction, path, attributes, security, mode, access, share, true, PathFormat.RelativePath), access)
{
}

#endregion // Transacted


#region Stream

/// <summary>Initializes a new instance of the <see cref="BackupFileStream"/> class for the specified file handle, with the specified read/write permission.</summary>
/// <param name="handle">A file handle for the file that this <see cref="BackupFileStream"/> object will encapsulate.</param>
/// <param name="access">A <see cref="FileSystemRights"/> constant that gets the <see cref="CanRead"/> and <see cref="CanWrite"/> properties of the <see cref="BackupFileStream"/> object.</param>

[SecurityCritical]
public BackupFileStream(SafeFileHandle handle, FileSystemRights access)
{
if (handle == null)
throw new ArgumentNullException("handle", Resources.Handle_Is_Invalid);

if (handle.IsInvalid)
{
handle.Close();
throw new ArgumentException(Resources.Handle_Is_Invalid);
}

if (handle.IsClosed)
throw new ArgumentException(Resources.Handle_Is_Closed);


SafeFileHandle = handle;

_canRead = (access & FileSystemRights.ReadData) != 0;
_canWrite = (access & FileSystemRights.WriteData) != 0;
_processSecurity = true;
}

#endregion // Stream

#endregion // Construction and Destruction

#region NotSupportedException

/// <summary>When overridden in a derived class, gets the length in bytes of the stream.</summary>
/// <value>This method always throws an exception.</value>
/// <exception cref="NotSupportedException"/>
public override long Length
{
get { throw new NotSupportedException(Resources.No_Stream_Seeking_Support); }
}

/// <summary>When overridden in a derived class, gets or sets the position within the current stream.</summary>
/// <value>This method always throws an exception.</value>
/// <exception cref="NotSupportedException"/>
public override long Position
{
get { throw new NotSupportedException(Resources.No_Stream_Seeking_Support); }
set { throw new NotSupportedException(Resources.No_Stream_Seeking_Support); }
}


/// <summary>When overridden in a derived class, sets the position within the current stream.</summary>
/// <param name="offset">A byte offset relative to the <paramref name="origin"/> parameter.</param>
/// <param name="origin">A value of type <see cref="System.IO.SeekOrigin"/> indicating the reference point used to obtain the new position.</param>
/// <returns>The new position within the current stream.</returns>
/// <remarks><para><note><para>This stream does not support seeking using this method, and calling this method will always throw <see cref="NotSupportedException"/>. See <see cref="Skip"/> for an alternative way of seeking forward.</para></note></para></remarks>
/// <exception cref="NotSupportedException"/>
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException(Resources.No_Stream_Seeking_Support);
}


/// <summary>When overridden in a derived class, sets the length of the current stream.</summary>
/// <param name="value">The desired length of the current stream in bytes.</param>
/// <remarks>This method is not supported by the <see cref="BackupFileStream"/> class, and calling it will always generate a <see cref="NotSupportedException"/>.</remarks>
/// <exception cref="NotSupportedException"/>
public override void SetLength(long value)
{
throw new NotSupportedException(Resources.No_Stream_Seeking_Support);
}
#endregion // NotSupportedException

#region Properties
/// <summary>Gets a value indicating whether the current stream supports reading.</summary>
/// <returns><see langword="true"/> if the stream supports reading, <see langword="false"/> otherwise.</returns>
public override bool CanRead
{
get { return _canRead; }
}

/// <summary>Gets a value indicating whether the current stream supports seeking.</summary>
/// <returns>This method always returns <see langword="false"/>.</returns>
public override bool CanSeek
{
get { return false; }
}

/// <summary>Gets a value indicating whether the current stream supports writing.</summary>
/// <returns><see langword="true"/> if the stream supports writing, <see langword="false"/> otherwise.</returns>
public override bool CanWrite
{
get { return _canWrite; }
}

/// <summary>Gets a <see cref="SafeFileHandle"/> object that represents the operating system file handle for the file that the current <see cref="BackupFileStream"/> object encapsulates.</summary>
/// <value>A <see cref="SafeFileHandle"/> object that represents the operating system file handle for the file that
/// the current <see cref="BackupFileStream"/> object encapsulates.</value>
private SafeFileHandle SafeFileHandle { get; set; }

#endregion // Properties

#region Methods

/// <summary>Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.</summary>
/// <remarks>This method will not backup the access-control list (ACL) data for the file or directory.</remarks>
/// <param name="buffer">
/// An array of bytes. When this method returns, the buffer contains the specified byte array with the values between
/// <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the
/// current source.
/// </param>
/// <param name="offset">
/// The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream.
/// </param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
/// <returns>
/// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not
/// currently available, or zero (0) if the end of the stream has been reached.
/// </returns>
///
/// <exception cref="System.ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="System.ArgumentOutOfRangeException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="ObjectDisposedException"/>
public override int Read(byte[] buffer, int offset, int count)
{
return Read(buffer, offset, count, false);
}

/// <summary>When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.</summary>
/// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values
/// between <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the current source.</param>
/// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream.</param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
/// <param name="processSecurity">Indicates whether the function will backup the access-control list (ACL) data for the file or directory.</param>
/// <returns>
/// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not
/// currently available, or zero (0) if the end of the stream has been reached.
/// </returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentOutOfRangeException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="ObjectDisposedException"/>
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
[SecurityCritical]
public int Read(byte[] buffer, int offset, int count, bool processSecurity)
{
if (buffer == null)
throw new ArgumentNullException("buffer");

if (!CanRead)
throw new NotSupportedException("Stream does not support reading");

if (offset + count > buffer.Length)
throw new ArgumentException("The sum of offset and count is larger than the size of the buffer.");

if (offset < 0)
throw new ArgumentOutOfRangeException("offset", offset, Resources.Negative_Offset);

if (count < 0)
throw new ArgumentOutOfRangeException("count", count, Resources.Negative_Count);


using (var safeBuffer = new SafeGlobalMemoryBufferHandle(count))
{
uint numberOfBytesRead;

if (!NativeMethods.BackupRead(SafeFileHandle, safeBuffer, (uint)safeBuffer.Capacity, out numberOfBytesRead, false, processSecurity, ref _context))
NativeError.ThrowException(Marshal.GetLastWin32Error());

// See File.GetAccessControlCore(): .CopyTo() does not work there?
safeBuffer.CopyTo(buffer, offset, count);

return (int)numberOfBytesRead;
}
}


/// <summary>Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.</summary>
/// <overloads>
/// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
/// </overloads>
/// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.</param>
/// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.</param>
/// <param name="count">The number of bytes to be written to the current stream.</param>
/// <exception cref="ArgumentException"/>
/// <exception cref="System.ArgumentNullException"/>
/// <exception cref="System.ArgumentOutOfRangeException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="ObjectDisposedException"/>
/// <remarks>This method will not process the access-control list (ACL) data for the file or directory.</remarks>
public override void Write(byte[] buffer, int offset, int count)
{
Write(buffer, offset, count, false);
}

/// <summary>When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.</summary>
/// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.</param>
/// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.</param>
/// <param name="count">The number of bytes to be written to the current stream.</param>
/// <param name="processSecurity">Specifies whether the function will restore the access-control list (ACL) data for the file or directory.
/// If this is <see langword="true"/> you need to specify <see cref="FileSystemRights.TakeOwnership"/> and <see cref="FileSystemRights.ChangePermissions"/> access when
/// opening the file or directory handle. If the handle does not have those access rights, the operating system denies
/// access to the ACL data, and ACL data restoration will not occur.</param>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="System.ArgumentOutOfRangeException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="ObjectDisposedException"/>
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
[SecurityCritical]
public void Write(byte[] buffer, int offset, int count, bool processSecurity)
{
if (buffer == null)
throw new ArgumentNullException("buffer");

if (offset < 0)
throw new ArgumentOutOfRangeException("offset", offset, Resources.Negative_Offset);

if (count < 0)
throw new ArgumentOutOfRangeException("count", count, Resources.Negative_Count);

if (offset + count > buffer.Length)
throw new ArgumentException(Resources.Buffer_Not_Large_Enough);


using (var safeBuffer = new SafeGlobalMemoryBufferHandle(count))
{
safeBuffer.CopyFrom(buffer, offset, count);

uint bytesWritten;

if (!NativeMethods.BackupWrite(SafeFileHandle, safeBuffer, (uint)safeBuffer.Capacity, out bytesWritten, false, processSecurity, ref _context))
NativeError.ThrowException(Marshal.GetLastWin32Error());
}
}


/// <summary>Clears all buffers for this stream and causes any buffered data to be written to the underlying device.</summary>
public override void Flush()
{
if (!NativeMethods.FlushFileBuffers(SafeFileHandle))
NativeError.ThrowException(Marshal.GetLastWin32Error());
}


/// <summary>Skips ahead the specified number of bytes from the current stream.</summary>
/// <remarks><para>This method represents the Win32 API implementation of <see href="http://msdn.microsoft.com/en-us/library/aa362509(VS.85).aspx">BackupSeek</see>.</para>
/// <para>
/// Applications use the <see cref="Skip"/> method to skip portions of a data stream that cause errors. This function does not
/// seek across stream headers. For example, this function cannot be used to skip the stream name. If an application
/// attempts to seek past the end of a substream, the function fails, the return value indicates the actual number of bytes
/// the function seeks, and the file position is placed at the start of the next stream header.
/// </para>
/// </remarks>
/// <param name="bytes">The number of bytes to skip.</param>
/// <returns>The number of bytes actually skipped.</returns>
[SecurityCritical]
public long Skip(long bytes)
{
uint lowSought, highSought;
if (!NativeMethods.BackupSeek(SafeFileHandle, NativeMethods.GetLowOrderDword(bytes), NativeMethods.GetHighOrderDword(bytes), out lowSought, out highSought, ref _context))
{
int lastError = Marshal.GetLastWin32Error();

// Error Code 25 indicates a seek error, we just skip that here.
if (lastError != Win32Errors.NO_ERROR && lastError != Win32Errors.ERROR_SEEK)
NativeError.ThrowException(lastError);
}

return NativeMethods.ToLong(highSought, lowSought);
}


/// <summary>Gets a <see cref="FileSecurity"/> object that encapsulates the access control list (ACL) entries for the file described by the current <see cref="BackupFileStream"/> object.</summary>
/// <exception cref="IOException"/>
/// <returns>
/// A <see cref="FileSecurity"/> object that encapsulates the access control list (ACL) entries for the file described by the current
/// <see cref="BackupFileStream"/> object.
/// </returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
[SecurityCritical]
public FileSecurity GetAccessControl()
{
IntPtr pSidOwner, pSidGroup, pDacl, pSacl;
SafeGlobalMemoryBufferHandle pSecurityDescriptor;

uint lastError = SecurityNativeMethods.GetSecurityInfo(SafeFileHandle, ObjectType.FileObject,
SecurityInformation.Group | SecurityInformation.Owner | SecurityInformation.Label | SecurityInformation.Dacl | SecurityInformation.Sacl,
out pSidOwner, out pSidGroup, out pDacl, out pSacl, out pSecurityDescriptor);

try
{
if (lastError != Win32Errors.ERROR_SUCCESS)
NativeError.ThrowException((int)lastError);

if (pSecurityDescriptor != null && pSecurityDescriptor.IsInvalid)
{
pSecurityDescriptor.Close();
throw new IOException(Resources.Returned_Invalid_Security_Descriptor);
}

uint length = SecurityNativeMethods.GetSecurityDescriptorLength(pSecurityDescriptor);

byte[] managedBuffer = new byte[length];

// .CopyTo() does not work there?
if (pSecurityDescriptor != null)
pSecurityDescriptor.CopyTo(managedBuffer, 0, (int) length);


var fs = new FileSecurity();
fs.SetSecurityDescriptorBinaryForm(managedBuffer);

return fs;
}
finally
{
if (pSecurityDescriptor != null)
pSecurityDescriptor.Close();
}
}


/// <summary>Applies access control list (ACL) entries described by a <see cref="FileSecurity"/> object to the file described by the current <see cref="BackupFileStream"/> object.</summary>
/// <param name="fileSecurity">A <see cref="FileSecurity"/> object that describes an ACL entry to apply to the current file.</param>
[SecurityCritical]
public void SetAccessControl(ObjectSecurity fileSecurity)
{
File.SetAccessControlCore(null, SafeFileHandle, fileSecurity, AccessControlSections.All, PathFormat.LongFullPath);
}


/// <summary>Prevents other processes from changing the <see cref="BackupFileStream"/> while permitting read access.</summary>
/// <param name="position">The beginning of the range to lock. The value of this parameter must be equal to or greater than zero (0).</param>
/// <param name="length">The range to be locked.</param>
/// <exception cref="ArgumentOutOfRangeException"/>
/// <exception cref="ObjectDisposedException"/>
[SecurityCritical]
public void Lock(long position, long length)
{
if (position < 0)
throw new ArgumentOutOfRangeException("position", position, Resources.Unlock_Position_Negative);

if (length < 0)
throw new ArgumentOutOfRangeException("length", length, Resources.Negative_Lock_Length);

if (!NativeMethods.LockFile(SafeFileHandle, NativeMethods.GetLowOrderDword(position), NativeMethods.GetHighOrderDword(position), NativeMethods.GetLowOrderDword(length), NativeMethods.GetHighOrderDword(length)))
NativeError.ThrowException(Marshal.GetLastWin32Error());
}


/// <summary>Allows access by other processes to all or part of a file that was previously locked.</summary>
/// <param name="position">The beginning of the range to unlock.</param>
/// <param name="length">The range to be unlocked.</param>
/// <exception cref="ArgumentOutOfRangeException"/>
/// <exception cref="ArgumentOutOfRangeException"/>
/// <exception cref="ObjectDisposedException"/>
[SecurityCritical]
public void Unlock(long position, long length)
{
if (position < 0)
throw new ArgumentOutOfRangeException("position", position, Resources.Unlock_Position_Negative);

if (length < 0)
throw new ArgumentOutOfRangeException("length", length, Resources.Negative_Lock_Length);

if (!NativeMethods.UnlockFile(SafeFileHandle, NativeMethods.GetLowOrderDword(position), NativeMethods.GetHighOrderDword(position), NativeMethods.GetLowOrderDword(length), NativeMethods.GetHighOrderDword(length)))
NativeError.ThrowException(Marshal.GetLastWin32Error());
}


/// <summary>Reads a stream header from the current <see cref="BackupFileStream"/>.</summary>
/// <returns>The stream header read from the current <see cref="BackupFileStream"/>, or <see langword="null"/> if the end-of-file
/// was reached before the required number of bytes of a header could be read.</returns>
/// <exception cref="IOException"/>
/// <remarks>The stream must be positioned at where an actual header starts for the returned object to represent valid
/// information.</remarks>
[SecurityCritical]
public BackupStreamInfo ReadStreamInfo()
{
var sizeOf = Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID));

using (var hBuf = new SafeGlobalMemoryBufferHandle(sizeOf))
{
uint numberOfBytesRead;

if (!NativeMethods.BackupRead(SafeFileHandle, hBuf, (uint) sizeOf, out numberOfBytesRead, false, _processSecurity, ref _context))
NativeError.ThrowException();


if (numberOfBytesRead == 0)
return null;


if (numberOfBytesRead < sizeOf)
throw new IOException(Resources.Read_Incomplete_Header);

var streamID = hBuf.PtrToStructure<NativeMethods.WIN32_STREAM_ID>(0);

uint nameLength = (uint) Math.Min(streamID.dwStreamNameSize, hBuf.Capacity);


if (!NativeMethods.BackupRead(SafeFileHandle, hBuf, nameLength, out numberOfBytesRead, false, _processSecurity, ref _context))
NativeError.ThrowException();

string name = hBuf.PtrToStringUni(0, (int) nameLength/2);

return new BackupStreamInfo(streamID, name);
}
}

#endregion // Methods

#region Disposable Members

/// <summary>Releases the unmanaged resources used by the <see cref="System.IO.Stream"/> and optionally releases the managed resources.</summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
protected override void Dispose(bool disposing)
{
// If one of the constructors previously threw an exception,
// than the object hasn't been initialized properly and call from finalize will fail.

if (SafeFileHandle != null && !SafeFileHandle.IsInvalid)
{
if (_context != IntPtr.Zero)
{
try
{
uint temp;

// MSDN: To release the memory used by the data structure, call BackupRead with the bAbort parameter set to TRUE when the backup operation is complete.
if (!NativeMethods.BackupRead(SafeFileHandle, new SafeGlobalMemoryBufferHandle(), 0, out temp, true, false, ref _context))
NativeError.ThrowException(Marshal.GetLastWin32Error());
}
finally
{
_context = IntPtr.Zero;
SafeFileHandle.Close();
}
}
}

base.Dispose(disposing);
}

/// <summary>Releases unmanaged resources and performs other cleanup operations before the <see cref="BackupFileStream"/> is reclaimed by garbage collection.</summary>
~BackupFileStream()
{
Dispose(false);
}

#endregion // Disposable Members
}
}

+ 84
- 0
AlphaFS/Filesystem/BackupStreamInfo.cs View File

@@ -0,0 +1,84 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>The <see cref="BackupStreamInfo"/> structure contains stream header data.</summary>
/// <seealso cref="BackupFileStream"/>
public sealed class BackupStreamInfo
{
#region Private Fields

private readonly long m_size;
private readonly string m_name;
private readonly BackupStreamType m_streamType;
private readonly StreamAttributes m_attributes;

#endregion

#region Constructor

/// <summary>Initializes a new instance of the <see cref="BackupStreamInfo"/> class.</summary>
/// <param name="streamID">The stream ID.</param>
/// <param name="name">The name.</param>
internal BackupStreamInfo(NativeMethods.WIN32_STREAM_ID streamID, string name)
{
m_name = name;
m_size = (long) streamID.Size;
m_attributes = streamID.dwStreamAttributes;
m_streamType = streamID.dwStreamId;
}

#endregion

#region Public Properties

/// <summary>Gets the size of the data in the substream, in bytes.</summary>
/// <value>The size of the data in the substream, in bytes.</value>
public long Size
{
get { return m_size; }
}

/// <summary>Gets a string that specifies the name of the alternative data stream.</summary>
/// <value>A string that specifies the name of the alternative data stream.</value>
public string Name
{
get { return m_name; }
}

/// <summary>Gets the type of the data in the stream.</summary>
/// <value>The type of the data in the stream.</value>
public BackupStreamType StreamType
{
get { return m_streamType; }
}

/// <summary>Gets the attributes of the data to facilitate cross-operating system transfer.</summary>
/// <value>Attributes of the data to facilitate cross-operating system transfer.</value>
public StreamAttributes Attributes
{
get { return m_attributes; }
}

#endregion // Public Properties
}
}

+ 177
- 0
AlphaFS/Filesystem/ByHandleFileInfo.cs View File

@@ -0,0 +1,177 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
#region ByHandleFileInfo

/// <summary>Contains information that the GetFileInformationByHandle function retrieves.</summary>
[SerializableAttribute]
[SecurityCritical]
public sealed class ByHandleFileInfo
{
#region Constructor

internal ByHandleFileInfo(NativeMethods.BY_HANDLE_FILE_INFORMATION fibh)
{
CreationTimeUtc = DateTime.FromFileTimeUtc(fibh.ftCreationTime);
LastAccessTimeUtc = DateTime.FromFileTimeUtc(fibh.ftLastAccessTime);
LastWriteTimeUtc = DateTime.FromFileTimeUtc(fibh.ftLastWriteTime);

Attributes = fibh.dwFileAttributes;
FileIndex = NativeMethods.ToLong(fibh.nFileIndexHigh, fibh.nFileIndexLow);
FileSize = NativeMethods.ToLong(fibh.nFileSizeHigh, fibh.nFileSizeLow);
NumberOfLinks = fibh.nNumberOfLinks;
VolumeSerialNumber = fibh.dwVolumeSerialNumber;
}

#endregion // Constructor

#region Properties

#region Attributes

/// <summary>Gets the file attributes.</summary>
/// <value>The file attributes.</value>
public FileAttributes Attributes { get; private set; }

#endregion // Attributes

#region CreationTime

/// <summary>Gets the time this entry was created.</summary>
/// <value>The time this entry was created.</value>
public DateTime CreationTime
{
get { return CreationTimeUtc.ToLocalTime(); }
}

#endregion // CreationTime

#region CreationTimeUtc

/// <summary>Gets the time, in coordinated universal time (UTC), this entry was created.</summary>
/// <value>The time, in coordinated universal time (UTC), this entry was created.</value>
public DateTime CreationTimeUtc { get; private set; }

#endregion // CreationTimeUtc

#region LastAccessTime

/// <summary>Gets the time this entry was last accessed.
/// For a file, the structure specifies the last time that a file is read from or written to.
/// For a directory, the structure specifies when the directory is created.
/// For both files and directories, the specified date is correct, but the time of day is always set to midnight.
/// If the underlying file system does not support the last access time, this member is zero (0).
/// </summary>
/// <value>The time this entry was last accessed.</value>
public DateTime LastAccessTime
{
get { return LastAccessTimeUtc.ToLocalTime(); }
}

#endregion // LastAccessTime

#region LastAccessTimeUtc

/// <summary>Gets the time, in coordinated universal time (UTC), this entry was last accessed.
/// For a file, the structure specifies the last time that a file is read from or written to.
/// For a directory, the structure specifies when the directory is created.
/// For both files and directories, the specified date is correct, but the time of day is always set to midnight.
/// If the underlying file system does not support the last access time, this member is zero (0).
/// </summary>
/// <value>The time, in coordinated universal time (UTC), this entry was last accessed.</value>
public DateTime LastAccessTimeUtc { get; private set; }

#endregion // LastAccessTimeUtc

#region LastWriteTime

/// <summary>Gets the time this entry was last modified.
/// For a file, the structure specifies the last time that a file is written to.
/// For a directory, the structure specifies when the directory is created.
/// If the underlying file system does not support the last access time, this member is zero (0).
/// </summary>
/// <value>The time this entry was last modified.</value>
public DateTime LastWriteTime
{
get { return LastWriteTimeUtc.ToLocalTime(); }
}

#endregion // LastWriteTime

#region LastWriteTimeUtc

/// <summary>Gets the time, in coordinated universal time (UTC), this entry was last modified.
/// For a file, the structure specifies the last time that a file is written to.
/// For a directory, the structure specifies when the directory is created.
/// If the underlying file system does not support the last access time, this member is zero (0).
/// </summary>
/// <value>The time, in coordinated universal time (UTC), this entry was last modified.</value>
public DateTime LastWriteTimeUtc { get; private set; }

#endregion // LastWriteTimeUtc

#region VolumeSerialNumber

/// <summary>Gets the serial number of the volume that contains a file.</summary>
/// <value>The serial number of the volume that contains a file.</value>
public int VolumeSerialNumber { get; private set; }

#endregion // VolumeSerialNumber

#region FileSize

/// <summary>Gets the size of the file.</summary>
/// <value>The size of the file.</value>
public long FileSize { get; private set; }

#endregion // FileSize

#region NumberOfLinks

/// <summary>Gets the number of links to this file. For the FAT file system this member is always 1. For the NTFS file system, it can be more than 1.</summary>
/// <value>The number of links to this file. </value>
public int NumberOfLinks { get; private set; }

#endregion // NumberOfLinks

#region FileIndex

/// <summary>
/// Gets the unique identifier associated with the file. The identifier and the volume serial number uniquely identify a
/// file on a single computer. To determine whether two open handles represent the same file, combine the identifier
/// and the volume serial number for each file and compare them.
/// </summary>
/// <value>The unique identifier of the file.</value>
public long FileIndex { get; private set; }

#endregion // FileIndex

#endregion // Properties
}

#endregion // ByHandleFileInfo
}

+ 56
- 0
AlphaFS/Filesystem/ChangeErrorMode.cs View File

@@ -0,0 +1,56 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Controls whether the system will handle the specified types of serious errors or whether the process will handle them.</summary>
/// <remarks>Minimum supported client: Windows 2000 Professional</remarks>
/// <remarks>Minimum supported server: Windows 2000 Server</remarks>
public sealed class ChangeErrorMode : IDisposable
{
private readonly ErrorMode _oldMode;

/// <summary>ChangeErrorMode is for the Win32 SetThreadErrorMode() method, used to suppress possible pop-ups.</summary>
/// <param name="mode">One of the <see cref="ErrorMode"/> values.</param>
public ChangeErrorMode(ErrorMode mode)
{
if (IsAtLeastWindows7)
SetThreadErrorMode(mode, out _oldMode);
else
_oldMode = SetErrorMode(mode);
}

void IDisposable.Dispose()
{
ErrorMode oldMode;

if (IsAtLeastWindows7)
SetThreadErrorMode(_oldMode, out oldMode);
else
SetErrorMode(_oldMode);
}
}
}
}

+ 28
- 0
AlphaFS/Filesystem/CopyMoveProgressRoutine.cs View File

@@ -0,0 +1,28 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Callback used by CopyFileXxx and MoveFileXxx to report progress about the copy/move operation.</summary>
public delegate CopyMoveProgressResult CopyMoveProgressRoutine(long totalFileSize, long totalBytesTransferred, long streamSize, long streamBytesTransferred, int streamNumber, CopyMoveProgressCallbackReason callbackReason, object userData);
}

+ 82
- 0
AlphaFS/Filesystem/CopyMoveResult.cs View File

@@ -0,0 +1,82 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Class for CopyMoveResult that contains the results for the Copy or Move action.</summary>
public sealed class CopyMoveResult
{
/// <summary>Create a CopyMoveResult class instance for the Copy or Move action.</summary>
/// <param name="source">Indicates the source file or directory.</param>
/// <param name="destination">Indicates the destination file or directory.</param>
/// <param name="isCanceled">Indicates if the action was canceled.</param>
/// <param name="errorCode">The error code encountered during the Copy or Move action.</param>
public CopyMoveResult(string source, string destination, bool isCanceled, int errorCode)
{
Source = source;
Destination = destination;
IsCanceled = isCanceled;
ErrorCode = errorCode;
}


/// <summary>The error code encountered during the Copy or Move action.</summary>
/// <value>0 (zero) indicates success.</value>
public int ErrorCode { get; internal set; }


/// <summary>The error message from the <see cref="ErrorCode"/> that was encountered during the Copy or Move action.</summary>
/// <value>A message describing the error.</value>
[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]
public string ErrorMessage
{
get { return new Win32Exception(ErrorCode).Message; }
}


/// <summary>When true indicates that the Copy or Move action was canceled.</summary>
/// <value><see langword="true"/> when the Copy/Move action was canceled. Otherwise <see langword="false"/>.</value>
public bool IsCanceled { get; internal set; }


/// <summary>Indicates the source file or directory.</summary>
public string Source { get; private set; }


/// <summary>Indicates the destination file or directory.</summary>
public string Destination { get; private set; }


/// <summary>The total number of folders copied.</summary>
public long TotalFolders { get; internal set; }


/// <summary>The total number of files copied.</summary>
public long TotalFiles { get; internal set; }


/// <summary>The total number of bytes copied.</summary>
public long TotalBytes { get; internal set; }
}
}

+ 459
- 0
AlphaFS/Filesystem/Device.cs View File

@@ -0,0 +1,459 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using Alphaleonis.Win32.Network;
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;
using System.Text;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Provides static methods to retrieve device resource information from a local or remote host.</summary>
public static class Device
{
#region EnumerateDevices

/// <summary>Enumerates all available devices on the local host.</summary>
/// <returns><see cref="IEnumerable{DeviceInfo}"/> instances of type <see cref="DeviceGuid"/> from the local host.</returns>
/// <param name="deviceGuid">One of the <see cref="DeviceGuid"/> devices.</param>
[SecurityCritical]
public static IEnumerable<DeviceInfo> EnumerateDevices(DeviceGuid deviceGuid)
{
return EnumerateDevices(null, deviceGuid);
}

/// <summary>Enumerates all available devices of type <see cref="DeviceGuid"/> on the local or remote host.</summary>
/// <returns><see cref="IEnumerable{DeviceInfo}"/> instances of type <see cref="DeviceGuid"/> for the specified <paramref name="hostName"/>.</returns>
/// <param name="hostName">The name of the local or remote host on which the device resides. <see langword="null"/> refers to the local host.</param>
/// <param name="deviceGuid">One of the <see cref="DeviceGuid"/> devices.</param>
[SecurityCritical]
public static IEnumerable<DeviceInfo> EnumerateDevices(string hostName, DeviceGuid deviceGuid)
{
return EnumerateDevicesCore(null, hostName, deviceGuid);
}

#endregion // EnumerateDevices

#region Internal Methods

#region EnumerateDevicesCore

/// <summary>Enumerates all available devices on the local or remote host.</summary>
[SecurityCritical]
internal static IEnumerable<DeviceInfo> EnumerateDevicesCore(SafeHandle safeHandle, string hostName, DeviceGuid deviceInterfaceGuid)
{
var callerHandle = safeHandle != null;
var deviceGuid = new Guid(Utils.GetEnumDescription(deviceInterfaceGuid));


// CM_Connect_Machine()
// MSDN Note: Beginning in Windows 8 and Windows Server 2012 functionality to access remote machines has been removed.
// You cannot access remote machines when running on these versions of Windows.
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff537948%28v=vs.85%29.aspx

SafeCmConnectMachineHandle safeMachineHandle;
var lastError = NativeMethods.CM_Connect_Machine(Path.LocalToUncCore(Host.GetUncName(hostName), false, false, false), out safeMachineHandle);

if (safeMachineHandle != null && safeMachineHandle.IsInvalid)
{
safeMachineHandle.Close();
NativeError.ThrowException(lastError, Resources.Handle_Is_Invalid);
}

using (safeMachineHandle)
{
// Start at the "Root" of the device tree of the specified machine.
if (!callerHandle)
safeHandle = NativeMethods.SetupDiGetClassDevsEx(ref deviceGuid, IntPtr.Zero, IntPtr.Zero,
NativeMethods.SetupDiGetClassDevsExFlags.Present |
NativeMethods.SetupDiGetClassDevsExFlags.DeviceInterface,
IntPtr.Zero, hostName, IntPtr.Zero);

if (safeHandle != null && safeHandle.IsInvalid)
{
safeHandle.Close();
NativeError.ThrowException(Marshal.GetLastWin32Error(), Resources.Handle_Is_Invalid);
}


try
{
uint memberInterfaceIndex = 0;
var deviceInterfaceData = CreateDeviceInterfaceDataInstance();

// Start enumerating Device Interfaces.
while (NativeMethods.SetupDiEnumDeviceInterfaces(safeHandle, IntPtr.Zero, ref deviceGuid, memberInterfaceIndex++, ref deviceInterfaceData))
{
lastError = Marshal.GetLastWin32Error();
if (lastError != Win32Errors.NO_ERROR)
NativeError.ThrowException(lastError, hostName);


var deviceInfoData = CreateDeviceInfoDataInstance();
var deviceInterfaceDetailData = GetDeviceInterfaceDetailDataInstance(safeHandle, deviceInterfaceData, deviceInfoData);

// Get device interace details.
if (!NativeMethods.SetupDiGetDeviceInterfaceDetail(safeHandle, ref deviceInterfaceData, ref deviceInterfaceDetailData, NativeMethods.DefaultFileBufferSize, IntPtr.Zero, ref deviceInfoData))
{
lastError = Marshal.GetLastWin32Error();
if (lastError != Win32Errors.NO_ERROR)
NativeError.ThrowException(lastError, hostName);
}

// Create DeviceInfo instance.
// Set DevicePath property of DeviceInfo instance.
var deviceInfo = new DeviceInfo(hostName) { DevicePath = deviceInterfaceDetailData.DevicePath };


// Current InstanceId is at the "USBSTOR" level, so we
// need up "move up" one level to get to the "USB" level.
uint ptrPrevious;

// CM_Get_Parent_Ex()
// Note: Using this function to access remote machines is not supported
// beginning with Windows 8 and Windows Server 2012, as this functionality has been removed.
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff538615%28v=vs.85%29.aspx

lastError = NativeMethods.CM_Get_Parent_Ex(out ptrPrevious, deviceInfoData.DevInst, 0, safeMachineHandle);
if (lastError != Win32Errors.CR_SUCCESS)
NativeError.ThrowException(lastError, hostName);


// Now we get the InstanceID of the USB level device.
using (var safeBuffer = new SafeGlobalMemoryBufferHandle(NativeMethods.DefaultFileBufferSize))
{
// CM_Get_Device_ID_Ex()
// Note: Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012,
// as this functionality has been removed.
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff538411%28v=vs.85%29.aspx

lastError = NativeMethods.CM_Get_Device_ID_Ex(deviceInfoData.DevInst, safeBuffer, (uint)safeBuffer.Capacity, 0, safeMachineHandle);
if (lastError != Win32Errors.CR_SUCCESS)
NativeError.ThrowException(lastError, hostName);

// Add to instance.
deviceInfo.InstanceId = safeBuffer.PtrToStringUni();
}

#region Get Registry Properties

using (var safeBuffer = new SafeGlobalMemoryBufferHandle(NativeMethods.DefaultFileBufferSize))
{
uint regType;
string dataString;
var safeBufferCapacity = (uint) safeBuffer.Capacity;


if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.BaseContainerId, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
{
dataString = safeBuffer.PtrToStringUni();
if (!Utils.IsNullOrWhiteSpace(dataString))
deviceInfo.BaseContainerId = new Guid(dataString);
}

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.ClassGuid, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
{
dataString = safeBuffer.PtrToStringUni();
if (!Utils.IsNullOrWhiteSpace(dataString))
deviceInfo.ClassGuid = new Guid(dataString);
}


if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.Class, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.Class = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.CompatibleIds, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.CompatibleIds = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.DeviceDescription, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.DeviceDescription = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.Driver, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.Driver = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.EnumeratorName, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.EnumeratorName = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.FriendlyName, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.FriendlyName = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.HardwareId, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.HardwareId = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.LocationInformation, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.LocationInformation = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.LocationPaths, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.LocationPaths = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.Manufacturer, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.Manufacturer = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.PhysicalDeviceObjectName, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.PhysicalDeviceObjectName = safeBuffer.PtrToStringUni();

if (NativeMethods.SetupDiGetDeviceRegistryProperty(safeHandle, ref deviceInfoData, NativeMethods.SetupDiGetDeviceRegistryPropertyEnum.Service, out regType, safeBuffer, safeBufferCapacity, IntPtr.Zero))
deviceInfo.Service = safeBuffer.PtrToStringUni();
}

#endregion // Get Registry Properties

yield return deviceInfo;

// Get new structure instance.
deviceInterfaceData = CreateDeviceInterfaceDataInstance();
}
}
finally
{
// Handle is ours, dispose.
if (!callerHandle && safeHandle != null)
safeHandle.Close();
}
}
}

#endregion // EnumerateDevicesCore

#region GetLinkTargetInfoCore

/// <summary>Get information about the target of a mount point or symbolic link on an NTFS file system.</summary>
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Disposing is controlled.")]
[SecurityCritical]
internal static LinkTargetInfo GetLinkTargetInfoCore(SafeFileHandle safeHandle)
{
// Start with a large buffer to prevent a 2nd call.
// MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16384
uint bytesReturned = 4*NativeMethods.DefaultFileBufferSize;
using (var safeBuffer = new SafeGlobalMemoryBufferHandle((int) bytesReturned))
{
while (true)
{
// DeviceIoControlMethod.Buffered = 0,
// DeviceIoControlFileDevice.FileSystem = 9
// FsctlGetReparsePoint = (DeviceIoControlFileDevice.FileSystem << 16) | (42 << 2) | DeviceIoControlMethod.Buffered | (0 << 14)

if (!NativeMethods.DeviceIoControl(safeHandle, ((9 << 16) | (42 << 2) | 0 | (0 << 14)), IntPtr.Zero, 0, safeBuffer, (uint) safeBuffer.Capacity, out bytesReturned, IntPtr.Zero))
{
var lastError = Marshal.GetLastWin32Error();
switch ((uint) lastError)
{
case Win32Errors.ERROR_MORE_DATA:
case Win32Errors.ERROR_INSUFFICIENT_BUFFER:
if (safeBuffer.Capacity < bytesReturned)
{
safeBuffer.Close();
break;
}

NativeError.ThrowException(lastError);
break;
}
}
else
break;
}


var marshalReparseBuffer = (int) Marshal.OffsetOf(typeof(NativeMethods.ReparseDataBufferHeader), "data");

var header = safeBuffer.PtrToStructure<NativeMethods.ReparseDataBufferHeader>(0);

var dataOffset = (int) (marshalReparseBuffer + (header.ReparseTag == ReparsePointTag.MountPoint
? Marshal.OffsetOf(typeof (NativeMethods.MountPointReparseBuffer), "data")
: Marshal.OffsetOf(typeof (NativeMethods.SymbolicLinkReparseBuffer), "data")).ToInt64());

var dataBuffer = new byte[bytesReturned - dataOffset];


switch (header.ReparseTag)
{
case ReparsePointTag.MountPoint:
var mountPoint = safeBuffer.PtrToStructure<NativeMethods.MountPointReparseBuffer>(marshalReparseBuffer);

safeBuffer.CopyTo(dataOffset, dataBuffer, 0, dataBuffer.Length);

return new LinkTargetInfo(
Encoding.Unicode.GetString(dataBuffer, mountPoint.SubstituteNameOffset, mountPoint.SubstituteNameLength),
Encoding.Unicode.GetString(dataBuffer, mountPoint.PrintNameOffset, mountPoint.PrintNameLength));


case ReparsePointTag.SymLink:
var symLink = safeBuffer.PtrToStructure<NativeMethods.SymbolicLinkReparseBuffer>(marshalReparseBuffer);

safeBuffer.CopyTo(dataOffset, dataBuffer, 0, dataBuffer.Length);

return new SymbolicLinkTargetInfo(
Encoding.Unicode.GetString(dataBuffer, symLink.SubstituteNameOffset, symLink.SubstituteNameLength),
Encoding.Unicode.GetString(dataBuffer, symLink.PrintNameOffset, symLink.PrintNameLength), symLink.Flags);


default:
throw new UnrecognizedReparsePointException();
}
}
}

#endregion // GetLinkTargetInfoCore

#region ToggleCompressionCore

/// <summary>Sets the NTFS compression state of a file or directory on a volume whose file system supports per-file and per-directory compression.</summary>
/// <param name="isFolder">Specifies that <paramref name="path"/> is a file or directory.</param>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a folder or file to compress or decompress.</param>
/// <param name="compress"><see langword="true"/> = compress, <see langword="false"/> = decompress</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>

[SecurityCritical]
internal static void ToggleCompressionCore(bool isFolder, KernelTransaction transaction, string path, bool compress, PathFormat pathFormat)
{
using (var handle = File.CreateFileCore(transaction, path, isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.Normal, null, FileMode.Open, FileSystemRights.Modify, FileShare.None, true, pathFormat))
{
// DeviceIoControlMethod.Buffered = 0,
// DeviceIoControlFileDevice.FileSystem = 9
// FsctlSetCompression = (DeviceIoControlFileDevice.FileSystem << 16) | (16 << 2) | DeviceIoControlMethod.Buffered | ((FileAccess.Read | FileAccess.Write) << 14)

// 0 = Decompress, 1 = Compress.
InvokeIoControlUnknownSize(handle, ((9 << 16) | (16 << 2) | 0 | ((uint)(FileAccess.Read | FileAccess.Write) << 14)), (compress) ? 1 : 0);
}
}

#endregion // ToggleCompressionCore


#region Private

#region CreateDeviceInfoDataInstance

/// <summary>Builds a DeviceInfo Data structure.</summary>
/// <returns>An initialized NativeMethods.SP_DEVINFO_DATA instance.</returns>
[SecurityCritical]
private static NativeMethods.SP_DEVINFO_DATA CreateDeviceInfoDataInstance()
{
var did = new NativeMethods.SP_DEVINFO_DATA();
did.cbSize = (uint) Marshal.SizeOf(did);

return did;
}

#endregion // CreateDeviceInfoDataInstance

#region CreateDeviceInterfaceDataInstance

/// <summary>Builds a Device Interface Data structure.</summary>
/// <returns>An initialized NativeMethods.SP_DEVICE_INTERFACE_DATA instance.</returns>
[SecurityCritical]
private static NativeMethods.SP_DEVICE_INTERFACE_DATA CreateDeviceInterfaceDataInstance()
{
var did = new NativeMethods.SP_DEVICE_INTERFACE_DATA();
did.cbSize = (uint) Marshal.SizeOf(did);

return did;
}

#endregion // CreateDeviceInterfaceDataInstance

#region GetDeviceInterfaceDetailDataInstance

/// <summary>Builds a Device Interface Detail Data structure.</summary>
/// <returns>An initialized NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA instance.</returns>
[SecurityCritical]
private static NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA GetDeviceInterfaceDetailDataInstance(SafeHandle safeHandle, NativeMethods.SP_DEVICE_INTERFACE_DATA deviceInterfaceData, NativeMethods.SP_DEVINFO_DATA deviceInfoData)
{
// Build a Device Interface Detail Data structure.
var didd = new NativeMethods.SP_DEVICE_INTERFACE_DETAIL_DATA
{
cbSize = (IntPtr.Size == 4) ? (uint) (Marshal.SystemDefaultCharSize + 4) : 8
};

// Get device interace details.
if (!NativeMethods.SetupDiGetDeviceInterfaceDetail(safeHandle, ref deviceInterfaceData, ref didd, NativeMethods.DefaultFileBufferSize, IntPtr.Zero, ref deviceInfoData))
{
var lastError = Marshal.GetLastWin32Error();
if (lastError != Win32Errors.NO_ERROR)
NativeError.ThrowException(lastError);
}

return didd;
}

#endregion // GetDeviceInterfaceDetailDataInstance

#region InvokeIoControlUnknownSize

/// <summary>Repeatedly invokes InvokeIoControl with the specified input until enough memory has been allocated.</summary>
[SecurityCritical]
private static byte[] InvokeIoControlUnknownSize<TV>(SafeFileHandle handle, uint controlCode, TV input, uint increment = 128)
{
byte[] output;
uint bytesReturned;

var inputSize = (uint) Marshal.SizeOf(input);
var outputLength = increment;

do
{
output = new byte[outputLength];
if (!NativeMethods.DeviceIoControl(handle, controlCode, input, inputSize, output, outputLength, out bytesReturned, IntPtr.Zero))
{
var lastError = Marshal.GetLastWin32Error();
switch ((uint)lastError)
{
case Win32Errors.ERROR_MORE_DATA:
case Win32Errors.ERROR_INSUFFICIENT_BUFFER:
outputLength += increment;
break;

default:
NativeError.ThrowException(lastError);
break;
}
}
else
break;

} while (true);

// Return the result
if (output.Length == bytesReturned)
return output;

var res = new byte[bytesReturned];
Array.Copy(output, res, bytesReturned);

return res;
}

#endregion // InvokeIoControlUnknownSize

#endregion // Private

#endregion // Internal Methods
}
}

+ 141
- 0
AlphaFS/Filesystem/DeviceInfo.cs View File

@@ -0,0 +1,141 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using Alphaleonis.Win32.Network;
using System;
using System.Collections.Generic;
using System.Security;
using System.Security.Permissions;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Provides access to information of a device, on a local or remote host.</summary>
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
[SerializableAttribute]
[SecurityCritical]
public sealed class DeviceInfo
{
#region Constructors
/// <summary>Initializes a DeviceInfo class.</summary>
[SecurityCritical]
public DeviceInfo()
{
HostName = Host.GetUncName();
}

/// <summary>Initializes a DeviceInfo class.</summary>
/// <param name="host">The DNS or NetBIOS name of the remote server. <see langword="null"/> refers to the local host.</param>
[SecurityCritical]
public DeviceInfo(string host)
{
HostName = Host.GetUncName(host).Replace(Path.UncPrefix, string.Empty);
}

#endregion // Constructors


#region Methods

/// <summary>Enumerates all available devices on the local host.</summary>
/// <param name="deviceGuid">One of the <see cref="DeviceGuid"/> devices.</param>
/// <returns><see cref="IEnumerable{DeviceInfo}"/> instances of type <see cref="DeviceGuid"/> from the local host.</returns>
[SecurityCritical]
public IEnumerable<DeviceInfo> EnumerateDevices(DeviceGuid deviceGuid)
{
return Device.EnumerateDevicesCore(null, HostName, deviceGuid);
}
#endregion // Methods


#region Properties

/// <summary>Represents the <see cref="Guid"/> value of the base container identifier (ID) .The Windows Plug and Play (PnP) manager assigns this value to the device node (devnode).</summary>
public Guid BaseContainerId { get; internal set; }


/// <summary>Represents the name of the device setup class that a device instance belongs to.</summary>
public string Class { get; internal set; }


/// <summary>Represents the <see cref="Guid"/> of the device setup class that a device instance belongs to.</summary>
public Guid ClassGuid { get; internal set; }


/// <summary>Represents the list of compatible identifiers for a device instance.</summary>
public string CompatibleIds { get; internal set; }


/// <summary>Represents a description of a device instance.</summary>
public string DeviceDescription { get; internal set; }


/// <summary>The device interface path.</summary>
public string DevicePath { get; internal set; }


/// <summary>Represents the registry entry name of the driver key for a device instance.</summary>
public string Driver { get; internal set; }


/// <summary>Represents the name of the enumerator for a device instance.</summary>
public string EnumeratorName { get; internal set; }


/// <summary>Represents the friendly name of a device instance.</summary>
public string FriendlyName { get; internal set; }


/// <summary>Represents the list of hardware identifiers for a device instance.</summary>
public string HardwareId { get; internal set; }


/// <summary>The host name that was passed to the class constructor.</summary>
public string HostName { get; internal set; }


/// <summary>Gets the instance Id of the device.</summary>
public string InstanceId { get; internal set; }


/// <summary>Represents the bus-specific physical location of a device instance.</summary>
public string LocationInformation { get; internal set; }


/// <summary>Represents the location of a device instance in the device tree.</summary>
public string LocationPaths { get; internal set; }


/// <summary>Represents the name of the manufacturer of a device instance.</summary>
public string Manufacturer { get; internal set; }


/// <summary>Encapsulates the physical device location information provided by a device's firmware to Windows.</summary>
public string PhysicalDeviceObjectName { get; internal set; }


/// <summary>Represents the name of the service that is installed for a device instance.</summary>
public string Service { get; internal set; }

#endregion // Properties
}
}

+ 484
- 0
AlphaFS/Filesystem/Directory Class/Directory.Compression.cs View File

@@ -0,0 +1,484 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region Compress

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <remarks>This will only compress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to compress.</param>
[SecurityCritical]
public static void Compress(string path)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <remarks>This will only compress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Compress(string path, PathFormat pathFormat)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, pathFormat);
}



/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static void Compress(string path, DirectoryEnumerationOptions options)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Compress(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, true, pathFormat);
}
#region Transactional

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <remarks>This will only compress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to compress.</param>
[SecurityCritical]
public static void CompressTransacted(KernelTransaction transaction, string path)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <remarks>This will only compress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void CompressTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, pathFormat);
}



/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static void CompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void CompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, true, pathFormat);
}

#endregion // Transactional

#endregion // Compress

#region Decompress

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <remarks>This will only decompress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decompress.</param>
[SecurityCritical]
public static void Decompress(string path)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <remarks>This will only decompress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decompress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Decompress(string path, PathFormat pathFormat)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, pathFormat);
}



/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decompress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static void Decompress(string path, DirectoryEnumerationOptions options)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decompress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Decompress(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, false, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <remarks>This will only decompress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to decompress.</param>
[SecurityCritical]
public static void DecompressTransacted(KernelTransaction transaction, string path)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <remarks>This will only decompress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to decompress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DecompressTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, pathFormat);
}

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to decompress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static void DecompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to decompress.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DecompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, false, pathFormat);
}

#endregion // Transactional

#endregion // Decompress

#region DisableCompression

/// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method disables the directory-compression attribute. It will not decompress the current contents of the directory. However, newly created files and directories will be uncompressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path to a directory to decompress.</param>
[SecurityCritical]
public static void DisableCompression(string path)
{
Device.ToggleCompressionCore(true, null, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method disables the directory-compression attribute. It will not decompress the current contents of the directory. However, newly created files and directories will be uncompressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path to a directory to decompress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DisableCompression(string path, PathFormat pathFormat)
{
Device.ToggleCompressionCore(true, null, path, false, pathFormat);
}



/// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method disables the directory-compression attribute. It will not decompress the current contents of the directory. However, newly created files and directories will be uncompressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory to decompress.</param>
[SecurityCritical]
public static void DisableCompressionTransacted(KernelTransaction transaction, string path)
{
Device.ToggleCompressionCore(true, transaction, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method disables the directory-compression attribute. It will not decompress the current contents of the directory. However, newly created files and directories will be uncompressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <param name="path">A path to a directory to decompress.</param>
[SecurityCritical]
public static void DisableCompressionTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
Device.ToggleCompressionCore(true, transaction, path, false, pathFormat);
}
#endregion // DisableCompression

#region EnableCompression

/// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method enables the directory-compression attribute. It will not compress the current contents of the directory. However, newly created files and directories will be compressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path to a directory to compress.</param>
[SecurityCritical]
public static void EnableCompression(string path)
{
Device.ToggleCompressionCore(true, null, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method enables the directory-compression attribute. It will not compress the current contents of the directory. However, newly created files and directories will be compressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path to a directory to compress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void EnableCompression(string path, PathFormat pathFormat)
{
Device.ToggleCompressionCore(true, null, path, true, pathFormat);
}



/// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method enables the directory-compression attribute. It will not compress the current contents of the directory. However, newly created files and directories will be compressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory to compress.</param>
[SecurityCritical]
public static void EnableCompressionTransacted(KernelTransaction transaction, string path)
{
Device.ToggleCompressionCore(true, transaction, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
/// <remarks>This method enables the directory-compression attribute. It will not compress the current contents of the directory. However, newly created files and directories will be compressed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory to compress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void EnableCompressionTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
Device.ToggleCompressionCore(true, transaction, path, true, pathFormat);
}
#endregion // EnableCompression

#region Internal Methods

/// <summary>Compress/decompress Non-/Transacted files/directories.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path that describes a directory to compress.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="compress"><see langword="true"/> compress, when <see langword="false"/> decompress.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static void CompressDecompressCore(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, bool compress, PathFormat pathFormat)
{
string pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

// Process directories and files.
foreach (var fsei in EnumerateFileSystemEntryInfosCore<string>(transaction, pathLp, searchPattern, options | DirectoryEnumerationOptions.AsLongPath, PathFormat.LongFullPath))
Device.ToggleCompressionCore(true, transaction, fsei, compress, PathFormat.LongFullPath);

// Compress the root directory, the given path.
Device.ToggleCompressionCore(true, transaction, pathLp, compress, PathFormat.LongFullPath);
}

#endregion // Internal Methods
}
}

+ 969
- 0
AlphaFS/Filesystem/Directory Class/Directory.CopyMove.cs View File

@@ -0,0 +1,969 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region Copy

// .NET: Directory class does not contain the Copy() method.
// Mimic .NET File.Copy() methods.

/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath)
{
return CopyMoveCore(null, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}



/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, bool overwrite)
{
return CopyMoveCore(null, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, bool overwrite, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}


#region Transactional

/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is not allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}



/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, bool overwrite)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies an existing directory to a new directory. Overwriting a directory of the same name is allowed.
/// <remarks>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="overwrite"><see langword="true"/> if the destination directory should ignoring the read-only and hidden attributes and overwrite; otherwise, <see langword="false"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, bool overwrite, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, null, pathFormat);
}

#endregion // Transactional

#endregion // Copy


#region Copy (CopyOptions)

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, null, null, null, pathFormat);
}

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Copy(string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
}


#region Transactional

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, null, null, null, pathFormat);
}



/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Copies a directory and its contents to a new location, <see cref="CopyOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult CopyTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, copyOptions, null, progressHandler, userProgressData, null, pathFormat);
}
#endregion // Transactional

#endregion // Copy (CopyOptions)


#region Move

#region .NET

/// <summary>Moves a file or a directory and its contents to a new location.
/// <remarks>
/// <para>This method does not work across disk volumes.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location.
/// <remarks>
/// <para>This method does not work across disk volumes.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, pathFormat);
}


#region Transactional

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location.
/// <remarks>
/// <para>This method does not work across disk volumes.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location.
/// <remarks>
/// <para>This method does not work across disk volumes.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, MoveOptions.None, null, null, null, pathFormat);
}
#endregion // Transactional

#endregion // Move


#region Move (MoveOptions)

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, null, null, null, pathFormat);
}



/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult Move(string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(null, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, pathFormat);
}


#region Transactional

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, null, null, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, null, null, null, pathFormat);
}



/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Moves a file or a directory and its contents to a new location, <see cref="MoveOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <returns>A <see cref="CopyMoveResult"/> class with the status of the Move action.</returns>
/// <remarks>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static CopyMoveResult MoveTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
return CopyMoveCore(transaction, sourcePath, destinationPath, null, moveOptions, progressHandler, userProgressData, null, pathFormat);
}

#endregion // Transactional

#endregion // Move (MoveOptions)


#region Internal Methods

/// <summary>Copy/move a Non-/Transacted file or directory including its children to a new location,
/// <see cref="CopyOptions"/> or <see cref="MoveOptions"/> can be specified,
/// and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>You cannot use the Move method to overwrite an existing file, unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.ReplaceExisting"/>.</para>
/// <para>Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an IOException.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with the status of the Copy or Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory path.</param>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the file has been copied/moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="copyMoveResult"></param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SecurityCritical]
internal static CopyMoveResult CopyMoveCore(KernelTransaction transaction, string sourcePath, string destinationPath, CopyOptions? copyOptions, MoveOptions? moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, CopyMoveResult copyMoveResult, PathFormat pathFormat)
{
#region Setup

var sourcePathLp = sourcePath;
var destinationPathLp = destinationPath;
var skipPathChecks = pathFormat == PathFormat.LongFullPath;


if (!skipPathChecks)
{
Path.CheckSupportedPathFormat(sourcePathLp, true, true);
Path.CheckSupportedPathFormat(destinationPathLp, true, true);


// MSDN: .NET 4+ Trailing spaces are removed from the end of the path parameters before moving the directory.
// TrimEnd() is also applied for AlphaFS implementation of method Directory.Copy(), .NET does not have this method.

const GetFullPathOptions fullPathOptions = GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator;

sourcePathLp = Path.GetExtendedLengthPathCore(transaction, sourcePath, pathFormat, fullPathOptions);
destinationPathLp = Path.GetExtendedLengthPathCore(transaction, destinationPath, pathFormat, fullPathOptions);


// MSDN: .NET3.5+: IOException: The sourceDirName and destDirName parameters refer to the same file or directory.
if (sourcePathLp.Equals(destinationPathLp, StringComparison.OrdinalIgnoreCase))
NativeError.ThrowException(Win32Errors.ERROR_SAME_DRIVE, destinationPathLp);
}


var emulateMove = false;

// Determine Copy or Move action.
var isCopy = File.DetermineIsCopy(copyOptions, moveOptions);
var isMove = !isCopy;

var cmr = copyMoveResult ?? new CopyMoveResult(sourcePathLp, destinationPathLp, false, (int) Win32Errors.ERROR_SUCCESS);


// Execute once only.
if (!skipPathChecks && isMove)
{
// Compare the root part of both paths.
var equalRootPaths = Path.GetPathRoot(sourcePathLp, false).Equals(Path.GetPathRoot(destinationPathLp, false), StringComparison.OrdinalIgnoreCase);

// Method Volume.IsSameVolume() returns true when both paths refer to the same volume, even if one of the paths is a UNC path.
// For example, src = C:\TempSrc and dst = \\localhost\C$\TempDst
var isSameVolume = equalRootPaths || Volume.IsSameVolume(sourcePathLp, destinationPathLp);

isMove = isSameVolume && equalRootPaths;

if (!isMove)
{
// A Move() can be emulated by using Copy() and Delete(), but only if the CopyAllowed flag is set.
isMove = ((MoveOptions) moveOptions & MoveOptions.CopyAllowed) != 0;

// MSDN: .NET3.5+: IOException: An attempt was made to move a directory to a different volume.
if (!isMove)
NativeError.ThrowException(Win32Errors.ERROR_NOT_SAME_DEVICE, sourcePathLp, destinationPathLp);
}


// The NativeMethod.MoveFileXxx() methods fail when:
// - A directory is being moved;
// - One of the paths is a UNC path, even though both paths refer to the same volume.
// For example, src = C:\TempSrc and dst = \\localhost\C$\TempDst
if (isMove)
{
var srcIsUncPath = Path.IsUncPathCore(sourcePathLp, false, false);
var dstIsUncPath = Path.IsUncPathCore(destinationPathLp, false, false);

isMove = srcIsUncPath && dstIsUncPath;
if (!isMove)
isMove = !srcIsUncPath && !dstIsUncPath;
}


isMove = isMove && isSameVolume && equalRootPaths;


// Emulate Move().
if (!isMove)
{
emulateMove = true;

moveOptions = null;

isCopy = true;
copyOptions = CopyOptions.FailIfExists;
}
}
#endregion // Setup


#region Copy

if (isCopy)
{
CreateDirectoryCore(transaction, destinationPathLp, null, null, false, PathFormat.LongFullPath);

foreach (var fsei in EnumerateFileSystemEntryInfosCore<FileSystemEntryInfo>(transaction, sourcePathLp, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath))
{
var newDestinationPathLp = Path.CombineCore(false, destinationPathLp, fsei.FileName);

cmr = fsei.IsDirectory
? CopyMoveCore(transaction, fsei.LongFullPath, newDestinationPathLp, copyOptions, moveOptions, progressHandler, userProgressData, cmr, PathFormat.LongFullPath)
: File.CopyMoveCore(false, transaction, fsei.LongFullPath, newDestinationPathLp, false, copyOptions, moveOptions, progressHandler, userProgressData, cmr, PathFormat.LongFullPath);


if (cmr.ErrorCode == Win32Errors.ERROR_SUCCESS)
{
if (fsei.IsDirectory)
cmr.TotalFolders++;
else
{
cmr.TotalFiles++;
cmr.TotalBytes += fsei.FileSize;
}


// Remove the folder or file when copying was successful.
if (emulateMove)
{
if (fsei.IsDirectory)
DeleteDirectoryCore(fsei, transaction, null, true, true, false, true, PathFormat.LongFullPath);
else
File.DeleteFileCore(transaction, fsei.LongFullPath, true, PathFormat.LongFullPath);
}
}


if (cmr.IsCanceled)
return cmr;
}


// Remove source folder.
if (emulateMove && cmr.ErrorCode == Win32Errors.ERROR_SUCCESS)
DeleteDirectoryCore(null, transaction, sourcePathLp, true, true, false, true, PathFormat.LongFullPath);
}

#endregion // Copy


#region Move

else
{
// MoveOptions.ReplaceExisting: This value cannot be used if lpNewFileName or lpExistingFileName names a directory.
if (((MoveOptions) moveOptions & MoveOptions.ReplaceExisting) != 0)
DeleteDirectoryCore(null, transaction, destinationPathLp, true, true, false, true, PathFormat.LongFullPath);


// Moves a file or directory, including its children.
// Copies an existing directory, including its children to a new directory.
cmr = File.CopyMoveCore(true, transaction, sourcePathLp, destinationPathLp, false, copyOptions, moveOptions, progressHandler, userProgressData, cmr, PathFormat.LongFullPath);
}

#endregion // Move


return cmr;
}

#endregion // Internal Methods
}
}

+ 195
- 0
AlphaFS/Filesystem/Directory Class/Directory.CountFileSystemObjects.cs View File

@@ -0,0 +1,195 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory path.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjects(string path, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath).Count();
}

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory path.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static long CountFileSystemObjects(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat).Count();
}



/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjects(string path, string searchPattern, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath).Count();
}

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static long CountFileSystemObjects(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat).Count();
}

#region Transactional

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjectsTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath).Count();
}

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static long CountFileSystemObjectsTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat).Count();
}



/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjectsTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath).Count();
}

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static long CountFileSystemObjectsTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat).Count();
}
#endregion // Transactional
}
}

+ 800
- 0
AlphaFS/Filesystem/Directory Class/Directory.CreateDirectory.cs View File

@@ -0,0 +1,800 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Creates all directories and subdirectories in the specified path unless they already exist.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path)
{
return CreateDirectoryCore(null, path, null, null, false, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, null, null, false, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, bool compress)
{
return CreateDirectoryCore(null, path, null, null, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, null, null, compress, pathFormat);
}



/// <summary>Creates all the directories in the specified path, unless the already exist, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity)
{
return CreateDirectoryCore(null, path, null, directorySecurity, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, null, directorySecurity, false, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity, bool compress)
{
return CreateDirectoryCore(null, path, null, directorySecurity, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, null, directorySecurity, compress, pathFormat);
}



/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath)
{
return CreateDirectoryCore(null, path, templatePath, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, templatePath, null, false, pathFormat);
}



/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, bool compress)
{
return CreateDirectoryCore(null, path, templatePath, null, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, templatePath, null, compress, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, DirectorySecurity directorySecurity)
{
return CreateDirectoryCore(null, path, templatePath, directorySecurity, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, DirectorySecurity directorySecurity, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, templatePath, directorySecurity, false, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, DirectorySecurity directorySecurity, bool compress)
{
return CreateDirectoryCore(null, path, templatePath, directorySecurity, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectory(string path, string templatePath, DirectorySecurity directorySecurity, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(null, path, templatePath, directorySecurity, compress, pathFormat);
}

#region Transactional

/// <summary>Creates all directories and subdirectories in the specified path unless they already exist.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path)
{
return CreateDirectoryCore(transaction, path, null, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, null, null, false, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, bool compress)
{
return CreateDirectoryCore(transaction, path, null, null, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, null, null, compress, pathFormat);
}



/// <summary>Creates all the directories in the specified path, unless the already exist, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, DirectorySecurity directorySecurity)
{
return CreateDirectoryCore(transaction, path, null, directorySecurity, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, DirectorySecurity directorySecurity, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, null, directorySecurity, false, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, DirectorySecurity directorySecurity, bool compress)
{
return CreateDirectoryCore(transaction, path, null, directorySecurity, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path, applying the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, DirectorySecurity directorySecurity, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, null, directorySecurity, compress, pathFormat);
}



/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath)
{
return CreateDirectoryCore(transaction, path, templatePath, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, templatePath, null, false, pathFormat);
}



/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, bool compress)
{
return CreateDirectoryCore(transaction, path, templatePath, null, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates a new directory, with the attributes of a specified template directory.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, templatePath, null, compress, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, DirectorySecurity directorySecurity)
{
return CreateDirectoryCore(transaction, path, templatePath, directorySecurity, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, DirectorySecurity directorySecurity, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, templatePath, directorySecurity, false, pathFormat);
}



/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, DirectorySecurity directorySecurity, bool compress)
{
return CreateDirectoryCore(transaction, path, templatePath, directorySecurity, compress, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Creates all the directories in the specified path of a specified template directory and applies the specified Windows security.</summary>
/// <returns>An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static DirectoryInfo CreateDirectoryTransacted(KernelTransaction transaction, string path, string templatePath, DirectorySecurity directorySecurity, bool compress, PathFormat pathFormat)
{
return CreateDirectoryCore(transaction, path, templatePath, directorySecurity, compress, pathFormat);
}

#endregion // Transactional
#region Internal Methods

/// <summary>Creates a new directory with the attributes of a specified template directory (if one is specified).
/// If the underlying file system supports security on files and directories, the function applies the specified security descriptor to the new directory.
/// The new directory retains the other attributes of the specified template directory.
/// </summary>
/// <returns>
/// <para>Returns an object that represents the directory at the specified path.</para>
/// <para>This object is returned regardless of whether a directory at the specified path already exists.</para>
/// </returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory. May be <see langword="null"/> to indicate that no template should be used.</param>
/// <param name="directorySecurity">The <see cref="DirectorySecurity"/> access control to apply to the directory, may be null.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SecurityCritical]
internal static DirectoryInfo CreateDirectoryCore(KernelTransaction transaction, string path, string templatePath, ObjectSecurity directorySecurity, bool compress, PathFormat pathFormat)
{
bool fullCheck = pathFormat == PathFormat.RelativePath;

Path.CheckSupportedPathFormat(path, fullCheck, fullCheck);
Path.CheckSupportedPathFormat(templatePath, fullCheck, fullCheck);

string pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);

// Return DirectoryInfo instance if the directory specified by path already exists.
if (File.ExistsCore(true, transaction, pathLp, PathFormat.LongFullPath))
return new DirectoryInfo(transaction, pathLp, PathFormat.LongFullPath);

// MSDN: .NET 3.5+: IOException: The directory specified by path is a file or the network name was not found.
if (File.ExistsCore(false, transaction, pathLp, PathFormat.LongFullPath))
NativeError.ThrowException(Win32Errors.ERROR_ALREADY_EXISTS, pathLp);


string templatePathLp = Utils.IsNullOrWhiteSpace(templatePath)
? null
: Path.GetExtendedLengthPathCore(transaction, templatePath, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);

#region Construct Full Path

string longPathPrefix = Path.IsUncPathCore(path, false, false) ? Path.LongPathUncPrefix : Path.LongPathPrefix;
path = Path.GetRegularPathCore(pathLp, GetFullPathOptions.None, false);

int length = path.Length;
if (length >= 2 && Path.IsDVsc(path[length - 1], false))
--length;

int rootLength = Path.GetRootLength(path, false);
if (length == 2 && Path.IsDVsc(path[1], false))
throw new ArgumentException(Resources.Cannot_Create_Directory, path);


// Check if directories are missing.
var list = new Stack<string>(100);

if (length > rootLength)
{
for (int index = length - 1; index >= rootLength; --index)
{
string path1 = path.Substring(0, index + 1);
string path2 = longPathPrefix + path1.TrimStart('\\');

if (!File.ExistsCore(true, transaction, path2, PathFormat.LongFullPath))
list.Push(path2);

while (index > rootLength && !Path.IsDVsc(path[index], false))
--index;
}
}

#endregion // Construct Full Path


// Directory security.
using (var securityAttributes = new Security.NativeMethods.SecurityAttributes(directorySecurity))
{
// Create the directory paths.
while (list.Count > 0)
{
string folderLp = list.Pop();

// In the ANSI version of this function, the name is limited to 248 characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2013-01-13: MSDN confirms LongPath usage.

if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista
? (templatePathLp == null
? NativeMethods.CreateDirectory(folderLp, securityAttributes)
: NativeMethods.CreateDirectoryEx(templatePathLp, folderLp, securityAttributes))
: NativeMethods.CreateDirectoryTransacted(templatePathLp, folderLp, securityAttributes, transaction.SafeHandle)))
{
int lastError = Marshal.GetLastWin32Error();

switch ((uint) lastError)
{
// MSDN: .NET 3.5+: If the directory already exists, this method does nothing.
// MSDN: .NET 3.5+: IOException: The directory specified by path is a file.
case Win32Errors.ERROR_ALREADY_EXISTS:
if (File.ExistsCore(false, transaction, pathLp, PathFormat.LongFullPath))
NativeError.ThrowException(lastError, pathLp);

if (File.ExistsCore(false, transaction, folderLp, PathFormat.LongFullPath))
NativeError.ThrowException(Win32Errors.ERROR_PATH_NOT_FOUND, folderLp);
break;

case Win32Errors.ERROR_BAD_NET_NAME:
NativeError.ThrowException(lastError, pathLp);
break;

case Win32Errors.ERROR_DIRECTORY:
// MSDN: .NET 3.5+: NotSupportedException: path contains a colon character (:) that is not part of a drive label ("C:\").
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.Unsupported_Path_Format, path));

default:
NativeError.ThrowException(lastError, folderLp);
break;
}
}

else if (compress)
Device.ToggleCompressionCore(true, transaction, folderLp, true, PathFormat.LongFullPath);
}

return new DirectoryInfo(transaction, pathLp, PathFormat.LongFullPath);
}
}

#endregion // Internal Methods
}
}

+ 126
- 0
AlphaFS/Filesystem/Directory Class/Directory.CurrentDirectory.cs View File

@@ -0,0 +1,126 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>
/// Gets the current working directory of the application.
/// <para>
/// MSDN: Multithreaded applications and shared library code should not use the GetCurrentDirectory function and should avoid using relative path names.
/// The current directory state written by the SetCurrentDirectory function is stored as a global variable in each process,
/// therefore multithreaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value.
/// <para>This limitation also applies to the SetCurrentDirectory and GetFullPathName functions. The exception being when the application is guaranteed to be running in a single thread,
/// for example parsing file names from the command line argument string in the main thread prior to creating any additional threads.</para>
/// <para>Using relative path names in multithreaded applications or shared library code can yield unpredictable results and is not supported.</para>
/// </para>
/// </summary>
/// <returns>The path of the current working directory without a trailing directory separator.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate"), SecurityCritical]
public static string GetCurrentDirectory()
{
var nameBuffer = new StringBuilder(NativeMethods.MaxPathUnicode);

// SetCurrentDirectory()
// In the ANSI version of this function, the name is limited to 248 characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2016-09-29: MSDN does not confirm LongPath usage but a Unicode version of this function exists.

var folderNameLength = NativeMethods.GetCurrentDirectory((uint) nameBuffer.Capacity, nameBuffer);
var lastError = Marshal.GetLastWin32Error();

if (folderNameLength == 0)
NativeError.ThrowException(lastError);

if (folderNameLength > NativeMethods.MaxPathUnicode)
throw new PathTooLongException(string.Format(CultureInfo.InvariantCulture, "Path is greater than {0} characters: {1}", NativeMethods.MaxPathUnicode, folderNameLength));

return nameBuffer.ToString();
}


/// <summary>
/// Sets the application's current working directory to the specified directory.
/// <para>
/// MSDN: Multithreaded applications and shared library code should not use the GetCurrentDirectory function and should avoid using relative path names.
/// The current directory state written by the SetCurrentDirectory function is stored as a global variable in each process,
/// therefore multithreaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value.
/// <para>This limitation also applies to the SetCurrentDirectory and GetFullPathName functions. The exception being when the application is guaranteed to be running in a single thread,
/// for example parsing file names from the command line argument string in the main thread prior to creating any additional threads.</para>
/// <para>Using relative path names in multithreaded applications or shared library code can yield unpredictable results and is not supported.</para>
/// </para>
/// </summary>
/// <param name="path">The path to which the current working directory is set.</param>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
[SecurityCritical]
public static void SetCurrentDirectory(string path)
{
SetCurrentDirectory(path, PathFormat.RelativePath);
}


/// <summary>
/// Sets the application's current working directory to the specified directory.
/// <para>
/// MSDN: Multithreaded applications and shared library code should not use the GetCurrentDirectory function and should avoid using relative path names.
/// The current directory state written by the SetCurrentDirectory function is stored as a global variable in each process,
/// therefore multithreaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value.
/// <para>This limitation also applies to the SetCurrentDirectory and GetFullPathName functions. The exception being when the application is guaranteed to be running in a single thread,
/// for example parsing file names from the command line argument string in the main thread prior to creating any additional threads.</para>
/// <para>Using relative path names in multithreaded applications or shared library code can yield unpredictable results and is not supported.</para>
/// </para>
/// </summary>
/// <param name="path">The path to which the current working directory is set.</param>
/// <param name="pathFormat">Indicates the format of the path parameter.</param>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
[SecurityCritical]
public static void SetCurrentDirectory(string path, PathFormat pathFormat)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");

var fullCheck = pathFormat == PathFormat.RelativePath;
Path.CheckSupportedPathFormat(path, fullCheck, fullCheck);
var pathLp = Path.GetExtendedLengthPathCore(null, path, pathFormat, GetFullPathOptions.AddTrailingDirectorySeparator);

if (pathFormat == PathFormat.FullPath)
pathLp = Path.GetRegularPathCore(pathLp, GetFullPathOptions.None, false);


// SetCurrentDirectory()
// In the ANSI version of this function, the name is limited to 248 characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2016-09-29: MSDN confirms LongPath usage starting with Windows 10, version 1607.

if (!NativeMethods.SetCurrentDirectory(pathLp))
NativeError.ThrowException(Marshal.GetLastWin32Error(), pathLp);
}
}
}

+ 417
- 0
AlphaFS/Filesystem/Directory Class/Directory.Delete.cs View File

@@ -0,0 +1,417 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Deletes an empty directory from a specified path.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="path">The name of the empty directory to remove. This directory must be writable and empty.</param>
[SecurityCritical]
public static void Delete(string path)
{
DeleteDirectoryCore(null, null, path, false, false, true, false, PathFormat.RelativePath);
}

/// <summary>Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
[SecurityCritical]
public static void Delete(string path, bool recursive)
{
DeleteDirectoryCore(null, null, path, recursive, false, !recursive, false, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Deletes an empty directory from a specified path.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="path">The name of the empty directory to remove. This directory must be writable and empty.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Delete(string path, PathFormat pathFormat)
{
DeleteDirectoryCore(null, null, path, false, false, true, false, pathFormat);
}



/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Delete(string path, bool recursive, PathFormat pathFormat)
{
DeleteDirectoryCore(null, null, path, recursive, false, !recursive, false, pathFormat);
}



/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of files and directories.</param>
[SecurityCritical]
public static void Delete(string path, bool recursive, bool ignoreReadOnly)
{
DeleteDirectoryCore(null, null, path, recursive, ignoreReadOnly, !recursive, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of files and directories.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Delete(string path, bool recursive, bool ignoreReadOnly, PathFormat pathFormat)
{
DeleteDirectoryCore(null, null, path, recursive, ignoreReadOnly, !recursive, false, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Deletes an empty directory from a specified path.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the empty directory to remove. This directory must be writable and empty.</param>
[SecurityCritical]
public static void DeleteTransacted(KernelTransaction transaction, string path)
{
DeleteDirectoryCore(null, transaction, path, false, false, true, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes an empty directory from a specified path.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the empty directory to remove. This directory must be writable and empty.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
DeleteDirectoryCore(null, transaction, path, false, false, true, false, pathFormat);
}



/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
[SecurityCritical]
public static void DeleteTransacted(KernelTransaction transaction, string path, bool recursive)
{
DeleteDirectoryCore(null, transaction, path, recursive, false, !recursive, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteTransacted(KernelTransaction transaction, string path, bool recursive, PathFormat pathFormat)
{
DeleteDirectoryCore(null, transaction, path, recursive, false, !recursive, false, pathFormat);
}



/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of files and directories.</param>
[SecurityCritical]
public static void DeleteTransacted(KernelTransaction transaction, string path, bool recursive, bool ignoreReadOnly)
{
DeleteDirectoryCore(null, transaction, path, recursive, ignoreReadOnly, !recursive, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove.</param>
/// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in <paramref name="path"/>. <see langword="false"/> otherwise.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of files and directories.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteTransacted(KernelTransaction transaction, string path, bool recursive, bool ignoreReadOnly, PathFormat pathFormat)
{
DeleteDirectoryCore(null, transaction, path, recursive, ignoreReadOnly, !recursive, false, pathFormat);
}

#endregion // Transactional

#region Internal Methods

/// <summary>Deletes the specified directory and, if indicated, any subdirectories in the directory.</summary>
/// <remarks>The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <param name="fileSystemEntryInfo">A FileSystemEntryInfo instance. Use either <paramref name="fileSystemEntryInfo"/> or <paramref name="path"/>, not both.</param>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove. Use either <paramref name="path"/> or <paramref name="fileSystemEntryInfo"/>, not both.</param>
/// <param name="recursive"><see langword="true"/> to remove all files and subdirectories recursively; <see langword="false"/> otherwise only the top level empty directory.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only attribute of files and directories.</param>
/// <param name="requireEmpty"><see langword="true"/> requires the directory must be empty.</param>
/// <param name="continueOnNotExist"><see langword="true"/> does not throw an Exception when the file system object does not exist.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SecurityCritical]
internal static void DeleteDirectoryCore(FileSystemEntryInfo fileSystemEntryInfo, KernelTransaction transaction, string path, bool recursive, bool ignoreReadOnly, bool requireEmpty, bool continueOnNotExist, PathFormat pathFormat)
{
#region Setup

if (pathFormat == PathFormat.RelativePath)
Path.CheckSupportedPathFormat(path, true, true);

if (fileSystemEntryInfo == null)
{
// MSDN: .NET 3.5+: DirectoryNotFoundException:
// Path does not exist or could not be found.
// Path refers to a file instead of a directory.
// The specified path is invalid (for example, it is on an unmapped drive).

fileSystemEntryInfo = File.GetFileSystemEntryInfoCore(true, transaction, Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator), continueOnNotExist, pathFormat);
}

if (fileSystemEntryInfo == null)
return;

string pathLp = fileSystemEntryInfo.LongFullPath;

#endregion // Setup

// Do not follow mount points nor symbolic links, but do delete the reparse point itself.

// If directory is reparse point, disable recursion.
if (recursive && fileSystemEntryInfo.IsReparsePoint)
recursive = false;


// Check to see if this is a mount point, and unmount it.
if (fileSystemEntryInfo.IsMountPoint)
{
int lastError = Volume.DeleteVolumeMountPointCore(pathLp, true);

if (lastError != Win32Errors.ERROR_SUCCESS && lastError != Win32Errors.ERROR_PATH_NOT_FOUND)
NativeError.ThrowException(lastError, pathLp);

// Now it is safe to delete the actual directory.
}


if (recursive)
{
// Enumerate all file system objects.
foreach (var fsei in EnumerateFileSystemEntryInfosCore<FileSystemEntryInfo>(transaction, pathLp, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath))
{
if (fsei.IsDirectory)
DeleteDirectoryCore(fsei, transaction, null, true, ignoreReadOnly, requireEmpty, true, PathFormat.LongFullPath);
else
File.DeleteFileCore(transaction, fsei.LongFullPath, ignoreReadOnly, PathFormat.LongFullPath);
}
}

#region Remove

startRemoveDirectory:

if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista

// RemoveDirectory() / RemoveDirectoryTransacted()
// In the ANSI version of this function, the name is limited to MAX_PATH characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2014-09-09: MSDN confirms LongPath usage.

// RemoveDirectory on a symbolic link will remove the link itself.

? NativeMethods.RemoveDirectory(pathLp)
: NativeMethods.RemoveDirectoryTransacted(pathLp, transaction.SafeHandle)))
{
int lastError = Marshal.GetLastWin32Error();
switch ((uint) lastError)
{
case Win32Errors.ERROR_DIR_NOT_EMPTY:
if (requireEmpty)
// MSDN: .NET 3.5+: IOException: The directory specified by path is not an empty directory.
throw new DirectoryNotEmptyException(pathLp);

goto startRemoveDirectory;


case Win32Errors.ERROR_DIRECTORY:
// MSDN: .NET 3.5+: DirectoryNotFoundException: Path refers to a file instead of a directory.
if (File.ExistsCore(false, transaction, pathLp, PathFormat.LongFullPath))
throw new DirectoryNotFoundException(string.Format(CultureInfo.CurrentCulture, "({0}) {1}", Win32Errors.ERROR_INVALID_PARAMETER, string.Format(CultureInfo.CurrentCulture, Resources.Target_Directory_Is_A_File, pathLp)));
break;


case Win32Errors.ERROR_PATH_NOT_FOUND:
if (continueOnNotExist)
return;
break;

case Win32Errors.ERROR_SHARING_VIOLATION:
// MSDN: .NET 3.5+: IOException: The directory is being used by another process or there is an open handle on the directory.
NativeError.ThrowException(lastError, pathLp);
break;

case Win32Errors.ERROR_ACCESS_DENIED:
var data = new NativeMethods.WIN32_FILE_ATTRIBUTE_DATA();
int dataInitialised = File.FillAttributeInfoCore(transaction, pathLp, ref data, false, true);

if (data.dwFileAttributes != (FileAttributes) (-1))
{
if ((data.dwFileAttributes & FileAttributes.ReadOnly) != 0)
{
// MSDN: .NET 3.5+: IOException: The directory specified by path is read-only.

if (ignoreReadOnly)
{
// Reset directory attributes.
File.SetAttributesCore(true, transaction, pathLp, FileAttributes.Normal, true, PathFormat.LongFullPath);
goto startRemoveDirectory;
}

// MSDN: .NET 3.5+: IOException: The directory is read-only.
throw new DirectoryReadOnlyException(pathLp);
}
}

if (dataInitialised == Win32Errors.ERROR_SUCCESS)
// MSDN: .NET 3.5+: UnauthorizedAccessException: The caller does not have the required permission.
NativeError.ThrowException(lastError, pathLp);

break;
}

// MSDN: .NET 3.5+: IOException:
// A file with the same name and location specified by path exists.
// The directory specified by path is read-only, or recursive is false and path is not an empty directory.
// The directory is the application's current working directory.
// The directory contains a read-only file.
// The directory is being used by another process.

NativeError.ThrowException(lastError, pathLp);
}

#endregion // Remove
}

#endregion // Internal Methods
}
}

+ 211
- 0
AlphaFS/Filesystem/Directory Class/Directory.DeleteEmptySubdirectories.cs View File

@@ -0,0 +1,211 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
[SecurityCritical]
public static void DeleteEmptySubdirectories(string path, bool recursive)
{
DeleteEmptySubdirectoriesCore(null, null, path, recursive, false, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteEmptySubdirectories(string path, bool recursive, PathFormat pathFormat)
{
DeleteEmptySubdirectoriesCore(null, null, path, recursive, false, true, pathFormat);
}



/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of empty directories.</param>
[SecurityCritical]
public static void DeleteEmptySubdirectories(string path, bool recursive, bool ignoreReadOnly)
{
DeleteEmptySubdirectoriesCore(null, null, path, recursive, ignoreReadOnly, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of empty directories.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteEmptySubdirectories(string path, bool recursive, bool ignoreReadOnly, PathFormat pathFormat)
{
DeleteEmptySubdirectoriesCore(null, null, path, recursive, ignoreReadOnly, true, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
[SecurityCritical]
public static void DeleteEmptySubdirectoriesTransacted(KernelTransaction transaction, string path, bool recursive)
{
DeleteEmptySubdirectoriesCore(null, transaction, path, recursive, false, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteEmptySubdirectoriesTransacted(KernelTransaction transaction, string path, bool recursive, PathFormat pathFormat)
{
DeleteEmptySubdirectoriesCore(null, transaction, path, recursive, false, true, pathFormat);
}



/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of empty directories.</param>
[SecurityCritical]
public static void DeleteEmptySubdirectoriesTransacted(KernelTransaction transaction, string path, bool recursive, bool ignoreReadOnly)
{
DeleteEmptySubdirectoriesCore(null, transaction, path, recursive, ignoreReadOnly, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Deletes empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove empty subdirectories from.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of empty directories.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DeleteEmptySubdirectoriesTransacted(KernelTransaction transaction, string path, bool recursive, bool ignoreReadOnly, PathFormat pathFormat)
{
DeleteEmptySubdirectoriesCore(null, transaction, path, recursive, ignoreReadOnly, true, pathFormat);
}

#endregion // Transactional

#region Internal Methods

/// <summary>Delete empty subdirectories from the specified directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="fileSystemEntryInfo">A FileSystemEntryInfo instance. Use either <paramref name="fileSystemEntryInfo"/> or <paramref name="path"/>, not both.</param>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The name of the directory to remove empty subdirectories from. Use either <paramref name="path"/> or <paramref name="fileSystemEntryInfo"/>, not both.</param>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of empty directories.</param>
/// <param name="initialize">When <see langword="true"/> indicates the method is called externally.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static void DeleteEmptySubdirectoriesCore(FileSystemEntryInfo fileSystemEntryInfo, KernelTransaction transaction, string path, bool recursive, bool ignoreReadOnly, bool initialize, PathFormat pathFormat)
{
#region Setup

if (pathFormat == PathFormat.RelativePath)
Path.CheckSupportedPathFormat(path, true, true);

if (fileSystemEntryInfo == null)
{
if (!File.ExistsCore(true, transaction, path, pathFormat))
NativeError.ThrowException(Win32Errors.ERROR_PATH_NOT_FOUND, path);

fileSystemEntryInfo = File.GetFileSystemEntryInfoCore(true, transaction, Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck) , false, pathFormat);
}

if (fileSystemEntryInfo == null)
throw new ArgumentNullException("path");

string pathLp = fileSystemEntryInfo.LongFullPath;

#endregion // Setup

// Ensure path is a directory.
if (!fileSystemEntryInfo.IsDirectory)
throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.Target_Directory_Is_A_File, pathLp));

var dirEnumOptions = DirectoryEnumerationOptions.Folders;

if (recursive)
dirEnumOptions |= DirectoryEnumerationOptions.Recursive;

foreach (var fsei in EnumerateFileSystemEntryInfosCore<FileSystemEntryInfo>(transaction, pathLp, Path.WildcardStarMatchAll, dirEnumOptions, PathFormat.LongFullPath))
DeleteEmptySubdirectoriesCore(fsei, transaction, null, recursive, ignoreReadOnly, false, PathFormat.LongFullPath);


if (!EnumerateFileSystemEntryInfosCore<string>(transaction, pathLp, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath).Any())
{
// Prevent deleting path itself.
if (!initialize)
DeleteDirectoryCore(fileSystemEntryInfo, transaction, null, false, ignoreReadOnly, true, true, PathFormat.LongFullPath);
}
}

#endregion // Internal Methods
}
}

+ 154
- 0
AlphaFS/Filesystem/Directory Class/Directory.EncryptedDirectoryRaw.cs View File

@@ -0,0 +1,154 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.IO;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region Export

/// <summary>[AlphaFS] Backs up (export) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
/// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
/// </summary>
/// <remarks>
/// <para>The directory being backed up is not decrypted; it is backed up in its encrypted state.</para>
/// <para>If the caller does not have access to the key for the file, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to export encrypted files. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
/// <para>To backup an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/> overloads and specify the directory to backup along with the destination stream of the backup data.</para>
/// <para>This function is intended for the backup of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted directories.</para>
/// <para>Note that this method does not back up the files inside the directory, only the directory entry itself.</para>
/// </remarks>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/>
/// <param name="fileName">The name of the file to be backed up.</param>
/// <param name="outputStream">The destination stream to which the backup data will be written.</param>
public static void ExportEncryptedDirectoryRaw(string fileName, Stream outputStream)
{
File.ImportExportEncryptedFileDirectoryRawCore(true, false, outputStream, fileName, PathFormat.RelativePath, false);
}

/// <summary>[AlphaFS] Backs up (export) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
/// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
/// </summary>
/// <remarks>
/// <para>The directory being backed up is not decrypted; it is backed up in its encrypted state.</para>
/// <para>If the caller does not have access to the key for the file, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to export encrypted files. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
/// <para>To backup an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/> overloads and specify the directory to backup along with the destination stream of the backup data.</para>
/// <para>This function is intended for the backup of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted directories.</para>
/// <para>Note that this method does not back up the files inside the directory, only the directory entry itself.</para>
/// </remarks>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/>
/// <param name="fileName">The name of the file to be backed up.</param>
/// <param name="outputStream">The destination stream to which the backup data will be written.</param>
/// <param name="pathFormat">The path format of the <paramref name="fileName"/> parameter.</param>
public static void ExportEncryptedDirectoryRaw(string fileName, Stream outputStream, PathFormat pathFormat)
{
File.ImportExportEncryptedFileDirectoryRawCore(true, false, outputStream, fileName, pathFormat, false);
}

#endregion // Export

#region Import

/// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
/// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
/// </summary>
/// <remarks>
/// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
/// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
/// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
/// </remarks>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
/// <param name="inputStream">The stream to read previously backed up data from.</param>
/// <param name="destinationPath">The path of the destination directory to restore to.</param>
public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath)
{
File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, PathFormat.RelativePath, false);
}

/// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
/// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
/// </summary>
/// <remarks>
/// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
/// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
/// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
/// </remarks>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
/// <param name="inputStream">The stream to read previously backed up data from.</param>
/// <param name="destinationPath">The path of the destination directory to restore to.</param>
/// <param name="pathFormat">The path format of the <paramref name="destinationPath"/> parameter.</param>
public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath, PathFormat pathFormat)
{
File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, pathFormat, false);
}


/// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
/// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
/// </summary>
/// <remarks>
/// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
/// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
/// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
/// </remarks>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
/// <param name="inputStream">The stream to read previously backed up data from.</param>
/// <param name="destinationPath">The path of the destination directory to restore to.</param>
/// <param name="overwriteHidden">If set to <see langword="true"/> a hidden directory will be overwritten on import.</param>
public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath, bool overwriteHidden)
{
File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, PathFormat.RelativePath, overwriteHidden);
}

/// <summary>[AlphaFS] Restores (import) encrypted directories. This is one of a group of Encrypted File System (EFS) functions that is
/// intended to implement backup and restore functionality, while maintaining files in their encrypted state.
/// </summary>
/// <remarks>
/// <para>If the caller does not have access to the key for the directory, the caller needs <see cref="Alphaleonis.Win32.Security.Privilege.Backup"/> to restore encrypted directories. See <see cref="Alphaleonis.Win32.Security.PrivilegeEnabler"/>.</para>
/// <para>To restore an encrypted directory call one of the <see cref="O:Alphaleonis.Win32.Filesystem.Directory.ImportEncryptedDirectoryRaw"/> overloads and specify the file to restore along with the destination stream of the restored data.</para>
/// <para>This function is intended for the restoration of only encrypted directories; see <see cref="BackupFileStream"/> for backup of unencrypted files.</para>
/// </remarks>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ExportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.File.ImportEncryptedFileRaw"/>
/// <seealso cref="O:Alphaleonis.Win32.Filesystem.Directory.ExportEncryptedDirectoryRaw"/>
/// <param name="inputStream">The stream to read previously backed up data from.</param>
/// <param name="destinationPath">The path of the destination directory to restore to.</param>
/// <param name="overwriteHidden">If set to <see langword="true"/> a hidden directory will be overwritten on import.</param>
/// <param name="pathFormat">The path format of the <paramref name="destinationPath"/> parameter.</param>
public static void ImportEncryptedDirectoryRaw(Stream inputStream, string destinationPath, bool overwriteHidden, PathFormat pathFormat)
{
File.ImportExportEncryptedFileDirectoryRawCore(false, true, inputStream, destinationPath, pathFormat, overwriteHidden);
}

#endregion // Import
}
}

+ 272
- 0
AlphaFS/Filesystem/Directory Class/Directory.Encryption.cs View File

@@ -0,0 +1,272 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region Decrypt

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decrypt.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Decrypt(string path, PathFormat pathFormat)
{
EncryptDecryptDirectoryCore(path, false, false, pathFormat);
}

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decrypt.</param>
/// <param name="recursive"><see langword="true"/> to decrypt the directory recursively. <see langword="false"/> only decrypt the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Decrypt(string path, bool recursive, PathFormat pathFormat)
{
EncryptDecryptDirectoryCore(path, false, recursive, pathFormat);
}

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decrypt.</param>
[SecurityCritical]
public static void Decrypt(string path)
{
EncryptDecryptDirectoryCore(path, false, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to decrypt.</param>
/// <param name="recursive"><see langword="true"/> to decrypt the directory recursively. <see langword="false"/> only decrypt the directory.</param>
[SecurityCritical]
public static void Decrypt(string path, bool recursive)
{
EncryptDecryptDirectoryCore(path, false, recursive, PathFormat.RelativePath);
}

#endregion // Decrypt

#region Encrypt

/// <summary>[AlphaFS] Encrypts a directory so that only the account used to encrypt the directory can decrypt it.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to encrypt.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Encrypt(string path, PathFormat pathFormat)
{
EncryptDecryptDirectoryCore(path, true, false, pathFormat);
}

/// <summary>[AlphaFS] Encrypts a directory so that only the account used to encrypt the directory can decrypt it.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to encrypt.</param>
/// <param name="recursive"><see langword="true"/> to encrypt the directory recursively. <see langword="false"/> only encrypt the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void Encrypt(string path, bool recursive, PathFormat pathFormat)
{
EncryptDecryptDirectoryCore(path, true, recursive, pathFormat);
}


/// <summary>[AlphaFS] Encrypts a directory so that only the account used to encrypt the directory can decrypt it.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to encrypt.</param>
[SecurityCritical]
public static void Encrypt(string path)
{
EncryptDecryptDirectoryCore(path, true, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Encrypts a directory so that only the account used to encrypt the directory can decrypt it.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to encrypt.</param>
/// <param name="recursive"><see langword="true"/> to encrypt the directory recursively. <see langword="false"/> only encrypt the directory.</param>
[SecurityCritical]
public static void Encrypt(string path, bool recursive)
{
EncryptDecryptDirectoryCore(path, true, recursive, PathFormat.RelativePath);
}

#endregion // Encrypt
#region DisableEncryption

/// <summary>[AlphaFS] Disables encryption of the specified directory and the files in it.
/// <para>This method only creates/modifies the file "Desktop.ini" in the root of <paramref name="path"/> and disables encryption by writing: "Disable=1"</para>
/// <para>This method does not affect encryption of files and subdirectories below the indicated directory.</para>
/// </summary>
/// <param name="path">The name of the directory for which to disable encryption.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void DisableEncryption(string path, PathFormat pathFormat)
{
EnableDisableEncryptionCore(path, false, pathFormat);
}

/// <summary>[AlphaFS] Disables encryption of the specified directory and the files in it.
/// <para>This method only creates/modifies the file "Desktop.ini" in the root of <paramref name="path"/> and disables encryption by writing: "Disable=1"</para>
/// <para>This method does not affect encryption of files and subdirectories below the indicated directory.</para>
/// </summary>
/// <param name="path">The name of the directory for which to disable encryption.</param>
[SecurityCritical]
public static void DisableEncryption(string path)
{
EnableDisableEncryptionCore(path, false, PathFormat.RelativePath);
}

#endregion // DisableEncryption

#region EnableEncryption

/// <summary>[AlphaFS] Enables encryption of the specified directory and the files in it.
/// <para>This method only creates/modifies the file "Desktop.ini" in the root of <paramref name="path"/> and enables encryption by writing: "Disable=0"</para>
/// <para>This method does not affect encryption of files and subdirectories below the indicated directory.</para>
/// </summary>
/// <param name="path">The name of the directory for which to enable encryption.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void EnableEncryption(string path, PathFormat pathFormat)
{
EnableDisableEncryptionCore(path, true, pathFormat);
}

/// <summary>[AlphaFS] Enables encryption of the specified directory and the files in it.
/// <para>This method only creates/modifies the file "Desktop.ini" in the root of <paramref name="path"/> and enables encryption by writing: "Disable=0"</para>
/// <para>This method does not affect encryption of files and subdirectories below the indicated directory.</para>
/// </summary>
/// <param name="path">The name of the directory for which to enable encryption.</param>
[SecurityCritical]
public static void EnableEncryption(string path)
{
EnableDisableEncryptionCore(path, true, PathFormat.RelativePath);
}

#endregion // EnableEncryption
#region Internal Methods

/// <summary>Enables/disables encryption of the specified directory and the files in it.
/// <para>This method only creates/modifies the file "Desktop.ini" in the root of <paramref name="path"/> and enables/disables encryption by writing: "Disable=0" or "Disable=1".</para>
/// <para>This method does not affect encryption of files and subdirectories below the indicated directory.</para>
/// </summary>
/// <param name="path">The name of the directory for which to enable encryption.</param>
/// <param name="enable"><see langword="true"/> enabled encryption, <see langword="false"/> disables encryption.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static void EnableDisableEncryptionCore(string path, bool enable, PathFormat pathFormat)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");

string pathLp = Path.GetExtendedLengthPathCore(null, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

// EncryptionDisable()
// In the ANSI version of this function, the name is limited to 248 characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.

if (!NativeMethods.EncryptionDisable(pathLp, !enable))
NativeError.ThrowException(pathLp);
}

/// <summary>Decrypts/encrypts a directory recursively so that only the account used to encrypt the directory can decrypt it.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">A path that describes a directory to encrypt.</param>
/// <param name="encrypt"><see langword="true"/> encrypt, <see langword="false"/> decrypt.</param>
/// <param name="recursive"><see langword="true"/> to decrypt the directory recursively. <see langword="false"/> only decrypt files and directories in the root of <paramref name="path"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static void EncryptDecryptDirectoryCore(string path, bool encrypt, bool recursive, PathFormat pathFormat)
{
string pathLp = Path.GetExtendedLengthPathCore(null, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

var options = DirectoryEnumerationOptions.FilesAndFolders | DirectoryEnumerationOptions.AsLongPath;

// Process folders and files when recursive.
if (recursive)
{
options |= DirectoryEnumerationOptions.Recursive;

foreach (string fsei in EnumerateFileSystemEntryInfosCore<string>(null, pathLp, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath))
File.EncryptDecryptFileCore(true, fsei, encrypt, PathFormat.LongFullPath);
}

// Process the root folder, the given path.
File.EncryptDecryptFileCore(true, pathLp, encrypt, PathFormat.LongFullPath);
}

#endregion // Internal Methods
}
}

+ 69
- 0
AlphaFS/Filesystem/Directory Class/Directory.EnumerateAlternateDataStreams.cs View File

@@ -0,0 +1,69 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Collections.Generic;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
/// <param name="path">The path to the directory to enumerate streams of.</param>
/// <returns>The streams of type :$DATA in the specified directory.</returns>
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams(string path)
{
return File.EnumerateAlternateDataStreamsCore(null, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
/// <param name="path">The path to the directory to enumerate streams of.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <returns>The streams of type :$DATA in the specified directory.</returns>
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams(string path, PathFormat pathFormat)
{
return File.EnumerateAlternateDataStreamsCore(null, path, pathFormat);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path to the directory to enumerate streams of.</param>
/// <returns>The streams of type :$DATA in the specified directory.</returns>
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsTransacted(KernelTransaction transaction, string path)
{
return File.EnumerateAlternateDataStreamsCore(transaction, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Enumerates the streams of type :$DATA from the specified directory.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path to the directory to enumerate streams of.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <returns>The streams of type :$DATA in the specified directory.</returns>
[SecurityCritical]
public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.EnumerateAlternateDataStreamsCore(transaction, path, pathFormat);
}
}
}

+ 500
- 0
AlphaFS/Filesystem/Directory Class/Directory.EnumerateDirectories.cs View File

@@ -0,0 +1,500 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Security;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
}

/// <summary>Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
}

/// <summary>Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Folders, pathFormat);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files; // Remove enumeration of files.
options |= DirectoryEnumerationOptions.Folders; // Add enumeration of directories.

return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
}


#region Transactional

/// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Folders, pathFormat);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory instances in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of directory instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the directories in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
}

#endregion // Transactional
}
}

+ 230
- 0
AlphaFS/Filesystem/Directory Class/Directory.EnumerateFileIdBothDirectoryInfo.cs View File

@@ -0,0 +1,230 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in <see cref="FileShare.ReadWrite"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="path">A path to a directory from which to retrieve information.</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfo(string path)
{
return EnumerateFileIdBothDirectoryInfoCore(null, null, path, FileShare.ReadWrite, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in <see cref="FileShare.ReadWrite"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="path">A path to a directory from which to retrieve information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfo(string path, PathFormat pathFormat)
{
return EnumerateFileIdBothDirectoryInfoCore(null, null, path, FileShare.ReadWrite, false, pathFormat);
}



/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in specified <see cref="FileShare"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="path">A path to a directory from which to retrieve information.</param>
/// <param name="shareMode">The <see cref="FileShare"/> mode with which to open a handle to the directory.</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfo(string path, FileShare shareMode)
{
return EnumerateFileIdBothDirectoryInfoCore(null, null, path, shareMode, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in specified <see cref="FileShare"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="path">A path to a directory from which to retrieve information.</param>
/// <param name="shareMode">The <see cref="FileShare"/> mode with which to open a handle to the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfo(string path, FileShare shareMode, PathFormat pathFormat)
{
return EnumerateFileIdBothDirectoryInfoCore(null, null, path, shareMode, false, pathFormat);
}



/// <summary>[AlphaFS] Retrieves information about files in the directory handle specified.</summary>
/// <returns>An IEnumerable of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="handle">An open handle to the directory from which to retrieve information.</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfo(SafeFileHandle handle)
{
// FileShare has no effect since a handle is already opened.
return EnumerateFileIdBothDirectoryInfoCore(null, handle, null, FileShare.ReadWrite, false, PathFormat.RelativePath);
}

#region Transactional

/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in <see cref="FileShare.ReadWrite"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory from which to retrieve information.</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfoTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileIdBothDirectoryInfoCore(transaction, null, path, FileShare.ReadWrite, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in <see cref="FileShare.ReadWrite"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory from which to retrieve information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfoTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return EnumerateFileIdBothDirectoryInfoCore(transaction, null, path, FileShare.ReadWrite, false, pathFormat);
}



/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in specified <see cref="FileShare"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory from which to retrieve information.</param>
/// <param name="shareMode">The <see cref="FileShare"/> mode with which to open a handle to the directory.</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfoTransacted(KernelTransaction transaction, string path, FileShare shareMode)
{
return EnumerateFileIdBothDirectoryInfoCore(transaction, null, path, shareMode, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Retrieves information about files in the directory specified by <paramref name="path"/> in specified <see cref="FileShare"/> mode.</summary>
/// <returns>An enumeration of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">A path to a directory from which to retrieve information.</param>
/// <param name="shareMode">The <see cref="FileShare"/> mode with which to open a handle to the directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfoTransacted(KernelTransaction transaction, string path, FileShare shareMode, PathFormat pathFormat)
{
return EnumerateFileIdBothDirectoryInfoCore(transaction, null, path, shareMode, false, pathFormat);
}

#endregion // Transactional

#region Internal Methods

/// <summary>Returns an enumerable collection of information about files in the directory handle specified.</summary>
/// <returns>An IEnumerable of <see cref="FileIdBothDirectoryInfo"/> records for each file system entry in the specified diretory.</returns>
/// <remarks>
/// <para>Either use <paramref name="path"/> or <paramref name="safeHandle"/>, not both.</para>
/// <para>
/// The number of files that are returned for each call to GetFileInformationByHandleEx depends on the size of the buffer that is passed to the function.
/// Any subsequent calls to GetFileInformationByHandleEx on the same handle will resume the enumeration operation after the last file is returned.
/// </para>
/// </remarks>
/// <param name="transaction">The transaction.</param>
/// <param name="safeHandle">An open handle to the directory from which to retrieve information.</param>
/// <param name="path">A path to the directory.</param>
/// <param name="shareMode">The <see cref="FileShare"/> mode with which to open a handle to the directory.</param>
/// <param name="continueOnException"><see langword="true"/> suppress any Exception that might be thrown as a result from a failure, such as ACLs protected directories or non-accessible reparse points.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static IEnumerable<FileIdBothDirectoryInfo> EnumerateFileIdBothDirectoryInfoCore(KernelTransaction transaction, SafeFileHandle safeHandle, string path, FileShare shareMode, bool continueOnException, PathFormat pathFormat)
{
if (!NativeMethods.IsAtLeastWindowsVista)
throw new PlatformNotSupportedException(Resources.Requires_Windows_Vista_Or_Higher);

bool callerHandle = safeHandle != null;
if (!callerHandle)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");

string pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

safeHandle = File.CreateFileCore(transaction, pathLp, ExtendedFileAttributes.BackupSemantics, null, FileMode.Open, FileSystemRights.ReadData, shareMode, true, PathFormat.LongFullPath);
}


try
{
if (!NativeMethods.IsValidHandle(safeHandle, Marshal.GetLastWin32Error(), !continueOnException))
yield break;

var fileNameOffset = (int)Marshal.OffsetOf(typeof(NativeMethods.FILE_ID_BOTH_DIR_INFO), "FileName");

using (var safeBuffer = new SafeGlobalMemoryBufferHandle(NativeMethods.DefaultFileBufferSize))
{
while (true)
{
if (!NativeMethods.GetFileInformationByHandleEx(safeHandle, NativeMethods.FileInfoByHandleClass.FileIdBothDirectoryInfo, safeBuffer, (uint)safeBuffer.Capacity))
{
uint lastError = (uint)Marshal.GetLastWin32Error();
switch (lastError)
{
case Win32Errors.ERROR_SUCCESS:
case Win32Errors.ERROR_NO_MORE_FILES:
case Win32Errors.ERROR_HANDLE_EOF:
yield break;

case Win32Errors.ERROR_MORE_DATA:
continue;

default:
NativeError.ThrowException(lastError, path);
yield break; // we should never get to this yield break.
}
}
int offset = 0;
NativeMethods.FILE_ID_BOTH_DIR_INFO fibdi;
do
{
fibdi = safeBuffer.PtrToStructure<NativeMethods.FILE_ID_BOTH_DIR_INFO>(offset);
string fileName = safeBuffer.PtrToStringUni(offset + fileNameOffset, (int)(fibdi.FileNameLength / 2));

if (!fileName.Equals(Path.CurrentDirectoryPrefix, StringComparison.OrdinalIgnoreCase) &&
!fileName.Equals(Path.ParentDirectoryPrefix, StringComparison.OrdinalIgnoreCase))
yield return new FileIdBothDirectoryInfo(fibdi, fileName);

offset += fibdi.NextEntryOffset;
}
while (fibdi.NextEntryOffset != 0);
}
}
}
finally
{
// Handle is ours, dispose.
if (!callerHandle && safeHandle != null)
safeHandle.Close();
}
}

#endregion // Internal Methods
}
}

+ 472
- 0
AlphaFS/Filesystem/Directory Class/Directory.EnumerateFileSystemEntries.cs View File

@@ -0,0 +1,472 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Security;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}



/// <summary>Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
}



#region Transactional

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names and directory names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of file system entries in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
}

#endregion // Transactional
}
}

+ 670
- 0
AlphaFS/Filesystem/Directory Class/Directory.EnumerateFileSystemEntryInfos.cs View File

@@ -0,0 +1,670 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern" /> in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfos<T>(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(null, path, searchPattern, options, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system entries that match a <paramref name="searchPattern"/> in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public static IEnumerable<T> EnumerateFileSystemEntryInfosTransacted<T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<T>(transaction, path, searchPattern, options, pathFormat);
}
#endregion // Transactional

#region Internal Methods

/// <summary>Returns an enumerable collection of file system entries in a specified path using <see cref="DirectoryEnumerationOptions"/>.</summary>
/// <returns>The matching file system entries. The type of the items is determined by the type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <typeparam name="T">The type to return. This may be one of the following types:
/// <list type="definition">
/// <item>
/// <term><see cref="FileSystemEntryInfo"/></term>
/// <description>This method will return instances of <see cref="FileSystemEntryInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="FileSystemInfo"/></term>
/// <description>This method will return instances of <see cref="DirectoryInfo"/> and <see cref="FileInfo"/> instances.</description>
/// </item>
/// <item>
/// <term><see cref="string"/></term>
/// <description>This method will return the full path of each item.</description>
/// </item>
/// </list>
/// </typeparam>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static IEnumerable<T> EnumerateFileSystemEntryInfosCore<T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Enable BasicSearch and LargeCache by default.
options |= DirectoryEnumerationOptions.BasicSearch | DirectoryEnumerationOptions.LargeCache;

return new FindFileSystemEntryInfo(true, transaction, path, searchPattern, options, typeof(T), pathFormat).Enumerate<T>();
}

#endregion // Internal Methods
}
}

+ 502
- 0
AlphaFS/Filesystem/Directory Class/Directory.EnumerateFiles.cs View File

@@ -0,0 +1,502 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Security;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
}

/// <summary>Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
}

/// <summary>Returns an enumerable collection of file names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Files, pathFormat);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders; // Remove enumeration of directories.
options |= DirectoryEnumerationOptions.Files; // Add enumeration of files.

return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, pathFormat);
}



#region Transactional
/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file instances instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Files, pathFormat);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file instances instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>, and optionally searches subdirectories.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the specified <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption, PathFormat pathFormat)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file names in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat);
}



/// <summary>[AlphaFS] Returns an enumerable collection of file instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file instances that match a <paramref name="searchPattern"/> in a specified <paramref name="path"/>.</summary>
/// <returns>An enumerable collection of the full names (including paths) for the files in the directory specified by <paramref name="path"/> and that match the <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static IEnumerable<string> EnumerateFilesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, pathFormat);
}

#endregion // Transactional
}
}

+ 110
- 0
AlphaFS/Filesystem/Directory Class/Directory.Exists.cs View File

@@ -0,0 +1,110 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Determines whether the given path refers to an existing directory on disk.</summary>
/// <returns>
/// <para>Returns <see langword="true"/> if <paramref name="path"/> refers to an existing directory.</para>
/// <para>Returns <see langword="false"/> if the directory does not exist or an error occurs when trying to determine if the specified file exists.</para>
/// </returns>
/// <remarks>
/// The Exists method returns <see langword="false"/> if any error occurs while trying to determine if the specified file exists.
/// This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters,
/// a failing or missing disk, or if the caller does not have permission to read the file.
/// </remarks>
/// <param name="path">The path to test.</param>
[SecurityCritical]
public static bool Exists(string path)
{
return File.ExistsCore(true, null, path, PathFormat.RelativePath);
}

#endregion // .NET



/// <summary>[AlphaFS] Determines whether the given path refers to an existing directory on disk.</summary>
/// <returns>
/// <para>Returns <see langword="true"/> if <paramref name="path"/> refers to an existing directory.</para>
/// <para>Returns <see langword="false"/> if the directory does not exist or an error occurs when trying to determine if the specified file exists.</para>
/// </returns>
/// <remarks>
/// The Exists method returns <see langword="false"/> if any error occurs while trying to determine if the specified file exists.
/// This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters,
/// a failing or missing disk, or if the caller does not have permission to read the file.
/// </remarks>
/// <param name="path">The path to test.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static bool Exists(string path, PathFormat pathFormat)
{
return File.ExistsCore(true, null, path, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Determines whether the given path refers to an existing directory on disk.</summary>
/// <returns>
/// <para>Returns <see langword="true"/> if <paramref name="path"/> refers to an existing directory.</para>
/// <para>Returns <see langword="false"/> if the directory does not exist or an error occurs when trying to determine if the specified file exists.</para>
/// </returns>
/// <remarks>
/// The Exists method returns <see langword="false"/> if any error occurs while trying to determine if the specified file exists.
/// This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters,
/// a failing or missing disk, or if the caller does not have permission to read the file.
/// </remarks>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path to test.</param>
[SecurityCritical]
public static bool ExistsTransacted(KernelTransaction transaction, string path)
{
return File.ExistsCore(true, transaction, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Determines whether the given path refers to an existing directory on disk.</summary>
/// <returns>
/// <para>Returns <see langword="true"/> if <paramref name="path"/> refers to an existing directory.</para>
/// <para>Returns <see langword="false"/> if the directory does not exist or an error occurs when trying to determine if the specified file exists.</para>
/// </returns>
/// <remarks>
/// The Exists method returns <see langword="false"/> if any error occurs while trying to determine if the specified file exists.
/// This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters,
/// a failing or missing disk, or if the caller does not have permission to read the file.
/// </remarks>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path to test.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static bool ExistsTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.ExistsCore(true, transaction, path, pathFormat);
}

#endregion // Transactional
}
}

+ 113
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetAccessControl.cs View File

@@ -0,0 +1,113 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;
using Alphaleonis.Win32.Security;
using Microsoft.Win32.SafeHandles;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>Gets a <see cref="DirectorySecurity"/> object that encapsulates the access control list (ACL) entries for the specified directory.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the file described by the <paramref name="path"/> parameter.</returns>
/// <exception cref="IOException"/>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The path to a directory containing a <see cref="DirectorySecurity"/> object that describes the file's access control list (ACL) information.</param>
[SecurityCritical]
public static DirectorySecurity GetAccessControl(string path)
{
return File.GetAccessControlCore<DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, PathFormat.RelativePath);
}

/// <summary>Gets a <see cref="DirectorySecurity"/> object that encapsulates the specified type of access control list (ACL) entries for a particular directory.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the directory described by the <paramref name="path"/> parameter. </returns>
/// <exception cref="IOException"/>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The path to a directory containing a <see cref="DirectorySecurity"/> object that describes the directory's access control list (ACL) information.</param>
/// <param name="includeSections">One (or more) of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to receive.</param>
[SecurityCritical]
public static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections)
{
return File.GetAccessControlCore<DirectorySecurity>(true, path, includeSections, PathFormat.RelativePath);
}


/// <summary>[AlphaFS] Gets a <see cref="DirectorySecurity"/> object that encapsulates the access control list (ACL) entries for the specified directory.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the file described by the <paramref name="path"/> parameter.</returns>
/// <exception cref="IOException"/>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The path to a directory containing a <see cref="DirectorySecurity"/> object that describes the file's access control list (ACL) information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DirectorySecurity GetAccessControl(string path, PathFormat pathFormat)
{
return File.GetAccessControlCore<DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, pathFormat);
}

/// <summary>[AlphaFS] Gets a <see cref="DirectorySecurity"/> object that encapsulates the specified type of access control list (ACL) entries for a particular directory.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the directory described by the <paramref name="path"/> parameter. </returns>
/// <exception cref="IOException"/>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="path">The path to a directory containing a <see cref="DirectorySecurity"/> object that describes the directory's access control list (ACL) information.</param>
/// <param name="includeSections">One (or more) of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to receive.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections, PathFormat pathFormat)
{
return File.GetAccessControlCore<DirectorySecurity>(true, path, includeSections, pathFormat);
}


/// <summary>[AlphaFS] Gets a <see cref="DirectorySecurity"/> object that encapsulates the access control list (ACL) entries for the specified directory handle.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the file described by the <paramref name="handle"/> parameter.</returns>
/// <exception cref="IOException"/>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="handle">A <see cref="SafeHandle"/> to a directory containing a <see cref="DirectorySecurity"/> object that describes the directory's access control list (ACL) information.</param>
[SecurityCritical]
public static DirectorySecurity GetAccessControl(SafeFileHandle handle)
{
return File.GetAccessControlHandleCore<DirectorySecurity>(false, true, handle, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, SecurityInformation.None);
}

/// <summary>[AlphaFS] Gets a <see cref="DirectorySecurity"/> object that encapsulates the specified type of access control list (ACL) entries for a particular directory handle.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the directory described by the <paramref name="handle"/> parameter. </returns>
/// <exception cref="IOException"/>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <param name="handle">A <see cref="SafeHandle"/> to a directory containing a <see cref="DirectorySecurity"/> object that describes the directory's access control list (ACL) information.</param>
/// <param name="includeSections">One (or more) of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to receive.</param>
[SecurityCritical]
public static DirectorySecurity GetAccessControl(SafeFileHandle handle, AccessControlSections includeSections)
{
return File.GetAccessControlHandleCore<DirectorySecurity>(false, true, handle, includeSections, SecurityInformation.None);
}
}
}

+ 138
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetChangeTime.cs View File

@@ -0,0 +1,138 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using Microsoft.Win32.SafeHandles;
using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
[SecurityCritical]
public static DateTime GetChangeTime(string path)
{
return File.GetChangeTimeCore(true, null, null, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetChangeTime(string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(true, null, null, path, false, pathFormat);
}


/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="path">The file for which to obtain change date and time information, in Coordinated Universal Time (UTC) format.</param>
[SecurityCritical]
public static DateTime GetChangeTimeUtc(string path)
{
return File.GetChangeTimeCore(true, null, null, path, true, PathFormat.RelativePath);
}
/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="path">The file for which to obtain change date and time information, in Coordinated Universal Time (UTC) format.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetChangeTimeUtc(string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(true, null, null, path, true, pathFormat);
}



/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="safeHandle">An open handle to the directory from which to retrieve information.</param>
[SecurityCritical]
public static DateTime GetChangeTime(SafeFileHandle safeHandle)
{
return File.GetChangeTimeCore(true, null, safeHandle, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="safeHandle">An open handle to the directory from which to retrieve information.</param>
[SecurityCritical]
public static DateTime GetChangeTimeUtc(SafeFileHandle safeHandle)
{
return File.GetChangeTimeCore(true, null, safeHandle, null, true, PathFormat.RelativePath);
}
#region Transactional

/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
[SecurityCritical]
public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, string path)
{
return File.GetChangeTimeCore(true, transaction, null, path, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetChangeTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(true, transaction, null, path, false, pathFormat);
}



/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The file for which to obtain change date and time information, in Coordinated Universal Time (UTC) format.</param>
[SecurityCritical]
public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction, string path)
{
return File.GetChangeTimeCore(true, transaction, null, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the change date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the change date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The file for which to obtain change date and time information, in Coordinated Universal Time (UTC) format.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetChangeTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetChangeTimeCore(true, transaction, null, path, true, pathFormat);
}

#endregion // Transactional
}
}

+ 124
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetCreationTime.cs View File

@@ -0,0 +1,124 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Gets the creation date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
[SecurityCritical]
public static DateTime GetCreationTime(string path)
{
return File.GetCreationTimeCore(null, path, false, PathFormat.RelativePath).ToLocalTime();
}



/// <summary>Gets the creation date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="path">The directory for which to obtain creation date and time information, in Coordinated Universal Time (UTC) format.</param>
[SecurityCritical]
public static DateTime GetCreationTimeUtc(string path)
{
return File.GetCreationTimeCore(null, path, true, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Gets the creation date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetCreationTime(string path, PathFormat pathFormat)
{
return File.GetCreationTimeCore(null, path, false, pathFormat).ToLocalTime();
}



/// <summary>[AlphaFS] Gets the creation date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="path">The directory for which to obtain creation date and time information, in Coordinated Universal Time (UTC) format.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetCreationTimeUtc(string path, PathFormat pathFormat)
{
return File.GetCreationTimeCore(null, path, true, pathFormat);
}


#region Transactional

/// <summary>[AlphaFS] Gets the creation date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
[SecurityCritical]
public static DateTime GetCreationTimeTransacted(KernelTransaction transaction, string path)
{
return File.GetCreationTimeCore(transaction, path, false, PathFormat.RelativePath).ToLocalTime();
}

/// <summary>[AlphaFS] Gets the creation date and time of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain creation date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetCreationTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetCreationTimeCore(transaction, path, false, pathFormat).ToLocalTime();
}



/// <summary>[AlphaFS] Gets the creation date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain creation date and time information, in Coordinated Universal Time (UTC) format.</param>
[SecurityCritical]
public static DateTime GetCreationTimeUtcTransacted(KernelTransaction transaction, string path)
{
return File.GetCreationTimeCore(transaction, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the creation date and time, in Coordinated Universal Time (UTC) format, of the specified directory.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the creation date and time for the specified directory. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain creation date and time information, in Coordinated Universal Time (UTC) format.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetCreationTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetCreationTimeCore(transaction, path, true, pathFormat);
}

#endregion // Transactional
}
}

+ 210
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetDirectories.cs View File

@@ -0,0 +1,210 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
// Since Directory.GetDirectories() is less efficient than Directory.EnumerateDirectories(),
// only .NET and AlphaFS Transactional methods are implemented. No additional overloaded methods.

#region .NET

/// <summary>Returns the names of subdirectories (including their paths) in the specified directory.</summary>
/// <returns>An array of the full names (including paths) of subdirectories in the specified path, or an empty array if no directories are found.</returns>
/// <remarks>
/// <para>The names returned by this method are prefixed with the directory information provided in path.</para>
/// <para>The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static string[] GetDirectories(string path)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of subdirectories (including their paths) that match the specified search pattern in the specified directory.</summary>
/// <returns>An array of the full names (including paths) of the subdirectories that match the search pattern in the specified directory, or an empty array if no directories are found.</returns>
/// <remarks>
/// <para>The names returned by this method are prefixed with the directory information provided in path.</para>
/// <para>The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static string[] GetDirectories(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of the subdirectories (including their paths) that match the specified search pattern in the specified directory, and optionally searches subdirectories.</summary>
/// <returns>An array of the full names (including paths) of the subdirectories that match the specified criteria, or an empty array if no directories are found.</returns>
/// <remarks>
/// <para>The names returned by this method are prefixed with the directory information provided in path.</para>
/// <para>The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static string[] GetDirectories(string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath).ToArray();
}

#endregion // .NET

#region Transactional

/// <summary>Returns the names of subdirectories (including their paths) in the specified directory.</summary>
/// <returns>An array of the full names (including paths) of subdirectories in the specified path, or an empty array if no directories are found.</returns>
/// <remarks>
/// <para>The names returned by this method are prefixed with the directory information provided in path.</para>
/// <para>The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static string[] GetDirectoriesTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of subdirectories (including their paths) that match the specified search pattern in the specified directory.</summary>
/// <returns>An array of the full names (including paths) of the subdirectories that match the search pattern in the specified directory, or an empty array if no directories are found.</returns>
/// <remarks>
/// <para>The names returned by this method are prefixed with the directory information provided in path.</para>
/// <para>The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static string[] GetDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of the subdirectories (including their paths) that match the specified search pattern in the specified directory, and optionally searches subdirectories.</summary>
/// <returns>An array of the full names (including paths) of the subdirectories that match the specified criteria, or an empty array if no directories are found.</returns>
/// <remarks>
/// <para>The names returned by this method are prefixed with the directory information provided in path.</para>
/// <para>The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static string[] GetDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath).ToArray();
}

#endregion // Transactional
}
}

+ 115
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetDirectoryRoot.cs View File

@@ -0,0 +1,115 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Returns the volume information, root information, or both for the specified path.</summary>
/// <returns>The volume information, root information, or both for the specified path, or <see langword="null"/> if <paramref name="path"/> path does not contain root directory information.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="NotSupportedException"/>
/// <param name="path">The path of a file or directory.</param>
[SecurityCritical]
public static string GetDirectoryRoot(string path)
{
return GetDirectoryRootCore(null, path, PathFormat.RelativePath);
}

#endregion // .NET
/// <summary>Returns the volume information, root information, or both for the specified path.</summary>
/// <returns>The volume information, root information, or both for the specified path, or <see langword="null"/> if <paramref name="path"/> path does not contain root directory information.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="NotSupportedException"/>
/// <param name="path">The path of a file or directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static string GetDirectoryRoot(string path, PathFormat pathFormat)
{
return GetDirectoryRootCore(null, path, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Returns the volume information, root information, or both for the specified path.</summary>
/// <returns>The volume information, root information, or both for the specified path, or <see langword="null"/> if <paramref name="path"/> path does not contain root directory information.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="NotSupportedException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path of a file or directory.</param>
[SecurityCritical]
public static string GetDirectoryRootTransacted(KernelTransaction transaction, string path)
{
return GetDirectoryRootCore(transaction, path, PathFormat.RelativePath);
}

/// <summary>Returns the volume information, root information, or both for the specified path.</summary>
/// <returns>The volume information, root information, or both for the specified path, or <see langword="null"/> if <paramref name="path"/> path does not contain root directory information.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="NotSupportedException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path of a file or directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static string GetDirectoryRootTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return GetDirectoryRootCore(transaction, path, pathFormat);
}
#endregion // Transactional

#region Internal Methods

/// <summary>Returns the volume information, root information, or both for the specified path.</summary>
/// <returns>The volume information, root information, or both for the specified path, or <see langword="null"/> if <paramref name="path"/> path does not contain root directory information.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="NotSupportedException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path of a file or directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static string GetDirectoryRootCore(KernelTransaction transaction, string path, PathFormat pathFormat)
{
Path.CheckInvalidUncPath(path);

string pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.CheckInvalidPathChars);

pathLp = Path.GetRegularPathCore(pathLp, GetFullPathOptions.None, false);

string rootPath = Path.GetPathRoot(pathLp, false);

return Utils.IsNullOrWhiteSpace(rootPath) ? null : rootPath;
}

#endregion // Internal Methods
}
}

+ 210
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetFileSystemEntries.cs View File

@@ -0,0 +1,210 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
// Since Directory.GetFileSystemEntries() is less efficient than Directory.EnumerateFileSystemEntries(),
// only .NET and AlphaFS Transactional methods are implemented. No additional overloaded methods.

#region .NET

/// <summary>Returns the names of all files and subdirectories in the specified directory.</summary>
/// <returns>An string[] array of the names of files and subdirectories in the specified directory.</returns>
/// <remarks>
/// <para>The EnumerateFileSystemEntries and GetFileSystemEntries methods differ as follows: When you use EnumerateFileSystemEntries,
/// you can start enumerating the collection of entries before the whole collection is returned; when you use GetFileSystemEntries,
/// you must wait for the whole array of entries to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory for which file and subdirectory names are returned.</param>
[SecurityCritical]
public static string[] GetFileSystemEntries(string path)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns an array of file system entries that match the specified search criteria.</summary>
/// <returns>An string[] array of file system entries that match the specified search criteria.</returns>
/// <remarks>
/// <para>The EnumerateFileSystemEntries and GetFileSystemEntries methods differ as follows: When you use EnumerateFileSystemEntries,
/// you can start enumerating the collection of entries before the whole collection is returned; when you use GetFileSystemEntries,
/// you must wait for the whole array of entries to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The path to be searched.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static string[] GetFileSystemEntries(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath).ToArray();
}

/// <summary>Gets an array of all the file names and directory names that match a <paramref name="searchPattern"/> in a specified path, and optionally searches subdirectories.</summary>
/// <returns>An string[] array of file system entries that match the specified search criteria.</returns>
/// <remarks>
/// <para>The EnumerateFileSystemEntries and GetFileSystemEntries methods differ as follows: When you use EnumerateFileSystemEntries,
/// you can start enumerating the collection of entries before the whole collection is returned; when you use GetFileSystemEntries,
/// you must wait for the whole array of entries to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath).ToArray();
}

#endregion // .NET

#region Transactional

/// <summary>Returns the names of all files and subdirectories in the specified directory.</summary>
/// <returns>An string[] array of the names of files and subdirectories in the specified directory.</returns>
/// <remarks>
/// <para>The EnumerateFileSystemEntries and GetFileSystemEntries methods differ as follows: When you use EnumerateFileSystemEntries,
/// you can start enumerating the collection of entries before the whole collection is returned; when you use GetFileSystemEntries,
/// you must wait for the whole array of entries to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which file and subdirectory names are returned.</param>
[SecurityCritical]
public static string[] GetFileSystemEntriesTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns an array of file system entries that match the specified search criteria.</summary>
/// <returns>An string[] array of file system entries that match the specified search criteria.</returns>
/// <remarks>
/// <para>The EnumerateFileSystemEntries and GetFileSystemEntries methods differ as follows: When you use EnumerateFileSystemEntries,
/// you can start enumerating the collection of entries before the whole collection is returned; when you use GetFileSystemEntries,
/// you must wait for the whole array of entries to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path to be searched.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static string[] GetFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath).ToArray();
}

/// <summary>Gets an array of all the file names and directory names that match a <paramref name="searchPattern"/> in a specified path, and optionally searches subdirectories.</summary>
/// <returns>An string[] array of file system entries that match the specified search criteria.</returns>
/// <remarks>
/// <para>The EnumerateFileSystemEntries and GetFileSystemEntries methods differ as follows: When you use EnumerateFileSystemEntries,
/// you can start enumerating the collection of entries before the whole collection is returned; when you use GetFileSystemEntries,
/// you must wait for the whole array of entries to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static string[] GetFileSystemEntriesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath).ToArray();
}

#endregion // Transactional
}
}

+ 216
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetFiles.cs View File

@@ -0,0 +1,216 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
// Since Directory.GetFiles() is less efficient than Directory.EnumerateFiles(),
// only .NET and AlphaFS Transactional methods are implemented. No additional overloaded methods.

#region .NET

/// <summary>Returns the names of files (including their paths) in the specified directory.</summary>
/// <returns>An array of the full names (including paths) for the files in the specified directory, or an empty array if no files are found.</returns>
/// <remarks>
/// <para>The returned file names are appended to the supplied <paramref name="path"/> parameter.</para>
/// <para>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</para>
/// <para>The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static string[] GetFiles(string path)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of files (including their paths) that match the specified search pattern in the specified directory.</summary>
/// <returns>An array of the full names (including paths) for the files in the specified directory that match the specified search pattern, or an empty array if no files are found.</returns>
/// <remarks>
/// <para>The returned file names are appended to the supplied <paramref name="path"/> parameter.</para>
/// <para>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</para>
/// <para>The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static string[] GetFiles(string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of files (including their paths) that match the specified search pattern in the current directory, and optionally searches subdirectories.</summary>
/// <returns>An array of the full names (including paths) for the files in the specified directory that match the specified search pattern and option, or an empty array if no files are found.</returns>
/// <remarks>
/// <para>The returned file names are appended to the supplied <paramref name="path"/> parameter.</para>
/// <para>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</para>
/// <para>The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(null, path, searchPattern, options, PathFormat.RelativePath).ToArray();
}

#endregion // .NET

#region Transactional

/// <summary>Returns the names of files (including their paths) in the specified directory.</summary>
/// <returns>An array of the full names (including paths) for the files in the specified directory, or an empty array if no files are found.</returns>
/// <remarks>
/// <para>The returned file names are appended to the supplied <paramref name="path"/> parameter.</para>
/// <para>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</para>
/// <para>The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
[SecurityCritical]
public static string[] GetFilesTransacted(KernelTransaction transaction, string path)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of files (including their paths) that match the specified search pattern in the specified directory.</summary>
/// <returns>An array of the full names (including paths) for the files in the specified directory that match the specified search pattern, or an empty array if no files are found.</returns>
/// <remarks>
/// <para>The returned file names are appended to the supplied <paramref name="path"/> parameter.</para>
/// <para>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</para>
/// <para>The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public static string[] GetFilesTransacted(KernelTransaction transaction, string path, string searchPattern)
{
return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.RelativePath).ToArray();
}

/// <summary>Returns the names of files (including their paths) that match the specified search pattern in the current directory, and optionally searches subdirectories.</summary>
/// <returns>An array of the full names (including paths) for the files in the specified directory that match the specified search pattern and option, or an empty array if no files are found.</returns>
/// <remarks>
/// <para>The returned file names are appended to the supplied <paramref name="path"/> parameter.</para>
/// <para>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</para>
/// <para>The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to search.</param>
/// <param name="searchPattern">
/// The search string to match against the names of directories in <paramref name="path"/>.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public static string[] GetFilesTransacted(KernelTransaction transaction, string path, string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return EnumerateFileSystemEntryInfosCore<string>(transaction, path, searchPattern, options, PathFormat.RelativePath).ToArray();
}

#endregion // Transactional
}
}

+ 121
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetLastAccessTime.cs View File

@@ -0,0 +1,121 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Gets the date and time that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain access date and time information.</param>
[SecurityCritical]
public static DateTime GetLastAccessTime(string path)
{
return File.GetLastAccessTimeCore(null, path, false, PathFormat.RelativePath).ToLocalTime();
}

/// <summary>Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
/// <param name="path">The directory for which to obtain access date and time information.</param>
[SecurityCritical]
public static DateTime GetLastAccessTimeUtc(string path)
{
return File.GetLastAccessTimeCore(null, path, true, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Gets the date and time that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain access date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastAccessTime(string path, PathFormat pathFormat)
{
return File.GetLastAccessTimeCore(null, path, false, pathFormat).ToLocalTime();
}



/// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
/// <param name="path">The directory for which to obtain access date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastAccessTimeUtc(string path, PathFormat pathFormat)
{
return File.GetLastAccessTimeCore(null, path, true, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Gets the date and time that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain access date and time information.</param>
[SecurityCritical]
public static DateTime GetLastAccessTimeTransacted(KernelTransaction transaction, string path)
{
return File.GetLastAccessTimeCore(transaction, path, false, PathFormat.RelativePath).ToLocalTime();
}

/// <summary>[AlphaFS] Gets the date and time that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain access date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastAccessTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetLastAccessTimeCore(transaction, path, false, pathFormat).ToLocalTime();
}



/// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain access date and time information.</param>
[SecurityCritical]
public static DateTime GetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path)
{
return File.GetLastAccessTimeCore(transaction, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last accessed. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain access date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetLastAccessTimeCore(transaction, path, true, pathFormat);
}
#endregion // Transactional
}
}

+ 123
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetLastWriteTime.cs View File

@@ -0,0 +1,123 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Gets the date and time that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain write date and time information.</param>
[SecurityCritical]
public static DateTime GetLastWriteTime(string path)
{
return File.GetLastWriteTimeCore(null, path, false, PathFormat.RelativePath).ToLocalTime();
}



/// <summary>Gets the date and time, in coordinated universal time (UTC) time, that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in UTC time.</returns>
/// <param name="path">The directory for which to obtain write date and time information.</param>
[SecurityCritical]
public static DateTime GetLastWriteTimeUtc(string path)
{
return File.GetLastWriteTimeCore(null, path, true, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Gets the date and time that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in local time.</returns>
/// <param name="path">The directory for which to obtain write date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastWriteTime(string path, PathFormat pathFormat)
{
return File.GetLastWriteTimeCore(null, path, false, pathFormat).ToLocalTime();
}



/// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC) time, that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in UTC time.</returns>
/// <param name="path">The directory for which to obtain write date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastWriteTimeUtc(string path, PathFormat pathFormat)
{
return File.GetLastWriteTimeCore(null, path, true, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Gets the date and time that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain write date and time information.</param>
[SecurityCritical]
public static DateTime GetLastWriteTimeTransacted(KernelTransaction transaction, string path)
{
return File.GetLastWriteTimeCore(transaction, path, false, PathFormat.RelativePath).ToLocalTime();
}

/// <summary>[AlphaFS] Gets the date and time that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in local time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain write date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastWriteTimeTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetLastWriteTimeCore(transaction, path, false, pathFormat).ToLocalTime();
}



/// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC) time, that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain write date and time information.</param>
[SecurityCritical]
public static DateTime GetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path)
{
return File.GetLastWriteTimeCore(transaction, path, true, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the date and time, in coordinated universal time (UTC) time, that the specified directory was last written to.</summary>
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified directory was last written to. This value is expressed in UTC time.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to obtain write date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DateTime GetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return File.GetLastWriteTimeCore(transaction, path, true, pathFormat);
}
#endregion // Transactional
}
}

+ 150
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetLogicalDrives.cs View File

@@ -0,0 +1,150 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Retrieves the names of the logical drives on this computer in the form "&lt;drive letter&gt;:\".</summary>
/// <returns>An array of type <see cref="String"/> that represents the logical drives on a computer.</returns>
[SecurityCritical]
public static string[] GetLogicalDrives()
{
return EnumerateLogicalDrivesCore(false, false).Select(drive => drive.Name).ToArray();
}

#endregion // .NET
/// <summary>[AlphaFS] Retrieves the names of the logical drives on this computer in the form "&lt;drive letter&gt;:\".</summary>
/// <returns>An array of type <see cref="String"/> that represents the logical drives on a computer.</returns>
/// <param name="fromEnvironment">Retrieve logical drives as known by the Environment.</param>
/// <param name="isReady">Retrieve only when accessible (IsReady) logical drives.</param>
[SecurityCritical]
public static string[] GetLogicalDrives(bool fromEnvironment, bool isReady)
{
return EnumerateLogicalDrivesCore(fromEnvironment, isReady).Select(drive => drive.Name).ToArray();
}


/// <summary>[AlphaFS] Enumerates the drive names of all logical drives on a computer.</summary>
/// <returns>An IEnumerable of type <see cref="Alphaleonis.Win32.Filesystem.DriveInfo"/> that represents the logical drives on a computer.</returns>
/// <param name="fromEnvironment">Retrieve logical drives as known by the Environment.</param>
/// <param name="isReady">Retrieve only when accessible (IsReady) logical drives.</param>
[SecurityCritical]
public static IEnumerable<DriveInfo> EnumerateLogicalDrives(bool fromEnvironment, bool isReady)
{
return EnumerateLogicalDrivesCore(fromEnvironment, isReady);
}

#region Internal Methods

/// <summary>Enumerates the drive names of all logical drives on a computer.</summary>
/// <returns>An IEnumerable of type <see cref="Alphaleonis.Win32.Filesystem.DriveInfo"/> that represents the logical drives on a computer.</returns>
/// <param name="fromEnvironment">Retrieve logical drives as known by the Environment.</param>
/// <param name="isReady">Retrieve only when accessible (IsReady) logical drives.</param>
[SecurityCritical]
internal static IEnumerable<DriveInfo> EnumerateLogicalDrivesCore(bool fromEnvironment, bool isReady)
{
#region Get from Environment

if (fromEnvironment)
{
IEnumerable<string> drivesEnv = isReady
? Environment.GetLogicalDrives().Where(ld => File.ExistsCore(true, null, ld, PathFormat.FullPath))
: Environment.GetLogicalDrives().Select(ld => ld);

foreach (string drive in drivesEnv)
{
// Optionally check Drive .IsReady.
if (isReady)
{
if (File.ExistsCore(true, null, drive, PathFormat.FullPath))
yield return new DriveInfo(drive);
}
else
yield return new DriveInfo(drive);
}

yield break;
}

#endregion // Get from Environment

#region Get through NativeMethod

uint lastError = NativeMethods.GetLogicalDrives();
if (lastError == Win32Errors.ERROR_SUCCESS)
NativeError.ThrowException((int)lastError);

uint drives = lastError;
int count = 0;
while (drives != 0)
{
if ((drives & 1) != 0)
++count;

drives >>= 1;
}

string[] result = new string[count];
char[] root = { 'A', Path.VolumeSeparatorChar };

drives = lastError;
count = 0;

while (drives != 0)
{
if ((drives & 1) != 0)
{
string drive = new string(root);

if (isReady)
{
// Optionally check Drive .IsReady.
if (File.ExistsCore(true, null, drive, PathFormat.FullPath))
yield return new DriveInfo(drive);
}
else
{
// Ready or not.
yield return new DriveInfo(drive);
}

result[count++] = drive;
}

drives >>= 1;
root[0]++;
}

#endregion // Get through NativeMethod
}

#endregion // Internal Methods
}
}

+ 92
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetParent.cs View File

@@ -0,0 +1,92 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Retrieves the parent directory of the specified path, including both absolute and relative paths.</summary>
/// <param name="path">The path for which to retrieve the parent directory.</param>
/// <returns>The parent directory, or <see langword="null"/> if <paramref name="path"/> is the root directory, including the root of a UNC server or share name.</returns>
[SecurityCritical]
public static DirectoryInfo GetParent(string path)
{
return GetParentCore(null, path, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Retrieves the parent directory of the specified path, including both absolute and relative paths.</summary>
/// <returns>The parent directory, or <see langword="null"/> if <paramref name="path"/> is the root directory, including the root of a UNC server or share name.</returns>
/// <param name="path">The path for which to retrieve the parent directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DirectoryInfo GetParent(string path, PathFormat pathFormat)
{
return GetParentCore(null, path, pathFormat);
}

#endregion // .NET
/// <summary>[AlphaFS] Retrieves the parent directory of the specified path, including both absolute and relative paths.</summary>
/// <returns>The parent directory, or <see langword="null"/> if <paramref name="path"/> is the root directory, including the root of a UNC server or share name.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path for which to retrieve the parent directory.</param>
[SecurityCritical]
public static DirectoryInfo GetParentTransacted(KernelTransaction transaction, string path)
{
return GetParentCore(transaction, path, PathFormat.RelativePath);
}

/// <summary>Retrieves the parent directory of the specified path, including both absolute and relative paths.</summary>
/// <returns>The parent directory, or <see langword="null"/> if <paramref name="path"/> is the root directory, including the root of a UNC server or share name.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path for which to retrieve the parent directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static DirectoryInfo GetParentTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return GetParentCore(transaction, path, pathFormat);
}

#region Internal Methods

/// <summary>Retrieves the parent directory of the specified path, including both absolute and relative paths.</summary>
/// <returns>The parent directory, or <see langword="null"/> if <paramref name="path"/> is the root directory, including the root of a UNC server or share name.</returns>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path for which to retrieve the parent directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static DirectoryInfo GetParentCore(KernelTransaction transaction, string path, PathFormat pathFormat)
{
string pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.CheckInvalidPathChars);

pathLp = Path.GetRegularPathCore(pathLp, GetFullPathOptions.None, false);
string dirName = Path.GetDirectoryName(pathLp, false);

return Utils.IsNullOrWhiteSpace(dirName) ? null : new DirectoryInfo(transaction, dirName, PathFormat.RelativePath);
}

#endregion // Internal Methods
}
}

+ 286
- 0
AlphaFS/Filesystem/Directory Class/Directory.GetProperties.cs View File

@@ -0,0 +1,286 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The target directory.</param>
[SecurityCritical]
public static Dictionary<string, long> GetProperties(string path)
{
return GetPropertiesCore(null, path, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The target directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static Dictionary<string, long> GetProperties(string path, PathFormat pathFormat)
{
return GetPropertiesCore(null, path, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}


/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The target directory.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static Dictionary<string, long> GetProperties(string path, DirectoryEnumerationOptions options)
{
return GetPropertiesCore(null, path, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The target directory.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static Dictionary<string, long> GetProperties(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return GetPropertiesCore(null, path, options, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The target directory.</param>
[SecurityCritical]
public static Dictionary<string, long> GetPropertiesTransacted(KernelTransaction transaction, string path)
{
return GetPropertiesCore(transaction, path, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The target directory.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static Dictionary<string, long> GetPropertiesTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
{
return GetPropertiesCore(transaction, path, DirectoryEnumerationOptions.FilesAndFolders, pathFormat);
}


/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The target directory.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static Dictionary<string, long> GetPropertiesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
{
return GetPropertiesCore(transaction, path, options, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The target directory.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static Dictionary<string, long> GetPropertiesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return GetPropertiesCore(transaction, path, options, pathFormat);
}
#endregion // Transactional

#region Internal Methods

/// <summary>[AlphaFS] Gets the properties of the particular directory without following any symbolic links or mount points.
/// <para>Properties include aggregated info from <see cref="FileAttributes"/> of each encountered file system object, plus additional ones: Total, File, Size and Error.</para>
/// <para><b>Total:</b> is the total number of enumerated objects.</para>
/// <para><b>File:</b> is the total number of files. File is considered when object is neither <see cref="FileAttributes.Directory"/> nor <see cref="FileAttributes.ReparsePoint"/>.</para>
/// <para><b>Size:</b> is the total size of enumerated objects.</para>
/// <para><b>Error:</b> is the total number of errors encountered during enumeration.</para>
/// </summary>
/// <returns>A dictionary mapping the keys mentioned above to their respective aggregated values.</returns>
/// <remarks><b>Directory:</b> is an object which has <see cref="FileAttributes.Directory"/> attribute without <see cref="FileAttributes.ReparsePoint"/> one.</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The target directory.</param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static Dictionary<string, long> GetPropertiesCore(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
long total = 0;
long size = 0;

const string propFile = "File";
const string propTotal = "Total";
const string propSize = "Size";
var typeOfAttrs = typeof(FileAttributes);
var attributes = Enum.GetValues(typeOfAttrs);
var props = Enum.GetNames(typeOfAttrs).OrderBy(attrs => attrs).ToDictionary<string, string, long>(name => name, name => 0);
var pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

foreach (var fsei in EnumerateFileSystemEntryInfosCore<FileSystemEntryInfo>(transaction, pathLp, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath))
{
total++;

if (!fsei.IsDirectory)
size += fsei.FileSize;

var fsei1 = fsei;

foreach (var attributeMarker in attributes.Cast<FileAttributes>().Where(attributeMarker => (fsei1.Attributes & attributeMarker) != 0))
props[((attributeMarker & FileAttributes.Directory) != 0 ? FileAttributes.Directory : attributeMarker).ToString()]++;
}

// Adjust regular files count.
props.Add(propFile, total - props[FileAttributes.Directory.ToString()] - props[FileAttributes.ReparsePoint.ToString()]);
props.Add(propTotal, total);
props.Add(propSize, size);

return props;
}

#endregion // Internal Methods
}
}

+ 58
- 0
AlphaFS/Filesystem/Directory Class/Directory.HasInheritedPermissions.cs View File

@@ -0,0 +1,58 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security.AccessControl;
using System.Security.Principal;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Check if the directory has permission inheritance enabled.</summary>
/// <returns><see langword="true"/> if permission inheritance is enabled, <see langword="false"/> if permission inheritance is disabled.</returns>
/// <param name="path">The full path to the directory to check.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
public static bool HasInheritedPermissions(string path, PathFormat pathFormat)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");

var acl = File.GetAccessControlCore<DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, pathFormat);

return acl.GetAccessRules(false, true, typeof(SecurityIdentifier)).Count > 0;
}


/// <summary>[AlphaFS] Check if the directory has permission inheritance enabled.</summary>
/// <param name="path">The full path to the directory to check.</param>
/// <returns><see langword="true"/> if permission inheritance is enabled, <see langword="false"/> if permission inheritance is disabled.</returns>
public static bool HasInheritedPermissions(string path)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");

var acl = File.GetAccessControlCore<DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, PathFormat.RelativePath);

return acl.GetAccessRules(false, true, typeof(SecurityIdentifier)).Count > 0;
}
}
}

+ 104
- 0
AlphaFS/Filesystem/Directory Class/Directory.SetAccessControl.cs View File

@@ -0,0 +1,104 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;
using System.Security;
using System.Security.AccessControl;
using Microsoft.Win32.SafeHandles;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the specified directory.</summary>
/// <param name="path">A directory to add or remove access control list (ACL) entries from.</param>
/// <param name="directorySecurity">A <see cref="DirectorySecurity "/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static void SetAccessControl(string path, DirectorySecurity directorySecurity)
{
File.SetAccessControlCore(path, null, directorySecurity, AccessControlSections.All, PathFormat.RelativePath);
}

/// <summary>Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the specified directory.</summary>
/// <remarks>Note that unlike <see cref="System.IO.File.SetAccessControl"/> this method does <b>not</b> automatically
/// determine what parts of the specified <see cref="DirectorySecurity"/> instance has been modified. Instead, the
/// parameter <paramref name="includeSections"/> is used to specify what entries from <paramref name="directorySecurity"/> to apply to <paramref name="path"/>.</remarks>
/// <param name="path">A directory to add or remove access control list (ACL) entries from.</param>
/// <param name="directorySecurity">A <see cref="DirectorySecurity "/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
/// <param name="includeSections">One or more of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to set.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static void SetAccessControl(string path, DirectorySecurity directorySecurity, AccessControlSections includeSections)
{
File.SetAccessControlCore(path, null, directorySecurity, includeSections, PathFormat.RelativePath);
}


/// <summary>[AlphaFS] Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the specified directory.</summary>
/// <param name="path">A directory to add or remove access control list (ACL) entries from.</param>
/// <param name="directorySecurity">A <see cref="DirectorySecurity "/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static void SetAccessControl(string path, DirectorySecurity directorySecurity, PathFormat pathFormat)
{
File.SetAccessControlCore(path, null, directorySecurity, AccessControlSections.All, pathFormat);
}

/// <summary>[AlphaFS] Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the specified directory.</summary>
/// <remarks>Note that unlike <see cref="System.IO.File.SetAccessControl"/> this method does <b>not</b> automatically
/// determine what parts of the specified <see cref="DirectorySecurity"/> instance has been modified. Instead, the
/// parameter <paramref name="includeSections"/> is used to specify what entries from <paramref name="directorySecurity"/> to apply to <paramref name="path"/>.</remarks>
/// <param name="path">A directory to add or remove access control list (ACL) entries from.</param>
/// <param name="directorySecurity">A <see cref="DirectorySecurity "/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
/// <param name="includeSections">One or more of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to set.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static void SetAccessControl(string path, DirectorySecurity directorySecurity, AccessControlSections includeSections, PathFormat pathFormat)
{
File.SetAccessControlCore(path, null, directorySecurity, includeSections, pathFormat);
}


/// <summary>Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the specified directory.</summary>
/// <param name="handle">A <see cref="SafeFileHandle"/> to a file to add or remove access control list (ACL) entries from.</param>
/// <param name="directorySecurity">A <see cref="DirectorySecurity "/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static void SetAccessControl(SafeFileHandle handle, DirectorySecurity directorySecurity)
{
File.SetAccessControlCore(null, handle, directorySecurity, AccessControlSections.All, PathFormat.LongFullPath);
}

/// <summary>Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the specified directory.</summary>
/// <param name="handle">A <see cref="SafeFileHandle"/> to a file to add or remove access control list (ACL) entries from.</param>
/// <param name="directorySecurity">A <see cref="DirectorySecurity "/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
/// <param name="includeSections">One or more of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to set.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public static void SetAccessControl(SafeFileHandle handle, DirectorySecurity directorySecurity, AccessControlSections includeSections)
{
File.SetAccessControlCore(null, handle, directorySecurity, includeSections, PathFormat.LongFullPath);
}
}
}

+ 169
- 0
AlphaFS/Filesystem/Directory Class/Directory.SetCreationTime.cs View File

@@ -0,0 +1,169 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Sets the date and time the directory was created.</summary>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetCreationTime(string path, DateTime creationTime)
{
File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), null, null, false, PathFormat.RelativePath);
}



/// <summary>Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
{
File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, null, null, false, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetCreationTime(string path, DateTime creationTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), null, null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
[SecurityCritical]
public static void SetCreationTime(string path, DateTime creationTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), null, null, modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, null, null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, null, null, modifyReparsePoint, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), null, null, false, PathFormat.RelativePath);
}
/// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), null, null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time the directory was created.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetCreationTimeTransacted(KernelTransaction transaction, string path, DateTime creationTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), null, null, modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, null, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, null, null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the directory was created.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the creation date and time information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetCreationTimeUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, null, null, modifyReparsePoint, pathFormat);
}

#endregion // Transactional
}
}

+ 169
- 0
AlphaFS/Filesystem/Directory Class/Directory.SetLastAccessTime.cs View File

@@ -0,0 +1,169 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Sets the date and time that the specified directory was last accessed.</summary>
/// <param name="path">The file for which to set the access date and time information.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetLastAccessTime(string path, DateTime lastAccessTime)
{
File.SetFsoDateTimeCore(true, null, path, null, lastAccessTime.ToUniversalTime(), null, false, PathFormat.RelativePath);
}



/// <summary>Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
{
File.SetFsoDateTimeCore(true, null, path, null, lastAccessTimeUtc, null, false, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
/// <param name="path">The file for which to set the access date and time information.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTime(string path, DateTime lastAccessTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, lastAccessTime.ToUniversalTime(), null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
/// <param name="path">The file for which to set the access date and time information.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTime(string path, DateTime lastAccessTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, lastAccessTime.ToUniversalTime(), null, modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, lastAccessTimeUtc, null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, lastAccessTimeUtc, null, modifyReparsePoint, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime)
{
File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTime.ToUniversalTime(), null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTime.ToUniversalTime(), null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last accessed.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTimeTransacted(KernelTransaction transaction, string path, DateTime lastAccessTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTime.ToUniversalTime(), null, modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc)
{
File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTimeUtc, null, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTimeUtc, null, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last accessed.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the access date and time information.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastAccessTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastAccessTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, lastAccessTimeUtc, null, modifyReparsePoint, pathFormat);
}
#endregion // Transactional
}
}

+ 167
- 0
AlphaFS/Filesystem/Directory Class/Directory.SetLastWriteTime.cs View File

@@ -0,0 +1,167 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
#region .NET

/// <summary>Sets the date and time that the specified directory was last written to.</summary>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetLastWriteTime(string path, DateTime lastWriteTime)
{
File.SetFsoDateTimeCore(true, null, path, null, null, lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
}



/// <summary>Sets the date and time, in coordinated universal time (UTC), that the specified directory was last written to.</summary>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
{
File.SetFsoDateTimeCore(true, null, path, null, null, lastWriteTimeUtc, false, PathFormat.RelativePath);
}

#endregion // .NET

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last written to.</summary>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTime(string path, DateTime lastWriteTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, null, lastWriteTime.ToUniversalTime(), false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last written to.</summary>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTime(string path, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, null, lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last written to.</summary>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, null, lastWriteTimeUtc, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last written to.</summary>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, null, null, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last written to.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetLastWriteTimeTransacted(KernelTransaction transaction, string path, DateTime lastWriteTime)
{
File.SetFsoDateTimeCore(true, transaction, path, null, null, lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last written to.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTimeTransacted(KernelTransaction transaction, string path, DateTime lastWriteTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, null, lastWriteTime.ToUniversalTime(), false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time that the specified directory was last written to.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTimeTransacted(KernelTransaction transaction, string path, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, null, lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last written to.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastWriteTimeUtc)
{
File.SetFsoDateTimeCore(true, transaction, path, null, null, lastWriteTimeUtc, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last written to.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastWriteTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, null, lastWriteTimeUtc, false, pathFormat);
}

/// <summary>[AlphaFS] Sets the date and time, in coordinated universal time (UTC), that the specified directory was last written to.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the date and time information.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetLastWriteTimeUtcTransacted(KernelTransaction transaction, string path, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, null, null, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
}

#endregion // Transactional
}
}

+ 187
- 0
AlphaFS/Filesystem/Directory Class/Directory.SetTimestamps.cs View File

@@ -0,0 +1,187 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Sets all the date and time stamps for the specified directory, at once.</summary>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetTimestamps(string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime)
{
File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets all the date and time stamps for the specified directory, at once.</summary>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestamps(string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, pathFormat);
}

/// <summary>[AlphaFS] Sets all the date and time stamps for the specified directory, at once.</summary>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestamps(string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified directory, at once.</summary>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetTimestampsUtc(string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc)
{
File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified directory, at once.</summary>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestampsUtc(string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, pathFormat);
}

/// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified directory, at once.</summary>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestampsUtc(string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, null, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Sets all the date and time stamps for the specified directory, at once.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
[SecurityCritical]
public static void SetTimestampsTransacted(KernelTransaction transaction, string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets all the date and time stamps for the specified directory, at once.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestampsTransacted(KernelTransaction transaction, string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), false, pathFormat);
}

/// <summary>[AlphaFS] Sets all the date and time stamps for the specified directory, at once.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTime">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in local time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestampsTransacted(KernelTransaction transaction, string path, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTime.ToUniversalTime(), lastAccessTime.ToUniversalTime(), lastWriteTime.ToUniversalTime(), modifyReparsePoint, pathFormat);
}



/// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified directory, at once.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
[SecurityCritical]
public static void SetTimestampsUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified directory, at once.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestampsUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, false, pathFormat);
}

/// <summary>[AlphaFS] Sets all the date and time stamps, in coordinated universal time (UTC), for the specified directory, at once.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory for which to set the dates and times information.</param>
/// <param name="creationTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the creation date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="lastWriteTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last write date and time of <paramref name="path"/>. This value is expressed in UTC time.</param>
/// <param name="modifyReparsePoint">If <see langword="true"/>, the date and time information will apply to the reparse point (symlink or junction) and not the file or directory linked to. No effect if <paramref name="path"/> does not refer to a reparse point.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void SetTimestampsUtcTransacted(KernelTransaction transaction, string path, DateTime creationTimeUtc, DateTime lastAccessTimeUtc, DateTime lastWriteTimeUtc, bool modifyReparsePoint, PathFormat pathFormat)
{
File.SetFsoDateTimeCore(true, transaction, path, creationTimeUtc, lastAccessTimeUtc, lastWriteTimeUtc, modifyReparsePoint, pathFormat);
}

#endregion // Transactional
}
}

+ 76
- 0
AlphaFS/Filesystem/Directory Class/Directory.TransferTimestamps.cs View File

@@ -0,0 +1,76 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class Directory
{
/// <summary>[AlphaFS] Transfers the date and time stamps for the specified directories.</summary>
/// <remarks>This method uses BackupSemantics flag to get Timestamp changed for directories.</remarks>
/// <param name="sourcePath">The source directory to get the date and time stamps from.</param>
/// <param name="destinationPath">The destination directory to set the date and time stamps.</param>
[SecurityCritical]
public static void TransferTimestamps(string sourcePath, string destinationPath)
{
File.TransferTimestampsCore(true, null, sourcePath, destinationPath, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Transfers the date and time stamps for the specified directories.</summary>
/// <remarks>This method uses BackupSemantics flag to get Timestamp changed for directories.</remarks>
/// <param name="sourcePath">The source directory to get the date and time stamps from.</param>
/// <param name="destinationPath">The destination directory to set the date and time stamps.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void TransferTimestamps(string sourcePath, string destinationPath, PathFormat pathFormat)
{
File.TransferTimestampsCore(true, null, sourcePath, destinationPath, pathFormat);
}

#region Transactional

/// <summary>[AlphaFS] Transfers the date and time stamps for the specified directories.</summary>
/// <remarks>This method uses BackupSemantics flag to get Timestamp changed for directories.</remarks>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory to get the date and time stamps from.</param>
/// <param name="destinationPath">The destination directory to set the date and time stamps.</param>
[SecurityCritical]
public static void TransferTimestampsTransacted(KernelTransaction transaction, string sourcePath, string destinationPath)
{
File.TransferTimestampsCore(true, transaction, sourcePath, destinationPath, PathFormat.RelativePath);
}

/// <summary>[AlphaFS] Transfers the date and time stamps for the specified directories.</summary>
/// <remarks>This method uses BackupSemantics flag to get Timestamp changed for directories.</remarks>
/// <param name="transaction">The transaction.</param>
/// <param name="sourcePath">The source directory to get the date and time stamps from.</param>
/// <param name="destinationPath">The destination directory to set the date and time stamps.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public static void TransferTimestampsTransacted(KernelTransaction transaction, string sourcePath, string destinationPath, PathFormat pathFormat)
{
File.TransferTimestampsCore(true, transaction, sourcePath, destinationPath, pathFormat);
}
#endregion // Transactional
}
}

+ 31
- 0
AlphaFS/Filesystem/Directory Class/Directory.cs View File

@@ -0,0 +1,31 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Exposes static methods for creating, moving, and enumerating through directories and subdirectories.
/// <para>This class cannot be inherited.</para>
/// </summary>
public static partial class Directory
{
// This file only exists for the documentation.
}
}

+ 128
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Compression.cs View File

@@ -0,0 +1,128 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region AlphaFS

#region Compress

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <remarks>This will only compress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public void Compress()
{
Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public void Compress(DirectoryEnumerationOptions options)
{
Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, options, true, PathFormat.LongFullPath);
}

#endregion // Compress

#region Decompress

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <remarks>This will only decompress the root items (non recursive).</remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public void Decompress()
{
Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public void Decompress(DirectoryEnumerationOptions options)
{
Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, options, false, PathFormat.LongFullPath);
}

#endregion // Decompress

#region DisableCompression

/// <summary>[AlphaFS] Disables compression of the specified directory and the files in it.</summary>
/// <remarks>
/// This method disables the directory-compression attribute. It will not decompress the current contents of the directory.
/// However, newly created files and directories will be uncompressed.
/// </remarks>
[SecurityCritical]
public void DisableCompression()
{
Device.ToggleCompressionCore(true, Transaction, LongFullName, false, PathFormat.LongFullPath);
}

#endregion // DisableCompression

#region EnableCompression

/// <summary>[AlphaFS] Enables compression of the specified directory and the files in it.</summary>
/// <remarks>
/// This method enables the directory-compression attribute. It will not compress the current contents of the directory.
/// However, newly created files and directories will be compressed.
/// </remarks>
[SecurityCritical]
public void EnableCompression()
{
Device.ToggleCompressionCore(true, Transaction, LongFullName, true, PathFormat.LongFullPath);
}

#endregion // EnableCompression

#endregion // AlphaFS
}
}

+ 459
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.CopyToMoveTo.cs View File

@@ -0,0 +1,459 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region CopyTo

// .NET: Directory class does not contain the Copy() method.
// Mimic .NET File.Copy() methods.

/// <summary>[AlphaFS] Copies a <see cref="DirectoryInfo"/> instance and its contents to a new path.
/// <remarks>
/// <para>Use this method to prevent overwriting of an existing directory by default.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A new <see cref="DirectoryInfo"/> instance if the directory was completely copied.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
[SecurityCritical]
public DirectoryInfo CopyTo(string destinationPath)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, CopyOptions.FailIfExists, null, null, null, out destinationPathLp, PathFormat.RelativePath);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Copies a <see cref="DirectoryInfo"/> instance and its contents to a new path.
/// <remarks>
/// <para>Use this method to prevent overwriting of an existing directory by default.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A new <see cref="DirectoryInfo"/> instance if the directory was completely copied.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public DirectoryInfo CopyTo(string destinationPath, PathFormat pathFormat)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, CopyOptions.FailIfExists, null, null, null, out destinationPathLp, pathFormat);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}



/// <summary>[AlphaFS] Copies an existing directory to a new directory, allowing the overwriting of an existing directory, <see cref="CopyOptions"/> can be specified.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>
/// <para>Returns a new directory, or an overwrite of an existing directory if <paramref name="copyOptions"/> is not <see cref="CopyOptions.FailIfExists"/>.</para>
/// <para>If the directory exists and <paramref name="copyOptions"/> contains <see cref="CopyOptions.FailIfExists"/>, an <see cref="IOException"/> is thrown.</para>
/// </returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public DirectoryInfo CopyTo(string destinationPath, CopyOptions copyOptions)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, copyOptions, null, null, null, out destinationPathLp, PathFormat.RelativePath);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Copies an existing directory to a new directory, allowing the overwriting of an existing directory, <see cref="CopyOptions"/> can be specified.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>
/// <para>Returns a new directory, or an overwrite of an existing directory if <paramref name="copyOptions"/> is not <see cref="CopyOptions.FailIfExists"/>.</para>
/// <para>If the directory exists and <paramref name="copyOptions"/> contains <see cref="CopyOptions.FailIfExists"/>, an <see cref="IOException"/> is thrown.</para>
/// </returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public DirectoryInfo CopyTo(string destinationPath, CopyOptions copyOptions, PathFormat pathFormat)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, copyOptions, null, null, null, out destinationPathLp, pathFormat);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}



/// <summary>[AlphaFS] Copies an existing directory to a new directory, allowing the overwriting of an existing directory, <see cref="CopyOptions"/> can be specified.
/// <para>and the possibility of notifying the application of its progress through a callback function.</para>
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public CopyMoveResult CopyTo(string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
string destinationPathLp;
var cmr = CopyToMoveToCore(destinationPath, copyOptions, null, progressHandler, userProgressData, out destinationPathLp, PathFormat.RelativePath);
CopyToMoveToCoreRefresh(destinationPath, destinationPathLp);
return cmr;
}

/// <summary>[AlphaFS] Copies an existing directory to a new directory, allowing the overwriting of an existing directory, <see cref="CopyOptions"/> can be specified.
/// <para>and the possibility of notifying the application of its progress through a callback function.</para>
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the directory is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public CopyMoveResult CopyTo(string destinationPath, CopyOptions copyOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
string destinationPathLp;
var cmr = CopyToMoveToCore(destinationPath, copyOptions, null, progressHandler, userProgressData, out destinationPathLp, pathFormat);
CopyToMoveToCoreRefresh(destinationPath, destinationPathLp);
return cmr;
}

#endregion // CopyTo


#region MoveTo

#region .NET

/// <summary>Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path.
/// <remarks>
/// <para>Use this method to prevent overwriting of an existing directory by default.</para>
/// <para>This method does not work across disk volumes.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">
/// <para>The name and path to which to move this directory.</para>
/// <para>The destination cannot be another disk volume or a directory with the identical name.</para>
/// <para>It can be an existing directory to which you want to add this directory as a subdirectory.</para>
/// </param>
[SecurityCritical]
public CopyMoveResult MoveTo(string destinationPath)
{
string destinationPathLp;
var copyMoveResult = CopyToMoveToCore(destinationPath, null, MoveOptions.None, null, null, out destinationPathLp, PathFormat.RelativePath);
CopyToMoveToCoreRefresh(destinationPath, destinationPathLp);

return copyMoveResult;
}

#endregion // .NET


#region AlphaFS

/// <summary>Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path.
/// <remarks>
/// <para>Use this method to prevent overwriting of an existing directory by default.</para>
/// <para>This method does not work across disk volumes.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A new <see cref="DirectoryInfo"/> instance if the directory was completely moved.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">
/// <para>The name and path to which to move this directory.</para>
/// <para>The destination cannot be another disk volume or a directory with the identical name.</para>
/// <para>It can be an existing directory to which you want to add this directory as a subdirectory.</para>
/// </param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public DirectoryInfo MoveTo(string destinationPath, PathFormat pathFormat)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, null, MoveOptions.None, null, null, out destinationPathLp, pathFormat);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}



/// <summary>[AlphaFS] Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path, <see cref="MoveOptions"/> can be specified.
/// <remarks>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A new <see cref="DirectoryInfo"/> instance if the directory was completely moved.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">
/// <para>The name and path to which to move this directory.</para>
/// <para>The destination cannot be another disk volume unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>, or a directory with the identical name.</para>
/// <para>It can be an existing directory to which you want to add this directory as a subdirectory.</para>
/// </param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public DirectoryInfo MoveTo(string destinationPath, MoveOptions moveOptions)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, null, moveOptions, null, null, out destinationPathLp, PathFormat.RelativePath);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path, <see cref="MoveOptions"/> can be specified.
/// <remarks>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A new <see cref="DirectoryInfo"/> instance if the directory was completely moved.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">
/// <para>The name and path to which to move this directory.</para>
/// <para>The destination cannot be another disk volume unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>, or a directory with the identical name.</para>
/// <para>It can be an existing directory to which you want to add this directory as a subdirectory.</para>
/// </param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public DirectoryInfo MoveTo(string destinationPath, MoveOptions moveOptions, PathFormat pathFormat)
{
string destinationPathLp;
CopyToMoveToCore(destinationPath, null, moveOptions, null, null, out destinationPathLp, pathFormat);
return new DirectoryInfo(Transaction, destinationPathLp, PathFormat.LongFullPath);
}



/// <summary>[AlphaFS] Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path, <see cref="MoveOptions"/> can be specified,
/// <para>and the possibility of notifying the application of its progress through a callback function.</para>
/// <remarks>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">
/// <para>The name and path to which to move this directory.</para>
/// <para>The destination cannot be another disk volume unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>, or a directory with the identical name.</para>
/// <para>It can be an existing directory to which you want to add this directory as a subdirectory.</para>
/// </param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
[SecurityCritical]
public CopyMoveResult MoveTo(string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData)
{
string destinationPathLp;
var cmr = CopyToMoveToCore(destinationPath, null, moveOptions, progressHandler, userProgressData, out destinationPathLp, PathFormat.RelativePath);
CopyToMoveToCoreRefresh(destinationPath, destinationPathLp);
return cmr;
}



/// <summary>[AlphaFS] Moves a <see cref="DirectoryInfo"/> instance and its contents to a new path, <see cref="MoveOptions"/> can be specified,
/// <para>and the possibility of notifying the application of its progress through a callback function.</para>
/// <remarks>
/// <para>Use this method to allow or prevent overwriting of an existing directory.</para>
/// <para>This method does not work across disk volumes unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>.</para>
/// <para>Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method.</para>
/// <para>If two directories have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">
/// <para>The name and path to which to move this directory.</para>
/// <para>The destination cannot be another disk volume unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.CopyAllowed"/>, or a directory with the identical name.</para>
/// <para>It can be an existing directory to which you want to add this directory as a subdirectory.</para>
/// </param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the directory is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the directory has been moved. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
public CopyMoveResult MoveTo(string destinationPath, MoveOptions moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
{
string destinationPathLp;
var cmr = CopyToMoveToCore(destinationPath, null, moveOptions, progressHandler, userProgressData, out destinationPathLp, pathFormat);
CopyToMoveToCoreRefresh(destinationPath, destinationPathLp);
return cmr;
}

#endregion // AlphaFS

#endregion // MoveTo


#region Internal Methods

/// <summary>Copy/move a Non-/Transacted file or directory including its children to a new location,
/// <see cref="CopyOptions"/> or <see cref="MoveOptions"/> can be specified, and the possibility of notifying the application of its progress through a callback function.
/// <remarks>
/// <para>Option <see cref="CopyOptions.NoBuffering"/> is recommended for very large file transfers.</para>
/// <para>You cannot use the Move method to overwrite an existing file, unless <paramref name="moveOptions"/> contains <see cref="MoveOptions.ReplaceExisting"/>.</para>
/// <para>Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an IOException.</para>
/// </remarks>
/// </summary>
/// <returns>A <see cref="CopyMoveResult"/> class with details of the Copy or Move action.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="destinationPath">The destination directory path.</param>
/// <param name="copyOptions"><see cref="CopyOptions"/> that specify how the file is to be copied. This parameter can be <see langword="null"/>.</param>
/// <param name="moveOptions"><see cref="MoveOptions"/> that specify how the file is to be moved. This parameter can be <see langword="null"/>.</param>
/// <param name="progressHandler">A callback function that is called each time another portion of the file has been copied. This parameter can be <see langword="null"/>.</param>
/// <param name="userProgressData">The argument to be passed to the callback function. This parameter can be <see langword="null"/>.</param>
/// <param name="longFullPath">Returns the retrieved long full path.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
private CopyMoveResult CopyToMoveToCore(string destinationPath, CopyOptions? copyOptions, MoveOptions? moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, out string longFullPath, PathFormat pathFormat)
{
var destinationPathLp = Path.GetExtendedLengthPathCore(null, destinationPath, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
longFullPath = destinationPathLp;

// Returns false when CopyMoveProgressResult is PROGRESS_CANCEL or PROGRESS_STOP.
return Directory.CopyMoveCore(Transaction, LongFullName, destinationPathLp, copyOptions, moveOptions, progressHandler, userProgressData, null, PathFormat.LongFullPath);
}


private void CopyToMoveToCoreRefresh(string destinationPath, string destinationPathLp)
{
LongFullName = destinationPathLp;
FullPath = Path.GetRegularPathCore(destinationPathLp, GetFullPathOptions.None, false);

OriginalPath = destinationPath;
DisplayPath = Path.GetRegularPathCore(OriginalPath, GetFullPathOptions.None, false);

// Flush any cached information about the directory.
Reset();
}

#endregion // Internal Methods
}
}

+ 70
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.CountFileSystemObjects.cs View File

@@ -0,0 +1,70 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region AlphaFS

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public long CountFileSystemObjects(DirectoryEnumerationOptions options)
{
return Directory.EnumerateFileSystemEntryInfosCore<string>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath).Count();
}

/// <summary>[AlphaFS] Counts file system objects: files, folders or both) in a given directory.</summary>
/// <returns>The counted number of file system objects.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public long CountFileSystemObjects(string searchPattern, DirectoryEnumerationOptions options)
{
return Directory.EnumerateFileSystemEntryInfosCore<string>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).Count();
}

#endregion // AlphaFS
}
}

+ 81
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Create.cs View File

@@ -0,0 +1,81 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;
using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Creates a directory.</summary>
/// <remarks>If the directory already exists, this method does nothing.</remarks>

[SecurityCritical]
public void Create()
{
Directory.CreateDirectoryCore(Transaction, LongFullName, null, null, false, PathFormat.LongFullPath);
}

/// <summary>Creates a directory using a <see cref="System.Security.AccessControl.DirectorySecurity"/> object.</summary>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <remarks>If the directory already exists, this method does nothing.</remarks>

[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public void Create(DirectorySecurity directorySecurity)
{
Directory.CreateDirectoryCore(Transaction, LongFullName, null, directorySecurity, false, PathFormat.LongFullPath);
}

#endregion // .NET

#region AlphaFS

/// <summary>[AlphaFS] Creates a directory using a <see cref="System.Security.AccessControl.DirectorySecurity"/> object.</summary>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <remarks>If the directory already exists, this method does nothing.</remarks>

[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public void Create(bool compress)
{
Directory.CreateDirectoryCore(Transaction, LongFullName, null, null, compress, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Creates a directory using a <see cref="System.Security.AccessControl.DirectorySecurity"/> object.</summary>
/// <param name="directorySecurity">The access control to apply to the directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <remarks>If the directory already exists, this method does nothing.</remarks>

[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public void Create(DirectorySecurity directorySecurity, bool compress)
{
Directory.CreateDirectoryCore(Transaction, LongFullName, null, directorySecurity, compress, PathFormat.LongFullPath);
}

#endregion // AlphaFS
}
}

+ 165
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.CreateSubdirectory.cs View File

@@ -0,0 +1,165 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.</summary>
/// <param name="path">The specified path. This cannot be a different disk volume.</param>
/// <returns>The last directory specified in <paramref name="path"/>.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>

[SecurityCritical]
public DirectoryInfo CreateSubdirectory(string path)
{
return CreateSubdirectoryCore(path, null, null, false);
}

/// <summary>Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.</summary>
/// <param name="path">The specified path. This cannot be a different disk volume.</param>
/// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
/// <returns>The last directory specified in <paramref name="path"/>.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>

[SecurityCritical]
public DirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity)
{
return CreateSubdirectoryCore(path, null, directorySecurity, false);
}

#endregion // .NET

#region AlphaFS

/// <summary>[AlphaFS] Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.</summary>
/// <returns>The last directory specified in <paramref name="path"/>.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>
/// <param name="path">The specified path. This cannot be a different disk volume.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SecurityCritical]
public DirectoryInfo CreateSubdirectory(string path, bool compress)
{
return CreateSubdirectoryCore(path, null, null, compress);
}

/// <summary>[AlphaFS] Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.</summary>
/// <param name="path">The specified path. This cannot be a different disk volume.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <returns>The last directory specified in <paramref name="path"/>.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>

[SecurityCritical]
public DirectoryInfo CreateSubdirectory(string path, string templatePath, bool compress)
{
return CreateSubdirectoryCore(path, templatePath, null, compress);
}


/// <summary>[AlphaFS] Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.</summary>
/// <param name="path">The specified path. This cannot be a different disk volume.</param>
/// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <returns>The last directory specified in <paramref name="path"/>.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>

[SecurityCritical]
public DirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity, bool compress)
{
return CreateSubdirectoryCore(path, null, directorySecurity, compress);
}

/// <summary>[AlphaFS] Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="DirectoryInfo"/> class.</summary>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="path">The specified path. This cannot be a different disk volume.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
/// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
/// <returns>The last directory specified in <paramref name="path"/>.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>

[SecurityCritical]
public DirectoryInfo CreateSubdirectory(string path, string templatePath, DirectorySecurity directorySecurity, bool compress)
{
return CreateSubdirectoryCore(path, templatePath, directorySecurity, compress);
}

#endregion // AlphaFS

#region Internal Methods

/// <summary>Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class.</summary>
/// <returns>The last directory specified in path as an <see cref="DirectoryInfo"/> object.</returns>
/// <remarks>
/// Any and all directories specified in path are created, unless some part of path is invalid.
/// The path parameter specifies a directory path, not a file path.
/// If the subdirectory already exists, this method does nothing.
/// </remarks>
/// <param name="path">The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
/// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
/// <param name="compress">When <see langword="true"/> compresses the directory.</param>
[SecurityCritical]
private DirectoryInfo CreateSubdirectoryCore(string path, string templatePath, DirectorySecurity directorySecurity, bool compress)
{
string pathLp = Path.CombineCore(false, LongFullName, path);
string templatePathLp = templatePath == null ? null :
Path.GetExtendedLengthPathCore(Transaction, templatePath, PathFormat.RelativePath, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);

if (string.Compare(LongFullName, 0, pathLp, 0, LongFullName.Length, StringComparison.OrdinalIgnoreCase) != 0)
throw new ArgumentException(Resources.Invalid_Subpath, pathLp);

return Directory.CreateDirectoryCore(Transaction, pathLp, templatePathLp, directorySecurity, compress, PathFormat.LongFullPath);
}

#endregion // Internal Methods
}
}

+ 28
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Decrypt.cs View File

@@ -0,0 +1,28 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
}
}

+ 88
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Delete.cs View File

@@ -0,0 +1,88 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Deletes this <see cref="DirectoryInfo"/> if it is empty.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public override void Delete()
{
Directory.DeleteDirectoryCore(null, Transaction, LongFullName, false, false, true, false, PathFormat.LongFullPath);
}

/// <summary>Deletes this instance of a <see cref="DirectoryInfo"/>, specifying whether to delete subdirectories and files.</summary>
/// <remarks>
/// <para>If the <see cref="DirectoryInfo"/> has no files or subdirectories, this method deletes the <see cref="DirectoryInfo"/> even if recursive is <see langword="false"/>.</para>
/// <para>Attempting to delete a <see cref="DirectoryInfo"/> that is not empty when recursive is false throws an <see cref="IOException"/>.</para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="recursive"><see langword="true"/> to delete this directory, its subdirectories, and all files; otherwise, <see langword="false"/>.</param>
[SecurityCritical]
public void Delete(bool recursive)
{
Directory.DeleteDirectoryCore(null, Transaction, LongFullName, recursive, false, !recursive, false, PathFormat.LongFullPath);
}

#endregion // .NET

#region AlphaFS

/// <summary>[AlphaFS] Deletes this instance of a <see cref="DirectoryInfo"/>, specifying whether to delete files and subdirectories.</summary>
/// <remarks>
/// <para>If the <see cref="DirectoryInfo"/> has no files or subdirectories, this method deletes the <see cref="DirectoryInfo"/> even if recursive is <see langword="false"/>.</para>
/// <para>Attempting to delete a <see cref="DirectoryInfo"/> that is not empty when recursive is false throws an <see cref="IOException"/>.</para>
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="recursive"><see langword="true"/> to delete this directory, its subdirectories, and all files; otherwise, <see langword="false"/>.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> ignores read only attribute of files and directories.</param>
[SecurityCritical]
public void Delete(bool recursive, bool ignoreReadOnly)
{
Directory.DeleteDirectoryCore(null, Transaction, LongFullName, recursive, ignoreReadOnly, !recursive, false, PathFormat.LongFullPath);
}

#endregion // AlphaFS
}
}

+ 57
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.DeleteEmptySubdirectories.cs View File

@@ -0,0 +1,57 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region AlphaFS

/// <summary>[AlphaFS] Deletes empty subdirectories from the <see cref="DirectoryInfo"/> instance.</summary>
[SecurityCritical]
public void DeleteEmptySubdirectories()
{
Directory.DeleteEmptySubdirectoriesCore(null, Transaction, LongFullName, false, false, true, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Deletes empty subdirectories from the <see cref="DirectoryInfo"/> instance.</summary>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
[SecurityCritical]
public void DeleteEmptySubdirectories(bool recursive)
{
Directory.DeleteEmptySubdirectoriesCore(null, Transaction, LongFullName, recursive, false, true, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Deletes empty subdirectories from the <see cref="DirectoryInfo"/> instance.</summary>
/// <param name="recursive"><see langword="true"/> deletes empty subdirectories from this directory and its subdirectories.</param>
/// <param name="ignoreReadOnly"><see langword="true"/> overrides read only <see cref="FileAttributes"/> of empty directories.</param>
[SecurityCritical]
public void DeleteEmptySubdirectories(bool recursive, bool ignoreReadOnly)
{
Directory.DeleteEmptySubdirectoriesCore(null, Transaction, LongFullName, recursive, ignoreReadOnly, true, PathFormat.LongFullPath);
}

#endregion // AlphaFS
}
}

+ 122
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Encryption.cs View File

@@ -0,0 +1,122 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region AlphaFS

#region Decrypt

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public void Decrypt()
{
Directory.EncryptDecryptDirectoryCore(LongFullName, false, false, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="recursive"><see langword="true"/> to decrypt the directory recursively. <see langword="false"/> only decrypt files and directories in the root of the directory.</param>
[SecurityCritical]
public void Decrypt(bool recursive)
{
Directory.EncryptDecryptDirectoryCore(LongFullName, false, recursive, PathFormat.LongFullPath);
}

#endregion // Decrypt
#region DisableEncryption

/// <summary>[AlphaFS] Disables encryption of the specified directory and the files in it. It does not affect encryption of subdirectories below the indicated directory.</summary>
/// <returns><see langword="true"/> on success, <see langword="false"/> otherwise.</returns>
/// <remarks>This method will create/change the file "Desktop.ini" and wil set Encryption value: "Disable=0"</remarks>
[SecurityCritical]
public void DisableEncryption()
{
Directory.EnableDisableEncryptionCore(LongFullName, false, PathFormat.LongFullPath);
}

#endregion // DisableEncryption

#region EnableEncryption

/// <summary>[AlphaFS] Enables encryption of the specified directory and the files in it. It does not affect encryption of subdirectories below the indicated directory.</summary>
/// <returns><see langword="true"/> on success, <see langword="false"/> otherwise.</returns>
/// <remarks>This method will create/change the file "Desktop.ini" and wil set Encryption value: "Disable=1"</remarks>
[SecurityCritical]
public void EnableEncryption()
{
Directory.EnableDisableEncryptionCore(LongFullName, true, PathFormat.LongFullPath);
}

#endregion // EnableEncryption

#region Encrypt

/// <summary>[AlphaFS] Encrypts a directory so that only the account used to encrypt the directory can decrypt it.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public void Encrypt()
{
Directory.EncryptDecryptDirectoryCore(LongFullName, true, false, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Decrypts a directory that was encrypted by the current account using the Encrypt method.</summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="recursive"><see langword="true"/> to encrypt the directory recursively. <see langword="false"/> only encrypt files and directories in the root of the directory.</param>
[SecurityCritical]
public void Encrypt(bool recursive)
{
Directory.EncryptDecryptDirectoryCore(LongFullName, true, recursive, PathFormat.LongFullPath);
}

#endregion // Encrypt

#endregion // AlphaFS
}
}

+ 37
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateAlternateDataStreams.cs View File

@@ -0,0 +1,37 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Collections.Generic;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
/// <summary>[AlphaFS] Returns an enumerable collection of <see cref="AlternateDataStreamInfo"/> instances for the directory.</summary>
/// <returns>An enumerable collection of <see cref="AlternateDataStreamInfo"/> instances for the directory.</returns>
[SecurityCritical]
public IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams()
{
return File.EnumerateAlternateDataStreamsCore(Transaction, LongFullName, PathFormat.LongFullPath);
}
}
}

+ 138
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateDirectories.cs View File

@@ -0,0 +1,138 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Returns an enumerable collection of directory information in the current directory.</summary>
/// <returns>An enumerable collection of directories in the current directory.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public IEnumerable<DirectoryInfo> EnumerateDirectories()
{
return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of directory information that matches a specified search pattern.</summary>
/// <returns>An enumerable collection of directories that matches <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public IEnumerable<DirectoryInfo> EnumerateDirectories(string searchPattern)
{
return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of directory information that matches a specified search pattern and search subdirectory option.</summary>
/// <returns>An enumerable collection of directories that matches <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public IEnumerable<DirectoryInfo> EnumerateDirectories(string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
}

#endregion // .NET



/// <summary>[AlphaFS] Returns an enumerable collection of directory information in the current directory.</summary>
/// <returns>An enumerable collection of directories in the current directory.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public IEnumerable<DirectoryInfo> EnumerateDirectories(DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of directory information that matches a specified search pattern.</summary>
/// <returns>An enumerable collection of directories that matches <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public IEnumerable<DirectoryInfo> EnumerateDirectories(string searchPattern, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Files;
options |= DirectoryEnumerationOptions.Folders;

return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.Folders | options, PathFormat.LongFullPath);
}
}
}

+ 136
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateFileSystemInfos.cs View File

@@ -0,0 +1,136 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Returns an enumerable collection of file system information in the current directory.</summary>
/// <returns>An enumerable collection of file system information in the current directory. </returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos()
{
return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of file system information that matches a specified search pattern.</summary>
/// <returns>An enumerable collection of file system information objects that matches <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string searchPattern)
{
return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of file system information that matches a specified search pattern and search subdirectory option.</summary>
/// <returns>An enumerable collection of file system information objects that matches <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
}

#endregion // .NET



/// <summary>[AlphaFS] Returns an enumerable collection of file system information in the current directory.</summary>
/// <returns>An enumerable collection of file system information in the current directory. </returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(DirectoryEnumerationOptions options)
{
return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath);
}

/// <summary>[AlphaFS] Returns an enumerable collection of file system information that matches a specified search pattern.</summary>
/// <returns>An enumerable collection of file system information objects that matches <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string searchPattern, DirectoryEnumerationOptions options)
{
return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
}
}
}

+ 138
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.EnumerateFiles.cs View File

@@ -0,0 +1,138 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Returns an enumerable collection of file information in the current directory.</summary>
/// <returns>An enumerable collection of the files in the current directory.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public IEnumerable<FileInfo> EnumerateFiles()
{
return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of file information that matches a search pattern.</summary>
/// <returns>An enumerable collection of files that matches <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public IEnumerable<FileInfo> EnumerateFiles(string searchPattern)
{
return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of file information that matches a specified search pattern and search subdirectory option.</summary>
/// <returns>An enumerable collection of files that matches <paramref name="searchPattern"/> and <paramref name="searchOption"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public IEnumerable<FileInfo> EnumerateFiles(string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
}

#endregion // .NET



/// <summary>Returns an enumerable collection of file information in the current directory.</summary>
/// <returns>An enumerable collection of the files in the current directory.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public IEnumerable<FileInfo> EnumerateFiles(DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath);
}

/// <summary>Returns an enumerable collection of file information that matches a search pattern.</summary>
/// <returns>An enumerable collection of files that matches <paramref name="searchPattern"/>.</returns>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public IEnumerable<FileInfo> EnumerateFiles(string searchPattern, DirectoryEnumerationOptions options)
{
// Adhere to the method name.
options &= ~DirectoryEnumerationOptions.Folders;
options |= DirectoryEnumerationOptions.Files;

return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath);
}
}
}

+ 52
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetAccessControl.cs View File

@@ -0,0 +1,52 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Gets a <see cref="DirectorySecurity"/> object that encapsulates the access control list (ACL) entries for the directory described by the current DirectoryInfo object.</summary>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the directory.</returns>

[SecurityCritical]
public DirectorySecurity GetAccessControl()
{
return File.GetAccessControlCore<DirectorySecurity>(true, LongFullName, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, PathFormat.LongFullPath);
}

/// <summary>Gets a <see cref="DirectorySecurity"/> object that encapsulates the specified type of access control list (ACL) entries for the directory described by the current <see cref="DirectoryInfo"/> object.</summary>
/// <param name="includeSections">One of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to receive.</param>
/// <returns>A <see cref="DirectorySecurity"/> object that encapsulates the access control rules for the file described by the path parameter.</returns>

[SecurityCritical]
public DirectorySecurity GetAccessControl(AccessControlSections includeSections)
{
return File.GetAccessControlCore<DirectorySecurity>(true, LongFullName, includeSections, PathFormat.LongFullPath);
}

#endregion // .NET
}
}

+ 110
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetDirectories.cs View File

@@ -0,0 +1,110 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Returns the subdirectories of the current directory.</summary>
/// <returns>An array of <see cref="DirectoryInfo"/> objects.</returns>
/// <remarks>If there are no subdirectories, this method returns an empty array. This method is not recursive.</remarks>
/// <remarks>
/// The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public DirectoryInfo[] GetDirectories()
{
return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Folders, PathFormat.LongFullPath).ToArray();
}

/// <summary>Returns an array of directories in the current <see cref="DirectoryInfo"/> matching the given search criteria.</summary>
/// <returns>An array of type <see cref="DirectoryInfo"/> matching <paramref name="searchPattern"/>.</returns>
/// <remarks>
/// The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
[SecurityCritical]
public DirectoryInfo[] GetDirectories(string searchPattern)
{
return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.Folders, PathFormat.LongFullPath).ToArray();
}

/// <summary>Returns an array of directories in the current <see cref="DirectoryInfo"/> matching the given search criteria and using a value to determine whether to search subdirectories.</summary>
/// <returns>An array of type <see cref="DirectoryInfo"/> matching <paramref name="searchPattern"/>.</returns>
/// <remarks>If there are no subdirectories, or no subdirectories match the searchPattern parameter, this method returns an empty array.</remarks>
/// <remarks>
/// The EnumerateDirectories and GetDirectories methods differ as follows: When you use EnumerateDirectories, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetDirectories, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateDirectories can be more efficient.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
[SecurityCritical]
public DirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Folders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return Directory.EnumerateFileSystemEntryInfosCore<DirectoryInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).ToArray();
}

#endregion // .NET
}
}

+ 124
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetFileSystemInfos.cs View File

@@ -0,0 +1,124 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Returns an array of strongly typed <see cref="FileSystemInfo"/> entries representing all the files and subdirectories in a directory.</summary>
/// <returns>An array of strongly typed <see cref="FileSystemInfo"/> entries.</returns>
/// <remarks>
/// For subdirectories, the <see cref="FileSystemInfo"/> objects returned by this method can be cast to the derived class <see cref="DirectoryInfo"/>.
/// Use the <see cref="FileAttributes"/> value returned by the <see cref="FileSystemInfo.Attributes"/> property to determine whether the <see cref="FileSystemInfo"/> represents a file or a directory.
/// </remarks>
/// <remarks>
/// If there are no files or directories in the DirectoryInfo, this method returns an empty array. This method is not recursive.
/// For subdirectories, the FileSystemInfo objects returned by this method can be cast to the derived class DirectoryInfo.
/// Use the FileAttributes value returned by the Attributes property to determine whether the FileSystemInfo represents a file or a directory.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public FileSystemInfo[] GetFileSystemInfos()
{
return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath).ToArray();
}

/// <summary>Retrieves an array of strongly typed <see cref="FileSystemInfo"/> objects representing the files and subdirectories that match the specified search criteria.</summary>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <returns>An array of strongly typed <see cref="FileSystemInfo"/> entries.</returns>
/// <remarks>
/// For subdirectories, the <see cref="FileSystemInfo"/> objects returned by this method can be cast to the derived class <see cref="DirectoryInfo"/>.
/// Use the <see cref="FileAttributes"/> value returned by the <see cref="FileSystemInfo.Attributes"/> property to determine whether the <see cref="FileSystemInfo"/> represents a file or a directory.
/// </remarks>
/// <remarks>
/// If there are no files or directories in the DirectoryInfo, this method returns an empty array. This method is not recursive.
/// For subdirectories, the FileSystemInfo objects returned by this method can be cast to the derived class DirectoryInfo.
/// Use the FileAttributes value returned by the Attributes property to determine whether the FileSystemInfo represents a file or a directory.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public FileSystemInfo[] GetFileSystemInfos(string searchPattern)
{
return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.FilesAndFolders, PathFormat.LongFullPath).ToArray();
}

/// <summary>Retrieves an array of strongly typed <see cref="FileSystemInfo"/> objects representing the files and subdirectories that match the specified search criteria.</summary>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <returns>An array of strongly typed <see cref="FileSystemInfo"/> entries.</returns>
/// <remarks>
/// For subdirectories, the <see cref="FileSystemInfo"/> objects returned by this method can be cast to the derived class <see cref="DirectoryInfo"/>.
/// Use the <see cref="FileAttributes"/> value returned by the <see cref="FileSystemInfo.Attributes"/> property to determine whether the <see cref="FileSystemInfo"/> represents a file or a directory.
/// </remarks>
/// <remarks>
/// If there are no files or directories in the DirectoryInfo, this method returns an empty array. This method is not recursive.
/// For subdirectories, the FileSystemInfo objects returned by this method can be cast to the derived class DirectoryInfo.
/// Use the FileAttributes value returned by the Attributes property to determine whether the FileSystemInfo represents a file or a directory.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")]
[SecurityCritical]
public FileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.FilesAndFolders | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return Directory.EnumerateFileSystemEntryInfosCore<FileSystemInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).ToArray();
}

#endregion // .NET
}
}

+ 114
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.GetFiles.cs View File

@@ -0,0 +1,114 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Returns a file list from the current directory.</summary>
/// <returns>An array of type <see cref="FileInfo"/>.</returns>
/// <remarks>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</remarks>
/// <remarks>If there are no files in the <see cref="DirectoryInfo"/>, this method returns an empty array.</remarks>
/// <remarks>
/// The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public FileInfo[] GetFiles()
{
return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.Files, PathFormat.LongFullPath).ToArray();
}

/// <summary>Returns a file list from the current directory matching the given search pattern.</summary>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <returns>An array of type <see cref="FileInfo"/>.</returns>
/// <remarks>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</remarks>
/// <remarks>If there are no files in the <see cref="DirectoryInfo"/>, this method returns an empty array.</remarks>
/// <remarks>
/// The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public FileInfo[] GetFiles(string searchPattern)
{
return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, searchPattern, DirectoryEnumerationOptions.Files, PathFormat.LongFullPath).ToArray();
}

/// <summary>Returns a file list from the current directory matching the given search pattern and using a value to determine whether to search subdirectories.</summary>
/// <param name="searchPattern">
/// The search string to match against the names of directories in path.
/// This parameter can contain a combination of valid literal path and wildcard
/// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
/// </param>
/// <param name="searchOption">
/// One of the <see cref="SearchOption"/> enumeration values that specifies whether the <paramref name="searchOption"/>
/// should include only the current directory or should include all subdirectories.
/// </param>
/// <returns>An array of type <see cref="FileInfo"/>.</returns>
/// <remarks>The order of the returned file names is not guaranteed; use the Sort() method if a specific sort order is required.</remarks>
/// <remarks>If there are no files in the <see cref="DirectoryInfo"/>, this method returns an empty array.</remarks>
/// <remarks>
/// The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of names
/// before the whole collection is returned; when you use GetFiles, you must wait for the whole array of names to be returned before you can access the array.
/// Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.
/// </remarks>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryNotFoundException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
[SecurityCritical]
public FileInfo[] GetFiles(string searchPattern, SearchOption searchOption)
{
var options = DirectoryEnumerationOptions.Files | ((searchOption == SearchOption.AllDirectories) ? DirectoryEnumerationOptions.Recursive : 0);

return Directory.EnumerateFileSystemEntryInfosCore<FileInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).ToArray();
}

#endregion // .NET
}
}

+ 39
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.Refresh.cs View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region .NET

/// <summary>Refreshes the state of the object.</summary>
[SecurityCritical]
public new void Refresh()
{
base.Refresh();
}

#endregion // .NET
}
}

+ 39
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.RefreshEntryInfo.cs View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
#region AlphaFS

/// <summary>Refreshes the state of the <see cref="FileSystemEntryInfo"/> EntryInfo instance.</summary>
[SecurityCritical]
public new void RefreshEntryInfo()
{
base.RefreshEntryInfo();
}

#endregion // AlphaFS
}
}

+ 49
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.SetAccessControl.cs View File

@@ -0,0 +1,49 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;
using System.Security;
using System.Security.AccessControl;

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
/// <summary>Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the directory described by the current DirectoryInfo object.</summary>
/// <param name="directorySecurity">A <see cref="DirectorySecurity"/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public void SetAccessControl(DirectorySecurity directorySecurity)
{
File.SetAccessControlCore(LongFullName, null, directorySecurity, AccessControlSections.All, PathFormat.LongFullPath);
}

/// <summary>Applies access control list (ACL) entries described by a <see cref="DirectorySecurity"/> object to the directory described by the current DirectoryInfo object.</summary>
/// <param name="directorySecurity">A <see cref="DirectorySecurity"/> object that describes an ACL entry to apply to the directory described by the path parameter.</param>
/// <param name="includeSections">One or more of the <see cref="AccessControlSections"/> values that specifies the type of access control list (ACL) information to set.</param>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SecurityCritical]
public void SetAccessControl(DirectorySecurity directorySecurity, AccessControlSections includeSections)
{
File.SetAccessControlCore(LongFullName, null, directorySecurity, includeSections, PathFormat.LongFullPath);
}
}
}

+ 33
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.ToString.cs View File

@@ -0,0 +1,33 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
partial class DirectoryInfo
{
/// <summary>Returns the original path that was passed by the user.</summary>
/// <returns>A string that represents this object.</returns>
public override string ToString()
{
return DisplayPath;
}
}
}

+ 203
- 0
AlphaFS/Filesystem/DirectoryInfo Class/DirectoryInfo.cs View File

@@ -0,0 +1,203 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.</summary>
[SerializableAttribute]
public sealed partial class DirectoryInfo : FileSystemInfo
{
#region Constructors

#region .NET

/// <summary>Initializes a new instance of the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/> class on the specified path.</summary>
/// <param name="path">The path on which to create the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/>.</param>
/// <remarks>
/// This constructor does not check if a directory exists. This constructor is a placeholder for a string that is used to access the disk in subsequent operations.
/// The path parameter can be a file name, including a file on a Universal Naming Convention (UNC) share.
/// </remarks>
public DirectoryInfo(string path) : this(null, path, PathFormat.RelativePath)
{
}

#endregion // .NET

#region AlphaFS

/// <summary>[AlphaFS] Initializes a new instance of the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/> class on the specified path.</summary>
/// <param name="path">The path on which to create the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <remarks>This constructor does not check if a directory exists. This constructor is a placeholder for a string that is used to access the disk in subsequent operations.</remarks>
public DirectoryInfo(string path, PathFormat pathFormat) : this(null, path, pathFormat)
{
}

/// <summary>[AlphaFS] Special internal implementation.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="fullPath">The full path on which to create the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/>.</param>
/// <param name="junk1">Not used.</param>
/// <param name="junk2">Not used.</param>
/// <remarks>This constructor does not check if a directory exists. This constructor is a placeholder for a string that is used to access the disk in subsequent operations.</remarks>
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "junk1")]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "junk2")]
private DirectoryInfo(KernelTransaction transaction, string fullPath, bool junk1, bool junk2)
{
IsDirectory = true;
Transaction = transaction;

LongFullName = Path.GetLongPathCore(fullPath, GetFullPathOptions.None);

OriginalPath = Path.GetFileName(fullPath, true);

FullPath = fullPath;

DisplayPath = OriginalPath.Length != 2 || OriginalPath[1] != Path.VolumeSeparatorChar ? OriginalPath : Path.CurrentDirectoryPrefix;
}

#region Transactional

/// <summary>[AlphaFS] Initializes a new instance of the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/> class on the specified path.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path on which to create the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/>.</param>
/// <remarks>This constructor does not check if a directory exists. This constructor is a placeholder for a string that is used to access the disk in subsequent operations.</remarks>
public DirectoryInfo(KernelTransaction transaction, string path) : this(transaction, path, PathFormat.RelativePath)
{
}

/// <summary>[AlphaFS] Initializes a new instance of the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/> class on the specified path.</summary>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The path on which to create the <see cref="Alphaleonis.Win32.Filesystem.DirectoryInfo"/>.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
/// <remarks>This constructor does not check if a directory exists. This constructor is a placeholder for a string that is used to access the disk in subsequent operations.</remarks>
public DirectoryInfo(KernelTransaction transaction, string path, PathFormat pathFormat)
{
InitializeCore(true, transaction, path, pathFormat);
}

#endregion // Transactional

#endregion // AlphaFS

#endregion // Constructors
#region Properties

#region .NET

#region Exists

/// <summary>Gets a value indicating whether the directory exists.</summary>
/// <remarks>
/// <para>The <see cref="Exists"/> property returns <see langword="false"/> if any error occurs while trying to determine if the
/// specified directory exists.</para>
/// <para>This can occur in situations that raise exceptions such as passing a directory name with invalid characters or too many
/// characters,</para>
/// <para>a failing or missing disk, or if the caller does not have permission to read the directory.</para>
/// </remarks>
/// <value><see langword="true"/> if the directory exists; otherwise, <see langword="false"/>.</value>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public override bool Exists
{
[SecurityCritical]
get
{
try
{
if (DataInitialised == -1)
Refresh();

FileAttributes attrs = Win32AttributeData.dwFileAttributes;
return DataInitialised == 0 && attrs != (FileAttributes) (-1) && (attrs & FileAttributes.Directory) != 0;
}
catch
{
return false;
}
}
}

#endregion // Exists

#region Name

/// <summary>Gets the name of this <see cref="DirectoryInfo"/> instance.</summary>
/// <value>The directory name.</value>
/// <remarks>
/// <para>This Name property returns only the name of the directory, such as "Bin".</para>
/// <para>To get the full path, such as "c:\public\Bin", use the FullName property.</para>
/// </remarks>
public override string Name
{
get
{
// GetDirName()
return FullPath.Length > 3
? Path.GetFileName(Path.RemoveTrailingDirectorySeparator(FullPath, false), true)
: FullPath;
}
}

#endregion // Name

#region Parent

/// <summary>Gets the parent directory of a specified subdirectory.</summary>
/// <value>The parent directory, or null if the path is null or if the file path denotes a root (such as "\", "C:", or * "\\server\share").</value>
public DirectoryInfo Parent
{
[SecurityCritical]
get
{
string path = FullPath;

if (path.Length > 3)
path = Path.RemoveTrailingDirectorySeparator(FullPath, false);

string dirName = Path.GetDirectoryName(path, false);
return dirName == null ? null : new DirectoryInfo(Transaction, dirName, true, true);
}
}

#endregion // Parent

#region Root

/// <summary>Gets the root portion of the directory.</summary>
/// <value>An object that represents the root of the directory.</value>
public DirectoryInfo Root
{
[SecurityCritical]
get { return new DirectoryInfo(Transaction, Path.GetPathRoot(FullPath, false), PathFormat.RelativePath); }
}

#endregion // Root

#endregion // .NET

#endregion // Properties
}
}

+ 265
- 0
AlphaFS/Filesystem/DiskSpaceInfo.cs View File

@@ -0,0 +1,265 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space,
/// the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.
/// <para>This class cannot be inherited.</para>
/// </summary>
[SerializableAttribute]
[SecurityCritical]
public sealed class DiskSpaceInfo
{
#region Constructor

/// <summary>Initializes a DiskSpaceInfo instance.</summary>
/// <param name="drivePath">A valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z' or a network share in the format: \\server\share</param>
/// <Remark>This is a Lazyloading object; call <see cref="Refresh()"/> to populate all properties first before accessing.</Remark>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
[SecurityCritical]
public DiskSpaceInfo(string drivePath)
{
if (Utils.IsNullOrWhiteSpace(drivePath))
throw new ArgumentNullException("drivePath");

if (drivePath.Length == 1)
DriveName += Path.VolumeSeparatorChar;
else
DriveName = Path.GetPathRoot(drivePath, false);

if (Utils.IsNullOrWhiteSpace(DriveName))
throw new ArgumentException("Argument must be a drive letter (\"C\"), RootDir (\"C:\\\") or UNC path (\"\\\\server\\share\")");

// MSDN:
// If this parameter is a UNC name, it must include a trailing backslash (for example, "\\MyServer\MyShare\").
// Furthermore, a drive specification must have a trailing backslash (for example, "C:\").
// The calling application must have FILE_LIST_DIRECTORY access rights for this directory.
DriveName = Path.AddTrailingDirectorySeparator(DriveName, false);
}

/// <summary>Initializes a DiskSpaceInfo instance.</summary>
/// <param name="drivePath">A valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z' or a network share in the format: \\server\share</param>
/// <param name="spaceInfoType"><see langword="null"/> gets both size- and disk cluster information. <see langword="true"/> Get only disk cluster information, <see langword="false"/> Get only size information.</param>
/// <param name="refresh">Refreshes the state of the object.</param>
/// <param name="continueOnException"><see langword="true"/> suppress any Exception that might be thrown as a result from a failure, such as unavailable resources.</param>
[SecurityCritical]
public DiskSpaceInfo(string drivePath, bool? spaceInfoType, bool refresh, bool continueOnException) : this(drivePath)
{
if (spaceInfoType == null)
_initGetSpaceInfo = _initGetClusterInfo = true;

else
{
_initGetSpaceInfo = (bool) !spaceInfoType;
_initGetClusterInfo = (bool) spaceInfoType;
}

_continueOnAccessError = continueOnException;

if (refresh)
Refresh();
}

#endregion // Constructor

#region Fields

private readonly bool _initGetClusterInfo = true;
private readonly bool _initGetSpaceInfo = true;
private readonly bool _continueOnAccessError;

#endregion // Fields

#region Methods

#region Refresh

/// <summary>Refreshes the state of the object.</summary>
public void Refresh()
{
Reset();

using (new NativeMethods.ChangeErrorMode(NativeMethods.ErrorMode.FailCriticalErrors))
{
int lastError = (int) Win32Errors.NO_ERROR;

#region Get size information.

if (_initGetSpaceInfo)
{
long freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;

if (!NativeMethods.GetDiskFreeSpaceEx(DriveName, out freeBytesAvailable, out totalNumberOfBytes, out totalNumberOfFreeBytes))
lastError = Marshal.GetLastWin32Error();

else
{
FreeBytesAvailable = freeBytesAvailable;
TotalNumberOfBytes = totalNumberOfBytes;
TotalNumberOfFreeBytes = totalNumberOfFreeBytes;
}

if (!_continueOnAccessError && (lastError != Win32Errors.NO_ERROR && lastError != Win32Errors.ERROR_NOT_READY))
NativeError.ThrowException(DriveName);
}

#endregion // Get size information.

#region Get cluster information.

if (_initGetClusterInfo)
{
int sectorsPerCluster, bytesPerSector, numberOfFreeClusters;
uint totalNumberOfClusters;

if (!NativeMethods.GetDiskFreeSpace(DriveName, out sectorsPerCluster, out bytesPerSector, out numberOfFreeClusters, out totalNumberOfClusters))
lastError = Marshal.GetLastWin32Error();

else
{
BytesPerSector = bytesPerSector;
NumberOfFreeClusters = numberOfFreeClusters;
SectorsPerCluster = sectorsPerCluster;
TotalNumberOfClusters = totalNumberOfClusters;
}

if (!_continueOnAccessError && (lastError != Win32Errors.NO_ERROR && lastError != Win32Errors.ERROR_NOT_READY))
NativeError.ThrowException(DriveName);
}

#endregion // Get cluster information.
}
}

#endregion // Refresh

#region Reset

/// <summary>Initializes all <see ref="Alphaleonis.Win32.Filesystem.DiskSpaceInfo"/> properties to 0.</summary>
private void Reset()
{
if (_initGetSpaceInfo)
FreeBytesAvailable = TotalNumberOfBytes = TotalNumberOfFreeBytes = 0;

if (_initGetClusterInfo)
{
BytesPerSector = NumberOfFreeClusters = SectorsPerCluster = 0;
TotalNumberOfClusters = 0;
}
}

#endregion // Reset

#region ToString
/// <summary>Returns the drive name.</summary>
/// <returns>A string that represents this object.</returns>
public override string ToString()
{
return DriveName;
}

#endregion // ToString

#endregion // Methods

#region Properties

/// <summary>Indicates the amount of available free space on a drive, formatted as percentage.</summary>
public string AvailableFreeSpacePercent
{
get
{
return string.Format(CultureInfo.CurrentCulture, "{0:0.00}%", Utils.PercentCalculate(TotalNumberOfBytes - (TotalNumberOfBytes - TotalNumberOfFreeBytes), 0, TotalNumberOfBytes));
}
}

/// <summary>Indicates the amount of available free space on a drive, formatted as a unit size.</summary>
public string AvailableFreeSpaceUnitSize
{
get { return Utils.UnitSizeToText(TotalNumberOfFreeBytes); }
}

/// <summary>Returns the Clusters size.</summary>
public long ClusterSize
{
get { return SectorsPerCluster * BytesPerSector; }
}

/// <summary>Gets the name of a drive.</summary>
/// <returns>The name of the drive.</returns>
/// <remarks>This property is the name assigned to the drive, such as C:\ or E:\</remarks>
public string DriveName { get; private set; }

/// <summary>The total number of bytes on a disk that are available to the user who is associated with the calling thread, formatted as a unit size.</summary>
public string TotalSizeUnitSize
{
get { return Utils.UnitSizeToText(TotalNumberOfBytes); }
}

/// <summary>Indicates the amount of used space on a drive, formatted as percentage.</summary>
public string UsedSpacePercent
{
get
{
return string.Format(CultureInfo.CurrentCulture, "{0:0.00}%", Utils.PercentCalculate(TotalNumberOfBytes - FreeBytesAvailable, 0, TotalNumberOfBytes));
}
}

/// <summary>Indicates the amount of used space on a drive, formatted as a unit size.</summary>
public string UsedSpaceUnitSize
{
get { return Utils.UnitSizeToText(TotalNumberOfBytes - FreeBytesAvailable); }
}

/// <summary>The total number of free bytes on a disk that are available to the user who is associated with the calling thread.</summary>
public long FreeBytesAvailable { get; private set; }

/// <summary>The total number of bytes on a disk that are available to the user who is associated with the calling thread.</summary>
public long TotalNumberOfBytes { get; private set; }

/// <summary>The total number of free bytes on a disk.</summary>
public long TotalNumberOfFreeBytes { get; private set; }

/// <summary>The number of bytes per sector.</summary>
public int BytesPerSector { get; private set; }

/// <summary>The total number of free clusters on the disk that are available to the user who is associated with the calling thread.</summary>
public int NumberOfFreeClusters { get; private set; }

/// <summary>The number of sectors per cluster.</summary>
public int SectorsPerCluster { get; private set; }

/// <summary>The total number of clusters on the disk that are available to the user who is associated with the calling thread.
/// If per-user disk quotas are in use, this value may be less than the total number of clusters on the disk.
/// </summary>
public long TotalNumberOfClusters { get; private set; }


#endregion // Properties
}
}

+ 422
- 0
AlphaFS/Filesystem/DriveInfo.cs View File

@@ -0,0 +1,422 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Security;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Provides access to information on a local or remote drive.</summary>
/// <remarks>
/// This class models a drive and provides methods and properties to query for drive information.
/// Use DriveInfo to determine what drives are available, and what type of drives they are.
/// You can also query to determine the capacity and available free space on the drive.
/// </remarks>
[Serializable]
[SecurityCritical]
public sealed class DriveInfo
{
#region Private Fields

[NonSerialized]
private readonly VolumeInfo _volumeInfo;

[NonSerialized]
private readonly DiskSpaceInfo _dsi;

[NonSerialized]
private bool _initDsie;

[NonSerialized]
private DriveType? _driveType;

[NonSerialized]
private string _dosDeviceName;

[NonSerialized]
private DirectoryInfo _rootDirectory;

private readonly string _name;


#endregion

#region Constructors

/// <summary>Provides access to information on the specified drive.</summary>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentException"/>
/// <param name="driveName">
/// A valid drive path or drive letter.
/// <para>This can be either uppercase or lowercase,</para>
/// <para>'a' to 'z' or a network share in the format: \\server\share</para>
/// </param>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
[SecurityCritical]
public DriveInfo(string driveName)
{
if (Utils.IsNullOrWhiteSpace(driveName))
throw new ArgumentNullException("driveName");

if (driveName.Length == 1)
_name += Path.VolumeSeparatorChar;
else
_name = Path.GetPathRoot(driveName, false);

if (Utils.IsNullOrWhiteSpace(_name))
throw new ArgumentException("Argument must be a drive letter (\"C\"), RootDir (\"C:\\\") or UNC path (\"\\\\server\\share\")");

// If an exception is thrown, the original drivePath is used.
_name = Path.AddTrailingDirectorySeparator(_name, false);


// Initiate VolumeInfo() lazyload instance.
_volumeInfo = new VolumeInfo(_name, false, true);

// Initiate DiskSpaceInfo() lazyload instance.
_dsi = new DiskSpaceInfo(_name, null, false, true);
}

#endregion // Constructors

#region Properties

/// <summary>Indicates the amount of available free space on a drive.</summary>
/// <returns>The amount of free space available on the drive, in bytes.</returns>
/// <remarks>This property indicates the amount of free space available on the drive. Note that this number may be different from the <see cref="TotalFreeSpace"/> number because this property takes into account disk quotas.</remarks>
public long AvailableFreeSpace
{
get
{
GetDeviceInfo(3, 0);
return _dsi == null ? 0 : _dsi.FreeBytesAvailable;
}
}

/// <summary>Gets the name of the file system, such as NTFS or FAT32.</summary>
/// <remarks>Use DriveFormat to determine what formatting a drive uses.</remarks>
public string DriveFormat
{
get { return (string)GetDeviceInfo(0, 1); }
}

/// <summary>Gets the drive type.</summary>
/// <returns>One of the <see cref="System.IO.DriveType"/> values.</returns>
/// <remarks>
/// The DriveType property indicates whether a drive is any of: CDRom, Fixed, Unknown, Network, NoRootDirectory,
/// Ram, Removable, or Unknown. Values are listed in the <see cref="System.IO.DriveType"/> enumeration.
/// </remarks>
public DriveType DriveType
{
get { return (DriveType)GetDeviceInfo(2, 0); }
}

/// <summary>Gets a value indicating whether a drive is ready.</summary>
/// <returns><see langword="true"/> if the drive is ready; otherwise, <see langword="false"/>.</returns>
/// <remarks>
/// IsReady indicates whether a drive is ready. For example, it indicates whether a CD is in a CD drive or whether
/// a removable storage device is ready for read/write operations. If you do not test whether a drive is ready, and
/// it is not ready, querying the drive using DriveInfo will raise an IOException.
///
/// Do not rely on IsReady() to avoid catching exceptions from other members such as TotalSize, TotalFreeSpace, and DriveFormat.
/// Between the time that your code checks IsReady and then accesses one of the other properties
/// (even if the access occurs immediately after the check), a drive may have been disconnected or a disk may have been removed.
/// </remarks>
public bool IsReady
{
get { return File.ExistsCore(true, null, Name, PathFormat.LongFullPath); }
}


/// <summary>Gets the name of the drive.</summary>
/// <returns>The name of the drive.</returns>
/// <remarks>This property is the name assigned to the drive, such as C:\ or E:\</remarks>
public string Name
{
get { return _name; }
}

/// <summary>Gets the root directory of a drive.</summary>
/// <returns>A DirectoryInfo object that contains the root directory of the drive.</returns>
public DirectoryInfo RootDirectory
{
get { return (DirectoryInfo)GetDeviceInfo(2, 1); }
}

/// <summary>Gets the total amount of free space available on a drive.</summary>
/// <returns>The total free space available on a drive, in bytes.</returns>
/// <remarks>This property indicates the total amount of free space available on the drive, not just what is available to the current user.</remarks>
public long TotalFreeSpace
{
get
{
GetDeviceInfo(3, 0);
return _dsi == null ? 0 : _dsi.TotalNumberOfFreeBytes;
}
}

/// <summary>Gets the total size of storage space on a drive.</summary>
/// <returns>The total size of the drive, in bytes.</returns>
/// <remarks>This property indicates the total size of the drive in bytes, not just what is available to the current user.</remarks>
public long TotalSize
{
get
{
GetDeviceInfo(3, 0);
return _dsi == null ? 0 : _dsi.TotalNumberOfBytes;
}
}

/// <summary>Gets or sets the volume label of a drive.</summary>
/// <returns>The volume label.</returns>
/// <remarks>
/// The label length is determined by the operating system. For example, NTFS allows a volume label
/// to be up to 32 characters long. Note that <see langword="null"/> is a valid VolumeLabel.
/// </remarks>

public string VolumeLabel
{
get { return (string)GetDeviceInfo(0, 2); }
set { Volume.SetVolumeLabel(Name, value); }
}

/// <summary>[AlphaFS] Returns the <see ref="Alphaleonis.Win32.Filesystem.DiskSpaceInfo"/> instance.</summary>
public DiskSpaceInfo DiskSpaceInfo
{
get
{
GetDeviceInfo(3, 0);
return _dsi;
}
}

/// <summary>[AlphaFS] The MS-DOS device name.</summary>
public string DosDeviceName
{
get { return (string)GetDeviceInfo(1, 0); }
}

/// <summary>[AlphaFS] Indicates if this drive is a SUBST.EXE / DefineDosDevice drive mapping.</summary>
public bool IsDosDeviceSubstitute
{
get { return !Utils.IsNullOrWhiteSpace(DosDeviceName) && DosDeviceName.StartsWith(Path.SubstitutePrefix, StringComparison.OrdinalIgnoreCase); }
}

/// <summary>[AlphaFS] Indicates if this drive is a UNC path.</summary>
/// <remarks>Only retrieve this information if we're dealing with a real network share mapping: http://alphafs.codeplex.com/discussions/316583</remarks>
public bool IsUnc
{
get { return !IsDosDeviceSubstitute && DriveType == DriveType.Network; }
}

/// <summary>[AlphaFS] Determines whether the specified volume name is a defined volume on the current computer.</summary>
public bool IsVolume
{
get { return GetDeviceInfo(0, 0) != null; }
}

/// <summary>[AlphaFS] Contains information about a file-system volume.</summary>
/// <returns>A VolumeInfo object that contains file-system volume information of the drive.</returns>
public VolumeInfo VolumeInfo
{
get { return (VolumeInfo)GetDeviceInfo(0, 0); }
}


#endregion // Properties

#region Methods

/// <summary>Retrieves the drive names of all logical drives on a computer.</summary>
/// <returns>An array of type <see cref="Alphaleonis.Win32.Filesystem.DriveInfo"/> that represents the logical drives on a computer.</returns>
[SecurityCritical]
public static DriveInfo[] GetDrives()
{
return Directory.EnumerateLogicalDrivesCore(false, false).ToArray();
}

/// <summary>Returns a drive name as a string.</summary>
/// <returns>The name of the drive.</returns>
/// <remarks>This method returns the Name property.</remarks>
public override string ToString()
{
return _name;
}


/// <summary>[AlphaFS] Enumerates the drive names of all logical drives on a computer.</summary>
/// <param name="fromEnvironment">Retrieve logical drives as known by the Environment.</param>
/// <param name="isReady">Retrieve only when accessible (IsReady) logical drives.</param>
/// <returns>
/// An IEnumerable of type <see cref="Alphaleonis.Win32.Filesystem.DriveInfo"/> that represents
/// the logical drives on a computer.
/// </returns>
[SecurityCritical]
public static IEnumerable<DriveInfo> EnumerateDrives(bool fromEnvironment, bool isReady)
{
return Directory.EnumerateLogicalDrivesCore(fromEnvironment, isReady);
}


/// <summary>[AlphaFS] Gets the first available drive letter on the local system.</summary>
/// <returns>A drive letter as <see cref="char"/>. When no drive letters are available, an exception is thrown.</returns>
/// <remarks>The letters "A" and "B" are reserved for floppy drives and will never be returned by this function.</remarks>
public static char GetFreeDriveLetter()
{
return GetFreeDriveLetter(false);
}

/// <summary>Gets an available drive letter on the local system.</summary>
/// <param name="getLastAvailable">When <see langword="true"/> get the last available drive letter. When <see langword="false"/> gets the first available drive letter.</param>
/// <returns>A drive letter as <see cref="char"/>. When no drive letters are available, an exception is thrown.</returns>
/// <remarks>The letters "A" and "B" are reserved for floppy drives and will never be returned by this function.</remarks>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
[SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")]
public static char GetFreeDriveLetter(bool getLastAvailable)
{
IEnumerable<char> freeDriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ".Except(Directory.EnumerateLogicalDrivesCore(false, false).Select(d => d.Name[0]));

try
{
return getLastAvailable ? freeDriveLetters.Last() : freeDriveLetters.First();
}
catch
{
throw new Exception("There are no drive letters available.");
}
}

#endregion // Methods

#region Private Methods

/// <summary>Retrieves information about the file system and volume associated with the specified root file or directorystream.</summary>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
[SecurityCritical]
private object GetDeviceInfo(int type, int mode)
{
try
{
switch (type)
{
#region Volume

// VolumeInfo properties.
case 0:
if (Utils.IsNullOrWhiteSpace(_volumeInfo.FullPath))
_volumeInfo.Refresh();

switch (mode)
{
case 0:
// IsVolume, VolumeInfo
return _volumeInfo;

case 1:
// DriveFormat
return _volumeInfo == null ? DriveType.Unknown.ToString() : _volumeInfo.FileSystemName ?? DriveType.Unknown.ToString();

case 2:
// VolumeLabel
return _volumeInfo == null ? string.Empty : _volumeInfo.Name ?? string.Empty;
}
break;

// Volume related.
case 1:
switch (mode)
{
case 0:
// DosDeviceName

// Do not use ?? expression here.
if (_dosDeviceName == null)
_dosDeviceName = Volume.QueryDosDevice(Name).FirstOrDefault();

return _dosDeviceName;
}
break;

#endregion // Volume

#region Drive

// Drive related.
case 2:
switch (mode)
{
case 0:
// DriveType
// Do not use ?? expression here.
if (_driveType == null)
_driveType = Volume.GetDriveType(Name);

return _driveType;

case 1:
// RootDirectory

// Do not use ?? expression here.
if (_rootDirectory == null)
_rootDirectory = new DirectoryInfo(null, Name, PathFormat.RelativePath);

return _rootDirectory;
}
break;

// DiskSpaceInfo related.
case 3:
switch (mode)
{
case 0:
// AvailableFreeSpace, TotalFreeSpace, TotalSize, DiskSpaceInfo
if (!_initDsie)
{
_dsi.Refresh();
_initDsie = true;
}
break;
}
break;

#endregion // Drive
}
}
catch
{
}

return type == 0 && mode > 0 ? string.Empty : null;
}


#endregion // Private

}
}

+ 84
- 0
AlphaFS/Filesystem/Enumerations/BackupStreamType.cs View File

@@ -0,0 +1,84 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>The type of the data contained in the backup stream.</summary>
public enum BackupStreamType
{
/// <summary>This indicates an error.</summary>
None = 0,

/// <summary>BACKUP_DATA
/// <para>Standard data. This corresponds to the NTFS $DATA stream type on the default (unnamed) data stream.</para>
/// </summary>
Data = 1,

/// <summary>BACKUP_EA_DATA
/// <para>Extended attribute data. This corresponds to the NTFS $EA stream type.</para>
/// </summary>
ExtendedAttributesData = 2,

/// <summary>BACKUP_SECURITY_DATA
/// <para>Security descriptor data.</para>
/// </summary>
SecurityData = 3,

/// <summary>BACKUP_ALTERNATE_DATA
/// <para>Alternative data streams. This corresponds to the NTFS $DATA stream type on a named data stream.</para>
/// </summary>
AlternateData = 4,

/// <summary>BACKUP_LINK
/// <para>Hard link information. This corresponds to the NTFS $FILE_NAME stream type.</para>
/// </summary>
Link = 5,

/// <summary>BACKUP_PROPERTY_DATA
/// <para>Property data.</para>
/// </summary>
PropertyData = 6,

/// <summary>BACKUP_OBJECT_ID
/// <para>Objects identifiers. This corresponds to the NTFS $OBJECT_ID stream type.</para>
/// </summary>
ObjectId = 7,

/// <summary>BACKUP_REPARSE_DATA
/// <para>Reparse points. This corresponds to the NTFS $REPARSE_POINT stream type.</para>
/// </summary>
ReparseData = 8,

/// <summary>BACKUP_SPARSE_BLOCK
/// <para>Sparse file. This corresponds to the NTFS $DATA stream type for a sparse file.</para>
/// </summary>
SparseBlock = 9,

/// <summary>BACKUP_TXFS_DATA
/// <para>Transactional NTFS (TxF) data stream.</para>
/// </summary>
/// <remarks>Windows Server 2003 and Windows XP: This value is not supported.</remarks>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Txfs")]
TxfsData = 10
}
}

+ 37
- 0
AlphaFS/Filesystem/Enumerations/CopyMoveProgressCallbackReason.cs View File

@@ -0,0 +1,37 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Used by CopyFileXxx and MoveFileXxx. The reason that <see cref="CopyMoveProgressRoutine"/> was called.</summary>
public enum CopyMoveProgressCallbackReason
{
/// <summary>CALLBACK_CHUNK_FINISHED
/// <para>Another part of the data file was copied.</para>
/// </summary>
ChunkFinished = 0,

/// <summary>CALLBACK_STREAM_SWITCH
/// <para>Another stream was created and is about to be copied. This is the callback reason given when the callback routine is first invoked.</para>
/// </summary>
StreamSwitch = 1
}
}

+ 47
- 0
AlphaFS/Filesystem/Enumerations/CopyMoveProgressResult.cs View File

@@ -0,0 +1,47 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Used by CopyFileXxx and MoveFileXxx. The <see cref="CopyMoveProgressRoutine"/> function should return one of the following values.</summary>
public enum CopyMoveProgressResult
{
/// <summary>PROGRESS_CONTINUE
/// <para>Continue the copy operation.</para>
/// </summary>
Continue = 0,

/// <summary>PROGRESS_CANCEL
/// <para>Cancel the copy operation and delete the destination file.</para>
/// </summary>
Cancel = 1,

/// <summary>PROGRESS_STOP
/// <para>Stop the copy operation. It can be restarted at a later time.</para>
/// </summary>
Stop = 2,

/// <summary>PROGRESS_QUIET
/// <para>Continue the copy operation, but stop invoking <see cref="CopyMoveProgressRoutine"/> to report progress.</para>
/// </summary>
Quiet = 3
}
}

+ 69
- 0
AlphaFS/Filesystem/Enumerations/CopyOptions.cs View File

@@ -0,0 +1,69 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Flags that specify how a file or directory is to be copied.</summary>
[Flags]
public enum CopyOptions
{
/// <summary>No CopyOptions used, this allows overwriting the file.</summary>
None = 0,

/// <summary>COPY_FILE_FAIL_IF_EXISTS
/// <para>The copy operation fails immediately if the target file already exists.</para>
/// </summary>
FailIfExists = 1,

/// <summary>COPY_FILE_RESTARTABLE
/// <para>
/// Progress of the copy is tracked in the target file in case the copy fails. The failed copy can be restarted at a later time by specifying the same values
/// forexisting file name and new file name as those used in the call that failed. This can significantly slow down the copy operation as the new file may be
/// flushed multiple times during the copy operation.
/// </para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Restartable")]
Restartable = 2,

/// <summary>COPY_FILE_OPEN_SOURCE_FOR_WRITE
/// <para>The file is copied and the original file is opened for write access.</para>
/// </summary>
OpenSourceForWrite = 4,

/// <summary>COPY_FILE_ALLOW_DECRYPTED_DESTINATION
/// <para>An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted.</para>
/// </summary>
AllowDecryptedDestination = 8,

/// <summary>COPY_FILE_COPY_SYMLINK
/// <para>If the source file is a symbolic link, the destination file is also a symbolic link pointing to the same file that the source symbolic link is pointing to.</para>
/// </summary>
CopySymbolicLink = 2048,

/// <summary>COPY_FILE_NO_BUFFERING
/// <para>The copy operation is performed using unbuffered I/O, bypassing system I/O cache resources. Recommended for very large file transfers.</para>
/// </summary>
NoBuffering = 4096
}
}

+ 200
- 0
AlphaFS/Filesystem/Enumerations/DeviceGuid.cs View File

@@ -0,0 +1,200 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>System-Defined Device Interface Classes</summary>
/// <remarks>http://msdn.microsoft.com/en-us/library/windows/hardware/ff541389%28v=vs.85%29.aspx</remarks>
public enum DeviceGuid
{
#region 1394 and 61883 Devices

/// <summary>The BUS1394_CLASS_GUID device interface class is defined for 1394 bus devices.</summary>
[Description("6BDD1FC1-810F-11d0-BEC7-08002BE2092F")] Bus1394,

/// <summary>The GUID_61883_CLASS device interface class is defined for devices in the 61883 device setup class.</summary>
[Description("7EBEFBC0-3200-11d2-B4C2-00A0C9697D07")] Guid61883,

#endregion // 1394 and 61883 Devices

#region Battery and ACPI devices

/// <summary>The GUID_DEVICE_APPLICATIONLAUNCH_BUTTON device interface class is defined for Advanced Configuration and Power Interface (ACPI) application start buttons.</summary>
[Description("629758EE-986E-4D9E-8E47-DE27F8AB054D")] ApplicationLaunchButton,

/// <summary>The GUID_DEVICE_BATTERY device interface class is defined for battery devices.</summary>
[Description("72631E54-78A4-11D0-BCF7-00AA00B7B32A")] Battery,

/// <summary>The GUID_DEVICE_LID device interface class is defined for Advanced Configuration and Power Interface (ACPI) lid devices.</summary>
[Description("4AFA3D52-74A7-11d0-be5e-00A0C9062857")] Lid,

/// <summary>The GUID_DEVICE_MEMORY device interface class is defined for Advanced Configuration and Power Interface (ACPI) memory devices.</summary>
[Description("3FD0F03D-92E0-45FB-B75C-5ED8FFB01021")] Memory,

/// <summary>The GUID_DEVICE_MESSAGE_INDICATOR device interface class is defined for Advanced Configuration and Power Interface (ACPI) message indicator devices.</summary>
[Description("CD48A365-FA94-4CE2-A232-A1B764E5D8B4")] MessageIndicator,

/// <summary>The GUID_DEVICE_PROCESSOR device interface class is defined for Advanced Configuration and Power Interface (ACPI) processor devices.</summary>
[Description("97FADB10-4E33-40AE-359C-8BEF029DBDD0")] Processor,

/// <summary>The GUID_DEVICE_SYS_BUTTON device interface classis defined for Advanced Configuration and Power Interface (ACPI) system power button devices.</summary>
[Description("4AFA3D53-74A7-11d0-be5e-00A0C9062857")] SysButton,

/// <summary>The GUID_DEVICE_THERMAL_ZONE device interface class is defined for Advanced Configuration and Power Interface (ACPI) thermal zone devices.</summary>
[Description("4AFA3D51-74A7-11d0-be5e-00A0C9062857")] ThermalZone,

#endregion // Battery and ACPI devices

#region Bluetooth Devices

/// <summary>The GUID_BTHPORT_DEVICE_INTERFACE device interface class is defined for Bluetooth radios.</summary>
[Description("0850302A-B344-4fda-9BE9-90576B8D46F0")] Bluetooth,

#endregion // Bluetooth Devices

#region Display and Image Devices

/// <summary>The GUID_DEVINTERFACE_BRIGHTNESS device interface class is defined for display adapter drivers that operate in the context of the Windows Vista Display Driver Model and support brightness control of monitor child devices.</summary>
[Description("FDE5BBA4-B3F9-46FB-BDAA-0728CE3100B4")] Brightness,

/// <summary>The GUID_DEVINTERFACE_DISPLAY_ADAPTER device interface class is defined for display views that are supported by display adapters.</summary>
[Description("5B45201D-F2F2-4F3B-85BB-30FF1F953599")] DisplayAdapter,

/// <summary>The GUID_DEVINTERFACE_I2C device interface class is defined for display adapter drivers that operate in the context of the Windows Vista Display Driver Model and perform I2C transactions with monitor child devices.</summary>
[Description("2564AA4F-DDDB-4495-B497-6AD4A84163D7")] I2C,

/// <summary>The GUID_DEVINTERFACE_IMAGE device interface class is defined for WIA devices and Still Image (STI) devices, including digital cameras and scanners.</summary>
[Description("6BDD1FC6-810F-11D0-BEC7-08002BE2092F")] StillImage,

/// <summary>The GUID_DEVINTERFACE_MONITOR device interface class is defined for monitor devices.</summary>
[Description("E6F07B5F-EE97-4a90-B076-33F57BF4EAA7")] Monitor,

/// <summary>The GUID_DEVINTERFACE_OPM device interface class is defined for display adapter drivers that operate in the context of the Windows Vista Display Driver Model and support output protection management (OPM) for monitor child devices.</summary>
[Description("BF4672DE-6B4E-4BE4-A325-68A91EA49C09")] OutputProtectionManagement,

/// <summary>The GUID_DEVINTERFACE_VIDEO_OUTPUT_ARRIVAL device interface class is defined for child devices of display devices.</summary>
[Description("1AD9E4F0-F88D-4360-BAB9-4C2D55E564CD")] VideoOutputArrival,

/// <summary>The GUID_DISPLAY_DEVICE_ARRIVAL device interface class is defined for display adapters.</summary>
[Description("1CA05180-A699-450A-9A0C-DE4FBE3DDD89")] DisplayDeviceArrival,

#endregion // Display and Image Devices

#region Interactive Input Devices

/// <summary>The GUID_DEVINTERFACE_HID device interface class is defined for HID collections.</summary>
[Description("4D1E55B2-F16F-11CF-88CB-001111000030")] Hid,

/// <summary>The GUID_DEVINTERFACE_KEYBOARD device interface class is defined for keyboard devices.</summary>
[Description("4D1E55B2-F16F-11CF-88CB-001111000030")] Keyboard,

/// <summary>The GUID_DEVINTERFACE_MOUSE device interface class is defined for mouse devices.</summary>
[Description("378DE44C-56EF-11D1-BC8C-00A0C91405DD")] Mouse,

#endregion // Interactive Input Devices

#region Modem Devices

/// <summary>The GUID_DEVINTERFACE_MODEM device interface class is defined for modem devices.</summary>
[Description("2C7089AA-2E0E-11D1-B114-00C04FC2AAE4")] Modem,

#endregion // Modem Devices

#region Network Devices

/// <summary>The GUID_DEVINTERFACE_NET device interface class is defined for network devices.</summary>
[Description("CAC88484-7515-4C03-82E6-71A87ABAC361")] Network,

#endregion // Network Devices

#region Serial and Parallel Port Devices

/// <summary>The GUID_DEVINTERFACE_COMPORT device interface class is defined for COM ports.</summary>
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "ComPort")]
[Description("86E0D1E0-8089-11D0-9CE4-08003E301F73")] ComPort,

/// <summary>The GUID_DEVINTERFACE_PARALLEL device interface class is defined for parallel ports that support an IEEE 1284-compatible hardware interface.</summary>
[Description("97F76EF0-F883-11D0-AF1F-0000F800845C")] Parallel,

/// <summary>The GUID_DEVINTERFACE_PARCLASS device interface class is defined for devices that are attached to a parallel port.</summary>
[Description("811FC6A5-F728-11D0-A537-0000F8753ED1")] ParallelClass,

/// <summary>The GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR device interface class is defined for Plug and Play (PnP) serial ports.</summary>
[Description("4D36E978-E325-11CE-BFC1-08002BE10318")] SerialEnumBusEnumerator,

#endregion // Serial and Parallel Port Devices

#region Storage Devices

/// <summary>The GUID_DEVINTERFACE_CDCHANGER device interface class is defined for CD-ROM changer devices.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cdrom")]
[Description("53F56312-B6BF-11D0-94F2-00A0C91EFB8B")] CdromChanger,

/// <summary>The GUID_DEVINTERFACE_CDROM device interface class is defined for CD-ROM storage devices.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cdrom")]
[Description("53F56308-B6BF-11D0-94F2-00A0C91EFB8B")] Cdrom,

/// <summary>The GUID_DEVINTERFACE_DISK device interface class is defined for hard disk storage devices.</summary>
[Description("53F56307-B6BF-11D0-94F2-00A0C91EFB8B")] Disk,

/// <summary>The GUID_DEVINTERFACE_FLOPPY device interface class is defined for floppy disk storage devices.</summary>
[Description("53F56311-B6BF-11D0-94F2-00A0C91EFB8B")] Floppy,

/// <summary>The GUID_DEVINTERFACE_MEDIUMCHANGER device interface class is defined for medium changer devices.</summary>
[Description("53F56310-B6BF-11D0-94F2-00A0C91EFB8B")] MediumChanger,

/// <summary>The GUID_DEVINTERFACE_PARTITION device interface class is defined for partition devices.</summary>
[Description("53F5630A-B6BF-11D0-94F2-00A0C91EFB8B")] Partition,

/// <summary>The GUID_DEVINTERFACE_STORAGEPORT device interface class is defined for storage port devices.</summary>
[Description("2ACCFE60-C130-11D2-B082-00A0C91EFB8B")] StoragePort,

/// <summary>The GUID_DEVINTERFACE_TAPE device interface class is defined for tape storage devices.</summary>
[Description("53F5630B-B6BF-11D0-94F2-00A0C91EFB8B")] Tape,

/// <summary>The GUID_DEVINTERFACE_VOLUME device interface class is defined for volume devices.</summary>
[Description("53F5630D-B6BF-11D0-94F2-00A0C91EFB8B")] Volume,

/// <summary>The GUID_DEVINTERFACE_WRITEONCEDISK device interface class is defined for write-once disk devices.</summary>
[Description("53F5630C-B6BF-11D0-94F2-00A0C91EFB8B")] WriteOnceDisk,

#endregion // Storage Devices

#region USB Devices

/// <summary>The GUID_DEVINTERFACE_USB_DEVICE device interface class is defined for USB devices that are attached to a USB hub.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Usb")]
[Description("A5DCBF10-6530-11D2-901F-00C04FB951ED")] UsbDevice,

/// <summary>The GUID_DEVINTERFACE_USB_HOST_CONTROLLER device interface class is defined for USB host controller devices.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Usb")]
[Description("3ABF6F2D-71C4-462A-8A92-1E6861E6AF27")] UsbHostController,

/// <summary>The GUID_DEVINTERFACE_USB_HUB device interface class is defined for USB hub devices.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Usb")]
[Description("F18A0E88-C30C-11D0-8815-00A0C906BED8")] UsbHub

#endregion // USB Devices
}
}

+ 61
- 0
AlphaFS/Filesystem/Enumerations/DiGetClassFlags.cs View File

@@ -0,0 +1,61 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Specifies control options that filter the device information elements that are added to the device information set.</summary>
[Flags]
internal enum SetupDiGetClassDevsExFlags
{
/// <summary>DIGCF_DEFAULT
/// <para>Return only the device that is associated with the system default device interface, if one is set, for the specified device interface classes.</para>
/// </summary>
Default = 1, // only valid with DIGCF_DEVICEINTERFACE

/// <summary>DIGCF_PRESENT
/// <para>Return only devices that are currently present.</para>
/// </summary>
Present = 2,

/// <summary>DIGCF_ALLCLASSES
/// <para>Return a list of installed devices for the specified device setup classes or device interface classes.</para>
/// </summary>
AllClasses = 4,

/// <summary>DIGCF_PROFILE
/// <para>Return only devices that are a part of the current hardware profile.</para>
/// </summary>
Profile = 8,

/// <summary>DIGCF_DEVICEINTERFACE
/// <para>
/// Return devices that support device interfaces for the specified device interface classes.
/// This flag must be set in the Flags parameter if the Enumerator parameter specifies a Device Instance ID.
/// </para>
/// </summary>
DeviceInterface = 16,
}
}
}

+ 62
- 0
AlphaFS/Filesystem/Enumerations/DirectoryEnumerationOptions.cs View File

@@ -0,0 +1,62 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>[AlphaFS] Directory enumeration options, flags that specify how a directory is to be enumerated.</summary>
[Flags]
public enum DirectoryEnumerationOptions
{
/// <summary>None (do not use).</summary>
None = 0,

/// <summary>Enumerate files only.</summary>
Files = 1,

/// <summary>Enumerate directories only.</summary>
Folders = 2,

/// <summary>Enumerate files and directories.</summary>
FilesAndFolders = Files | Folders,

/// <summary>Return full path as long full path (Unicode format), only valid when return type is <see cref="string"/>.</summary>
AsLongPath = 4,

/// <summary>Skip reparse points during directory enumeration.</summary>
SkipReparsePoints = 8,

/// <summary>Suppress any Exception that might be thrown as a result from a failure, such as ACLs protected directories or non-accessible reparse points.</summary>
ContinueOnException = 16,

/// <summary>Specifies whether to search the current directory, or the current directory and all subdirectories.</summary>
Recursive = 32,

/// <summary>Enumerates the directory without querying the short file name, improving overall enumeration speed.</summary>
/// <remarks>This option is enabled by default if supported. This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
BasicSearch = 64,

/// <summary>Enumerates the directory using a larger buffer for directory queries, which can increase performance of the find operation.</summary>
/// <remarks>This option is enabled by default if supported. This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
LargeCache = 128
}
}

+ 60
- 0
AlphaFS/Filesystem/Enumerations/DosDeviceAttributes.cs View File

@@ -0,0 +1,60 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Defines the controllable aspects of the Volume.DefineDosDevice() method.</summary>
[Flags]
public enum DosDeviceAttributes
{
/// <summary>DDD_EXACT_MATCH_ON_REMOVE
/// <para>Default.</para>
/// </summary>
None = 0,

/// <summary>DDD_RAW_TARGET_PATH
/// <para>Uses the targetPath string as is. Otherwise, it is converted from an MS-DOS path to a path.</para>
/// </summary>
RawTargetPath = 1,

/// <summary>DDD_REMOVE_DEFINITION
/// <para>Removes the specified definition for the specified device.</para>
/// <para>To determine which definition to remove, the function walks the list of mappings for the device, looking for a match of targetPath against a prefix of each mapping associated with this device.</para>
/// <para>The first mapping that matches is the one removed, and then the function returns.</para>
/// <para>If targetPath is null or a pointer to a null string, the function will remove the first mapping associated with the device and pop the most recent one pushed.If there is nothing left to pop, the device name will be removed.</para>
/// <para>If this value is not specified, the string pointed to by the targetPath parameter will become the new mapping for this device.</para>
/// </summary>
RemoveDefinition = 2,

/// <summary>DDD_EXACT_MATCH_ON_REMOVE
/// <para>If this value is specified along with <see cref="RemoveDefinition"/>, the function will use an exact match to determine which mapping to remove.</para>
/// <para>Use this value to ensure that you do not delete something that you did not define.</para>
/// </summary>
ExactMatchOnRemove = 4,

/// <summary>DDD_NO_BROADCAST_SYSTEM
/// <para>Do not broadcast the WM_SETTINGCHANGE message.</para>
/// <para>By default, this message is broadcast to notify the shell and applications of the change.</para>
/// </summary>
NoBroadcastSystem = 8,
}
}

+ 45
- 0
AlphaFS/Filesystem/Enumerations/EncryptedFileRawMode.cs View File

@@ -0,0 +1,45 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
partial class NativeMethods
{
/// <summary>Indicates the operation to be performed when opening a file using the OpenEncryptedFileRaw.</summary>
[Flags]
internal enum EncryptedFileRawMode
{
/// <summary>(0) Open the file for export (backup).</summary>
CreateForExport = 0,

/// <summary>(1) The file is being opened for import (restore).</summary>
CreateForImport = 1,

/// <summary>(2) Import (restore) a directory containing encrypted files. This must be combined with one of the previous two flags to indicate the operation.</summary>
CreateForDir = 2,

/// <summary>(4) Overwrite a hidden file on import.</summary>
OverwriteHidden = 4
}
}
}

+ 48
- 0
AlphaFS/Filesystem/Enumerations/ErrorMode.cs View File

@@ -0,0 +1,48 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Enum for struct ChangeErrorMode.</summary>
[Flags]
internal enum ErrorMode
{
/// <summary>Use the system default, which is to display all error dialog boxes.</summary>
SystemDefault = 0,

/// <summary>The system does not display the critical-error-handler message box. Instead, the system sends the error to the calling process/thread.</summary>
FailCriticalErrors = 1,
/// <summary>The system does not display the Windows Error Reporting dialog.</summary>
NoGpfaultErrorbox = 2,

/// <summary>The system automatically fixes memory alignment faults and makes them invisible to the application. It does this for the calling process and any descendant processes. This feature is only supported by certain processor architectures.</summary>
NoAlignmentFaultExcept = 4,
/// <summary>The system does not display a message box when it fails to find a file. Instead, the error is returned to the calling process/thread.</summary>
NoOpenFileErrorbox = 32768
}
}
}

+ 143
- 0
AlphaFS/Filesystem/Enumerations/ExtendedFileAttributes.cs View File

@@ -0,0 +1,143 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Specifies how the operating system should open a file.</summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2217:DoNotMarkEnumsWithFlags")]
[Flags]
public enum ExtendedFileAttributes
{
/// <summary>If you pass <see cref="ExtendedFileAttributes.None"/>, the set of attributes is unspecified. <see cref="ExtendedFileAttributes.Normal"/> explicitly sets no attributes.</summary>
None = 0,

#region FILE_ATTRIBUTE - Attributes applying to any file

/// <summary>The file is read only. Applications can read the file, but cannot write to or delete it.</summary>
/// <remarks>Equals <see cref="FileAttributes.ReadOnly"/>1</remarks>
ReadOnly = FileAttributes.ReadOnly,

/// <summary>The file is hidden. Do not include it in an ordinary directory listing.</summary>
/// <remarks>Equals <see cref="FileAttributes.Hidden"/>2</remarks>
Hidden = FileAttributes.Hidden,

/// <summary>The file is part of or used exclusively by an operating system.</summary>
/// <remarks>Equals <see cref="FileAttributes.System"/>4</remarks>
System = FileAttributes.System,

/// <summary>The handle that identifies a directory.</summary>
/// <remarks>Equals <see cref="FileAttributes.Directory"/>16</remarks>
Directory = FileAttributes.Directory,

/// <summary>The file should be archived. Applications use this attribute to mark files for backup or removal.</summary>
/// <remarks>Equals <see cref="FileAttributes.Archive"/>32</remarks>
Archive = FileAttributes.Archive,

/// <summary>The file should be archived. Applications use this attribute to mark files for backup or removal.</summary>
/// <remarks>Equals <see cref="FileAttributes.Device"/>64</remarks>
Device = FileAttributes.Device,

/// <summary>The file does not have other attributes set. This attribute is valid only if used alone.</summary>
/// <remarks>Equals <see cref="FileAttributes.Normal"/>128</remarks>
Normal = FileAttributes.Normal,

/// <summary>The file is being used for temporary storage.</summary>
/// <remarks>Equals <see cref="FileAttributes.Temporary"/>256</remarks>
Temporary = FileAttributes.Temporary,

/// <summary>A file that is a sparse file.</summary>
/// <remarks>Equals <see cref="FileAttributes.SparseFile"/>512</remarks>
SparseFile = FileAttributes.SparseFile,

/// <summary>A file or directory that has an associated reparse point, or a file that is a symbolic link.</summary>
/// <remarks>Equals <see cref="FileAttributes.ReparsePoint"/>1024</remarks>
ReparsePoint = FileAttributes.ReparsePoint,

/// <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>
/// <remarks>Equals <see cref="FileAttributes.Compressed"/>2048</remarks>
Compressed = FileAttributes.Compressed,

/// <summary>The data of a file is not immediately available. This attribute indicates that file data is physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software. Applications should not arbitrarily change this attribute.</summary>
/// <remarks>Equals <see cref="FileAttributes.Offline"/>4096</remarks>
Offline = FileAttributes.Offline,

/// <summary>The file or directory is not to be indexed by the content indexing service.</summary>
/// <remarks>Equals <see cref="FileAttributes.NotContentIndexed"/>8192</remarks>
NotContentIndexed = FileAttributes.NotContentIndexed,

/// <summary>The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories.</summary>
/// <remarks>Equals <see cref="FileOptions.Encrypted"/>16384</remarks>
Encrypted = FileOptions.Encrypted,

#endregion // FILE_ATTRIBUTE - Attributes applying to any file

/// <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>
/// <remarks>This flag is not supported until Windows Server 2012.</remarks>
IntegrityStream = 32768,

/// <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>
/// <remarks>This flag is not supported until Windows Server 2012.</remarks>
NoScrubData = 131072,

/// <summary>...</summary>
FirstPipeInstance = 524288,

/// <summary>The file data is requested, but it should continue to be located in remote storage. It should not be transported back to local storage. This flag is for use by remote storage systems.</summary>
OpenNoRecall = 1048576,

/// <summary>Normal reparse point processing will not occur; an attempt to open the reparse point will be made. When a file is opened, a file handle is returned, whether or not the filter that controls the reparse point is operational. See MSDN documentation for more information.</summary>
OpenReparsePoint = 2097152,

/// <summary>Access will occur according to POSIX rules. This includes allowing multiple files with names, differing only in case, for file systems that support that naming. Use care when using this option, because files created with this flag may not be accessible by applications that are written for MS-DOS or 16-bit Windows.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Posix")]
PosixSemantics = 16777216,

/// <summary>The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead of a file handle.</summary>
BackupSemantics = 33554432,

/// <summary>The file is to be deleted immediately after all of its handles are closed, which includes the specified handle and any other open or duplicated handles. If there are existing open handles to a file, the call fails unless they were all opened with the <see cref="FileShare.Delete"/> share mode. Subsequent open requests for the file fail, unless the <see cref="FileShare.Delete"/> share mode is specified.</summary>
/// <remarks>Equals <see cref="FileOptions.DeleteOnClose"/>67108864</remarks>
DeleteOnClose = FileOptions.DeleteOnClose,

/// <summary>Access is intended to be sequential from beginning to end. The system can use this as a hint to optimize file caching.</summary>
/// <remarks>Equals <see cref="FileOptions.SequentialScan"/>134217728</remarks>
SequentialScan = FileOptions.SequentialScan,

/// <summary>Access is intended to be random. The system can use this as a hint to optimize file caching.</summary>
/// <remarks>Equals <see cref="FileOptions.RandomAccess"/>268435456</remarks>
RandomAccess = FileOptions.RandomAccess,

/// <summary>There are strict requirements for successfully working with files opened with the <see cref="NoBuffering"/> flag, for details see the section on "File Buffering" in the online MSDN documentation.</summary>
NoBuffering = 536870912,

/// <summary>The file or device is being opened or created for asynchronous I/O.</summary>
/// <remarks>Equals <see cref="FileOptions.Asynchronous"/>1073741824</remarks>
Overlapped = FileOptions.Asynchronous,

/// <summary>Write operations will not go through any intermediate cache, they will go directly to disk.</summary>
/// <remarks>Equals .NET <see cref="FileOptions.WriteThrough"/>-2147483648</remarks>
WriteThrough = FileOptions.WriteThrough
}
}

+ 44
- 0
AlphaFS/Filesystem/Enumerations/FINDEX_INFO_LEVELS.cs View File

@@ -0,0 +1,44 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>FINDEX_INFO_LEVELS Enumeration - Defines values that are used with the FindFirstFileEx function to specify the information level of the returned data.</summary>
/// <remarks>
/// <para>Minimum supported client: Windows XP [desktop apps | Windows Store apps]</para>
/// <para>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps]</para>
/// </remarks>
internal enum FINDEX_INFO_LEVELS
{
/// <summary>A standard set of attribute is returned in a <see cref="WIN32_FIND_DATA"/> structure.</summary>
Standard = 0,

/// <summary>The FindFirstFileEx function does not query the short file name, improving overall enumeration speed.</summary>
/// <remarks>This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
Basic = 1

///// <summary>This value is used for validation. Supported values are less than this value.</summary>
//MaxLevel
}
}
}

+ 58
- 0
AlphaFS/Filesystem/Enumerations/FileEncryptionStatus.cs View File

@@ -0,0 +1,58 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Represents the encryption status of the specified file.</summary>
public enum FileEncryptionStatus
{
/// <summary>The file can be encrypted.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Encryptable")]
Encryptable = 0,

/// <summary>The file is encrypted.</summary>
Encrypted = 1,

/// <summary>The file is a system file. System files cannot be encrypted.</summary>
SystemFile = 2,

/// <summary>The file is a root directory. Root directories cannot be encrypted.</summary>
RootDirectory = 3,

/// <summary>The file is a system directory. System directories cannot be encrypted.</summary>
SystemDirectory = 4,

/// <summary>The encryption status is unknown. The file may be encrypted.</summary>
Unknown = 5,

/// <summary>The file system does not support file encryption.</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Filesystem")]
NoFilesystemSupport = 6,

/// <summary>Reserved for future use.</summary>
UserDisallowed = 7,

/// <summary>The file is a read-only file.</summary>
ReadOnly = 8
}
}

+ 270
- 0
AlphaFS/Filesystem/Enumerations/FileInfoByHandleClass.cs View File

@@ -0,0 +1,270 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>FILE_INFO_BY_HANDLE_CLASS
/// <para>Identifies the type of file information that GetFileInformationByHandleEx should retrieve or SetFileInformationByHandle should set.</para>
/// </summary>
internal enum FileInfoByHandleClass
{
#region FILE_BASIC_INFO

/// <summary>FILE_BASIC_INFO
/// <para>Minimal information for the file should be retrieved or set. Used for file handles.</para>
/// </summary>
FileBasicInfo = 0,

#endregion // FILE_BASIC_INFO

#region FILE_STANDARD_INFO

///// <summary>FILE_STANDARD_INFO
///// <para>Extended information for the file should be retrieved. Used for file handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// </summary>
//FileStandardInfo = 1,

#endregion // FILE_STANDARD_INFO

#region FILE_NAME_INFO

///// <summary>FILE_NAME_INFO
///// <para>The file name should be retrieved. Used for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// </summary>
//FileNameInfo = 2,

#endregion // FILE_NAME_INFO

#region FILE_RENAME_INFO

///// <summary>FILE_RENAME_INFO
///// <para>The file name should be changed. Used for file handles.</para>
///// <para>Use only when calling <see cref="SetFileInformationByHandle"/>.</para>
///// </summary>
//FileRenameInfo = 3,

#endregion // FILE_RENAME_INFO

#region FILE_DISPOSITION_INFO

///// <summary>FILE_DISPOSITION_INFO
///// <para>The file should be deleted. Used for any handles.</para>
///// <para>Use only when calling <see cref="SetFileInformationByHandle"/>.</para>
///// </summary>
//FileDispositionInfo = 4,

#endregion // FILE_DISPOSITION_INFO

#region FILE_ALLOCATION_INFO

///// <summary>FILE_ALLOCATION_INFO
///// <para>The file allocation information should be changed. Used for file handles.</para>
///// <para>Use only when calling <see cref="SetFileInformationByHandle"/>.</para>
///// </summary>
//FileAllocationInfo = 5,

#endregion // FILE_ALLOCATION_INFO

#region FILE_END_OF_FILE_INFO

///// <summary>FILE_END_OF_FILE_INFO
///// <para>The end of the file should be set. Use only when calling <see cref="SetFileInformationByHandle"/>.</para>
///// </summary>
//FileEndOfFileInfo = 6,

#endregion // FILE_END_OF_FILE_INFO

#region FILE_STREAM_INFO

///// <summary>FILE_STREAM_INFO
///// <para>File stream information for the specified file should be retrieved. Used for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// </summary>
//FileStreamInfo = 7,

#endregion // FILE_STREAM_INFO

#region FILE_COMPRESSION_INFO

///// <summary>FILE_COMPRESSION_INFO
///// <para>File compression information should be retrieved. Used for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// </summary>
//FileCompressionInfo = 8,

#endregion // FILE_COMPRESSION_INFO

#region FILE_ATTRIBUTE_TAG_INFO

///// <summary>FILE_ATTRIBUTE_TAG_INFO
///// <para>File attribute information should be retrieved. Used for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// </summary>
//FileAttributeTagInfo = 9,

#endregion // FILE_ATTRIBUTE_TAG_INFO

#region FILE_ID_BOTH_DIR_INFO

/// <summary>FILE_ID_BOTH_DIR_INFO
/// <para>Files in the specified directory should be retrieved. Used for directory handles.</para>
/// <para>Use only when calling GetFileInformationByHandleEx.</para>
/// <remarks>
/// <para>The number of files returned for each call to GetFileInformationByHandleEx</para>
/// <para>depends on the size of the buffer that is passed to the function.</para>
/// <para>Any subsequent calls to GetFileInformationByHandleEx on the same handle</para>
/// <para>will resume the enumeration operation after the last file is returned.</para>
/// </remarks>
/// </summary>
FileIdBothDirectoryInfo = 10,

#endregion // FILE_ID_BOTH_DIR_INFO

#region FILE_ID_BOTH_DIR_INFO

///// <summary>FILE_ID_BOTH_DIR_INFO
///// <para>Identical to <see cref="FileIdBothDirectoryInfo"/>, but forces the enumeration operation to start again from the beginning.</para>
///// </summary>
//FileIdBothDirectoryInfoRestartInfo = 11,

#endregion // FILE_ID_BOTH_DIR_INFO

#region FILE_IO_PRIORITY_HINT_INFO

///// <summary>FILE_IO_PRIORITY_HINT_INFO
///// <para>Priority hint information should be set.Use only when calling <see cref="SetFileInformationByHandle"/>.</para>
///// </summary>
//FileIoPriorityHintInfo = 12,

#endregion // FILE_IO_PRIORITY_HINT_INFO

#region FILE_REMOTE_PROTOCOL_INFO

///// <summary>(13) FILE_REMOTE_PROTOCOL_INFO
///// <para>File remote protocol information should be retrieved.Use for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// </summary>
//FileRemoteProtocolInfo = 13,

#endregion // FILE_REMOTE_PROTOCOL_INFO

#region FILE_FULL_DIR_INFO

///// <summary>(14) FILE_FULL_DIR_INFO
///// <para>Files in the specified directory should be retrieved. Used for directory handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileFullDirectoryInfo = 14,

#endregion // FILE_FULL_DIR_INFO

#region FILE_FULL_DIR_INFO

///// <summary>FILE_FULL_DIR_INFO
///// <para>Identical to <see cref="FileFullDirectoryInfo"/>, but forces the enumeration operation to start again from the beginning. Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileFullDirectoryRestartInfo = 15,

#endregion // FILE_FULL_DIR_INFO

#region FILE_STORAGE_INFO

///// <summary>FILE_STORAGE_INFO
///// <para>File storage information should be retrieved. Use for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileStorageInfo = 16,

#endregion // FILE_STORAGE_INFO

#region FILE_ALIGNMENT_INFO

///// <summary>FILE_ALIGNMENT_INFO
///// <para>File alignment information should be retrieved. Use for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileAlignmentInfo = 17,

#endregion FILE_ALIGNMENT_INFO

#region FILE_ID_INFO

///// <summary>FILE_ID_INFO
///// <para>File information should be retrieved. Use for any handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileIdInfo = 18,

#endregion // FILE_ID_INFO

#region FILE_ID_EXTD_DIR_INFO

///// <summary>FILE_ID_EXTD_DIR_INFO
///// <para>Files in the specified directory should be retrieved. Used for directory handles.</para>
///// <para>Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileIdExtdDirectoryInfo = 19,

#endregion // FILE_ID_EXTD_DIR_INFO

#region FILE_ID_EXTD_DIR_INFO

///// <summary>FILE_ID_EXTD_DIR_INFO
///// <para>Identical to <see cref="FileIdExtdDirectoryInfo"/>, but forces the enumeration operation to start again from the beginning. Use only when calling GetFileInformationByHandleEx.</para>
///// <remarks>
///// <para>Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:</para>
///// <para>This value is not supported before Windows 8 and Windows Server 2012</para>
///// </remarks>
///// </summary>
//FileIdExtdDirectoryRestartInfo = 20

#endregion // FILE_ID_EXTD_DIR_INFO
}
}
}

+ 45
- 0
AlphaFS/Filesystem/Enumerations/FinalPathFormats.cs View File

@@ -0,0 +1,45 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Determines the format to convert a path to using <see cref="Alphaleonis.Win32.Filesystem.Path.GetFinalPathNameByHandle(Microsoft.Win32.SafeHandles.SafeFileHandle)"/></summary>
[Flags]
public enum FinalPathFormats
{
/// <summary>(FileNameNormalized / VolumeNameDos) Return the normalized drive name. This is the default.</summary>
None = 0,

/// <summary>Return the path with a volume GUID path instead of the drive name.</summary>
VolumeNameGuid = 1,

/// <summary>Return the path with the volume device path.</summary>
VolumeNameNT = 2,

/// <summary>Return the path with no drive information.</summary>
VolumeNameNone = 4,

/// <summary>Return the opened file name (not normalized).</summary>
FileNameOpened = 8
}
}

+ 43
- 0
AlphaFS/Filesystem/Enumerations/FindExAdditionalFlags.cs View File

@@ -0,0 +1,43 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Additional flags that control the search.</summary>
[Flags]
internal enum FindExAdditionalFlags
{
/// <summary>No additional flags used.</summary>
None = 0,

/// <summary>Searches are case-sensitive.</summary>
CaseSensitive = 1,

/// <summary>Uses a larger buffer for directory queries, which can increase performance of the find operation.</summary>
/// <remarks>This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
LargeFetch = 2
}
}
}

+ 57
- 0
AlphaFS/Filesystem/Enumerations/FindExSearchOps.cs View File

@@ -0,0 +1,57 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>FINDEX_SEARCH_OPS Enumeration - Defines values that are used with the FindFirstFileEx function to specify the type of filtering to perform.</summary>
/// <remarks>
/// <para>Minimum supported client: Windows XP [desktop apps | Windows Store apps]</para>
/// <para>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps]</para>
/// </remarks>
internal enum FINDEX_SEARCH_OPS
{
/// <summary>The search for a file that matches a specified file name.
/// <para>The lpSearchFilter parameter of FindFirstFileEx must be NULL when this search operation is used.</para>
/// </summary>
SearchNameMatch = 0,

/// <summary>This is an advisory flag. If the file system supports directory filtering,
/// <para>the function searches for a file that matches the specified name and is also a directory.</para>
/// <para>If the file system does not support directory filtering, this flag is silently ignored.</para>
/// <para>&#160;</para>
/// <remarks>
/// <para>The lpSearchFilter parameter of the FindFirstFileEx function must be NULL when this search value is used.</para>
/// <para>If directory filtering is desired, this flag can be used on all file systems,</para>
/// <para>but because it is an advisory flag and only affects file systems that support it,</para>
/// <para>the application must examine the file attribute data stored in the lpFindFileData parameter</para>
/// <para>of the FindFirstFileEx function to determine whether the function has returned a handle to a directory.</para>
/// </remarks>
/// </summary>
SearchLimitToDirectories = 1,

/// <summary>This filtering type is not available.</summary>
/// <remarks>For more information, see Device Interface Classes.</remarks>
SearchLimitToDevices = 2
}
}
}

+ 33
- 0
AlphaFS/Filesystem/Enumerations/GetFileExInfoLevels.cs View File

@@ -0,0 +1,33 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Defines values that are used with the GetFileAttributesEx and GetFileAttributesTransacted functions to specify the information level of the returned data.</summary>
public enum GetFileExInfoLevels
{
/// <summary>The GetFileAttributesEx or GetFileAttributesTransacted function retrieves a standard set of attribute information. The data is returned in a WIN32_FILE_ATTRIBUTE_DATA structure.</summary>
GetFileExInfoStandard = 0
}
}
}

+ 60
- 0
AlphaFS/Filesystem/Enumerations/GetFullPathOptions.cs View File

@@ -0,0 +1,60 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>A bitfield of flags for specifying options for various internal operations that convert paths to full paths.</summary>
[Flags]
public enum GetFullPathOptions
{
/// <summary>No special options applies.</summary>
None = 0,

/// <summary>Remove any trailing whitespace from the path.</summary>
TrimEnd = 1,

/// <summary>Add a trailing directory separator to the path (if one does not already exist).</summary>
AddTrailingDirectorySeparator = 2,

/// <summary>Remove the trailing directory separator from the path (if one exists).</summary>
RemoveTrailingDirectorySeparator = 4,

/// <summary>Return full path as long full path (Unicode format). Not valid for <see cref="Path.GetRegularPath"/>.</summary>
AsLongPath = 8,

/// <summary>Prevents any exception from being thrown if a filesystem object does not exist. Not valid for <see cref="Path.GetRegularPath"/>.</summary>
ContinueOnNonExist = 16,

/// <summary>Check that the path contains only valid path-characters.</summary>
CheckInvalidPathChars = 32,

/// <summary>Also check for wildcard (? and *) characters.</summary>
CheckAdditional = 64,

/// <summary>Do not trim the trailing dot or space.</summary>
KeepDotOrSpace = 128,

/// <summary>Performs both <see cref="CheckInvalidPathChars"/> and <see cref="CheckAdditional"/> checks.</summary>
FullCheck = CheckInvalidPathChars | CheckAdditional
}
}

+ 83
- 0
AlphaFS/Filesystem/Enumerations/MoveOptions.cs View File

@@ -0,0 +1,83 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Used by MoveFileXxx.Flags that specify how a file or directory is to be moved.</summary>
[Flags]
public enum MoveOptions
{
/// <summary>No MoveOptions used, this fails when the file name already exists.</summary>
None = 0,

/// <summary>MOVE_FILE_REPLACE_EXISTSING
/// <para>If the destination file name already exists, the function replaces its contents with the contents of the source file.</para>
/// <para>This value cannot be used if lpNewFileName or lpExistingFileName names a directory.</para>
/// <para>This value cannot be used if either source or destination names a directory.</para>
/// </summary>
ReplaceExisting = 1,

/// <summary>MOVE_FILE_COPY_ALLOWED
/// <para>If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions.</para>
/// <para>This value cannot be used with <see cref="MoveOptions.DelayUntilReboot"/>.</para>
/// </summary>
CopyAllowed = 2,

/// <summary>MOVE_FILE_DELAY_UNTIL_REBOOT
/// <para>
/// The system does not move the file until the operating system is restarted.
/// The system moves the file immediately after AUTOCHK is executed, but before creating any paging files.
/// </para>
/// <para>
/// Consequently, this parameter enables the function to delete paging files from previous startups.
/// This value can only be used if the process is in the context of a user who belongs to the administrators group or the LocalSystem account.
/// </para>
/// <para>This value cannot be used with <see cref="MoveOptions.CopyAllowed"/>.</para>
/// </summary>
DelayUntilReboot = 4,

/// <summary>MOVE_FILE_WRITE_THROUGH
/// <para>The function does not return until the file has actually been moved on the disk.</para>
/// <para>
/// Setting this value guarantees that a move performed as a copy and delete operation is flushed to disk before the function returns.
/// The flush occurs at the end of the copy operation.
/// </para>
/// <para>This value has no effect if <see cref="MoveOptions.DelayUntilReboot"/> is set.</para>
/// </summary>
WriteThrough = 8,

/// <summary>MOVE_FILE_CREATE_HARDLINK
/// <para>Reserved for future use.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hardlink")]
CreateHardlink = 16,

/// <summary>MOVE_FILE_FAIL_IF_NOT_TRACKABLE
/// <para>The function fails if the source file is a link source, but the file cannot be tracked after the move.</para>
/// <para>This situation can occur if the destination is a volume formatted with the FAT file system.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Trackable")]
FailIfNotTrackable = 32
}
}

+ 59
- 0
AlphaFS/Filesystem/Enumerations/PathFormat.cs View File

@@ -0,0 +1,59 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Indicates the format of a path passed to a method.</summary>
/// <remarks>
/// At some point in code you know the full path of file system objects, e.g.: "C:\Windows".
/// For example, Directory.EnumerateFileSystemEntries() will return all files and directories from a given path.
/// Most likely, some processing will happen on the results of the enum. The file or directory may be passed
/// on to another function. Whenever a file path is required, some performance can be gained.
/// <para>&#160;</para>
/// A path like: "C:\Windows" or "\\server\share" is considered a full path for a directory because it is rooted and has a drive/unc path.
/// If the method supports it, <see cref="PathFormat.FullPath"/> and <see cref="PathFormat.LongFullPath"/> will skip GetFullPath()
/// calls for path resolving of the object, while also avoiding path validation and checks.
/// Using <see cref="PathFormat.RelativePath"/> (default) will always call GetFullPath() and perform path validation and checks.
/// <para>&#160;</para>
/// When working in a loop with thousands of files, <see cref="PathFormat.LongFullPath"/> will give the best performance.
/// </remarks>
public enum PathFormat
{
/// <summary>The format of the path is automatically detected by the method and internally converted to an extended length path.
/// It can be either a standard (short) full path, an extended length (unicode) full path or a relative path.
/// <para>Example relative path: "Windows".</para>
/// </summary>
RelativePath,

/// <summary>The path is a full path in either normal or extended length (UNICODE) format.
/// Internally it will be converted to an extended length (UNICODE) path.
/// Using this option has a very slight performance advantage compared to using <see cref="RelativePath"/>.
/// <para>Example full path: "C:\Windows" or "\\server\share".</para>
/// </summary>
FullPath,

/// <summary>The path is an extended length path. No additional processing will be done on the path, and it will be used as is.
/// Using this option has a slight performance advantage compared to using <see cref="RelativePath"/>.
/// <para>Example long full path: "\\?\C:\Windows" or "\\?\UNC\server\share".</para>
/// </summary>
LongFullPath
}
}

+ 106
- 0
AlphaFS/Filesystem/Enumerations/ReparsePointTag.cs View File

@@ -0,0 +1,106 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Diagnostics.CodeAnalysis;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Enumeration specifying the different reparse point tags.</summary>
/// <remarks>
/// <para>Reparse tags, with the exception of IO_REPARSE_TAG_SYMLINK, are processed on the server and are not processed by a client after transmission over the wire.</para>
/// <para>Clients should treat associated reparse data as opaque data.</para>
/// </remarks>
public enum ReparsePointTag
{
/// <summary>The entry is not a reparse point.</summary>
None = 0,

/// <summary>IO_REPARSE_APPXSTREAM</summary>
AppXStream = unchecked ((int) 3221225492),

/// <summary>IO_REPARSE_TAG_CSV</summary>
Csv = unchecked ((int) 2147483657),

/// <summary>IO_REPARSE_TAG_DRIVER_EXTENDER
/// <para>Used by Home server drive extender.</para>
/// </summary>
DriverExtender = unchecked ((int) 2147483653),

/// <summary>IO_REPARSE_TAG_DEDUP</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dedup")]
Dedup = unchecked ((int) 2147483667),

/// <summary>IO_REPARSE_TAG_DFS
/// <para>Used by the DFS filter.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dfs")]
Dfs = unchecked ((int) 2147483658),

/// <summary>IO_REPARSE_TAG_DFSR
/// <para>Used by the DFS filter.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dfsr")]
Dfsr = unchecked ((int) 2147483666),

/// <summary>IO_REPARSE_TAG_FILTER_MANAGER
/// <para>Used by filter manager test harness.</para>
/// </summary>
FilterManager = unchecked ((int) 2147483659),

/// <summary>IO_REPARSE_TAG_HSM
/// <para>(Obsolete) Used by legacy Hierarchical Storage Manager Product.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hsm")]
Hsm = unchecked ((int) 3221225476),

/// <summary>IO_REPARSE_TAG_HSM2
/// <para>(Obsolete) Used by legacy Hierarchical Storage Manager Product.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hsm")]
Hsm2 = unchecked ((int) 2147483654),

/// <summary>IO_REPARSE_TAG_NFS
/// <para>NFS symlinks, Windows 8 / SMB3 and later.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Nfs")]
Nfs = unchecked ((int) 2147483668),

/// <summary>IO_REPARSE_TAG_MOUNT_POINT
/// <para>Used for mount point support.</para>
/// </summary>
MountPoint = unchecked ((int) 2684354563),

/// <summary>IO_REPARSE_TAG_SIS
/// <para>Used by single-instance storage (SIS) filter driver.</para>
/// </summary>
Sis = unchecked ((int) 2147483655),

/// <summary>IO_REPARSE_TAG_SYMLINK
/// <para>Used for symbolic link support.</para>
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sym")]
SymLink = unchecked ((int) 2684354572),

/// <summary>IO_REPARSE_TAG_WIM</summary>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Wim")]
Wim = unchecked ((int) 2147483656)
}
}

+ 40
- 0
AlphaFS/Filesystem/Enumerations/STREAM_INFO_LEVELS.cs View File

@@ -0,0 +1,40 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Defines values that are used with the FindFirstStreamW function to specify the information level of the returned data.</summary>
/// <remarks>
/// <para>Minimum supported client: Windows Vista [desktop apps only]</para>
/// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
/// </remarks>
internal enum STREAM_INFO_LEVELS
{
/// <summary>The FindFirstStreamW function retrieves standard stream information. The data is returned in a <see cref="WIN32_FIND_STREAM_DATA"/> structure.</summary>
FindStreamInfoStandard = 0,

/// <summary>Used to determine valid enumeration values. All supported enumeration values are less than FindStreamInfoMaxInfoLevel.</summary>
FindStreamInfoMaxInfoLevel = 1
}
}
}

+ 169
- 0
AlphaFS/Filesystem/Enumerations/SetupDiGetDeviceRegistryPropertyEnum.cs View File

@@ -0,0 +1,169 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Flags for SetupDiGetDeviceRegistryProperty().</summary>
internal enum SetupDiGetDeviceRegistryPropertyEnum
{
/// <summary>SPDRP_DEVICEDESC
/// <para>Represents a description of a device instance.</para>
/// </summary>
DeviceDescription = 0,

/// <summary>SPDRP_HARDWAREID
/// <para>Represents the list of hardware identifiers for a device instance.</para>
/// </summary>
HardwareId = 1,

/// <summary>SPDRP_COMPATIBLEIDS
/// <para>Represents the list of compatible identifiers for a device instance.</para>
/// </summary>
CompatibleIds = 2,

//SPDRP_UNUSED0 = 0x00000003,

/// <summary>SPDRP_CLASS
/// <para>Represents the name of the service that is installed for a device instance.</para>
/// </summary>
Service = 4,

//SPDRP_UNUSED1 = 0x00000005,
//SPDRP_UNUSED2 = 0x00000006,

/// <summary>SPDRP_CLASS
/// <para>Represents the name of the device setup class that a device instance belongs to.</para>
/// </summary>
Class = 7,

/// <summary>SPDRP_CLASSGUID
/// <para>Represents the <see cref="System.Guid"/> of the device setup class that a device instance belongs to.</para>
/// </summary>
ClassGuid = 8,

/// <summary>SPDRP_DRIVER
/// <para>Represents the registry entry name of the driver key for a device instance.</para>
/// </summary>
Driver = 9,

///// <summary>SPDRP_CONFIGFLAGS
///// Represents the configuration flags that are set for a device instance.
///// </summary>
//ConfigurationFlags = 10,

/// <summary>SPDRP_MFG
/// <para>Represents the name of the manufacturer of a device instance.</para>
/// </summary>
Manufacturer = 11,

/// <summary>SPDRP_FRIENDLYNAME
/// <para>Represents the friendly name of a device instance.</para>
/// </summary>
FriendlyName = 12,

/// <summary>SPDRP_LOCATION_INFORMATION
/// <para>Represents the bus-specific physical location of a device instance.</para>
/// </summary>
LocationInformation = 13,

/// <summary>SPDRP_PHYSICAL_DEVICE_LOCATION
/// <para>Encapsulates the physical device location information provided by a device's firmware to Windows.</para>
/// </summary>
PhysicalDeviceObjectName = 14,

///// <summary>SPDRP_CAPABILITIES
//// <para>Represents the capabilities of a device instance.</para>
//// </summary>
//Capabilities = 15,

///// <summary>SPDRP_UI_NUMBER - Represents a number for the device instance that can be displayed in a user interface item.</summary>
//UiNumber = 16,

///// <summary>SPDRP_UPPERFILTERS - Represents a list of the service names of the upper-level filter drivers that are installed for a device instance.</summary>
//UpperFilters = 17,

///// <summary>SPDRP_LOWERFILTERS - Represents a list of the service names of the lower-level filter drivers that are installed for a device instance.</summary>
//LowerFilters = 18,

///// <summary>SPDRP_BUSTYPEGUID - Represents the <see cref="Guid"/> that identifies the bus type of a device instance.</summary>
//BusTypeGuid = 19,

///// <summary>SPDRP_LEGACYBUSTYPE - Represents the legacy bus number of a device instance.</summary>
//LegacyBusType = 20,

///// <summary>SPDRP_BUSNUMBER - Represents the number that identifies the bus instance that a device instance is attached to.</summary>
//BusNumber = 21,

/// <summary>SPDRP_ENUMERATOR_NAME
/// <para>Represents the name of the enumerator for a device instance.</para>
/// </summary>
EnumeratorName = 22,

///// <summary>SPDRP_SECURITY - Represents a security descriptor structure for a device instance.</summary>
//Security = 23,

///// <summary>SPDRP_SECURITY_SDS - Represents a security descriptor string for a device instance.</summary>
//SecuritySds = 24,

///// <summary>SPDRP_DEVTYPE - Represents the device type of a device instance.</summary>
//DeviceType = 25,

///// <summary>SPDRP_EXCLUSIVE - Represents a Boolean value that determines whether a device instance can be opened for exclusive use.</summary>
//Exclusive = 26,

///// <summary>SPDRP_CHARACTERISTICS - Represents the characteristics of a device instance.</summary>
//Characteristics = 27,

///// <summary>SPDRP_ADDRESS - Represents the bus-specific address of a device instance.</summary>
//Address = 28,

///// <summary>SPDRP_UI_NUMBER_DESC_FORMAT - Represents a printf-compatible format string that you should use to display the value of the <see cref="UiNumber"/> device property for a device instance.</summary>
//UiNumberDescriptionFormat = 29,

///// <summary>SPDRP_DEVICE_POWER_DATA - Represents power information about a device instance.</summary>
//DevicePowerData = 30,

///// <summary>SPDRP_REMOVAL_POLICY - Represents the current removal policy for a device instance.</summary>
//RemovalPolicy = 31,

///// <summary>SPDRP_REMOVAL_POLICY_HW_DEFAULT - Represents the default removal policy for a device instance.</summary>
//RemovalPolicyDefault = 32,

///// <summary>SPDRP_REMOVAL_POLICY_OVERRIDE- Represents the removal policy override for a device instance.</summary>
//RemovalPolicyOverride = 33,

///// <summary>SPDRP_INSTALL_STATE - Represents the installation state of a device instance.</summary>
//InstallState = 34,

/// <summary>SPDRP_LOCATION_PATHS
/// <para>Represents the location of a device instance in the device tree.</para>
/// </summary>
LocationPaths = 35,

/// <summary>SPDRP_BASE_CONTAINERID
/// <para>Represents the <see cref="System.Guid"/> value of the base container identifier (ID) .The Windows Plug and Play (PnP) manager assigns this value to the device node (devnode).</para>
/// </summary>
BaseContainerId = 36
}
}
}

+ 56
- 0
AlphaFS/Filesystem/Enumerations/StreamAttributes.cs View File

@@ -0,0 +1,56 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>WIN32_STREAM_ID Attributes of data to facilitate cross-operating system transfer.</summary>
[Flags]
public enum StreamAttributes
{
/// <summary>STREAM_NORMAL_ATTRIBUTE
/// <para>This backup stream has no special attributes.</para>
/// </summary>
None = 0,

/// <summary>STREAM_MODIFIED_WHEN_READ
/// <para>Attribute set if the stream contains data that is modified when read.</para>
/// <para>Allows the backup application to know that verification of data will fail.</para>
/// </summary>
ModifiedWhenRead = 1,

/// <summary>STREAM_CONTAINS_SECURITY
/// <para>The backup stream contains security information.</para>
/// <para>This attribute applies only to backup stream of type <see cref="BackupStreamType.SecurityData"/>.</para>
/// </summary>
ContainsSecurity = 2,

/// <summary>Reserved.</summary>
ContainsProperties = 4,

/// <summary>STREAM_SPARSE_ATTRIBUTE
/// <para>The backup stream is part of a sparse file stream.</para>
/// <para>This attribute applies only to backup stream of type <see cref="BackupStreamType.Data"/>, <see cref="BackupStreamType.AlternateData"/>, and <see cref="BackupStreamType.SparseBlock"/>.</para>
/// </summary>
Sparse = 8
}
}

+ 34
- 0
AlphaFS/Filesystem/Enumerations/SymbolicLinkTarget.cs View File

@@ -0,0 +1,34 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Indicates whether the link target is a file or directory.</summary>
/// <remarks>Used by Win32 API CreateSymbolicLink()/CreateSymbolicLinkTransacted()</remarks>
public enum SymbolicLinkTarget
{
/// <summary>The link target is a file.</summary>
File = 0,

/// <summary>The link target is a directory.</summary>
Directory = 1
}
}

+ 33
- 0
AlphaFS/Filesystem/Enumerations/SymbolicLinkType.cs View File

@@ -0,0 +1,33 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Alphaleonis.Win32.Filesystem
{
/// <summary>Specifies the type of a symbolic link.</summary>
public enum SymbolicLinkType
{
/// <summary>The symbolic link is absolute.</summary>
Absolute = 0,

/// <summary>The symbolic link is relative.</summary>
Relative = 1,
}
}

+ 144
- 0
AlphaFS/Filesystem/Enumerations/VolumeInfoAttributes.cs View File

@@ -0,0 +1,144 @@
/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace Alphaleonis.Win32.Filesystem
{
internal static partial class NativeMethods
{
/// <summary>Volume Attributes used by the GetVolumeInfo() function.</summary>
[Flags]
internal enum VolumeInfoAttributes
{
/// <summary>No VolumeInfo attributes.</summary>
None = 0,

/// <summary>FILE_CASE_SENSITIVE_SEARCH
/// <para>The specified volume supports case-sensitive file names.</para>
/// </summary>
CaseSensitiveSearch = 1,

/// <summary>FILE_CASE_PRESERVED_NAMES
/// <para>The specified volume supports preserved case of file names when it places a name on disk.</para>
/// </summary>
CasePreservedNames = 2,

/// <summary>FILE_UNICODE_ON_DISK
/// <para>The specified volume supports Unicode in file names as they appear on disk.</para>
/// </summary>
UnicodeOnDisk = 4,

/// <summary>FILE_PERSISTENT_ACLS
/// <para>
/// The specified volume preserves and enforces access control lists (ACL).
/// For example, the NTFS file system preserves and enforces ACLs, and the FAT file system does not.
/// </para>
/// </summary>
PersistentAcls = 8,

/// <summary>FILE_FILE_COMPRESSION
/// <para>The specified volume supports file-based compression.</para>
/// </summary>
Compression = 16,

/// <summary>FILE_VOLUME_QUOTAS
/// <para>The specified volume supports disk quotas.</para>
/// </summary>
VolumeQuotas = 32,

/// <summary>FILE_SUPPORTS_SPARSE_FILES
/// <para>The specified volume supports sparse files.</para>
/// </summary>
SupportsSparseFiles = 64,

/// <summary>FILE_SUPPORTS_REPARSE_POINTS
/// <para>The specified volume supports re-parse points.</para>
/// </summary>
SupportsReparsePoints = 128,

/// <summary>(does not appear on MSDN)</summary>
SupportsRemoteStorage = 256,

/// <summary>FILE_VOLUME_IS_COMPRESSED
/// <para>The specified volume is a compressed volume, for example, a DoubleSpace volume.</para>
/// </summary>
VolumeIsCompressed = 32768,

/// <summary>FILE_SUPPORTS_OBJECT_IDS
/// <para>The specified volume supports object identifiers.</para>
/// </summary>
SupportsObjectIds = 65536,

/// <summary>FILE_SUPPORTS_ENCRYPTION
/// <para>The specified volume supports the Encrypted File System (EFS). For more information, see File Encryption.</para>
/// </summary>
SupportsEncryption = 131072,

/// <summary>FILE_NAMED_STREAMS
/// <para>The specified volume supports named streams.</para>
/// </summary>
NamedStreams = 262144,

/// <summary>FILE_READ_ONLY_VOLUME
/// <para>The specified volume is read-only.</para>
/// </summary>
ReadOnlyVolume = 524288,

/// <summary>FILE_SEQUENTIAL_WRITE_ONCE
/// <para>The specified volume is read-only.</para>
/// </summary>
SequentialWriteOnce = 1048576,

/// <summary>FILE_SUPPORTS_TRANSACTIONS
/// <para>The specified volume supports transactions.For more information, see About KTM.</para>
/// </summary>
SupportsTransactions = 2097152,

/// <summary>FILE_SUPPORTS_HARD_LINKS
/// <para>The specified volume supports hard links. For more information, see Hard Links and Junctions.</para>
/// </summary>
/// <remarks>Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
SupportsHardLinks = 4194304,

/// <summary>FILE_SUPPORTS_EXTENDED_ATTRIBUTES
/// <para>
/// The specified volume supports extended attributes. An extended attribute is a piece of application-specific metadata
/// that an application can associate with a file and is not part of the file's data.
/// </para>
/// </summary>
/// <remarks>Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
SupportsExtendedAttributes = 8388608,

/// <summary>FILE_SUPPORTS_OPEN_BY_FILE_ID
/// <para>The file system supports open by FileID. For more information, see FILE_ID_BOTH_DIR_INFO.</para>
/// </summary>
/// <remarks>Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
SupportsOpenByFileId = 16777216,

/// <summary>FILE_SUPPORTS_USN_JOURNAL
/// <para>The specified volume supports update sequence number (USN) journals. For more information, see Change Journal Records.</para>
/// </summary>
/// <remarks>Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported until Windows Server 2008 R2 and Windows 7.</remarks>
SupportsUsnJournal = 33554432
}
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save