Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

8 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.Security;
  23. using System.Security.AccessControl;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. partial class DirectoryInfo
  27. {
  28. #region .NET
  29. /// <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>
  30. /// <param name="path">The specified path. This cannot be a different disk volume.</param>
  31. /// <returns>The last directory specified in <paramref name="path"/>.</returns>
  32. /// <remarks>
  33. /// Any and all directories specified in path are created, unless some part of path is invalid.
  34. /// The path parameter specifies a directory path, not a file path.
  35. /// If the subdirectory already exists, this method does nothing.
  36. /// </remarks>
  37. [SecurityCritical]
  38. public DirectoryInfo CreateSubdirectory(string path)
  39. {
  40. return CreateSubdirectoryCore(path, null, null, false);
  41. }
  42. /// <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>
  43. /// <param name="path">The specified path. This cannot be a different disk volume.</param>
  44. /// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
  45. /// <returns>The last directory specified in <paramref name="path"/>.</returns>
  46. /// <remarks>
  47. /// Any and all directories specified in path are created, unless some part of path is invalid.
  48. /// The path parameter specifies a directory path, not a file path.
  49. /// If the subdirectory already exists, this method does nothing.
  50. /// </remarks>
  51. [SecurityCritical]
  52. public DirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity)
  53. {
  54. return CreateSubdirectoryCore(path, null, directorySecurity, false);
  55. }
  56. #endregion // .NET
  57. #region AlphaFS
  58. /// <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>
  59. /// <returns>The last directory specified in <paramref name="path"/>.</returns>
  60. /// <remarks>
  61. /// Any and all directories specified in path are created, unless some part of path is invalid.
  62. /// The path parameter specifies a directory path, not a file path.
  63. /// If the subdirectory already exists, this method does nothing.
  64. /// </remarks>
  65. /// <param name="path">The specified path. This cannot be a different disk volume.</param>
  66. /// <param name="compress">When <see langword="true"/> compresses the directory.</param>
  67. [SecurityCritical]
  68. public DirectoryInfo CreateSubdirectory(string path, bool compress)
  69. {
  70. return CreateSubdirectoryCore(path, null, null, compress);
  71. }
  72. /// <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>
  73. /// <param name="path">The specified path. This cannot be a different disk volume.</param>
  74. /// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
  75. /// <param name="compress">When <see langword="true"/> compresses the directory.</param>
  76. /// <returns>The last directory specified in <paramref name="path"/>.</returns>
  77. /// <remarks>
  78. /// Any and all directories specified in path are created, unless some part of path is invalid.
  79. /// The path parameter specifies a directory path, not a file path.
  80. /// If the subdirectory already exists, this method does nothing.
  81. /// </remarks>
  82. [SecurityCritical]
  83. public DirectoryInfo CreateSubdirectory(string path, string templatePath, bool compress)
  84. {
  85. return CreateSubdirectoryCore(path, templatePath, null, compress);
  86. }
  87. /// <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>
  88. /// <param name="path">The specified path. This cannot be a different disk volume.</param>
  89. /// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
  90. /// <param name="compress">When <see langword="true"/> compresses the directory.</param>
  91. /// <returns>The last directory specified in <paramref name="path"/>.</returns>
  92. /// <remarks>
  93. /// Any and all directories specified in path are created, unless some part of path is invalid.
  94. /// The path parameter specifies a directory path, not a file path.
  95. /// If the subdirectory already exists, this method does nothing.
  96. /// </remarks>
  97. [SecurityCritical]
  98. public DirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity, bool compress)
  99. {
  100. return CreateSubdirectoryCore(path, null, directorySecurity, compress);
  101. }
  102. /// <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>
  103. /// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
  104. /// <param name="path">The specified path. This cannot be a different disk volume.</param>
  105. /// <param name="compress">When <see langword="true"/> compresses the directory.</param>
  106. /// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
  107. /// <returns>The last directory specified in <paramref name="path"/>.</returns>
  108. /// <remarks>
  109. /// Any and all directories specified in path are created, unless some part of path is invalid.
  110. /// The path parameter specifies a directory path, not a file path.
  111. /// If the subdirectory already exists, this method does nothing.
  112. /// </remarks>
  113. [SecurityCritical]
  114. public DirectoryInfo CreateSubdirectory(string path, string templatePath, DirectorySecurity directorySecurity, bool compress)
  115. {
  116. return CreateSubdirectoryCore(path, templatePath, directorySecurity, compress);
  117. }
  118. #endregion // AlphaFS
  119. #region Internal Methods
  120. /// <summary>Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class.</summary>
  121. /// <returns>The last directory specified in path as an <see cref="DirectoryInfo"/> object.</returns>
  122. /// <remarks>
  123. /// Any and all directories specified in path are created, unless some part of path is invalid.
  124. /// The path parameter specifies a directory path, not a file path.
  125. /// If the subdirectory already exists, this method does nothing.
  126. /// </remarks>
  127. /// <param name="path">The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name.</param>
  128. /// <param name="templatePath">The path of the directory to use as a template when creating the new directory.</param>
  129. /// <param name="directorySecurity">The <see cref="DirectorySecurity"/> security to apply.</param>
  130. /// <param name="compress">When <see langword="true"/> compresses the directory.</param>
  131. [SecurityCritical]
  132. private DirectoryInfo CreateSubdirectoryCore(string path, string templatePath, DirectorySecurity directorySecurity, bool compress)
  133. {
  134. string pathLp = Path.CombineCore(false, LongFullName, path);
  135. string templatePathLp = templatePath == null ? null :
  136. Path.GetExtendedLengthPathCore(Transaction, templatePath, PathFormat.RelativePath, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);
  137. if (string.Compare(LongFullName, 0, pathLp, 0, LongFullName.Length, StringComparison.OrdinalIgnoreCase) != 0)
  138. throw new ArgumentException(Resources.Invalid_Subpath, pathLp);
  139. return Directory.CreateDirectoryCore(Transaction, pathLp, templatePathLp, directorySecurity, compress, PathFormat.LongFullPath);
  140. }
  141. #endregion // Internal Methods
  142. }
  143. }