You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

129 lines
5.6 KiB

  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System;
  22. using System.IO;
  23. using System.Security;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. partial class DirectoryInfo
  27. {
  28. #region AlphaFS
  29. #region Compress
  30. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  31. /// <remarks>This will only compress the root items (non recursive).</remarks>
  32. /// <exception cref="ArgumentException"/>
  33. /// <exception cref="ArgumentNullException"/>
  34. /// <exception cref="DirectoryNotFoundException"/>
  35. /// <exception cref="IOException"/>
  36. /// <exception cref="NotSupportedException"/>
  37. /// <exception cref="UnauthorizedAccessException"/>
  38. [SecurityCritical]
  39. public void Compress()
  40. {
  41. Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, PathFormat.LongFullPath);
  42. }
  43. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  44. /// <exception cref="ArgumentException"/>
  45. /// <exception cref="ArgumentNullException"/>
  46. /// <exception cref="DirectoryNotFoundException"/>
  47. /// <exception cref="IOException"/>
  48. /// <exception cref="NotSupportedException"/>
  49. /// <exception cref="UnauthorizedAccessException"/>
  50. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  51. [SecurityCritical]
  52. public void Compress(DirectoryEnumerationOptions options)
  53. {
  54. Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, options, true, PathFormat.LongFullPath);
  55. }
  56. #endregion // Compress
  57. #region Decompress
  58. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  59. /// <remarks>This will only decompress the root items (non recursive).</remarks>
  60. /// <exception cref="ArgumentException"/>
  61. /// <exception cref="ArgumentNullException"/>
  62. /// <exception cref="DirectoryNotFoundException"/>
  63. /// <exception cref="IOException"/>
  64. /// <exception cref="NotSupportedException"/>
  65. /// <exception cref="UnauthorizedAccessException"/>
  66. [SecurityCritical]
  67. public void Decompress()
  68. {
  69. Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, PathFormat.LongFullPath);
  70. }
  71. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  72. /// <exception cref="ArgumentException"/>
  73. /// <exception cref="ArgumentNullException"/>
  74. /// <exception cref="DirectoryNotFoundException"/>
  75. /// <exception cref="IOException"/>
  76. /// <exception cref="NotSupportedException"/>
  77. /// <exception cref="UnauthorizedAccessException"/>
  78. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  79. [SecurityCritical]
  80. public void Decompress(DirectoryEnumerationOptions options)
  81. {
  82. Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, options, false, PathFormat.LongFullPath);
  83. }
  84. #endregion // Decompress
  85. #region DisableCompression
  86. /// <summary>[AlphaFS] Disables compression of the specified directory and the files in it.</summary>
  87. /// <remarks>
  88. /// This method disables the directory-compression attribute. It will not decompress the current contents of the directory.
  89. /// However, newly created files and directories will be uncompressed.
  90. /// </remarks>
  91. [SecurityCritical]
  92. public void DisableCompression()
  93. {
  94. Device.ToggleCompressionCore(true, Transaction, LongFullName, false, PathFormat.LongFullPath);
  95. }
  96. #endregion // DisableCompression
  97. #region EnableCompression
  98. /// <summary>[AlphaFS] Enables compression of the specified directory and the files in it.</summary>
  99. /// <remarks>
  100. /// This method enables the directory-compression attribute. It will not compress the current contents of the directory.
  101. /// However, newly created files and directories will be compressed.
  102. /// </remarks>
  103. [SecurityCritical]
  104. public void EnableCompression()
  105. {
  106. Device.ToggleCompressionCore(true, Transaction, LongFullName, true, PathFormat.LongFullPath);
  107. }
  108. #endregion // EnableCompression
  109. #endregion // AlphaFS
  110. }
  111. }