Skip to content

Commit

Permalink
Merge pull request #38 from alphaleonis/AddHeadersDirectoryClass
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
Yomodo committed Jan 8, 2015
2 parents e80015b + 51760b1 commit bbd9353
Show file tree
Hide file tree
Showing 32 changed files with 734 additions and 498 deletions.
8 changes: 6 additions & 2 deletions AlphaFS.UnitTest/DirectoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3869,8 +3869,12 @@ public void GetParent()

try
{
// System.IO can not handle "\\?\": Illegal characters in path.
if (path != null && path.StartsWith(@"\\?", StringComparison.OrdinalIgnoreCase))
continue;

DirectoryInfo diActual = Directory.GetParent(path);
DirectoryInfo diExpected = Directory.GetParent(path);
System.IO.DirectoryInfo diExpected = System.IO.Directory.GetParent(path);

if (diActual == null || diExpected == null)
{
Expand All @@ -3887,7 +3891,7 @@ public void GetParent()
}
catch (Exception ex)
{
Console.WriteLine("\n\tCaught Exception: [{0}]", ex.Message.Replace(Environment.NewLine, " "));
Console.WriteLine("\n\tCaught Exception: [{0}]: [{1}]", ex.Message.Replace(Environment.NewLine, " "), path);

// Exception to the Exception.
if (path != null && !path.StartsWith(Path.GlobalRootPrefix, StringComparison.OrdinalIgnoreCase))
Expand Down
12 changes: 4 additions & 8 deletions AlphaFS/AlphaFS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<ItemGroup>
<Compile Include="Filesystem\AlternateDataStreamInfo.cs" />
<Compile Include="Filesystem\CopyMoveProgressRoutine.cs" />
<Compile Include="Filesystem\Directory Class\Directory.CountFileSystemObjects.cs" />
<Compile Include="Filesystem\Directory Class\Directory.DeleteEmptySubdirectories.cs" />
<Compile Include="Filesystem\Directory Class\Directory.AlternateDataStreams.cs" />
<Compile Include="Filesystem\Directory Class\Directory.Delete.cs" />
Expand All @@ -184,15 +185,10 @@
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.RefreshEntryInfo.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.GetAlternateDataStreamSize.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnumerateAlternateDataStreams.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Encrypt.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnableEncryption.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.EnableCompression.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.Decompress.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.DisableEncryption.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.DisableCompression.cs" />
<Compile Include="Filesystem\DirectoryInfo Class\DirectoryInfo.Compress.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.AddAlternateDataStream.cs" />
Expand Down Expand Up @@ -451,7 +447,7 @@
-->
<ProjectExtensions>
<VisualStudio>
<UserProperties Reset="1" AssemblyVersion="0" AssemblyFileVersion="0" StartDate="20080813" />
<UserProperties StartDate="20080813" AssemblyFileVersion="0" AssemblyVersion="0" Reset="1" />
</VisualStudio>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

namespace Alphaleonis.Win32.Filesystem
{
public static partial class Directory
partial class Directory
{
#region AlphaFS

#region AddAlternateDataStream

#region Non-Transactional
Expand Down Expand Up @@ -190,7 +192,7 @@ public static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreams
return AlternateDataStreamInfo.EnumerateAlternateDataStreamsInternal(null, transaction, null, path, null, streamType, pathFormat);
}

#endregion // Transacted
#endregion // Transactional

#endregion // EnumerateAlternateDataStreams

Expand Down Expand Up @@ -362,7 +364,7 @@ public static long GetAlternateDataStreamSize(KernelTransaction transaction, str
return AlternateDataStreamInfo.GetAlternateDataStreamSizeInternal(true, transaction, null, path, null, type, pathFormat);
}

#endregion // Transacted
#endregion // Transactional

#endregion GetAlternateDataStreamSize

Expand Down Expand Up @@ -473,5 +475,7 @@ public static void RemoveAlternateDataStream(KernelTransaction transaction, stri
#endregion // Transactional

#endregion // RemoveAlternateDataStream

#endregion // AlphaFS
}
}
30 changes: 24 additions & 6 deletions AlphaFS/Filesystem/Directory Class/Directory.Compression.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
/* Copyright (C) 2008-2015 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
{
public static partial class Directory
partial class Directory
{
#region Compress

Expand Down Expand Up @@ -96,7 +114,7 @@ public static void Compress(KernelTransaction transaction, string path, Director
CompressDecompressInternal(transaction, path, Path.WildcardStarMatchAll, directoryEnumerationOptions, true, PathFormat.Relative);
}

#endregion // Transacted
#endregion // Transactional

#endregion // Compress

Expand Down Expand Up @@ -190,7 +208,7 @@ public static void Decompress(KernelTransaction transaction, string path, Direct
CompressDecompressInternal(transaction, path, Path.WildcardStarMatchAll, directoryEnumerationOptions, false, PathFormat.Relative);
}

#endregion // Transacted
#endregion // Transactional

#endregion // Decompress

Expand Down
2 changes: 1 addition & 1 deletion AlphaFS/Filesystem/Directory Class/Directory.CopyMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

Expand Down
161 changes: 161 additions & 0 deletions AlphaFS/Filesystem/Directory Class/Directory.CountFileSystemObjects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/* Copyright (C) 2008-2015 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.Linq;
using System.Security;

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

#region Non-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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="path">The directory path.</param>
/// <param name="directoryEnumerationOptions"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjects(string path, DirectoryEnumerationOptions directoryEnumerationOptions)
{
return EnumerateFileSystemEntryInfosInternal<string>(null, path, Path.WildcardStarMatchAll, directoryEnumerationOptions, PathFormat.Relative).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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="path">The directory path.</param>
/// <param name="directoryEnumerationOptions"><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 directoryEnumerationOptions, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosInternal<string>(null, path, Path.WildcardStarMatchAll, directoryEnumerationOptions, 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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// <para>The search string to match against the names of directories in path. This parameter can contain a</para>
/// <para>combination of valid literal path and wildcard (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>)</para>
/// <para>characters, but does not support regular expressions.</para>
/// </param>
/// <param name="directoryEnumerationOptions"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjects(string path, string searchPattern, DirectoryEnumerationOptions directoryEnumerationOptions)
{
return EnumerateFileSystemEntryInfosInternal<string>(null, path, searchPattern, directoryEnumerationOptions, PathFormat.Relative).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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// <para>The search string to match against the names of directories in path. This parameter can contain a</para>
/// <para>combination of valid literal path and wildcard (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>)</para>
/// <para>characters, but does not support regular expressions.</para>
/// </param>
/// <param name="directoryEnumerationOptions"><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 directoryEnumerationOptions, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosInternal<string>(null, path, searchPattern, directoryEnumerationOptions, pathFormat).Count();
}

#endregion // Non-Transactional

#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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="directoryEnumerationOptions"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjects(KernelTransaction transaction, string path, DirectoryEnumerationOptions directoryEnumerationOptions)
{
return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, Path.WildcardStarMatchAll, directoryEnumerationOptions, PathFormat.Relative).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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="directoryEnumerationOptions"><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(KernelTransaction transaction, string path, DirectoryEnumerationOptions directoryEnumerationOptions, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, Path.WildcardStarMatchAll, directoryEnumerationOptions, 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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// <para>The search string to match against the names of directories in path. This parameter can contain a</para>
/// <para>combination of valid literal path and wildcard (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>)</para>
/// <para>characters, but does not support regular expressions.</para>
/// </param>
/// <param name="directoryEnumerationOptions"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
[SecurityCritical]
public static long CountFileSystemObjects(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions directoryEnumerationOptions)
{
return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, searchPattern, directoryEnumerationOptions, PathFormat.Relative).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="System.UnauthorizedAccessException">An exception is thrown case of access errors.</exception>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">
/// <para>The search string to match against the names of directories in path. This parameter can contain a</para>
/// <para>combination of valid literal path and wildcard (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>)</para>
/// <para>characters, but does not support regular expressions.</para>
/// </param>
/// <param name="directoryEnumerationOptions"><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(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions directoryEnumerationOptions, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, searchPattern, directoryEnumerationOptions, pathFormat).Count();
}

#endregion // Transactional

#endregion // AlphaFS
}
}
27 changes: 22 additions & 5 deletions AlphaFS/Filesystem/Directory Class/Directory.CreateDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
using Microsoft.Win32.SafeHandles;
/* Copyright (C) 2008-2015 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.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;
using System.Security.Principal;
using SearchOption = System.IO.SearchOption;

namespace Alphaleonis.Win32.Filesystem
{
public static partial class Directory
partial class Directory
{
#region Non-Transactional

Expand Down
Loading

0 comments on commit bbd9353

Please sign in to comment.