Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

485 rindas
26 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 Directory
  27. {
  28. #region Compress
  29. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  30. /// <remarks>This will only compress the root items (non recursive).</remarks>
  31. /// <exception cref="ArgumentException"/>
  32. /// <exception cref="ArgumentNullException"/>
  33. /// <exception cref="DirectoryNotFoundException"/>
  34. /// <exception cref="IOException"/>
  35. /// <exception cref="NotSupportedException"/>
  36. /// <exception cref="UnauthorizedAccessException"/>
  37. /// <param name="path">A path that describes a directory to compress.</param>
  38. [SecurityCritical]
  39. public static void Compress(string path)
  40. {
  41. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, PathFormat.RelativePath);
  42. }
  43. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  44. /// <remarks>This will only compress the root items (non recursive).</remarks>
  45. /// <exception cref="ArgumentException"/>
  46. /// <exception cref="ArgumentNullException"/>
  47. /// <exception cref="DirectoryNotFoundException"/>
  48. /// <exception cref="IOException"/>
  49. /// <exception cref="NotSupportedException"/>
  50. /// <exception cref="UnauthorizedAccessException"/>
  51. /// <param name="path">A path that describes a directory to compress.</param>
  52. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  53. [SecurityCritical]
  54. public static void Compress(string path, PathFormat pathFormat)
  55. {
  56. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, pathFormat);
  57. }
  58. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  59. /// <exception cref="ArgumentException"/>
  60. /// <exception cref="ArgumentNullException"/>
  61. /// <exception cref="DirectoryNotFoundException"/>
  62. /// <exception cref="IOException"/>
  63. /// <exception cref="NotSupportedException"/>
  64. /// <exception cref="UnauthorizedAccessException"/>
  65. /// <param name="path">A path that describes a directory to compress.</param>
  66. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  67. [SecurityCritical]
  68. public static void Compress(string path, DirectoryEnumerationOptions options)
  69. {
  70. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, true, PathFormat.RelativePath);
  71. }
  72. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  73. /// <exception cref="ArgumentException"/>
  74. /// <exception cref="ArgumentNullException"/>
  75. /// <exception cref="DirectoryNotFoundException"/>
  76. /// <exception cref="IOException"/>
  77. /// <exception cref="NotSupportedException"/>
  78. /// <exception cref="UnauthorizedAccessException"/>
  79. /// <param name="path">A path that describes a directory to compress.</param>
  80. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  81. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  82. [SecurityCritical]
  83. public static void Compress(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  84. {
  85. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, true, pathFormat);
  86. }
  87. #region Transactional
  88. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  89. /// <remarks>This will only compress the root items (non recursive).</remarks>
  90. /// <exception cref="ArgumentException"/>
  91. /// <exception cref="ArgumentNullException"/>
  92. /// <exception cref="DirectoryNotFoundException"/>
  93. /// <exception cref="IOException"/>
  94. /// <exception cref="NotSupportedException"/>
  95. /// <exception cref="UnauthorizedAccessException"/>
  96. /// <param name="transaction">The transaction.</param>
  97. /// <param name="path">A path that describes a directory to compress.</param>
  98. [SecurityCritical]
  99. public static void CompressTransacted(KernelTransaction transaction, string path)
  100. {
  101. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, PathFormat.RelativePath);
  102. }
  103. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  104. /// <remarks>This will only compress the root items (non recursive).</remarks>
  105. /// <exception cref="ArgumentException"/>
  106. /// <exception cref="ArgumentNullException"/>
  107. /// <exception cref="DirectoryNotFoundException"/>
  108. /// <exception cref="IOException"/>
  109. /// <exception cref="NotSupportedException"/>
  110. /// <exception cref="UnauthorizedAccessException"/>
  111. /// <param name="transaction">The transaction.</param>
  112. /// <param name="path">A path that describes a directory to compress.</param>
  113. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  114. [SecurityCritical]
  115. public static void CompressTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  116. {
  117. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, true, pathFormat);
  118. }
  119. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  120. /// <exception cref="ArgumentException"/>
  121. /// <exception cref="ArgumentNullException"/>
  122. /// <exception cref="DirectoryNotFoundException"/>
  123. /// <exception cref="IOException"/>
  124. /// <exception cref="NotSupportedException"/>
  125. /// <exception cref="UnauthorizedAccessException"/>
  126. /// <param name="transaction">The transaction.</param>
  127. /// <param name="path">A path that describes a directory to compress.</param>
  128. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  129. [SecurityCritical]
  130. public static void CompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
  131. {
  132. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, true, PathFormat.RelativePath);
  133. }
  134. /// <summary>[AlphaFS] Compresses a directory using NTFS compression.</summary>
  135. /// <exception cref="ArgumentException"/>
  136. /// <exception cref="ArgumentNullException"/>
  137. /// <exception cref="DirectoryNotFoundException"/>
  138. /// <exception cref="IOException"/>
  139. /// <exception cref="NotSupportedException"/>
  140. /// <exception cref="UnauthorizedAccessException"/>
  141. /// <param name="transaction">The transaction.</param>
  142. /// <param name="path">A path that describes a directory to compress.</param>
  143. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  144. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  145. [SecurityCritical]
  146. public static void CompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  147. {
  148. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, true, pathFormat);
  149. }
  150. #endregion // Transactional
  151. #endregion // Compress
  152. #region Decompress
  153. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  154. /// <remarks>This will only decompress the root items (non recursive).</remarks>
  155. /// <exception cref="ArgumentException"/>
  156. /// <exception cref="ArgumentNullException"/>
  157. /// <exception cref="DirectoryNotFoundException"/>
  158. /// <exception cref="IOException"/>
  159. /// <exception cref="NotSupportedException"/>
  160. /// <exception cref="UnauthorizedAccessException"/>
  161. /// <param name="path">A path that describes a directory to decompress.</param>
  162. [SecurityCritical]
  163. public static void Decompress(string path)
  164. {
  165. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, PathFormat.RelativePath);
  166. }
  167. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  168. /// <remarks>This will only decompress the root items (non recursive).</remarks>
  169. /// <exception cref="ArgumentException"/>
  170. /// <exception cref="ArgumentNullException"/>
  171. /// <exception cref="DirectoryNotFoundException"/>
  172. /// <exception cref="IOException"/>
  173. /// <exception cref="NotSupportedException"/>
  174. /// <exception cref="UnauthorizedAccessException"/>
  175. /// <param name="path">A path that describes a directory to decompress.</param>
  176. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  177. [SecurityCritical]
  178. public static void Decompress(string path, PathFormat pathFormat)
  179. {
  180. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, pathFormat);
  181. }
  182. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  183. /// <exception cref="ArgumentException"/>
  184. /// <exception cref="ArgumentNullException"/>
  185. /// <exception cref="DirectoryNotFoundException"/>
  186. /// <exception cref="IOException"/>
  187. /// <exception cref="NotSupportedException"/>
  188. /// <exception cref="UnauthorizedAccessException"/>
  189. /// <param name="path">A path that describes a directory to decompress.</param>
  190. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  191. [SecurityCritical]
  192. public static void Decompress(string path, DirectoryEnumerationOptions options)
  193. {
  194. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, false, PathFormat.RelativePath);
  195. }
  196. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  197. /// <exception cref="ArgumentException"/>
  198. /// <exception cref="ArgumentNullException"/>
  199. /// <exception cref="DirectoryNotFoundException"/>
  200. /// <exception cref="IOException"/>
  201. /// <exception cref="NotSupportedException"/>
  202. /// <exception cref="UnauthorizedAccessException"/>
  203. /// <param name="path">A path that describes a directory to decompress.</param>
  204. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  205. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  206. [SecurityCritical]
  207. public static void Decompress(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  208. {
  209. CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, false, pathFormat);
  210. }
  211. #region Transactional
  212. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  213. /// <remarks>This will only decompress the root items (non recursive).</remarks>
  214. /// <exception cref="ArgumentException"/>
  215. /// <exception cref="ArgumentNullException"/>
  216. /// <exception cref="DirectoryNotFoundException"/>
  217. /// <exception cref="IOException"/>
  218. /// <exception cref="NotSupportedException"/>
  219. /// <exception cref="UnauthorizedAccessException"/>
  220. /// <param name="transaction">The transaction.</param>
  221. /// <param name="path">A path that describes a directory to decompress.</param>
  222. [SecurityCritical]
  223. public static void DecompressTransacted(KernelTransaction transaction, string path)
  224. {
  225. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, PathFormat.RelativePath);
  226. }
  227. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  228. /// <remarks>This will only decompress the root items (non recursive).</remarks>
  229. /// <exception cref="ArgumentException"/>
  230. /// <exception cref="ArgumentNullException"/>
  231. /// <exception cref="DirectoryNotFoundException"/>
  232. /// <exception cref="IOException"/>
  233. /// <exception cref="NotSupportedException"/>
  234. /// <exception cref="UnauthorizedAccessException"/>
  235. /// <param name="transaction">The transaction.</param>
  236. /// <param name="path">A path that describes a directory to decompress.</param>
  237. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  238. [SecurityCritical]
  239. public static void DecompressTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  240. {
  241. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, DirectoryEnumerationOptions.FilesAndFolders, false, pathFormat);
  242. }
  243. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  244. /// <exception cref="ArgumentException"/>
  245. /// <exception cref="ArgumentNullException"/>
  246. /// <exception cref="DirectoryNotFoundException"/>
  247. /// <exception cref="IOException"/>
  248. /// <exception cref="NotSupportedException"/>
  249. /// <exception cref="UnauthorizedAccessException"/>
  250. /// <param name="transaction">The transaction.</param>
  251. /// <param name="path">A path that describes a directory to decompress.</param>
  252. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  253. [SecurityCritical]
  254. public static void DecompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
  255. {
  256. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, false, PathFormat.RelativePath);
  257. }
  258. /// <summary>[AlphaFS] Decompresses an NTFS compressed directory.</summary>
  259. /// <exception cref="ArgumentException"/>
  260. /// <exception cref="ArgumentNullException"/>
  261. /// <exception cref="DirectoryNotFoundException"/>
  262. /// <exception cref="IOException"/>
  263. /// <exception cref="NotSupportedException"/>
  264. /// <exception cref="UnauthorizedAccessException"/>
  265. /// <param name="transaction">The transaction.</param>
  266. /// <param name="path">A path that describes a directory to decompress.</param>
  267. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  268. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  269. [SecurityCritical]
  270. public static void DecompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
  271. {
  272. CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, false, pathFormat);
  273. }
  274. #endregion // Transactional
  275. #endregion // Decompress
  276. #region DisableCompression
  277. /// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
  278. /// <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>
  279. /// <exception cref="ArgumentException"/>
  280. /// <exception cref="ArgumentNullException"/>
  281. /// <exception cref="DirectoryNotFoundException"/>
  282. /// <exception cref="IOException"/>
  283. /// <exception cref="NotSupportedException"/>
  284. /// <exception cref="UnauthorizedAccessException"/>
  285. /// <param name="path">A path to a directory to decompress.</param>
  286. [SecurityCritical]
  287. public static void DisableCompression(string path)
  288. {
  289. Device.ToggleCompressionCore(true, null, path, false, PathFormat.RelativePath);
  290. }
  291. /// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
  292. /// <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>
  293. /// <exception cref="ArgumentException"/>
  294. /// <exception cref="ArgumentNullException"/>
  295. /// <exception cref="DirectoryNotFoundException"/>
  296. /// <exception cref="IOException"/>
  297. /// <exception cref="NotSupportedException"/>
  298. /// <exception cref="UnauthorizedAccessException"/>
  299. /// <param name="path">A path to a directory to decompress.</param>
  300. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  301. [SecurityCritical]
  302. public static void DisableCompression(string path, PathFormat pathFormat)
  303. {
  304. Device.ToggleCompressionCore(true, null, path, false, pathFormat);
  305. }
  306. /// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
  307. /// <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>
  308. /// <exception cref="ArgumentException"/>
  309. /// <exception cref="ArgumentNullException"/>
  310. /// <exception cref="DirectoryNotFoundException"/>
  311. /// <exception cref="IOException"/>
  312. /// <exception cref="NotSupportedException"/>
  313. /// <exception cref="UnauthorizedAccessException"/>
  314. /// <param name="transaction">The transaction.</param>
  315. /// <param name="path">A path to a directory to decompress.</param>
  316. [SecurityCritical]
  317. public static void DisableCompressionTransacted(KernelTransaction transaction, string path)
  318. {
  319. Device.ToggleCompressionCore(true, transaction, path, false, PathFormat.RelativePath);
  320. }
  321. /// <summary>[AlphaFS] Disables NTFS compression of the specified directory and the files in it.</summary>
  322. /// <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>
  323. /// <exception cref="ArgumentException"/>
  324. /// <exception cref="ArgumentNullException"/>
  325. /// <exception cref="DirectoryNotFoundException"/>
  326. /// <exception cref="IOException"/>
  327. /// <exception cref="NotSupportedException"/>
  328. /// <exception cref="UnauthorizedAccessException"/>
  329. /// <param name="transaction">The transaction.</param>
  330. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  331. /// <param name="path">A path to a directory to decompress.</param>
  332. [SecurityCritical]
  333. public static void DisableCompressionTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  334. {
  335. Device.ToggleCompressionCore(true, transaction, path, false, pathFormat);
  336. }
  337. #endregion // DisableCompression
  338. #region EnableCompression
  339. /// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
  340. /// <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>
  341. /// <exception cref="ArgumentException"/>
  342. /// <exception cref="ArgumentNullException"/>
  343. /// <exception cref="DirectoryNotFoundException"/>
  344. /// <exception cref="IOException"/>
  345. /// <exception cref="NotSupportedException"/>
  346. /// <exception cref="UnauthorizedAccessException"/>
  347. /// <param name="path">A path to a directory to compress.</param>
  348. [SecurityCritical]
  349. public static void EnableCompression(string path)
  350. {
  351. Device.ToggleCompressionCore(true, null, path, true, PathFormat.RelativePath);
  352. }
  353. /// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
  354. /// <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>
  355. /// <exception cref="ArgumentException"/>
  356. /// <exception cref="ArgumentNullException"/>
  357. /// <exception cref="DirectoryNotFoundException"/>
  358. /// <exception cref="IOException"/>
  359. /// <exception cref="NotSupportedException"/>
  360. /// <exception cref="UnauthorizedAccessException"/>
  361. /// <param name="path">A path to a directory to compress.</param>
  362. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  363. [SecurityCritical]
  364. public static void EnableCompression(string path, PathFormat pathFormat)
  365. {
  366. Device.ToggleCompressionCore(true, null, path, true, pathFormat);
  367. }
  368. /// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
  369. /// <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>
  370. /// <exception cref="ArgumentException"/>
  371. /// <exception cref="ArgumentNullException"/>
  372. /// <exception cref="DirectoryNotFoundException"/>
  373. /// <exception cref="IOException"/>
  374. /// <exception cref="NotSupportedException"/>
  375. /// <exception cref="UnauthorizedAccessException"/>
  376. /// <param name="transaction">The transaction.</param>
  377. /// <param name="path">A path to a directory to compress.</param>
  378. [SecurityCritical]
  379. public static void EnableCompressionTransacted(KernelTransaction transaction, string path)
  380. {
  381. Device.ToggleCompressionCore(true, transaction, path, true, PathFormat.RelativePath);
  382. }
  383. /// <summary>[AlphaFS] Enables NTFS compression of the specified directory and the files in it.</summary>
  384. /// <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>
  385. /// <exception cref="ArgumentException"/>
  386. /// <exception cref="ArgumentNullException"/>
  387. /// <exception cref="DirectoryNotFoundException"/>
  388. /// <exception cref="IOException"/>
  389. /// <exception cref="NotSupportedException"/>
  390. /// <exception cref="UnauthorizedAccessException"/>
  391. /// <param name="transaction">The transaction.</param>
  392. /// <param name="path">A path to a directory to compress.</param>
  393. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  394. [SecurityCritical]
  395. public static void EnableCompressionTransacted(KernelTransaction transaction, string path, PathFormat pathFormat)
  396. {
  397. Device.ToggleCompressionCore(true, transaction, path, true, pathFormat);
  398. }
  399. #endregion // EnableCompression
  400. #region Internal Methods
  401. /// <summary>Compress/decompress Non-/Transacted files/directories.</summary>
  402. /// <exception cref="ArgumentException"/>
  403. /// <exception cref="ArgumentNullException"/>
  404. /// <exception cref="DirectoryNotFoundException"/>
  405. /// <exception cref="IOException"/>
  406. /// <exception cref="NotSupportedException"/>
  407. /// <exception cref="UnauthorizedAccessException"/>
  408. /// <param name="transaction">The transaction.</param>
  409. /// <param name="path">A path that describes a directory to compress.</param>
  410. /// <param name="searchPattern">
  411. /// The search string to match against the names of directories in <paramref name="path"/>.
  412. /// This parameter can contain a combination of valid literal path and wildcard
  413. /// (<see cref="Path.WildcardStarMatchAll"/> and <see cref="Path.WildcardQuestion"/>) characters, but does not support regular expressions.
  414. /// </param>
  415. /// <param name="options"><see cref="DirectoryEnumerationOptions"/> flags that specify how the directory is to be enumerated.</param>
  416. /// <param name="compress"><see langword="true"/> compress, when <see langword="false"/> decompress.</param>
  417. /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
  418. [SecurityCritical]
  419. internal static void CompressDecompressCore(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, bool compress, PathFormat pathFormat)
  420. {
  421. string pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
  422. // Process directories and files.
  423. foreach (var fsei in EnumerateFileSystemEntryInfosCore<string>(transaction, pathLp, searchPattern, options | DirectoryEnumerationOptions.AsLongPath, PathFormat.LongFullPath))
  424. Device.ToggleCompressionCore(true, transaction, fsei, compress, PathFormat.LongFullPath);
  425. // Compress the root directory, the given path.
  426. Device.ToggleCompressionCore(true, transaction, pathLp, compress, PathFormat.LongFullPath);
  427. }
  428. #endregion // Internal Methods
  429. }
  430. }